Skip to content

Commit

Permalink
FEATURE: Don’t allow last collection of an asset in „folder mode“
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebobo committed Nov 1, 2024
1 parent 353e091 commit 25595cd
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Classes/GraphQL/Resolver/Type/QueryResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Flowpack\Media\Ui\GraphQL\Context\AssetSourceContext;
use Flowpack\Media\Ui\Infrastructure\Neos\Media\AssetProxyIteratorBuilder;
use Flowpack\Media\Ui\Service\AssetChangeLog;
use Flowpack\Media\Ui\Service\AssetCollectionService;
use Flowpack\Media\Ui\Service\SimilarityService;
use Flowpack\Media\Ui\Service\UsageDetailsService;
use Neos\Flow\Annotations as Flow;
Expand Down Expand Up @@ -114,6 +115,12 @@ class QueryResolver implements ResolverInterface
*/
protected $privilegeManager;

/**
* @Flow\Inject
* @var AssetCollectionService
*/
protected $assetCollectionService;

/**
* Returns total count of asset proxies in the given asset source
* @noinspection PhpUnusedParameterInspection
Expand Down Expand Up @@ -185,10 +192,13 @@ public function assetUsageCount($_, array $variables, AssetSourceContext $assetS
*/
public function config($_): array
{
$defaultAssetCollection = $this->assetCollectionService->getDefaultCollectionForCurrentSite();

return [
'uploadMaxFileSize' => $this->getMaximumFileUploadSize(),
'uploadMaxFileUploadLimit' => $this->getMaximumFileUploadLimit(),
'currentServerTime' => (new \DateTime())->format(DATE_W3C),
'defaultAssetCollectionId' => $defaultAssetCollection ? $this->persistenceManager->getIdentifierByObject($defaultAssetCollection) : null,
'canManageTags' => $this->privilegeManager->isPrivilegeTargetGranted('Flowpack.Media.Ui:ManageTags'),
'canManageAssetCollections' => $this->privilegeManager->isPrivilegeTargetGranted('Flowpack.Media.Ui:ManageAssetCollections'),
'canManageAssets' => $this->privilegeManager->isPrivilegeTargetGranted('Flowpack.Media.Ui:ManageAssets'),
Expand Down
1 change: 1 addition & 0 deletions Resources/Private/GraphQL/schema.root.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ type Config {
uploadMaxFileSize: FileSize!
uploadMaxFileUploadLimit: Int!
currentServerTime: DateTime!
defaultAssetCollectionId: AssetCollectionId
canManageAssetCollections: Boolean!
canManageTags: Boolean!
canManageAssets: Boolean!
Expand Down
2 changes: 2 additions & 0 deletions Resources/Private/JavaScript/core/src/hooks/useConfigQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface ConfigQueryResult {
uploadMaxFileSize: number;
uploadMaxFileUploadLimit: number;
currentServerTime: Date;
defaultAssetCollectionId: AssetCollectionId | null;
canManageAssetCollections: boolean;
canManageTags: boolean;
canManageAssets: boolean;
Expand All @@ -18,6 +19,7 @@ const DEFAULT_CONFIG: ConfigQueryResult = {
uploadMaxFileSize: 0,
uploadMaxFileUploadLimit: 0,
currentServerTime: new Date(),
defaultAssetCollectionId: null,
canManageAssetCollections: false,
canManageTags: false,
canManageAssets: false,
Expand Down
1 change: 1 addition & 0 deletions Resources/Private/JavaScript/core/src/queries/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const CONFIG = gql`
uploadMaxFileSize
uploadMaxFileUploadLimit
currentServerTime
defaultAssetCollectionId
canManageAssetCollections
canManageTags
canManageAssets
Expand Down
1 change: 1 addition & 0 deletions Resources/Private/JavaScript/dev-server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
uploadMaxFileSize: 1024 * 1024,
uploadMaxFileUploadLimit: 2,
currentServerTime: new Date(),
defaultAssetCollectionId: null,
canManageAssetCollections: true,
canManageTags: true,
canManageAssets: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useRecoilValue } from 'recoil';
import { Headline, MultiSelectBox, SelectBox } from '@neos-project/react-ui-components';

import { useIntl, useNotify, useMediaUi } from '@media-ui/core';
import { useSelectedAsset, useSetAssetCollections } from '@media-ui/core/src/hooks';
import { useConfigQuery, useSelectedAsset, useSetAssetCollections } from '@media-ui/core/src/hooks';
import { IconLabel } from '@media-ui/core/src/components';
import { featureFlagsState } from '@media-ui/core/src/state';
import { collectionPath, useAssetCollectionsQuery } from '@media-ui/feature-asset-collections';
Expand All @@ -19,6 +19,7 @@ const collectionsMatchAsset = (assetCollectionIds: string[], asset: Asset) => {
const CollectionSelectBox: React.FC = () => {
const Notify = useNotify();
const { translate } = useIntl();
const { config } = useConfigQuery();
const {
approvalAttainmentStrategy: { obtainApprovalToSetAssetCollections },
} = useMediaUi();
Expand Down Expand Up @@ -136,7 +137,7 @@ const CollectionSelectBox: React.FC = () => {
onSearchTermChange={handleSearchTermChange}
ListPreviewElement={AssetCollectionOptionPreviewElement}
displaySearchBox
allowEmpty
allowEmpty={false}
threshold={0}
/>
</>
Expand All @@ -158,7 +159,7 @@ const CollectionSelectBox: React.FC = () => {
onSearchTermChange={handleSearchTermChange}
ListPreviewElement={AssetCollectionOptionPreviewElement}
displaySearchBox
allowEmpty
allowEmpty={!config.defaultAssetCollectionId}
threshold={0}
/>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Headline, SelectBox } from '@neos-project/react-ui-components';

import { useIntl, useMediaUi, useNotify } from '@media-ui/core';
import { IconLabel } from '@media-ui/core/src/components';
import { useConfigQuery } from '@media-ui/core/src/hooks';
import {
collectionPath,
useAssetCollectionsQuery,
Expand All @@ -18,7 +17,6 @@ import * as classes from './ParentCollectionSelectBox.module.css';

const ParentCollectionSelectBox = () => {
const Notify = useNotify();
const { config } = useConfigQuery();
const { translate } = useIntl();
const { approvalAttainmentStrategy } = useMediaUi();
const { assetCollections } = useAssetCollectionsQuery();
Expand Down Expand Up @@ -98,7 +96,7 @@ const ParentCollectionSelectBox = () => {
</Headline>
<SelectBox
className={classes.collectionSelectBox}
disabled={!config.canManageAssetCollections || loading}
disabled={loading || filteredSelectBoxOptions.length === 0}
placeholder={translate('inspector.collections.placeholder', 'Select a collection')}
value={selectedAssetCollection.parent?.id}
optionValueField="id"
Expand Down

0 comments on commit 25595cd

Please sign in to comment.