@strapi/content-manager 5.45.0 → 5.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/content-manager.js +26 -2
- package/dist/admin/content-manager.js.map +1 -1
- package/dist/admin/content-manager.mjs +26 -2
- package/dist/admin/content-manager.mjs.map +1 -1
- package/dist/admin/hooks/useContentTypeSchema.js +4 -1
- package/dist/admin/hooks/useContentTypeSchema.js.map +1 -1
- package/dist/admin/hooks/useContentTypeSchema.mjs +4 -1
- package/dist/admin/hooks/useContentTypeSchema.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentLayout.js +67 -45
- package/dist/admin/hooks/useDocumentLayout.js.map +1 -1
- package/dist/admin/hooks/useDocumentLayout.mjs +67 -45
- package/dist/admin/hooks/useDocumentLayout.mjs.map +1 -1
- package/dist/admin/hooks/usePersistentQueryParams.js +4 -1
- package/dist/admin/hooks/usePersistentQueryParams.js.map +1 -1
- package/dist/admin/hooks/usePersistentQueryParams.mjs +4 -1
- package/dist/admin/hooks/usePersistentQueryParams.mjs.map +1 -1
- package/dist/admin/pages/ComponentConfigurationPage.js +7 -3
- package/dist/admin/pages/ComponentConfigurationPage.js.map +1 -1
- package/dist/admin/pages/ComponentConfigurationPage.mjs +7 -3
- package/dist/admin/pages/ComponentConfigurationPage.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.js +21 -4
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.mjs +19 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Code.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/Blocks/Link.mjs +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js +9 -6
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs +10 -7
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js +1 -34
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs +3 -35
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js +33 -18
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.mjs +34 -19
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksToolbar.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore.js +22 -0
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore.js.map +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore.mjs +20 -0
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore.mjs.map +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.js +15 -4
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.mjs +16 -5
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/ComponentCategory.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js +26 -4
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs +26 -4
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js +31 -0
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs +31 -0
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs.map +1 -1
- package/dist/admin/preview/components/InputPopover.js +3 -0
- package/dist/admin/preview/components/InputPopover.js.map +1 -1
- package/dist/admin/preview/components/InputPopover.mjs +3 -0
- package/dist/admin/preview/components/InputPopover.mjs.map +1 -1
- package/dist/admin/preview/hooks/usePreviewInputManager.js +24 -0
- package/dist/admin/preview/hooks/usePreviewInputManager.js.map +1 -1
- package/dist/admin/preview/hooks/usePreviewInputManager.mjs +24 -0
- package/dist/admin/preview/hooks/usePreviewInputManager.mjs.map +1 -1
- package/dist/admin/preview/utils/previewScript.js +616 -78
- package/dist/admin/preview/utils/previewScript.js.map +1 -1
- package/dist/admin/preview/utils/previewScript.mjs +616 -78
- package/dist/admin/preview/utils/previewScript.mjs.map +1 -1
- package/dist/admin/src/content-manager.d.ts +26 -0
- package/dist/admin/src/exports.d.ts +1 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/BlocksEditor.d.ts +14 -8
- package/dist/admin/src/pages/EditView/components/FormInputs/BlocksInput/DefaultBlocksStore.d.ts +3 -0
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/ComponentCard.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.d.ts +11 -1
- package/dist/server/homepage/services/homepage.js +12 -8
- package/dist/server/homepage/services/homepage.js.map +1 -1
- package/dist/server/homepage/services/homepage.mjs +12 -8
- package/dist/server/homepage/services/homepage.mjs.map +1 -1
- package/dist/server/services/metrics.js +1 -5
- package/dist/server/services/metrics.js.map +1 -1
- package/dist/server/services/metrics.mjs +1 -5
- package/dist/server/services/metrics.mjs.map +1 -1
- package/dist/server/src/homepage/services/homepage.d.ts.map +1 -1
- package/dist/server/src/services/metrics.d.ts.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentLayout.js","sources":["../../../admin/src/hooks/useDocumentLayout.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { SerializedError } from '@reduxjs/toolkit';\nimport {\n useNotification,\n useStrapiApp,\n useAPIErrorHandler,\n useQueryParams,\n} from '@strapi/admin/strapi-admin';\n\nimport { HOOKS } from '../constants/hooks';\nimport { useGetContentTypeConfigurationQuery } from '../services/contentTypes';\nimport { BaseQueryError } from '../utils/api';\nimport { getMainField } from '../utils/attributes';\n\nimport { useContentTypeSchema } from './useContentTypeSchema';\nimport {\n type ComponentsDictionary,\n type Document,\n type Schema,\n useDoc,\n useDocument,\n} from './useDocument';\n\nimport type { ComponentConfiguration } from '../../../shared/contracts/components';\nimport type {\n Metadatas,\n FindContentTypeConfiguration,\n Settings,\n} from '../../../shared/contracts/content-types';\nimport type { Filters, InputProps, Table } from '@strapi/admin/strapi-admin';\nimport type { Schema as SchemaUtils } from '@strapi/types';\n\ntype LayoutOptions = Schema['options'] & Schema['pluginOptions'] & object;\n\ninterface LayoutSettings extends Settings {\n displayName?: string;\n icon?: never;\n}\n\ninterface ListFieldLayout\n extends Table.Header<Document, ListFieldLayout>,\n Pick<Filters.Filter, 'mainField'> {\n attribute: SchemaUtils.Attribute.AnyAttribute | { type: 'custom' };\n}\n\ninterface ListLayout {\n layout: ListFieldLayout[];\n components?: never;\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['list'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\ninterface EditFieldSharedProps\n extends Omit<InputProps, 'hint' | 'label' | 'type'>,\n Pick<Filters.Filter, 'mainField'> {\n hint?: string;\n label: string;\n size: number;\n unique?: boolean;\n visible?: boolean;\n}\n\n/**\n * Map over all the types in Attribute Types and use that to create a union of new types where the attribute type\n * is under the property attribute and the type is under the property type.\n */\ntype EditFieldLayout = {\n [K in SchemaUtils.Attribute.Kind]: EditFieldSharedProps & {\n attribute: Extract<SchemaUtils.Attribute.AnyAttribute, { type: K }>;\n type: K;\n };\n}[SchemaUtils.Attribute.Kind];\n\ninterface EditLayout {\n layout: Array<Array<EditFieldLayout[]>>;\n components: {\n [uid: string]: {\n layout: Array<EditFieldLayout[]>;\n settings: ComponentConfiguration['settings'] & {\n displayName?: string;\n icon?: string;\n };\n };\n };\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['edit'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\n\n/**\n * Data required to resolve `mainField` when converting list column names to field layouts for\n * component and relation attributes; mirrors the fourth and fifth arguments of `formatListLayout`.\n */\ntype ListViewConversionContext = {\n componentConfigurations: FindContentTypeConfiguration.Response['data']['components'];\n componentSchemas: ComponentsDictionary;\n contentTypeSchemas: Schema[];\n};\n\ntype UseDocumentLayout = (model: string) => {\n error?: BaseQueryError | SerializedError;\n isLoading: boolean;\n /**\n * This is the layout for the edit view,\n */\n edit: EditLayout;\n list: ListLayout;\n /**\n * Populated when configuration is loaded; pass into `convertListLayoutToFieldLayouts` with\n * `list.metadatas` when mapping persisted list column names (e.g. custom displayed headers).\n */\n listViewConversionContext: ListViewConversionContext | null;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocumentLayout\n * -----------------------------------------------------------------------------------------------*/\n\nconst DEFAULT_SETTINGS = {\n bulkable: false,\n filterable: false,\n searchable: false,\n pagination: false,\n defaultSortBy: '',\n defaultSortOrder: 'asc',\n mainField: 'id',\n pageSize: 10,\n relationOpenMode: 'modal' as const,\n};\n\n/**\n * @alpha\n * @description This hook is used to get the layouts for either the edit view or list view of a specific content-type\n * including the layouts for the components used in the content-type. It also runs the mutation hook waterfall so the data\n * is consistent wherever it is used. It's a light wrapper around the `useDocument` hook, but provides the `skip` option a document\n * is not fetched, however, it does fetch the schemas & components if they do not already exist in the cache.\n *\n * If the fetch fails, it will display a notification to the user.\n *\n * @example\n * ```tsx\n * const { model } = useParams<{ model: string }>();\n * const { edit: { schema: layout } } = useDocumentLayout(model);\n *\n * return layout.map(panel => panel.map(row => row.map(field => <Field.Root {...field} />)))\n * ```\n *\n */\nconst useDocumentLayout: UseDocumentLayout = (model) => {\n const { schema, components } = useDocument({ model, collectionType: '' }, { skip: true });\n const [{ query }] = useQueryParams();\n const runHookWaterfall = useStrapiApp('useDocumentLayout', (state) => state.runHookWaterfall);\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();\n\n const { data, isLoading: isLoadingConfigs, error } = useGetContentTypeConfigurationQuery(model);\n\n const isLoading = isLoadingSchemas || isLoadingConfigs;\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schemas, schema, components]\n );\n\n const listLayout = React.useMemo(() => {\n return data && !isLoading\n ? formatListLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout);\n }, [data, isLoading, schemas, schema, components]);\n\n const { layout: edit } = React.useMemo(\n () =>\n runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {\n layout: editLayout,\n query,\n }),\n [editLayout, query, runHookWaterfall]\n );\n\n const listViewConversionContext = React.useMemo((): ListViewConversionContext | null => {\n if (!data || isLoading) {\n return null;\n }\n\n return {\n componentConfigurations: data.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n }, [data, isLoading, components, schemas]);\n\n return {\n error,\n isLoading,\n edit,\n list: listLayout,\n listViewConversionContext,\n } satisfies ReturnType<UseDocumentLayout>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the internal useDoc hook, as such it shouldn't be used outside of the\n * content-manager because it won't work as intended.\n */\nconst useDocLayout = () => {\n const { model } = useDoc();\n return useDocumentLayout(model);\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatEditLayout\n * -----------------------------------------------------------------------------------------------*/\ntype LayoutData = FindContentTypeConfiguration.Response['data'];\n\n/**\n * @internal\n * @description takes the configuration data, the schema & the components used in the schema and formats the edit view\n * versions of the schema & components. This is then used to render the edit view of the content-type.\n */\nconst formatEditLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): EditLayout => {\n let currentPanelIndex = 0;\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const panelledEditAttributes = convertEditLayoutToFieldLayouts(\n data.contentType.layouts.edit,\n schema?.attributes,\n data.contentType.metadatas,\n { configurations: data.components, schemas: components },\n schemas\n ).reduce<Array<EditFieldLayout[][]>>((panels, row) => {\n if (row.some((field) => field.type === 'dynamiczone')) {\n panels.push([row]);\n currentPanelIndex += 2;\n } else {\n if (!panels[currentPanelIndex]) {\n panels.push([row]);\n } else {\n panels[currentPanelIndex].push(row);\n }\n }\n\n return panels;\n }, []);\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n components[uid].attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: components[uid].info.icon,\n displayName: components[uid].info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.contentType.metadatas).reduce<EditLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.edit,\n };\n },\n {}\n );\n\n return {\n layout: panelledEditAttributes,\n components: componentEditAttributes,\n metadatas: editMetadatas,\n settings: {\n ...data.contentType.settings,\n displayName: schema?.info.displayName,\n },\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertEditLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the edit layout from either a content-type or a component\n * and formats it into a generic object that can be used to correctly render\n * the form fields.\n */\nconst convertEditLayoutToFieldLayouts = (\n rows: LayoutData['contentType']['layouts']['edit'],\n attributes: Schema['attributes'] = {},\n metadatas: Metadatas,\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return rows.map((row) =>\n row\n .map((field) => {\n const attribute = attributes[field.name];\n\n if (!attribute) {\n return null;\n }\n\n const { edit: metadata } = metadatas[field.name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n disabled: !metadata.editable,\n hint: metadata.description,\n label: metadata.label ?? '',\n name: field.name,\n // @ts-expect-error – mainField does exist on the metadata for a relation.\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n placeholder: metadata.placeholder ?? '',\n required: attribute.required ?? false,\n size: field.size,\n unique: 'unique' in attribute ? attribute.unique : false,\n visible: metadata.visible ?? true,\n type: attribute.type,\n };\n })\n .filter((field) => field !== null)\n ) as EditFieldLayout[][];\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatListLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the complete configuration data, the schema & the components used in the schema and\n * formats a list view layout for the content-type. This is much simpler than the edit view layout as there\n * are less options to consider.\n */\nconst formatListLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): ListLayout => {\n const listMetadatas = Object.entries(data.contentType.metadatas).reduce<ListLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.list,\n };\n },\n {}\n );\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const listAttributes = convertListLayoutToFieldLayouts(\n data.contentType.layouts.list,\n schema?.attributes,\n listMetadatas,\n { configurations: data.components, schemas: components },\n schemas\n );\n\n return {\n layout: listAttributes,\n settings: { ...data.contentType.settings, displayName: schema?.info.displayName },\n metadatas: listMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertListLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the columns from the list view configuration and formats them into a generic object\n * combinining metadata and attribute data.\n *\n * @note We do use this to reformat the list of strings when updating the displayed headers for the list view.\n */\nconst convertListLayoutToFieldLayouts = (\n columns: LayoutData['contentType']['layouts']['list'],\n attributes: Schema['attributes'] = {},\n metadatas: ListLayout['metadatas'],\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return columns\n .map((name) => {\n const attribute = attributes[name];\n\n if (!attribute) {\n return null;\n }\n\n const metadata = metadatas[name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n label: metadata.label ?? '',\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n name: name,\n searchable: metadata.searchable ?? true,\n sortable: metadata.sortable ?? true,\n } satisfies ListFieldLayout;\n })\n .filter((field) => field !== null) as ListFieldLayout[];\n};\n\nexport {\n useDocLayout,\n useDocumentLayout,\n convertListLayoutToFieldLayouts,\n convertEditLayoutToFieldLayouts,\n DEFAULT_SETTINGS,\n};\nexport type { EditLayout, EditFieldLayout, ListLayout, ListFieldLayout, UseDocumentLayout };\n"],"names":["DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","model","schema","components","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","schemas","useContentTypeSchema","data","isLoadingConfigs","error","useGetContentTypeConfigurationQuery","React","useEffect","type","message","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","listLayout","formatListLayout","edit","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","list","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","contentType","layouts","attributes","configurations","reduce","panels","row","some","field","push","componentEditAttributes","Object","entries","acc","uid","configuration","icon","info","displayName","editMetadatas","attribute","metadata","pluginOptions","rows","map","name","component","disabled","editable","hint","description","label","getMainField","placeholder","required","size","unique","visible","filter","listMetadatas","listAttributes","convertListLayoutToFieldLayouts","columns","sortable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuHA;;AAEkG,2GAE5FA,gBAAAA,GAAmB;IACvBC,QAAAA,EAAU,KAAA;IACVC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,aAAAA,EAAe,EAAA;IACfC,gBAAAA,EAAkB,KAAA;IAClBC,SAAAA,EAAW,IAAA;IACXC,QAAAA,EAAU,EAAA;IACVC,gBAAAA,EAAkB;AACpB;AAEA;;;;;;;;;;;;;;;;;IAkBA,MAAMC,oBAAuC,CAACC,KAAAA,GAAAA;AAC5C,IAAA,MAAM,EAAEC,MAAM,EAAEC,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AAA,EAAWsF,wBAAaZ,SAAAA,EAAWC,QAAAA,CAAS3E,SAAS,IAAIsC,QAAAA,CAAStC,SAAS,EAAE;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACAyD,IAAAA,EAAMA,IAAAA;YACNnF,UAAAA,EAAY+E,QAAAA,CAAS/E,UAAU,IAAI,IAAA;YACnCqG,QAAAA,EAAUtB,QAAAA,CAASsB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC9B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"useDocumentLayout.js","sources":["../../../admin/src/hooks/useDocumentLayout.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { SerializedError } from '@reduxjs/toolkit';\nimport {\n useNotification,\n useStrapiApp,\n useAPIErrorHandler,\n useQueryParams,\n} from '@strapi/admin/strapi-admin';\n\nimport { HOOKS } from '../constants/hooks';\nimport { useGetContentTypeConfigurationQuery } from '../services/contentTypes';\nimport { BaseQueryError } from '../utils/api';\nimport { getMainField } from '../utils/attributes';\n\nimport { useContentTypeSchema } from './useContentTypeSchema';\nimport {\n type ComponentsDictionary,\n type Document,\n type Schema,\n useDoc,\n useDocument,\n} from './useDocument';\n\nimport type { ComponentConfiguration } from '../../../shared/contracts/components';\nimport type {\n Metadatas,\n FindContentTypeConfiguration,\n Settings,\n} from '../../../shared/contracts/content-types';\nimport type { Filters, InputProps, Table } from '@strapi/admin/strapi-admin';\nimport type { Schema as SchemaUtils } from '@strapi/types';\n\ntype LayoutOptions = Schema['options'] & Schema['pluginOptions'] & object;\n\ninterface LayoutSettings extends Settings {\n displayName?: string;\n icon?: never;\n}\n\ninterface ListFieldLayout\n extends Table.Header<Document, ListFieldLayout>,\n Pick<Filters.Filter, 'mainField'> {\n attribute: SchemaUtils.Attribute.AnyAttribute | { type: 'custom' };\n}\n\ninterface ListLayout {\n layout: ListFieldLayout[];\n components?: never;\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['list'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\ninterface EditFieldSharedProps\n extends Omit<InputProps, 'hint' | 'label' | 'type'>,\n Pick<Filters.Filter, 'mainField'> {\n hint?: string;\n label: string;\n size: number;\n unique?: boolean;\n visible?: boolean;\n}\n\n/**\n * Map over all the types in Attribute Types and use that to create a union of new types where the attribute type\n * is under the property attribute and the type is under the property type.\n */\ntype EditFieldLayout = {\n [K in SchemaUtils.Attribute.Kind]: EditFieldSharedProps & {\n attribute: Extract<SchemaUtils.Attribute.AnyAttribute, { type: K }>;\n type: K;\n };\n}[SchemaUtils.Attribute.Kind];\n\ninterface EditLayout {\n layout: Array<Array<EditFieldLayout[]>>;\n components: {\n [uid: string]: {\n layout: Array<EditFieldLayout[]>;\n settings: ComponentConfiguration['settings'] & {\n displayName?: string;\n icon?: string;\n };\n };\n };\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['edit'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\n\n/**\n * Data required to resolve `mainField` when converting list column names to field layouts for\n * component and relation attributes; mirrors the fourth and fifth arguments of `formatListLayout`.\n */\ntype ListViewConversionContext = {\n componentConfigurations: FindContentTypeConfiguration.Response['data']['components'];\n componentSchemas: ComponentsDictionary;\n contentTypeSchemas: Schema[];\n};\n\ntype UseDocumentLayout = (model: string) => {\n error?: BaseQueryError | SerializedError;\n isLoading: boolean;\n /**\n * This is the layout for the edit view,\n */\n edit: EditLayout;\n list: ListLayout;\n /**\n * Populated when configuration is loaded; pass into `convertListLayoutToFieldLayouts` with\n * `list.metadatas` when mapping persisted list column names (e.g. custom displayed headers).\n */\n listViewConversionContext: ListViewConversionContext | null;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocumentLayout\n * -----------------------------------------------------------------------------------------------*/\n\nconst DEFAULT_SETTINGS = {\n bulkable: false,\n filterable: false,\n searchable: false,\n pagination: false,\n defaultSortBy: '',\n defaultSortOrder: 'asc',\n mainField: 'id',\n pageSize: 10,\n relationOpenMode: 'modal' as const,\n};\n\n/**\n * @alpha\n * @description This hook is used to get the layouts for either the edit view or list view of a specific content-type\n * including the layouts for the components used in the content-type. It also runs the mutation hook waterfall so the data\n * is consistent wherever it is used. It's a light wrapper around the `useDocument` hook, but provides the `skip` option a document\n * is not fetched, however, it does fetch the schemas & components if they do not already exist in the cache.\n *\n * If the fetch fails, it will display a notification to the user.\n *\n * @example\n * ```tsx\n * const { model } = useParams<{ model: string }>();\n * const { edit: { schema: layout } } = useDocumentLayout(model);\n *\n * return layout.map(panel => panel.map(row => row.map(field => <Field.Root {...field} />)))\n * ```\n *\n */\nconst useDocumentLayout: UseDocumentLayout = (model) => {\n const { schema, components } = useDocument({ model, collectionType: '' }, { skip: true });\n const [{ query }] = useQueryParams();\n const runHookWaterfall = useStrapiApp('useDocumentLayout', (state) => state.runHookWaterfall);\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();\n\n const {\n currentData: data,\n isLoading: isLoadingConfigs,\n error,\n } = useGetContentTypeConfigurationQuery(model);\n\n const isConfigResolvedForModel = data?.contentType?.uid === model;\n const isLoading = isLoadingSchemas || isLoadingConfigs || (!error && !isConfigResolvedForModel);\n const stableLayoutsByModelRef = React.useRef(\n new Map<\n string,\n {\n edit: EditLayout;\n list: ListLayout;\n listViewConversionContext: ListViewConversionContext | null;\n }\n >()\n );\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n const resolvedLayouts = React.useMemo(() => {\n if (!data || isLoading) {\n return null;\n }\n\n const edit = formatEditLayout(data, { schemas, schema, components });\n const list = formatListLayout(data, { schemas, schema, components });\n const listViewConversionContext: ListViewConversionContext = {\n componentConfigurations: data.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n\n return { edit, list, listViewConversionContext };\n }, [data, isLoading, schemas, schema, components]);\n\n React.useEffect(() => {\n if (resolvedLayouts) {\n stableLayoutsByModelRef.current.set(model, resolvedLayouts);\n }\n }, [model, resolvedLayouts]);\n\n const stableLayouts = resolvedLayouts ?? stableLayoutsByModelRef.current.get(model) ?? null;\n\n const editLayout = React.useMemo(\n () =>\n stableLayouts?.edit ??\n ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [stableLayouts]\n );\n\n const listLayout = React.useMemo(\n () =>\n stableLayouts?.list ??\n ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout),\n [stableLayouts]\n );\n\n const { layout: edit } = React.useMemo(\n () =>\n runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {\n layout: editLayout,\n query,\n }),\n [editLayout, query, runHookWaterfall]\n );\n\n const listViewConversionContext = stableLayouts?.listViewConversionContext ?? null;\n\n return {\n error,\n isLoading,\n edit,\n list: listLayout,\n listViewConversionContext,\n } satisfies ReturnType<UseDocumentLayout>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the internal useDoc hook, as such it shouldn't be used outside of the\n * content-manager because it won't work as intended.\n */\nconst useDocLayout = () => {\n const { model } = useDoc();\n return useDocumentLayout(model);\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatEditLayout\n * -----------------------------------------------------------------------------------------------*/\ntype LayoutData = FindContentTypeConfiguration.Response['data'];\n\n/**\n * @internal\n * @description takes the configuration data, the schema & the components used in the schema and formats the edit view\n * versions of the schema & components. This is then used to render the edit view of the content-type.\n */\nconst formatEditLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): EditLayout => {\n let currentPanelIndex = 0;\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const panelledEditAttributes = convertEditLayoutToFieldLayouts(\n data.contentType.layouts.edit,\n schema?.attributes,\n data.contentType.metadatas,\n { configurations: data.components, schemas: components },\n schemas\n ).reduce<Array<EditFieldLayout[][]>>((panels, row) => {\n if (row.some((field) => field.type === 'dynamiczone')) {\n panels.push([row]);\n currentPanelIndex += 2;\n } else {\n if (!panels[currentPanelIndex]) {\n panels.push([row]);\n } else {\n panels[currentPanelIndex].push(row);\n }\n }\n\n return panels;\n }, []);\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n const componentSchema = components[uid];\n\n // Persisted configuration can reference component UIDs absent from `/init`.\n if (!componentSchema) {\n return acc;\n }\n\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n componentSchema.attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: componentSchema.info.icon,\n displayName: componentSchema.info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.contentType.metadatas).reduce<EditLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.edit,\n };\n },\n {}\n );\n\n return {\n layout: panelledEditAttributes,\n components: componentEditAttributes,\n metadatas: editMetadatas,\n settings: {\n ...data.contentType.settings,\n displayName: schema?.info?.displayName,\n },\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertEditLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the edit layout from either a content-type or a component\n * and formats it into a generic object that can be used to correctly render\n * the form fields.\n */\nconst convertEditLayoutToFieldLayouts = (\n rows: LayoutData['contentType']['layouts']['edit'],\n attributes: Schema['attributes'] = {},\n metadatas: Metadatas,\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return rows.map((row) =>\n row\n .map((field) => {\n const attribute = attributes[field.name];\n\n if (!attribute) {\n return null;\n }\n\n const fieldMetadata = metadatas[field.name];\n if (!fieldMetadata) {\n return null;\n }\n\n const { edit: metadata } = fieldMetadata;\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? (components.configurations[attribute.component]?.settings ?? {})\n : {};\n\n return {\n attribute,\n disabled: !metadata.editable,\n hint: metadata.description,\n label: metadata.label ?? '',\n name: field.name,\n // @ts-expect-error – mainField does exist on the metadata for a relation.\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n placeholder: metadata.placeholder ?? '',\n required: attribute.required ?? false,\n size: field.size,\n unique: 'unique' in attribute ? attribute.unique : false,\n visible: metadata.visible ?? true,\n type: attribute.type,\n };\n })\n .filter((field) => field !== null)\n ) as EditFieldLayout[][];\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatListLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the complete configuration data, the schema & the components used in the schema and\n * formats a list view layout for the content-type. This is much simpler than the edit view layout as there\n * are less options to consider.\n */\nconst formatListLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): ListLayout => {\n const listMetadatas = Object.entries(data.contentType.metadatas).reduce<ListLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.list,\n };\n },\n {}\n );\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const listAttributes = convertListLayoutToFieldLayouts(\n data.contentType.layouts.list,\n schema?.attributes,\n listMetadatas,\n { configurations: data.components, schemas: components },\n schemas\n );\n\n return {\n layout: listAttributes,\n settings: { ...data.contentType.settings, displayName: schema?.info?.displayName },\n metadatas: listMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertListLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the columns from the list view configuration and formats them into a generic object\n * combinining metadata and attribute data.\n *\n * @note We do use this to reformat the list of strings when updating the displayed headers for the list view.\n */\nconst convertListLayoutToFieldLayouts = (\n columns: LayoutData['contentType']['layouts']['list'],\n attributes: Schema['attributes'] = {},\n metadatas: ListLayout['metadatas'],\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return columns\n .map((name) => {\n const attribute = attributes[name];\n\n if (!attribute) {\n return null;\n }\n\n const metadata = metadatas[name];\n if (!metadata) {\n return null;\n }\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? (components.configurations[attribute.component]?.settings ?? {})\n : {};\n\n return {\n attribute,\n label: metadata.label ?? '',\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n name: name,\n searchable: metadata.searchable ?? true,\n sortable: metadata.sortable ?? true,\n } satisfies ListFieldLayout;\n })\n .filter((field) => field !== null) as ListFieldLayout[];\n};\n\nexport {\n useDocLayout,\n useDocumentLayout,\n convertListLayoutToFieldLayouts,\n convertEditLayoutToFieldLayouts,\n DEFAULT_SETTINGS,\n};\nexport type { EditLayout, EditFieldLayout, ListLayout, ListFieldLayout, UseDocumentLayout };\n"],"names":["DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","model","schema","components","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","schemas","useContentTypeSchema","currentData","data","isLoadingConfigs","error","useGetContentTypeConfigurationQuery","isConfigResolvedForModel","contentType","uid","stableLayoutsByModelRef","React","useRef","Map","useEffect","type","message","resolvedLayouts","useMemo","edit","formatEditLayout","list","formatListLayout","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","current","set","stableLayouts","get","editLayout","layout","metadatas","options","settings","listLayout","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","layouts","attributes","configurations","reduce","panels","row","some","field","push","componentEditAttributes","Object","entries","acc","configuration","componentSchema","icon","info","displayName","editMetadatas","attribute","metadata","pluginOptions","rows","map","name","fieldMetadata","component","disabled","editable","hint","description","label","getMainField","placeholder","required","size","unique","visible","filter","listMetadatas","listAttributes","convertListLayoutToFieldLayouts","columns","sortable"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuHA;;AAEkG,2GAE5FA,gBAAAA,GAAmB;IACvBC,QAAAA,EAAU,KAAA;IACVC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,aAAAA,EAAe,EAAA;IACfC,gBAAAA,EAAkB,KAAA;IAClBC,SAAAA,EAAW,IAAA;IACXC,QAAAA,EAAU,EAAA;IACVC,gBAAAA,EAAkB;AACpB;AAEA;;;;;;;;;;;;;;;;;IAkBA,MAAMC,oBAAuC,CAACC,KAAAA,GAAAA;AAC5C,IAAA,MAAM,EAAEC,MAAM,EAAEC,UAAU,EAAE,GAAGC,uBAAAA,CAAY;AAAEH,QAAAA,KAAAA;QAAOI,cAAAA,EAAgB;KAAG,EAAG;QAAEC,IAAAA,EAAM;AAAK,KAAA,CAAA;AACvF,IAAA,MAAM,CAAC,EAAEC,KAAK,EAAE,CAAC,GAAGC,0BAAAA,EAAAA;AACpB,IAAA,MAAMC,mBAAmBC,wBAAAA,CAAa,mBAAA,EAAqB,CAACC,KAAAA,GAAUA,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OsF,OAAAA,CACJnB,GAAG,CAAC,CAACC,IAAAA,GAAAA;QACJ,MAAML,SAAAA,GAAYlB,YAAU,CAACuB,IAAAA,CAAK;AAElC,QAAA,IAAI,CAACL,SAAAA,EAAW;YACd,OAAO,IAAA;AACT,QAAA;QAEA,MAAMC,QAAAA,GAAW/B,SAAS,CAACmC,IAAAA,CAAK;AAChC,QAAA,IAAI,CAACJ,QAAAA,EAAU;YACb,OAAO,IAAA;AACT,QAAA;AAEA,QAAA,MAAM7B,WACJ4B,SAAAA,CAAUhD,IAAI,KAAK,WAAA,IAAe/B,aAC7BA,UAAAA,CAAW8D,cAAc,CAACiB,SAAAA,CAAUO,SAAS,CAAC,EAAEnC,QAAAA,IAAY,KAC7D,EAAC;QAEP,OAAO;AACL4B,YAAAA,SAAAA;YACAY,KAAAA,EAAOX,QAAAA,CAASW,KAAK,IAAI,EAAA;AACzBjG,YAAAA,SAAAA,EAAWkG,wBAAab,SAAAA,EAAWC,QAAAA,CAAStF,SAAS,IAAIyD,QAAAA,CAASzD,SAAS,EAAE;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACAoE,IAAAA,EAAMA,IAAAA;YACN9F,UAAAA,EAAY0F,QAAAA,CAAS1F,UAAU,IAAI,IAAA;YACnCiH,QAAAA,EAAUvB,QAAAA,CAASuB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC/B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;;;;;"}
|
|
@@ -48,8 +48,10 @@ import { useDocument, useDoc } from './useDocument.mjs';
|
|
|
48
48
|
const { toggleNotification } = useNotification();
|
|
49
49
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
|
50
50
|
const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();
|
|
51
|
-
const { data, isLoading: isLoadingConfigs, error } = useGetContentTypeConfigurationQuery(model);
|
|
52
|
-
const
|
|
51
|
+
const { currentData: data, isLoading: isLoadingConfigs, error } = useGetContentTypeConfigurationQuery(model);
|
|
52
|
+
const isConfigResolvedForModel = data?.contentType?.uid === model;
|
|
53
|
+
const isLoading = isLoadingSchemas || isLoadingConfigs || !error && !isConfigResolvedForModel;
|
|
54
|
+
const stableLayoutsByModelRef = React.useRef(new Map());
|
|
53
55
|
React.useEffect(()=>{
|
|
54
56
|
if (error) {
|
|
55
57
|
toggleNotification({
|
|
@@ -62,40 +64,62 @@ import { useDocument, useDoc } from './useDocument.mjs';
|
|
|
62
64
|
formatAPIError,
|
|
63
65
|
toggleNotification
|
|
64
66
|
]);
|
|
65
|
-
const
|
|
67
|
+
const resolvedLayouts = React.useMemo(()=>{
|
|
68
|
+
if (!data || isLoading) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
const edit = formatEditLayout(data, {
|
|
72
|
+
schemas,
|
|
73
|
+
schema,
|
|
74
|
+
components
|
|
75
|
+
});
|
|
76
|
+
const list = formatListLayout(data, {
|
|
66
77
|
schemas,
|
|
67
78
|
schema,
|
|
68
79
|
components
|
|
69
|
-
})
|
|
80
|
+
});
|
|
81
|
+
const listViewConversionContext = {
|
|
82
|
+
componentConfigurations: data.components,
|
|
83
|
+
componentSchemas: components,
|
|
84
|
+
contentTypeSchemas: schemas
|
|
85
|
+
};
|
|
86
|
+
return {
|
|
87
|
+
edit,
|
|
88
|
+
list,
|
|
89
|
+
listViewConversionContext
|
|
90
|
+
};
|
|
91
|
+
}, [
|
|
92
|
+
data,
|
|
93
|
+
isLoading,
|
|
94
|
+
schemas,
|
|
95
|
+
schema,
|
|
96
|
+
components
|
|
97
|
+
]);
|
|
98
|
+
React.useEffect(()=>{
|
|
99
|
+
if (resolvedLayouts) {
|
|
100
|
+
stableLayoutsByModelRef.current.set(model, resolvedLayouts);
|
|
101
|
+
}
|
|
102
|
+
}, [
|
|
103
|
+
model,
|
|
104
|
+
resolvedLayouts
|
|
105
|
+
]);
|
|
106
|
+
const stableLayouts = resolvedLayouts ?? stableLayoutsByModelRef.current.get(model) ?? null;
|
|
107
|
+
const editLayout = React.useMemo(()=>stableLayouts?.edit ?? {
|
|
70
108
|
layout: [],
|
|
71
109
|
components: {},
|
|
72
110
|
metadatas: {},
|
|
73
111
|
options: {},
|
|
74
112
|
settings: DEFAULT_SETTINGS
|
|
75
113
|
}, [
|
|
76
|
-
|
|
77
|
-
isLoading,
|
|
78
|
-
schemas,
|
|
79
|
-
schema,
|
|
80
|
-
components
|
|
114
|
+
stableLayouts
|
|
81
115
|
]);
|
|
82
|
-
const listLayout = React.useMemo(()=>{
|
|
83
|
-
return data && !isLoading ? formatListLayout(data, {
|
|
84
|
-
schemas,
|
|
85
|
-
schema,
|
|
86
|
-
components
|
|
87
|
-
}) : {
|
|
116
|
+
const listLayout = React.useMemo(()=>stableLayouts?.list ?? {
|
|
88
117
|
layout: [],
|
|
89
118
|
metadatas: {},
|
|
90
119
|
options: {},
|
|
91
120
|
settings: DEFAULT_SETTINGS
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
data,
|
|
95
|
-
isLoading,
|
|
96
|
-
schemas,
|
|
97
|
-
schema,
|
|
98
|
-
components
|
|
121
|
+
}, [
|
|
122
|
+
stableLayouts
|
|
99
123
|
]);
|
|
100
124
|
const { layout: edit } = React.useMemo(()=>runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {
|
|
101
125
|
layout: editLayout,
|
|
@@ -105,21 +129,7 @@ import { useDocument, useDoc } from './useDocument.mjs';
|
|
|
105
129
|
query,
|
|
106
130
|
runHookWaterfall
|
|
107
131
|
]);
|
|
108
|
-
const listViewConversionContext =
|
|
109
|
-
if (!data || isLoading) {
|
|
110
|
-
return null;
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
componentConfigurations: data.components,
|
|
114
|
-
componentSchemas: components,
|
|
115
|
-
contentTypeSchemas: schemas
|
|
116
|
-
};
|
|
117
|
-
}, [
|
|
118
|
-
data,
|
|
119
|
-
isLoading,
|
|
120
|
-
components,
|
|
121
|
-
schemas
|
|
122
|
-
]);
|
|
132
|
+
const listViewConversionContext = stableLayouts?.listViewConversionContext ?? null;
|
|
123
133
|
return {
|
|
124
134
|
error,
|
|
125
135
|
isLoading,
|
|
@@ -166,15 +176,20 @@ import { useDocument, useDoc } from './useDocument.mjs';
|
|
|
166
176
|
return panels;
|
|
167
177
|
}, []);
|
|
168
178
|
const componentEditAttributes = Object.entries(data.components).reduce((acc, [uid, configuration])=>{
|
|
179
|
+
const componentSchema = components[uid];
|
|
180
|
+
// Persisted configuration can reference component UIDs absent from `/init`.
|
|
181
|
+
if (!componentSchema) {
|
|
182
|
+
return acc;
|
|
183
|
+
}
|
|
169
184
|
acc[uid] = {
|
|
170
|
-
layout: convertEditLayoutToFieldLayouts(configuration.layouts.edit,
|
|
185
|
+
layout: convertEditLayoutToFieldLayouts(configuration.layouts.edit, componentSchema.attributes, configuration.metadatas, {
|
|
171
186
|
configurations: data.components,
|
|
172
187
|
schemas: components
|
|
173
188
|
}),
|
|
174
189
|
settings: {
|
|
175
190
|
...configuration.settings,
|
|
176
|
-
icon:
|
|
177
|
-
displayName:
|
|
191
|
+
icon: componentSchema.info.icon,
|
|
192
|
+
displayName: componentSchema.info.displayName
|
|
178
193
|
}
|
|
179
194
|
};
|
|
180
195
|
return acc;
|
|
@@ -191,7 +206,7 @@ import { useDocument, useDoc } from './useDocument.mjs';
|
|
|
191
206
|
metadatas: editMetadatas,
|
|
192
207
|
settings: {
|
|
193
208
|
...data.contentType.settings,
|
|
194
|
-
displayName: schema?.info
|
|
209
|
+
displayName: schema?.info?.displayName
|
|
195
210
|
},
|
|
196
211
|
options: {
|
|
197
212
|
...schema?.options,
|
|
@@ -213,8 +228,12 @@ import { useDocument, useDoc } from './useDocument.mjs';
|
|
|
213
228
|
if (!attribute) {
|
|
214
229
|
return null;
|
|
215
230
|
}
|
|
216
|
-
const
|
|
217
|
-
|
|
231
|
+
const fieldMetadata = metadatas[field.name];
|
|
232
|
+
if (!fieldMetadata) {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
const { edit: metadata } = fieldMetadata;
|
|
236
|
+
const settings = attribute.type === 'component' && components ? components.configurations[attribute.component]?.settings ?? {} : {};
|
|
218
237
|
return {
|
|
219
238
|
attribute,
|
|
220
239
|
disabled: !metadata.editable,
|
|
@@ -259,7 +278,7 @@ import { useDocument, useDoc } from './useDocument.mjs';
|
|
|
259
278
|
layout: listAttributes,
|
|
260
279
|
settings: {
|
|
261
280
|
...data.contentType.settings,
|
|
262
|
-
displayName: schema?.info
|
|
281
|
+
displayName: schema?.info?.displayName
|
|
263
282
|
},
|
|
264
283
|
metadatas: listMetadatas,
|
|
265
284
|
options: {
|
|
@@ -284,7 +303,10 @@ import { useDocument, useDoc } from './useDocument.mjs';
|
|
|
284
303
|
return null;
|
|
285
304
|
}
|
|
286
305
|
const metadata = metadatas[name];
|
|
287
|
-
|
|
306
|
+
if (!metadata) {
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
const settings = attribute.type === 'component' && components ? components.configurations[attribute.component]?.settings ?? {} : {};
|
|
288
310
|
return {
|
|
289
311
|
attribute,
|
|
290
312
|
label: metadata.label ?? '',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentLayout.mjs","sources":["../../../admin/src/hooks/useDocumentLayout.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { SerializedError } from '@reduxjs/toolkit';\nimport {\n useNotification,\n useStrapiApp,\n useAPIErrorHandler,\n useQueryParams,\n} from '@strapi/admin/strapi-admin';\n\nimport { HOOKS } from '../constants/hooks';\nimport { useGetContentTypeConfigurationQuery } from '../services/contentTypes';\nimport { BaseQueryError } from '../utils/api';\nimport { getMainField } from '../utils/attributes';\n\nimport { useContentTypeSchema } from './useContentTypeSchema';\nimport {\n type ComponentsDictionary,\n type Document,\n type Schema,\n useDoc,\n useDocument,\n} from './useDocument';\n\nimport type { ComponentConfiguration } from '../../../shared/contracts/components';\nimport type {\n Metadatas,\n FindContentTypeConfiguration,\n Settings,\n} from '../../../shared/contracts/content-types';\nimport type { Filters, InputProps, Table } from '@strapi/admin/strapi-admin';\nimport type { Schema as SchemaUtils } from '@strapi/types';\n\ntype LayoutOptions = Schema['options'] & Schema['pluginOptions'] & object;\n\ninterface LayoutSettings extends Settings {\n displayName?: string;\n icon?: never;\n}\n\ninterface ListFieldLayout\n extends Table.Header<Document, ListFieldLayout>,\n Pick<Filters.Filter, 'mainField'> {\n attribute: SchemaUtils.Attribute.AnyAttribute | { type: 'custom' };\n}\n\ninterface ListLayout {\n layout: ListFieldLayout[];\n components?: never;\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['list'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\ninterface EditFieldSharedProps\n extends Omit<InputProps, 'hint' | 'label' | 'type'>,\n Pick<Filters.Filter, 'mainField'> {\n hint?: string;\n label: string;\n size: number;\n unique?: boolean;\n visible?: boolean;\n}\n\n/**\n * Map over all the types in Attribute Types and use that to create a union of new types where the attribute type\n * is under the property attribute and the type is under the property type.\n */\ntype EditFieldLayout = {\n [K in SchemaUtils.Attribute.Kind]: EditFieldSharedProps & {\n attribute: Extract<SchemaUtils.Attribute.AnyAttribute, { type: K }>;\n type: K;\n };\n}[SchemaUtils.Attribute.Kind];\n\ninterface EditLayout {\n layout: Array<Array<EditFieldLayout[]>>;\n components: {\n [uid: string]: {\n layout: Array<EditFieldLayout[]>;\n settings: ComponentConfiguration['settings'] & {\n displayName?: string;\n icon?: string;\n };\n };\n };\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['edit'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\n\n/**\n * Data required to resolve `mainField` when converting list column names to field layouts for\n * component and relation attributes; mirrors the fourth and fifth arguments of `formatListLayout`.\n */\ntype ListViewConversionContext = {\n componentConfigurations: FindContentTypeConfiguration.Response['data']['components'];\n componentSchemas: ComponentsDictionary;\n contentTypeSchemas: Schema[];\n};\n\ntype UseDocumentLayout = (model: string) => {\n error?: BaseQueryError | SerializedError;\n isLoading: boolean;\n /**\n * This is the layout for the edit view,\n */\n edit: EditLayout;\n list: ListLayout;\n /**\n * Populated when configuration is loaded; pass into `convertListLayoutToFieldLayouts` with\n * `list.metadatas` when mapping persisted list column names (e.g. custom displayed headers).\n */\n listViewConversionContext: ListViewConversionContext | null;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocumentLayout\n * -----------------------------------------------------------------------------------------------*/\n\nconst DEFAULT_SETTINGS = {\n bulkable: false,\n filterable: false,\n searchable: false,\n pagination: false,\n defaultSortBy: '',\n defaultSortOrder: 'asc',\n mainField: 'id',\n pageSize: 10,\n relationOpenMode: 'modal' as const,\n};\n\n/**\n * @alpha\n * @description This hook is used to get the layouts for either the edit view or list view of a specific content-type\n * including the layouts for the components used in the content-type. It also runs the mutation hook waterfall so the data\n * is consistent wherever it is used. It's a light wrapper around the `useDocument` hook, but provides the `skip` option a document\n * is not fetched, however, it does fetch the schemas & components if they do not already exist in the cache.\n *\n * If the fetch fails, it will display a notification to the user.\n *\n * @example\n * ```tsx\n * const { model } = useParams<{ model: string }>();\n * const { edit: { schema: layout } } = useDocumentLayout(model);\n *\n * return layout.map(panel => panel.map(row => row.map(field => <Field.Root {...field} />)))\n * ```\n *\n */\nconst useDocumentLayout: UseDocumentLayout = (model) => {\n const { schema, components } = useDocument({ model, collectionType: '' }, { skip: true });\n const [{ query }] = useQueryParams();\n const runHookWaterfall = useStrapiApp('useDocumentLayout', (state) => state.runHookWaterfall);\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();\n\n const { data, isLoading: isLoadingConfigs, error } = useGetContentTypeConfigurationQuery(model);\n\n const isLoading = isLoadingSchemas || isLoadingConfigs;\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatEditLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schemas, schema, components]\n );\n\n const listLayout = React.useMemo(() => {\n return data && !isLoading\n ? formatListLayout(data, { schemas, schema, components })\n : ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout);\n }, [data, isLoading, schemas, schema, components]);\n\n const { layout: edit } = React.useMemo(\n () =>\n runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {\n layout: editLayout,\n query,\n }),\n [editLayout, query, runHookWaterfall]\n );\n\n const listViewConversionContext = React.useMemo((): ListViewConversionContext | null => {\n if (!data || isLoading) {\n return null;\n }\n\n return {\n componentConfigurations: data.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n }, [data, isLoading, components, schemas]);\n\n return {\n error,\n isLoading,\n edit,\n list: listLayout,\n listViewConversionContext,\n } satisfies ReturnType<UseDocumentLayout>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the internal useDoc hook, as such it shouldn't be used outside of the\n * content-manager because it won't work as intended.\n */\nconst useDocLayout = () => {\n const { model } = useDoc();\n return useDocumentLayout(model);\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatEditLayout\n * -----------------------------------------------------------------------------------------------*/\ntype LayoutData = FindContentTypeConfiguration.Response['data'];\n\n/**\n * @internal\n * @description takes the configuration data, the schema & the components used in the schema and formats the edit view\n * versions of the schema & components. This is then used to render the edit view of the content-type.\n */\nconst formatEditLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): EditLayout => {\n let currentPanelIndex = 0;\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const panelledEditAttributes = convertEditLayoutToFieldLayouts(\n data.contentType.layouts.edit,\n schema?.attributes,\n data.contentType.metadatas,\n { configurations: data.components, schemas: components },\n schemas\n ).reduce<Array<EditFieldLayout[][]>>((panels, row) => {\n if (row.some((field) => field.type === 'dynamiczone')) {\n panels.push([row]);\n currentPanelIndex += 2;\n } else {\n if (!panels[currentPanelIndex]) {\n panels.push([row]);\n } else {\n panels[currentPanelIndex].push(row);\n }\n }\n\n return panels;\n }, []);\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n components[uid].attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: components[uid].info.icon,\n displayName: components[uid].info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.contentType.metadatas).reduce<EditLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.edit,\n };\n },\n {}\n );\n\n return {\n layout: panelledEditAttributes,\n components: componentEditAttributes,\n metadatas: editMetadatas,\n settings: {\n ...data.contentType.settings,\n displayName: schema?.info.displayName,\n },\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertEditLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the edit layout from either a content-type or a component\n * and formats it into a generic object that can be used to correctly render\n * the form fields.\n */\nconst convertEditLayoutToFieldLayouts = (\n rows: LayoutData['contentType']['layouts']['edit'],\n attributes: Schema['attributes'] = {},\n metadatas: Metadatas,\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return rows.map((row) =>\n row\n .map((field) => {\n const attribute = attributes[field.name];\n\n if (!attribute) {\n return null;\n }\n\n const { edit: metadata } = metadatas[field.name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n disabled: !metadata.editable,\n hint: metadata.description,\n label: metadata.label ?? '',\n name: field.name,\n // @ts-expect-error – mainField does exist on the metadata for a relation.\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n placeholder: metadata.placeholder ?? '',\n required: attribute.required ?? false,\n size: field.size,\n unique: 'unique' in attribute ? attribute.unique : false,\n visible: metadata.visible ?? true,\n type: attribute.type,\n };\n })\n .filter((field) => field !== null)\n ) as EditFieldLayout[][];\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatListLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the complete configuration data, the schema & the components used in the schema and\n * formats a list view layout for the content-type. This is much simpler than the edit view layout as there\n * are less options to consider.\n */\nconst formatListLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): ListLayout => {\n const listMetadatas = Object.entries(data.contentType.metadatas).reduce<ListLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.list,\n };\n },\n {}\n );\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const listAttributes = convertListLayoutToFieldLayouts(\n data.contentType.layouts.list,\n schema?.attributes,\n listMetadatas,\n { configurations: data.components, schemas: components },\n schemas\n );\n\n return {\n layout: listAttributes,\n settings: { ...data.contentType.settings, displayName: schema?.info.displayName },\n metadatas: listMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertListLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the columns from the list view configuration and formats them into a generic object\n * combinining metadata and attribute data.\n *\n * @note We do use this to reformat the list of strings when updating the displayed headers for the list view.\n */\nconst convertListLayoutToFieldLayouts = (\n columns: LayoutData['contentType']['layouts']['list'],\n attributes: Schema['attributes'] = {},\n metadatas: ListLayout['metadatas'],\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return columns\n .map((name) => {\n const attribute = attributes[name];\n\n if (!attribute) {\n return null;\n }\n\n const metadata = metadatas[name];\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? components.configurations[attribute.component].settings\n : {};\n\n return {\n attribute,\n label: metadata.label ?? '',\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n name: name,\n searchable: metadata.searchable ?? true,\n sortable: metadata.sortable ?? true,\n } satisfies ListFieldLayout;\n })\n .filter((field) => field !== null) as ListFieldLayout[];\n};\n\nexport {\n useDocLayout,\n useDocumentLayout,\n convertListLayoutToFieldLayouts,\n convertEditLayoutToFieldLayouts,\n DEFAULT_SETTINGS,\n};\nexport type { EditLayout, EditFieldLayout, ListLayout, ListFieldLayout, UseDocumentLayout };\n"],"names":["DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","model","schema","components","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","schemas","useContentTypeSchema","data","isLoadingConfigs","error","useGetContentTypeConfigurationQuery","React","useEffect","type","message","editLayout","useMemo","formatEditLayout","layout","metadatas","options","settings","listLayout","formatListLayout","edit","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","list","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","contentType","layouts","attributes","configurations","reduce","panels","row","some","field","push","componentEditAttributes","Object","entries","acc","uid","configuration","icon","info","displayName","editMetadatas","attribute","metadata","pluginOptions","rows","map","name","component","disabled","editable","hint","description","label","getMainField","placeholder","required","size","unique","visible","filter","listMetadatas","listAttributes","convertListLayoutToFieldLayouts","columns","sortable"],"mappings":";;;;;;;;AAuHA;;AAEkG,2GAE5FA,gBAAAA,GAAmB;IACvBC,QAAAA,EAAU,KAAA;IACVC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,UAAAA,EAAY,KAAA;IACZC,aAAAA,EAAe,EAAA;IACfC,gBAAAA,EAAkB,KAAA;IAClBC,SAAAA,EAAW,IAAA;IACXC,QAAAA,EAAU,EAAA;IACVC,gBAAAA,EAAkB;AACpB;AAEA;;;;;;;;;;;;;;;;;IAkBA,MAAMC,oBAAuC,CAACC,KAAAA,GAAAA;AAC5C,IAAA,MAAM,EAAEC,MAAM,EAAEC,UAAU,EAAE,GAAGC,WAAAA,CAAY;AAAEH,QAAAA,KAAAA;QAAOI,cAAAA,EAAgB;KAAG,EAAG;QAAEC,IAAAA,EAAM;AAAK,KAAA,CAAA;AACvF,IAAA,MAAM,CAAC,EAAEC,KAAK,EAAE,CAAC,GAAGC,cAAAA,EAAAA;AACpB,IAAA,MAAMC,mBAAmBC,YAAAA,CAAa,mBAAA,EAAqB,CAACC,KAAAA,GAAUA,MAAMF,gBAAgB,CAAA;IAC5F,MAAM,EAAEG,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,kBAAAA,EAAAA;AACpD,IAAA,MAAM,EAAEC,SAAAA,EAAWC,gBAAgB,EAAEC,OAAO,EAAE,GAAGC,oBAAAA,EAAAA;IAEjD,MAAM,EAAEC,IAAI,EAAEJ,SAAAA,EAAWK,gBAAg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;IAWA,MAAM0D,+BAAAA,GAAkC,CACtCC,OAAAA,EACAxC,UAAAA,GAAmC,EAAE,EACrCpB,SAAAA,EACA9B,UAAAA,EAIAgB,OAAAA,GAAoB,EAAE,GAAA;IAEtB,OAAO0E,OAAAA,CACJlB,GAAG,CAAC,CAACC,IAAAA,GAAAA;QACJ,MAAML,SAAAA,GAAYlB,UAAU,CAACuB,IAAAA,CAAK;AAElC,QAAA,IAAI,CAACL,SAAAA,EAAW;YACd,OAAO,IAAA;AACT,QAAA;QAEA,MAAMC,QAAAA,GAAWvC,SAAS,CAAC2C,IAAAA,CAAK;AAEhC,QAAA,MAAMzC,QAAAA,GACJoC,SAAAA,CAAU5C,IAAI,KAAK,eAAexB,UAAAA,GAC9BA,UAAAA,CAAWmD,cAAc,CAACiB,UAAUM,SAAS,CAAC,CAAC1C,QAAQ,GACvD,EAAC;QAEP,OAAO;AACLoC,YAAAA,SAAAA;YACAW,KAAAA,EAAOV,QAAAA,CAASU,KAAK,IAAI,EAAA;AACzBrF,YAAAA,SAAAA,EAAWsF,aAAaZ,SAAAA,EAAWC,QAAAA,CAAS3E,SAAS,IAAIsC,QAAAA,CAAStC,SAAS,EAAE;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACAyD,IAAAA,EAAMA,IAAAA;YACNnF,UAAAA,EAAY+E,QAAAA,CAAS/E,UAAU,IAAI,IAAA;YACnCqG,QAAAA,EAAUtB,QAAAA,CAASsB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC9B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;"}
|
|
1
|
+
{"version":3,"file":"useDocumentLayout.mjs","sources":["../../../admin/src/hooks/useDocumentLayout.ts"],"sourcesContent":["import * as React from 'react';\n\nimport { SerializedError } from '@reduxjs/toolkit';\nimport {\n useNotification,\n useStrapiApp,\n useAPIErrorHandler,\n useQueryParams,\n} from '@strapi/admin/strapi-admin';\n\nimport { HOOKS } from '../constants/hooks';\nimport { useGetContentTypeConfigurationQuery } from '../services/contentTypes';\nimport { BaseQueryError } from '../utils/api';\nimport { getMainField } from '../utils/attributes';\n\nimport { useContentTypeSchema } from './useContentTypeSchema';\nimport {\n type ComponentsDictionary,\n type Document,\n type Schema,\n useDoc,\n useDocument,\n} from './useDocument';\n\nimport type { ComponentConfiguration } from '../../../shared/contracts/components';\nimport type {\n Metadatas,\n FindContentTypeConfiguration,\n Settings,\n} from '../../../shared/contracts/content-types';\nimport type { Filters, InputProps, Table } from '@strapi/admin/strapi-admin';\nimport type { Schema as SchemaUtils } from '@strapi/types';\n\ntype LayoutOptions = Schema['options'] & Schema['pluginOptions'] & object;\n\ninterface LayoutSettings extends Settings {\n displayName?: string;\n icon?: never;\n}\n\ninterface ListFieldLayout\n extends Table.Header<Document, ListFieldLayout>,\n Pick<Filters.Filter, 'mainField'> {\n attribute: SchemaUtils.Attribute.AnyAttribute | { type: 'custom' };\n}\n\ninterface ListLayout {\n layout: ListFieldLayout[];\n components?: never;\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['list'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\ninterface EditFieldSharedProps\n extends Omit<InputProps, 'hint' | 'label' | 'type'>,\n Pick<Filters.Filter, 'mainField'> {\n hint?: string;\n label: string;\n size: number;\n unique?: boolean;\n visible?: boolean;\n}\n\n/**\n * Map over all the types in Attribute Types and use that to create a union of new types where the attribute type\n * is under the property attribute and the type is under the property type.\n */\ntype EditFieldLayout = {\n [K in SchemaUtils.Attribute.Kind]: EditFieldSharedProps & {\n attribute: Extract<SchemaUtils.Attribute.AnyAttribute, { type: K }>;\n type: K;\n };\n}[SchemaUtils.Attribute.Kind];\n\ninterface EditLayout {\n layout: Array<Array<EditFieldLayout[]>>;\n components: {\n [uid: string]: {\n layout: Array<EditFieldLayout[]>;\n settings: ComponentConfiguration['settings'] & {\n displayName?: string;\n icon?: string;\n };\n };\n };\n metadatas: {\n [K in keyof Metadatas]: Metadatas[K]['edit'];\n };\n options: LayoutOptions;\n settings: LayoutSettings;\n}\n\n/**\n * Data required to resolve `mainField` when converting list column names to field layouts for\n * component and relation attributes; mirrors the fourth and fifth arguments of `formatListLayout`.\n */\ntype ListViewConversionContext = {\n componentConfigurations: FindContentTypeConfiguration.Response['data']['components'];\n componentSchemas: ComponentsDictionary;\n contentTypeSchemas: Schema[];\n};\n\ntype UseDocumentLayout = (model: string) => {\n error?: BaseQueryError | SerializedError;\n isLoading: boolean;\n /**\n * This is the layout for the edit view,\n */\n edit: EditLayout;\n list: ListLayout;\n /**\n * Populated when configuration is loaded; pass into `convertListLayoutToFieldLayouts` with\n * `list.metadatas` when mapping persisted list column names (e.g. custom displayed headers).\n */\n listViewConversionContext: ListViewConversionContext | null;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocumentLayout\n * -----------------------------------------------------------------------------------------------*/\n\nconst DEFAULT_SETTINGS = {\n bulkable: false,\n filterable: false,\n searchable: false,\n pagination: false,\n defaultSortBy: '',\n defaultSortOrder: 'asc',\n mainField: 'id',\n pageSize: 10,\n relationOpenMode: 'modal' as const,\n};\n\n/**\n * @alpha\n * @description This hook is used to get the layouts for either the edit view or list view of a specific content-type\n * including the layouts for the components used in the content-type. It also runs the mutation hook waterfall so the data\n * is consistent wherever it is used. It's a light wrapper around the `useDocument` hook, but provides the `skip` option a document\n * is not fetched, however, it does fetch the schemas & components if they do not already exist in the cache.\n *\n * If the fetch fails, it will display a notification to the user.\n *\n * @example\n * ```tsx\n * const { model } = useParams<{ model: string }>();\n * const { edit: { schema: layout } } = useDocumentLayout(model);\n *\n * return layout.map(panel => panel.map(row => row.map(field => <Field.Root {...field} />)))\n * ```\n *\n */\nconst useDocumentLayout: UseDocumentLayout = (model) => {\n const { schema, components } = useDocument({ model, collectionType: '' }, { skip: true });\n const [{ query }] = useQueryParams();\n const runHookWaterfall = useStrapiApp('useDocumentLayout', (state) => state.runHookWaterfall);\n const { toggleNotification } = useNotification();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n const { isLoading: isLoadingSchemas, schemas } = useContentTypeSchema();\n\n const {\n currentData: data,\n isLoading: isLoadingConfigs,\n error,\n } = useGetContentTypeConfigurationQuery(model);\n\n const isConfigResolvedForModel = data?.contentType?.uid === model;\n const isLoading = isLoadingSchemas || isLoadingConfigs || (!error && !isConfigResolvedForModel);\n const stableLayoutsByModelRef = React.useRef(\n new Map<\n string,\n {\n edit: EditLayout;\n list: ListLayout;\n listViewConversionContext: ListViewConversionContext | null;\n }\n >()\n );\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n const resolvedLayouts = React.useMemo(() => {\n if (!data || isLoading) {\n return null;\n }\n\n const edit = formatEditLayout(data, { schemas, schema, components });\n const list = formatListLayout(data, { schemas, schema, components });\n const listViewConversionContext: ListViewConversionContext = {\n componentConfigurations: data.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n\n return { edit, list, listViewConversionContext };\n }, [data, isLoading, schemas, schema, components]);\n\n React.useEffect(() => {\n if (resolvedLayouts) {\n stableLayoutsByModelRef.current.set(model, resolvedLayouts);\n }\n }, [model, resolvedLayouts]);\n\n const stableLayouts = resolvedLayouts ?? stableLayoutsByModelRef.current.get(model) ?? null;\n\n const editLayout = React.useMemo(\n () =>\n stableLayouts?.edit ??\n ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [stableLayouts]\n );\n\n const listLayout = React.useMemo(\n () =>\n stableLayouts?.list ??\n ({\n layout: [],\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as ListLayout),\n [stableLayouts]\n );\n\n const { layout: edit } = React.useMemo(\n () =>\n runHookWaterfall(HOOKS.MUTATE_EDIT_VIEW_LAYOUT, {\n layout: editLayout,\n query,\n }),\n [editLayout, query, runHookWaterfall]\n );\n\n const listViewConversionContext = stableLayouts?.listViewConversionContext ?? null;\n\n return {\n error,\n isLoading,\n edit,\n list: listLayout,\n listViewConversionContext,\n } satisfies ReturnType<UseDocumentLayout>;\n};\n\n/* -------------------------------------------------------------------------------------------------\n * useDocLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal this hook uses the internal useDoc hook, as such it shouldn't be used outside of the\n * content-manager because it won't work as intended.\n */\nconst useDocLayout = () => {\n const { model } = useDoc();\n return useDocumentLayout(model);\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatEditLayout\n * -----------------------------------------------------------------------------------------------*/\ntype LayoutData = FindContentTypeConfiguration.Response['data'];\n\n/**\n * @internal\n * @description takes the configuration data, the schema & the components used in the schema and formats the edit view\n * versions of the schema & components. This is then used to render the edit view of the content-type.\n */\nconst formatEditLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): EditLayout => {\n let currentPanelIndex = 0;\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const panelledEditAttributes = convertEditLayoutToFieldLayouts(\n data.contentType.layouts.edit,\n schema?.attributes,\n data.contentType.metadatas,\n { configurations: data.components, schemas: components },\n schemas\n ).reduce<Array<EditFieldLayout[][]>>((panels, row) => {\n if (row.some((field) => field.type === 'dynamiczone')) {\n panels.push([row]);\n currentPanelIndex += 2;\n } else {\n if (!panels[currentPanelIndex]) {\n panels.push([row]);\n } else {\n panels[currentPanelIndex].push(row);\n }\n }\n\n return panels;\n }, []);\n\n const componentEditAttributes = Object.entries(data.components).reduce<EditLayout['components']>(\n (acc, [uid, configuration]) => {\n const componentSchema = components[uid];\n\n // Persisted configuration can reference component UIDs absent from `/init`.\n if (!componentSchema) {\n return acc;\n }\n\n acc[uid] = {\n layout: convertEditLayoutToFieldLayouts(\n configuration.layouts.edit,\n componentSchema.attributes,\n configuration.metadatas,\n { configurations: data.components, schemas: components }\n ),\n settings: {\n ...configuration.settings,\n icon: componentSchema.info.icon,\n displayName: componentSchema.info.displayName,\n },\n };\n return acc;\n },\n {}\n );\n\n const editMetadatas = Object.entries(data.contentType.metadatas).reduce<EditLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.edit,\n };\n },\n {}\n );\n\n return {\n layout: panelledEditAttributes,\n components: componentEditAttributes,\n metadatas: editMetadatas,\n settings: {\n ...data.contentType.settings,\n displayName: schema?.info?.displayName,\n },\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertEditLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the edit layout from either a content-type or a component\n * and formats it into a generic object that can be used to correctly render\n * the form fields.\n */\nconst convertEditLayoutToFieldLayouts = (\n rows: LayoutData['contentType']['layouts']['edit'],\n attributes: Schema['attributes'] = {},\n metadatas: Metadatas,\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return rows.map((row) =>\n row\n .map((field) => {\n const attribute = attributes[field.name];\n\n if (!attribute) {\n return null;\n }\n\n const fieldMetadata = metadatas[field.name];\n if (!fieldMetadata) {\n return null;\n }\n\n const { edit: metadata } = fieldMetadata;\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? (components.configurations[attribute.component]?.settings ?? {})\n : {};\n\n return {\n attribute,\n disabled: !metadata.editable,\n hint: metadata.description,\n label: metadata.label ?? '',\n name: field.name,\n // @ts-expect-error – mainField does exist on the metadata for a relation.\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n placeholder: metadata.placeholder ?? '',\n required: attribute.required ?? false,\n size: field.size,\n unique: 'unique' in attribute ? attribute.unique : false,\n visible: metadata.visible ?? true,\n type: attribute.type,\n };\n })\n .filter((field) => field !== null)\n ) as EditFieldLayout[][];\n};\n\n/* -------------------------------------------------------------------------------------------------\n * formatListLayout\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the complete configuration data, the schema & the components used in the schema and\n * formats a list view layout for the content-type. This is much simpler than the edit view layout as there\n * are less options to consider.\n */\nconst formatListLayout = (\n data: LayoutData,\n {\n schemas,\n schema,\n components,\n }: { schemas: Schema[]; schema?: Schema; components: ComponentsDictionary }\n): ListLayout => {\n const listMetadatas = Object.entries(data.contentType.metadatas).reduce<ListLayout['metadatas']>(\n (acc, [attribute, metadata]) => {\n return {\n ...acc,\n [attribute]: metadata.list,\n };\n },\n {}\n );\n /**\n * The fields arranged by the panels, new panels are made for dynamic zones only.\n */\n const listAttributes = convertListLayoutToFieldLayouts(\n data.contentType.layouts.list,\n schema?.attributes,\n listMetadatas,\n { configurations: data.components, schemas: components },\n schemas\n );\n\n return {\n layout: listAttributes,\n settings: { ...data.contentType.settings, displayName: schema?.info?.displayName },\n metadatas: listMetadatas,\n options: {\n ...schema?.options,\n ...schema?.pluginOptions,\n ...data.contentType.options,\n },\n };\n};\n\n/* -------------------------------------------------------------------------------------------------\n * convertListLayoutToFieldLayouts\n * -----------------------------------------------------------------------------------------------*/\n\n/**\n * @internal\n * @description takes the columns from the list view configuration and formats them into a generic object\n * combinining metadata and attribute data.\n *\n * @note We do use this to reformat the list of strings when updating the displayed headers for the list view.\n */\nconst convertListLayoutToFieldLayouts = (\n columns: LayoutData['contentType']['layouts']['list'],\n attributes: Schema['attributes'] = {},\n metadatas: ListLayout['metadatas'],\n components?: {\n configurations: Record<string, ComponentConfiguration>;\n schemas: ComponentsDictionary;\n },\n schemas: Schema[] = []\n) => {\n return columns\n .map((name) => {\n const attribute = attributes[name];\n\n if (!attribute) {\n return null;\n }\n\n const metadata = metadatas[name];\n if (!metadata) {\n return null;\n }\n\n const settings: Partial<Settings> =\n attribute.type === 'component' && components\n ? (components.configurations[attribute.component]?.settings ?? {})\n : {};\n\n return {\n attribute,\n label: metadata.label ?? '',\n mainField: getMainField(attribute, metadata.mainField || settings.mainField, {\n schemas,\n components: components?.schemas ?? {},\n }),\n name: name,\n searchable: metadata.searchable ?? true,\n sortable: metadata.sortable ?? true,\n } satisfies ListFieldLayout;\n })\n .filter((field) => field !== null) as ListFieldLayout[];\n};\n\nexport {\n useDocLayout,\n useDocumentLayout,\n convertListLayoutToFieldLayouts,\n convertEditLayoutToFieldLayouts,\n DEFAULT_SETTINGS,\n};\nexport type { EditLayout, EditFieldLayout, ListLayout, ListFieldLayout, UseDocumentLayout };\n"],"names":["DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","model","schema","components","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","schemas","useContentTypeSchema","currentData","data","isLoadingConfigs","error","useGetContentTypeConfigurationQuery","isConfigResolvedForModel","contentType","uid","stableLayoutsByModelRef","React","useRef","Map","useEffect","type","message","resolvedLayouts","useMemo","edit","formatEditLayout","list","formatListLayout","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","current","set","stableLayouts","get","editLayout","layout","metadatas","options","settings","listLayout","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","layouts","attributes","configurations","reduce","panels","row","some","field","push","componentEditAttributes","Object","entries","acc","configuration","componentSchema","icon","info","displayName","editMetadatas","attribute","metadata","pluginOptions","rows","map","name","fieldMetadata","component","disabled","editable","hint","description","label","getMainField","placeholder","required","size","unique","visible","filter","listMetadatas","listAttributes","convertListLayoutToFieldLayouts","columns","sortable"],"mappings":";;;;;;;;AAuHA;;AAEkG,2GAE5FA,gBAAAA,GAAmB;IACvBC,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,CAASzD,SAAS,EAAE;AAC3EsB,gBAAAA,OAAAA;gBACAhB,UAAAA,EAAYA,UAAAA,EAAYgB,WAAW;AACrC,aAAA,CAAA;YACAoE,IAAAA,EAAMA,IAAAA;YACN9F,UAAAA,EAAY0F,QAAAA,CAAS1F,UAAU,IAAI,IAAA;YACnCiH,QAAAA,EAAUvB,QAAAA,CAASuB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC/B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;"}
|
|
@@ -62,7 +62,10 @@ const usePersistentPartialQueryParams = (config)=>{
|
|
|
62
62
|
for (const [keyPrefix, entry] of Object.entries(config)){
|
|
63
63
|
const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);
|
|
64
64
|
const paramsToPersist = filterObjectKeys(query, paths);
|
|
65
|
-
if (Object.keys(paramsToPersist).length === 0)
|
|
65
|
+
if (Object.keys(paramsToPersist).length === 0) {
|
|
66
|
+
window.localStorage.removeItem(key);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
66
69
|
window.localStorage.setItem(key, JSON.stringify(paramsToPersist));
|
|
67
70
|
}
|
|
68
71
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePersistentQueryParams.js","sources":["../../../admin/src/hooks/usePersistentQueryParams.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { usePersistentStateScope, useQueryParams } from '@strapi/admin/strapi-admin';\nimport get from 'lodash/get';\nimport set from 'lodash/set';\n\ntype PropertyPath = Parameters<typeof get>[1];\n\ninterface PersistentQueryConfigEntry {\n paths: PropertyPath[];\n scoped?: boolean;\n}\n\nconst filterObjectKeys = (obj: object, keys: PropertyPath[]) => {\n const result: Record<string, unknown> = {};\n\n for (const path of keys) {\n const value = get(obj, path);\n\n if (value !== undefined) {\n set(result, path, value);\n }\n }\n\n return result;\n};\n\nexport type PersistentQueryConfig = Record<string, PersistentQueryConfigEntry>;\n\nconst normalizeConfigEntry = (\n key: string,\n entry: PersistentQueryConfigEntry,\n scope: string | false | undefined\n) => {\n const { paths } = entry;\n const isScoped = entry.scoped === true && !!scope;\n\n return {\n key: isScoped ? `${key}:${scope}` : key,\n paths,\n };\n};\n\nexport const usePersistentPartialQueryParams = (config: PersistentQueryConfig) => {\n const scope = usePersistentStateScope();\n const [{ query }, setQuery] = useQueryParams();\n const clonedConfig = JSON.stringify(config);\n const [isHydrated, setIsHydrated] = useState(false);\n\n // load query params from local storge\n useEffect(() => {\n const mergedFilteredQuery: Record<string, unknown> = {};\n\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const savedQueryParams = window.localStorage.getItem(key);\n if (!savedQueryParams) continue;\n\n let parsedSavedParams: Record<string, unknown>;\n try {\n parsedSavedParams = JSON.parse(savedQueryParams);\n } catch {\n continue;\n }\n if (Object.keys(parsedSavedParams).length === 0) continue;\n\n const filteredQuery = filterObjectKeys(parsedSavedParams, paths);\n Object.assign(mergedFilteredQuery, filteredQuery);\n }\n\n if (Object.keys(mergedFilteredQuery).length > 0) {\n setQuery({ ...mergedFilteredQuery, ...query }, 'push', true);\n }\n setIsHydrated(true);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [clonedConfig, scope]);\n\n // update local storage\n useEffect(() => {\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const paramsToPersist = filterObjectKeys(query, paths);\n if (Object.keys(paramsToPersist).length === 0) continue;\n window.localStorage.setItem(key, JSON.stringify(paramsToPersist));\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [query, clonedConfig, scope]);\n\n return { isHydrated };\n};\n"],"names":["filterObjectKeys","obj","keys","result","path","value","get","undefined","set","normalizeConfigEntry","key","entry","scope","paths","isScoped","scoped","usePersistentPartialQueryParams","config","usePersistentStateScope","query","setQuery","useQueryParams","clonedConfig","JSON","stringify","isHydrated","setIsHydrated","useState","useEffect","mergedFilteredQuery","keyPrefix","Object","entries","savedQueryParams","window","localStorage","getItem","parsedSavedParams","parse","length","filteredQuery","assign","paramsToPersist","setItem"],"mappings":";;;;;;;AAaA,MAAMA,gBAAAA,GAAmB,CAACC,GAAAA,EAAaC,IAAAA,GAAAA;AACrC,IAAA,MAAMC,SAAkC,EAAC;IAEzC,KAAK,MAAMC,QAAQF,IAAAA,CAAM;QACvB,MAAMG,KAAAA,GAAQC,IAAIL,GAAAA,EAAKG,IAAAA,CAAAA;AAEvB,QAAA,IAAIC,UAAUE,SAAAA,EAAW;AACvBC,YAAAA,GAAAA,CAAIL,QAAQC,IAAAA,EAAMC,KAAAA,CAAAA;AACpB,QAAA;AACF,IAAA;IAEA,OAAOF,MAAAA;AACT,CAAA;AAIA,MAAMM,oBAAAA,GAAuB,CAC3BC,GAAAA,EACAC,KAAAA,EACAC,KAAAA,GAAAA;IAEA,MAAM,EAAEC,KAAK,EAAE,GAAGF,KAAAA;AAClB,IAAA,MAAMG,WAAWH,KAAAA,CAAMI,MAAM,KAAK,IAAA,IAAQ,CAAC,CAACH,KAAAA;IAE5C,OAAO;AACLF,QAAAA,GAAAA,EAAKI,WAAW,CAAA,EAAGJ,GAAAA,CAAI,CAAC,EAAEE,OAAO,GAAGF,GAAAA;AACpCG,QAAAA;AACF,KAAA;AACF,CAAA;AAEO,MAAMG,kCAAkC,CAACC,MAAAA,GAAAA;AAC9C,IAAA,MAAML,KAAAA,GAAQM,mCAAAA,EAAAA;AACd,IAAA,MAAM,CAAC,EAAEC,KAAK,EAAE,EAAEC,SAAS,GAAGC,0BAAAA,EAAAA;IAC9B,MAAMC,YAAAA,GAAeC,IAAAA,CAAKC,SAAS,CAACP,MAAAA,CAAAA;AACpC,IAAA,MAAM,CAACQ,UAAAA,EAAYC,aAAAA,CAAc,GAAGC,cAAAA,CAAS,KAAA,CAAA;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AAOC,OAAO,CAACf,MAAAA,CAAAA,CAAS;YACvD,MAAM,EAAEP,GAAG,EAAEG,KAAK,EAAE,GAAGJ,oBAAAA,CAAqBqB,WAAWnB,KAAAA,EAAOC,KAAAA,CAAAA;YAE9D,MAAM8B,eAAAA,GAAkB1C,iBAAiBmB,KAAAA,EAAON,KAAAA,CAAAA;AAChD,YAAA,IAAIkB,OAAO7B,IAAI,CAACwC,eAAAA,CAAAA,CAAiBH,MAAM,KAAK,CAAA,EAAG;AAC/
|
|
1
|
+
{"version":3,"file":"usePersistentQueryParams.js","sources":["../../../admin/src/hooks/usePersistentQueryParams.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { usePersistentStateScope, useQueryParams } from '@strapi/admin/strapi-admin';\nimport get from 'lodash/get';\nimport set from 'lodash/set';\n\ntype PropertyPath = Parameters<typeof get>[1];\n\ninterface PersistentQueryConfigEntry {\n paths: PropertyPath[];\n scoped?: boolean;\n}\n\nconst filterObjectKeys = (obj: object, keys: PropertyPath[]) => {\n const result: Record<string, unknown> = {};\n\n for (const path of keys) {\n const value = get(obj, path);\n\n if (value !== undefined) {\n set(result, path, value);\n }\n }\n\n return result;\n};\n\nexport type PersistentQueryConfig = Record<string, PersistentQueryConfigEntry>;\n\nconst normalizeConfigEntry = (\n key: string,\n entry: PersistentQueryConfigEntry,\n scope: string | false | undefined\n) => {\n const { paths } = entry;\n const isScoped = entry.scoped === true && !!scope;\n\n return {\n key: isScoped ? `${key}:${scope}` : key,\n paths,\n };\n};\n\nexport const usePersistentPartialQueryParams = (config: PersistentQueryConfig) => {\n const scope = usePersistentStateScope();\n const [{ query }, setQuery] = useQueryParams();\n const clonedConfig = JSON.stringify(config);\n const [isHydrated, setIsHydrated] = useState(false);\n\n // load query params from local storge\n useEffect(() => {\n const mergedFilteredQuery: Record<string, unknown> = {};\n\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const savedQueryParams = window.localStorage.getItem(key);\n if (!savedQueryParams) continue;\n\n let parsedSavedParams: Record<string, unknown>;\n try {\n parsedSavedParams = JSON.parse(savedQueryParams);\n } catch {\n continue;\n }\n if (Object.keys(parsedSavedParams).length === 0) continue;\n\n const filteredQuery = filterObjectKeys(parsedSavedParams, paths);\n Object.assign(mergedFilteredQuery, filteredQuery);\n }\n\n if (Object.keys(mergedFilteredQuery).length > 0) {\n setQuery({ ...mergedFilteredQuery, ...query }, 'push', true);\n }\n setIsHydrated(true);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [clonedConfig, scope]);\n\n // update local storage\n useEffect(() => {\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const paramsToPersist = filterObjectKeys(query, paths);\n if (Object.keys(paramsToPersist).length === 0) {\n window.localStorage.removeItem(key);\n continue;\n }\n\n window.localStorage.setItem(key, JSON.stringify(paramsToPersist));\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [query, clonedConfig, scope]);\n\n return { isHydrated };\n};\n"],"names":["filterObjectKeys","obj","keys","result","path","value","get","undefined","set","normalizeConfigEntry","key","entry","scope","paths","isScoped","scoped","usePersistentPartialQueryParams","config","usePersistentStateScope","query","setQuery","useQueryParams","clonedConfig","JSON","stringify","isHydrated","setIsHydrated","useState","useEffect","mergedFilteredQuery","keyPrefix","Object","entries","savedQueryParams","window","localStorage","getItem","parsedSavedParams","parse","length","filteredQuery","assign","paramsToPersist","removeItem","setItem"],"mappings":";;;;;;;AAaA,MAAMA,gBAAAA,GAAmB,CAACC,GAAAA,EAAaC,IAAAA,GAAAA;AACrC,IAAA,MAAMC,SAAkC,EAAC;IAEzC,KAAK,MAAMC,QAAQF,IAAAA,CAAM;QACvB,MAAMG,KAAAA,GAAQC,IAAIL,GAAAA,EAAKG,IAAAA,CAAAA;AAEvB,QAAA,IAAIC,UAAUE,SAAAA,EAAW;AACvBC,YAAAA,GAAAA,CAAIL,QAA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IAAAA,CAAKC,SAAS,CAACkB,eAAAA,CAAAA,CAAAA;AAClD,QAAA;;IAEF,CAAA,EAAG;AAACvB,QAAAA,KAAAA;AAAOG,QAAAA,YAAAA;AAAcV,QAAAA;AAAM,KAAA,CAAA;IAE/B,OAAO;AAAEa,QAAAA;AAAW,KAAA;AACtB;;;;"}
|
|
@@ -60,7 +60,10 @@ const usePersistentPartialQueryParams = (config)=>{
|
|
|
60
60
|
for (const [keyPrefix, entry] of Object.entries(config)){
|
|
61
61
|
const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);
|
|
62
62
|
const paramsToPersist = filterObjectKeys(query, paths);
|
|
63
|
-
if (Object.keys(paramsToPersist).length === 0)
|
|
63
|
+
if (Object.keys(paramsToPersist).length === 0) {
|
|
64
|
+
window.localStorage.removeItem(key);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
64
67
|
window.localStorage.setItem(key, JSON.stringify(paramsToPersist));
|
|
65
68
|
}
|
|
66
69
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePersistentQueryParams.mjs","sources":["../../../admin/src/hooks/usePersistentQueryParams.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { usePersistentStateScope, useQueryParams } from '@strapi/admin/strapi-admin';\nimport get from 'lodash/get';\nimport set from 'lodash/set';\n\ntype PropertyPath = Parameters<typeof get>[1];\n\ninterface PersistentQueryConfigEntry {\n paths: PropertyPath[];\n scoped?: boolean;\n}\n\nconst filterObjectKeys = (obj: object, keys: PropertyPath[]) => {\n const result: Record<string, unknown> = {};\n\n for (const path of keys) {\n const value = get(obj, path);\n\n if (value !== undefined) {\n set(result, path, value);\n }\n }\n\n return result;\n};\n\nexport type PersistentQueryConfig = Record<string, PersistentQueryConfigEntry>;\n\nconst normalizeConfigEntry = (\n key: string,\n entry: PersistentQueryConfigEntry,\n scope: string | false | undefined\n) => {\n const { paths } = entry;\n const isScoped = entry.scoped === true && !!scope;\n\n return {\n key: isScoped ? `${key}:${scope}` : key,\n paths,\n };\n};\n\nexport const usePersistentPartialQueryParams = (config: PersistentQueryConfig) => {\n const scope = usePersistentStateScope();\n const [{ query }, setQuery] = useQueryParams();\n const clonedConfig = JSON.stringify(config);\n const [isHydrated, setIsHydrated] = useState(false);\n\n // load query params from local storge\n useEffect(() => {\n const mergedFilteredQuery: Record<string, unknown> = {};\n\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const savedQueryParams = window.localStorage.getItem(key);\n if (!savedQueryParams) continue;\n\n let parsedSavedParams: Record<string, unknown>;\n try {\n parsedSavedParams = JSON.parse(savedQueryParams);\n } catch {\n continue;\n }\n if (Object.keys(parsedSavedParams).length === 0) continue;\n\n const filteredQuery = filterObjectKeys(parsedSavedParams, paths);\n Object.assign(mergedFilteredQuery, filteredQuery);\n }\n\n if (Object.keys(mergedFilteredQuery).length > 0) {\n setQuery({ ...mergedFilteredQuery, ...query }, 'push', true);\n }\n setIsHydrated(true);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [clonedConfig, scope]);\n\n // update local storage\n useEffect(() => {\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const paramsToPersist = filterObjectKeys(query, paths);\n if (Object.keys(paramsToPersist).length === 0) continue;\n window.localStorage.setItem(key, JSON.stringify(paramsToPersist));\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [query, clonedConfig, scope]);\n\n return { isHydrated };\n};\n"],"names":["filterObjectKeys","obj","keys","result","path","value","get","undefined","set","normalizeConfigEntry","key","entry","scope","paths","isScoped","scoped","usePersistentPartialQueryParams","config","usePersistentStateScope","query","setQuery","useQueryParams","clonedConfig","JSON","stringify","isHydrated","setIsHydrated","useState","useEffect","mergedFilteredQuery","keyPrefix","Object","entries","savedQueryParams","window","localStorage","getItem","parsedSavedParams","parse","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D,MAAM8B,eAAAA,GAAkB1C,iBAAiBmB,KAAAA,EAAON,KAAAA,CAAAA;AAChD,YAAA,IAAIkB,OAAO7B,IAAI,CAACwC,eAAAA,CAAAA,CAAiBH,MAAM,KAAK,CAAA,EAAG;AAC/
|
|
1
|
+
{"version":3,"file":"usePersistentQueryParams.mjs","sources":["../../../admin/src/hooks/usePersistentQueryParams.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nimport { usePersistentStateScope, useQueryParams } from '@strapi/admin/strapi-admin';\nimport get from 'lodash/get';\nimport set from 'lodash/set';\n\ntype PropertyPath = Parameters<typeof get>[1];\n\ninterface PersistentQueryConfigEntry {\n paths: PropertyPath[];\n scoped?: boolean;\n}\n\nconst filterObjectKeys = (obj: object, keys: PropertyPath[]) => {\n const result: Record<string, unknown> = {};\n\n for (const path of keys) {\n const value = get(obj, path);\n\n if (value !== undefined) {\n set(result, path, value);\n }\n }\n\n return result;\n};\n\nexport type PersistentQueryConfig = Record<string, PersistentQueryConfigEntry>;\n\nconst normalizeConfigEntry = (\n key: string,\n entry: PersistentQueryConfigEntry,\n scope: string | false | undefined\n) => {\n const { paths } = entry;\n const isScoped = entry.scoped === true && !!scope;\n\n return {\n key: isScoped ? `${key}:${scope}` : key,\n paths,\n };\n};\n\nexport const usePersistentPartialQueryParams = (config: PersistentQueryConfig) => {\n const scope = usePersistentStateScope();\n const [{ query }, setQuery] = useQueryParams();\n const clonedConfig = JSON.stringify(config);\n const [isHydrated, setIsHydrated] = useState(false);\n\n // load query params from local storge\n useEffect(() => {\n const mergedFilteredQuery: Record<string, unknown> = {};\n\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const savedQueryParams = window.localStorage.getItem(key);\n if (!savedQueryParams) continue;\n\n let parsedSavedParams: Record<string, unknown>;\n try {\n parsedSavedParams = JSON.parse(savedQueryParams);\n } catch {\n continue;\n }\n if (Object.keys(parsedSavedParams).length === 0) continue;\n\n const filteredQuery = filterObjectKeys(parsedSavedParams, paths);\n Object.assign(mergedFilteredQuery, filteredQuery);\n }\n\n if (Object.keys(mergedFilteredQuery).length > 0) {\n setQuery({ ...mergedFilteredQuery, ...query }, 'push', true);\n }\n setIsHydrated(true);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [clonedConfig, scope]);\n\n // update local storage\n useEffect(() => {\n for (const [keyPrefix, entry] of Object.entries(config)) {\n const { key, paths } = normalizeConfigEntry(keyPrefix, entry, scope);\n\n const paramsToPersist = filterObjectKeys(query, paths);\n if (Object.keys(paramsToPersist).length === 0) {\n window.localStorage.removeItem(key);\n continue;\n }\n\n window.localStorage.setItem(key, JSON.stringify(paramsToPersist));\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [query, clonedConfig, scope]);\n\n return { isHydrated };\n};\n"],"names":["filterObjectKeys","obj","keys","result","path","value","get","undefined","set","normalizeConfigEntry","key","entry","scope","paths","isScoped","scoped","usePersistentPartialQueryParams","config","usePersistentStateScope","query","setQuery","useQueryParams","clonedConfig","JSON","stringify","isHydrated","setIsHydrated","useState","useEffect","mergedFilteredQuery","keyPrefix","Object","entries","savedQueryParams","window","localStorage","getItem","parsedSavedParams","parse","length","filteredQuery","assign","paramsToPersist","removeItem","setItem"],"mappings":";;;;;AAaA,MAAMA,gBAAAA,GAAmB,CAACC,GAAAA,EAAaC,IAAAA,GAAAA;AACrC,IAAA,MAAMC,SAAkC,EAAC;IAEzC,KAAK,MAAMC,QAAQF,IAAAA,CAAM;QACvB,MAAMG,KAAAA,GAAQC,IAAIL,GAAAA,EAAKG,IAAAA,CAAAA;AAEvB,QAAA,IAAIC,UAAUE,SAAAA,EAAW;AACvBC,YAAAA,GAAAA,CAAIL,QAAQC,IAAAA,EAAMC,KAAAA,CAAAA;AACpB,QAAA;AACF,IAAA;IAEA,OAAOF,MAAAA;AACT,CAAA;AAIA,MAAMM,oBAAAA,GAAuB,CAC3BC,GAAAA,EACAC,KAAAA,EACAC,K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AA;IAE/B,OAAO;AAAEa,QAAAA;AAAW,KAAA;AACtB;;;;"}
|
|
@@ -201,12 +201,16 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
201
201
|
schemas: components
|
|
202
202
|
});
|
|
203
203
|
const componentEditAttributes = Object.entries(data.components).reduce((acc, [uid, configuration])=>{
|
|
204
|
+
const componentSchema = components[uid];
|
|
205
|
+
if (!componentSchema) {
|
|
206
|
+
return acc;
|
|
207
|
+
}
|
|
204
208
|
acc[uid] = {
|
|
205
|
-
layout: useDocumentLayout.convertEditLayoutToFieldLayouts(configuration.layouts.edit,
|
|
209
|
+
layout: useDocumentLayout.convertEditLayoutToFieldLayouts(configuration.layouts.edit, componentSchema.attributes, configuration.metadatas),
|
|
206
210
|
settings: {
|
|
207
211
|
...configuration.settings,
|
|
208
|
-
icon:
|
|
209
|
-
displayName:
|
|
212
|
+
icon: componentSchema.info.icon,
|
|
213
|
+
displayName: componentSchema.info.displayName
|
|
210
214
|
}
|
|
211
215
|
};
|
|
212
216
|
return acc;
|