Skip to content

Commit

Permalink
Conditionally enable metadata retrieval button in the toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
tnajdek committed Jan 13, 2025
1 parent 5bb0260 commit 9502ba3
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/js/component/item/actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,15 @@ const ItemActionsDesktop = memo(props => {
const selectedItemsCount = useSelector(state => state.current.itemKeys.length);
const isReadOnly = useSelector(state => (state.config.libraries.find(l => l.key === state.current.libraryKey) || {}).isReadOnly);
const isTrash = useSelector(state => state.current.isTrash);
const selectedContainsCollection = useSelector(state => state.current.itemKeys.some(key => state.libraries[state.current.libraryKey]?.dataObjects?.[key]?.[Symbol.for('type')] === 'collection'));
const selectedContainsCollection = useSelector(
state => state.current.itemKeys.some(
key => state.libraries[state.current.libraryKey]?.dataObjects?.[key]?.[Symbol.for('type')] === 'collection'
));
const selectedItemsCanBeRecognized = useSelector(state => state.current.itemKeys.every(
key => state.libraries[state.current.libraryKey]?.dataObjects?.[key]?.itemType === 'attachment'
&& state.libraries[state.current.libraryKey]?.dataObjects?.[key]?.contentType === 'application/pdf'
));

const collectionKey = useSelector(state => state.current.collectionKey);

const { handleCiteModalOpen, handleNewItemCreate, handleNewStandaloneNote, handleAddToCollectionModalOpen,
Expand Down Expand Up @@ -189,16 +197,16 @@ const ItemActionsDesktop = memo(props => {
<ToolGroup>
{!isTrash && (
<Fragment>
<Button
disabled={selectedItemsCount === 0}
icon
onClick={handleRetrieveMetadata}
onKeyDown={handleKeyDown}
tabIndex={-2}
title="Retrieve Metadata"
>
<Icon type="20/input-dual" width="20" height="20" />
</Button>
<Button
disabled={selectedItemsCount === 0 || !selectedItemsCanBeRecognized}
icon
onClick={handleRetrieveMetadata}
onKeyDown={handleKeyDown}
tabIndex={-2}
title="Retrieve Metadata"
>
<Icon type="20/input-dual" width="20" height="20" />
</Button>
<Button
disabled={selectedItemsCount === 0}
icon
Expand Down

0 comments on commit 9502ba3

Please sign in to comment.