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

[TASK] Render asset usage counter inside inspector action buttons #221

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
width: 100%;
margin-top: var(--theme-spacing-Full);
line-height: 1.5;
border-collapse: separate;
border-spacing: 0;
}

.usageTable th {
Expand All @@ -18,17 +20,13 @@

.usageTable td,
.usageTable th {
padding: var(--theme-spacing-Quarter);
padding: 0 var(--theme-spacing-Half);
height: var(--theme-unit);
}

.usageTable td:first-child,
.usageTable th:first-child {
padding-left: 0;
}

.usageTable td:last-child,
.usageTable th:last-child {
padding-right: 0;
.usageTable td {
border-top: 1px solid var(--theme-colors-ContrastDarker);
background-color: var(--theme-colors-ContrastNeutral);
}

/* This is for specificity; otherwise `.neos.neos-module a` would override this link style in the backend module */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.assetUsageBadge {
color: var(--theme-blue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the blue on white for the badge fits well with the rest of the module.
I would rather use white on one of our grey colors.

}
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
import React from 'react';
import { useRecoilState } from 'recoil';

import { Button, Icon } from '@neos-project/react-ui-components';
import { Badge, Button, Icon } from '@neos-project/react-ui-components';

import { useIntl } from '@media-ui/core';
import { useSelectedAsset } from '@media-ui/core/src/hooks';

import assetUsageDetailsModalState from '../state/assetUsageDetailsModalState';
import useAssetUsagesQuery from '@media-ui/feature-asset-usage/src/hooks/useAssetUsages';

import classes from './AssetUsagesToggleButton.module.css';

const AssetUsagesToggleButton: React.FC = () => {
const { isInUse } = useSelectedAsset();
const asset = useSelectedAsset();
const { assetUsageDetails, loading } = useAssetUsagesQuery(

Check warning on line 16 in Resources/Private/JavaScript/asset-usage/src/components/AssetUsagesToggleButton.tsx

View workflow job for this annotation

GitHub Actions / lint

'loading' is assigned a value but never used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I intentionally didn't do this due to performance reasons with the default usage strategy implementation. You could do it though if you check for the feature flag queryAssetUsage first before you query the usageDetails.
For that you could put the Badge also into a small component and only load it if the feature flag is active.

asset ? { assetId: asset.id, assetSourceId: asset.assetSource.id } : null
);
const [assetUsagesModalOpen, setAssetUsagesModalOpen] = useRecoilState(assetUsageDetailsModalState);
const { translate } = useIntl();

return (
<Button
disabled={isInUse === false}
disabled={asset.isInUse === false}
size="regular"
style={assetUsagesModalOpen ? 'brand' : 'lighter'}
hoverStyle="brand"
onClick={() => setAssetUsagesModalOpen(true)}
>
<Icon icon="link" />
{translate('assetUsageList.toggle', 'Show usages')}
{assetUsageDetails?.[0]?.usages ? (
<Badge label={assetUsageDetails[0].usages.length} className={classes.assetUsageBadge} />
) : (
<></>
)}
</Button>
);
};
Expand Down
Loading