Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added object browser icon view #5279

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cypress/tests/core/basic/objectBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ describe('Object Browser Tests', () => {
// The document is not in the list
cy.findByLabelText('Browse My Searchable Page').should('not.exist');
// And the list has only 1 item
cy.get('.ui.segment.object-listing li').should('have.length', 1);
cy.get('.ui.segment.object-listing .image-wrapper').should(
'have.length',
1,
);

// The image can be selected as usual
cy.findByLabelText('Select My Searchable Image').dblclick();
Expand Down
1 change: 1 addition & 0 deletions locales/ca/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3049,6 +3049,7 @@ msgid "Search input label"
msgstr "Cerca l'etiqueta d'entrada"

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/de/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3046,6 +3046,7 @@ msgid "Search input label"
msgstr "Label Suchfeld"

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/en/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3040,6 +3040,7 @@ msgid "Search input label"
msgstr ""

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/es/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3051,6 +3051,7 @@ msgid "Search input label"
msgstr "Etiqueta del campo de búsqueda"

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/eu/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3047,6 +3047,7 @@ msgid "Search input label"
msgstr "Bilaketa kutxaren etiketa"

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/fi/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3051,6 +3051,7 @@ msgid "Search input label"
msgstr "Hakukentän nimike"

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/fr/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3057,6 +3057,7 @@ msgid "Search input label"
msgstr "Label du champ de recherche"

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/it/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3040,6 +3040,7 @@ msgid "Search input label"
msgstr "Etichetta del campo di ricerca"

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/ja/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3048,6 +3048,7 @@ msgid "Search input label"
msgstr ""

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/nl/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3059,6 +3059,7 @@ msgid "Search input label"
msgstr ""

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/pt/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3048,6 +3048,7 @@ msgid "Search input label"
msgstr ""

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/pt_BR/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3050,6 +3050,7 @@ msgid "Search input label"
msgstr "Rótulo da caixa de busca"

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/ro/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3040,6 +3040,7 @@ msgid "Search input label"
msgstr "Căutați eticheta de intrare"

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
3 changes: 2 additions & 1 deletion locales/volto.pot
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
msgid ""
msgstr ""
"Project-Id-Version: Plone\n"
"POT-Creation-Date: 2023-10-02T11:59:20.013Z\n"
"POT-Creation-Date: 2023-10-06T11:50:27.347Z\n"
"Last-Translator: Plone i18n <[email protected]>\n"
"Language-Team: Plone i18n <[email protected]>\n"
"MIME-Version: 1.0\n"
Expand Down Expand Up @@ -3042,6 +3042,7 @@ msgid "Search input label"
msgstr ""

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions locales/zh_CN/LC_MESSAGES/volto.po
Original file line number Diff line number Diff line change
Expand Up @@ -3046,6 +3046,7 @@ msgid "Search input label"
msgstr "搜索输入标签"

#: components/manage/Blocks/Search/components/SearchDetails
#: components/manage/Sidebar/ObjectBrowserBody
#: components/theme/Search/Search
# defaultMessage: Search results
msgid "Search results"
Expand Down
1 change: 1 addition & 0 deletions news/5279.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added object browser icon view @robgietema
180 changes: 115 additions & 65 deletions src/components/manage/Sidebar/ObjectBrowserBody.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import clearSVG from '@plone/volto/icons/clear.svg';
import searchSVG from '@plone/volto/icons/zoom.svg';
import linkSVG from '@plone/volto/icons/link.svg';
import homeSVG from '@plone/volto/icons/home.svg';
import iconsSVG from '@plone/volto/icons/apps.svg';
import listSVG from '@plone/volto/icons/list-bullet.svg';

import ObjectBrowserNav from '@plone/volto/components/manage/Sidebar/ObjectBrowserNav';

Expand Down Expand Up @@ -132,6 +134,7 @@ class ObjectBrowserBody extends Component {
this.props.mode === 'image'
? this.props.searchableTypes || config.settings.imageObjects
: this.props.searchableTypes,
view: this.props.mode === 'image' ? 'icons' : 'list',
};
this.searchInputRef = React.createRef();
}
Expand Down Expand Up @@ -201,10 +204,28 @@ class ObjectBrowserBody extends Component {
showSearchInput: !prevState.showSearchInput,
}),
() => {
if (this.searchInputRef?.current) this.searchInputRef.current.focus();
if (this.searchInputRef?.current) {
this.searchInputRef.current.focus();
} else {
this.props.searchContent(
this.state.currentFolder,
{
'path.depth': 1,
sort_on: 'getObjPositionInParent',
metadata_fields: '_all',
b_size: 1000,
},
`${this.props.block}-${this.props.mode}`,
);
}
},
);

toggleView = () =>
this.setState((prevState) => ({
view: prevState.view === 'icons' ? 'list' : 'icons',
}));

onSearch = (e) => {
const text = flattenToAppURL(e.target.value);
if (text.startsWith('/')) {
Expand Down Expand Up @@ -365,25 +386,9 @@ class ObjectBrowserBody extends Component {
*/
render() {
return (
<Segment.Group raised>
<Segment.Group raised className="object-browser">
<header className="header pulled">
<div className="vertical divider" />
{this.state.currentFolder === '/' ? (
<>
{this.props.mode === 'image' ? (
<Icon name={folderSVG} size="24px" />
) : (
<Icon name={linkSVG} size="24px" />
)}
</>
) : (
<button
aria-label={this.props.intl.formatMessage(messages.back)}
onClick={() => this.navigateTo(this.state.parentFolder)}
>
<Icon name={backSVG} size="24px" />
</button>
)}
{this.state.showSearchInput ? (
<Input
className="search"
Expand All @@ -393,20 +398,40 @@ class ObjectBrowserBody extends Component {
messages.SearchInputPlaceholder,
)}
/>
) : this.props.mode === 'image' ? (
<h2>
<FormattedMessage
id="Choose Image"
defaultMessage="Choose Image"
/>
</h2>
) : (
<h2>
<FormattedMessage
id="Choose Target"
defaultMessage="Choose Target"
/>
</h2>
<>
{this.state.currentFolder === '/' ? (
<>
{this.props.mode === 'image' ? (
<Icon name={folderSVG} size="24px" />
) : (
<Icon name={linkSVG} size="24px" />
)}
</>
) : (
<button
aria-label={this.props.intl.formatMessage(messages.back)}
onClick={() => this.navigateTo(this.state.parentFolder)}
>
<Icon name={backSVG} size="24px" />
</button>
)}
{this.props.mode === 'image' ? (
<h2>
<FormattedMessage
id="Choose Image"
defaultMessage="Choose Image"
/>
</h2>
) : (
<h2>
<FormattedMessage
id="Choose Target"
defaultMessage="Choose Target"
/>
</h2>
)}
</>
)}

<button
Expand All @@ -420,40 +445,63 @@ class ObjectBrowserBody extends Component {
</button>
</header>
<Segment secondary className="breadcrumbs" vertical>
<Breadcrumb>
{this.state.currentFolder !== '/' ? (
this.state.currentFolder.split('/').map((item, index, items) => {
return (
<React.Fragment key={`divider-${item}-${index}`}>
{index === 0 ? (
<Breadcrumb.Section onClick={() => this.navigateTo('/')}>
<Icon
className="home-icon"
name={homeSVG}
size="18px"
/>
</Breadcrumb.Section>
) : (
<>
<Breadcrumb.Divider key={`divider-${item.url}`} />
<Breadcrumb.Section
onClick={() =>
this.navigateTo(items.slice(0, index + 1).join('/'))
}
>
{item}
</Breadcrumb.Section>
</>
)}
</React.Fragment>
);
})
) : (
<Breadcrumb.Section onClick={() => this.navigateTo('/')}>
<Icon className="home-icon" name={homeSVG} size="18px" />
</Breadcrumb.Section>
)}
</Breadcrumb>
{this.props.mode === 'image' && (
<Icon
name={this.state.view === 'list' ? iconsSVG : listSVG}
size="24px"
className="mode-switch"
onClick={this.toggleView}
/>
)}
{!this.state.showSearchInput ? (
<Breadcrumb>
{this.state.currentFolder !== '/' ? (
this.state.currentFolder
.split('/')
.map((item, index, items) => {
return (
<React.Fragment key={`divider-${item}-${index}`}>
{index === 0 ? (
<Breadcrumb.Section
onClick={() => this.navigateTo('/')}
>
<Icon
className="home-icon"
name={homeSVG}
size="18px"
/>
</Breadcrumb.Section>
) : (
<>
<Breadcrumb.Divider key={`divider-${item.url}`} />
<Breadcrumb.Section
onClick={() =>
this.navigateTo(
items.slice(0, index + 1).join('/'),
)
}
>
{item}
</Breadcrumb.Section>
</>
)}
</React.Fragment>
);
})
) : (
<Breadcrumb.Section onClick={() => this.navigateTo('/')}>
<Icon className="home-icon" name={homeSVG} size="18px" />
</Breadcrumb.Section>
)}
</Breadcrumb>
) : (
<div className="searchResults">
<FormattedMessage
id="Search results"
defaultMessage="Search results"
/>
</div>
)}
</Segment>
{this.props.mode === 'multiple' && (
<Segment className="infos">
Expand Down Expand Up @@ -489,6 +537,7 @@ class ObjectBrowserBody extends Component {
handleClickOnItem={this.handleClickOnItem}
handleDoubleClickOnItem={this.handleDoubleClickOnItem}
mode={this.props.mode}
view={this.state.view}
navigateTo={this.navigateTo}
isSelectable={this.isSelectable}
/>
Expand All @@ -502,6 +551,7 @@ export default compose(
connect(
(state) => ({
searchSubrequests: state.search.subrequests,
lang: state.intl.locale,
}),
{ searchContent },
),
Expand Down
Loading
Loading