@strapi/content-manager 5.48.0 → 5.48.1
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/features/DocumentRBAC.js +9 -1
- package/dist/admin/features/DocumentRBAC.js.map +1 -1
- package/dist/admin/features/DocumentRBAC.mjs +9 -1
- package/dist/admin/features/DocumentRBAC.mjs.map +1 -1
- package/dist/admin/hooks/useContentTypeSchema.js +37 -17
- package/dist/admin/hooks/useContentTypeSchema.js.map +1 -1
- package/dist/admin/hooks/useContentTypeSchema.mjs +37 -17
- package/dist/admin/hooks/useContentTypeSchema.mjs.map +1 -1
- package/dist/admin/hooks/useDocumentLayout.js +43 -4
- package/dist/admin/hooks/useDocumentLayout.js.map +1 -1
- package/dist/admin/hooks/useDocumentLayout.mjs +43 -4
- package/dist/admin/hooks/useDocumentLayout.mjs.map +1 -1
- package/dist/admin/pages/ComponentConfigurationPage.js +6 -3
- package/dist/admin/pages/ComponentConfigurationPage.js.map +1 -1
- package/dist/admin/pages/ComponentConfigurationPage.mjs +6 -3
- package/dist/admin/pages/ComponentConfigurationPage.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js +5 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs +5 -2
- package/dist/admin/pages/EditView/components/FormInputs/BlocksInput/BlocksContent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js +11 -2
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs +11 -2
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js +9 -4
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs +9 -4
- package/dist/admin/pages/EditView/components/FormInputs/DynamicZone/Field.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/PreviewWysiwyg.js +2 -26
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/PreviewWysiwyg.js.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/PreviewWysiwyg.mjs +2 -26
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/PreviewWysiwyg.mjs.map +1 -1
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/utils/sanitizer.js +72 -0
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/utils/sanitizer.js.map +1 -0
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/utils/sanitizer.mjs +70 -0
- package/dist/admin/pages/EditView/components/FormInputs/Wysiwyg/utils/sanitizer.mjs.map +1 -0
- package/dist/admin/pages/ListConfiguration/ListConfigurationPage.js +4 -8
- package/dist/admin/pages/ListConfiguration/ListConfigurationPage.js.map +1 -1
- package/dist/admin/pages/ListConfiguration/ListConfigurationPage.mjs +5 -9
- package/dist/admin/pages/ListConfiguration/ListConfigurationPage.mjs.map +1 -1
- package/dist/admin/pages/ListConfiguration/components/SortDisplayedFields.js +6 -10
- package/dist/admin/pages/ListConfiguration/components/SortDisplayedFields.js.map +1 -1
- package/dist/admin/pages/ListConfiguration/components/SortDisplayedFields.mjs +6 -10
- package/dist/admin/pages/ListConfiguration/components/SortDisplayedFields.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/Filters.js +7 -9
- package/dist/admin/pages/ListView/components/Filters.js.map +1 -1
- package/dist/admin/pages/ListView/components/Filters.mjs +7 -9
- package/dist/admin/pages/ListView/components/Filters.mjs.map +1 -1
- package/dist/admin/pages/ListView/components/TableCells/Media.js +5 -4
- package/dist/admin/pages/ListView/components/TableCells/Media.js.map +1 -1
- package/dist/admin/pages/ListView/components/TableCells/Media.mjs +5 -4
- package/dist/admin/pages/ListView/components/TableCells/Media.mjs.map +1 -1
- package/dist/admin/pages/formatComponentConfigurationEditLayout.js +15 -9
- package/dist/admin/pages/formatComponentConfigurationEditLayout.js.map +1 -1
- package/dist/admin/pages/formatComponentConfigurationEditLayout.mjs +15 -9
- package/dist/admin/pages/formatComponentConfigurationEditLayout.mjs.map +1 -1
- package/dist/admin/services/components.js +3 -2
- package/dist/admin/services/components.js.map +1 -1
- package/dist/admin/services/components.mjs +3 -2
- package/dist/admin/services/components.mjs.map +1 -1
- package/dist/admin/services/contentTypes.js +4 -3
- package/dist/admin/services/contentTypes.js.map +1 -1
- package/dist/admin/services/contentTypes.mjs +4 -3
- package/dist/admin/services/contentTypes.mjs.map +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/DynamicZone/DynamicComponent.d.ts +1 -1
- package/dist/admin/src/pages/EditView/components/FormInputs/Wysiwyg/utils/sanitizer.d.ts +2 -0
- package/dist/admin/src/pages/ListConfiguration/components/SortDisplayedFields.d.ts +2 -2
- package/dist/admin/src/pages/ListView/components/TableCells/Media.d.ts +2 -2
- package/dist/admin/src/pages/formatComponentConfigurationEditLayout.d.ts +3 -1
- package/dist/admin/src/utils/layouts/normalizeContentManagerLayout.d.ts +24 -0
- package/dist/admin/translations/en.json.js +1 -0
- package/dist/admin/translations/en.json.js.map +1 -1
- package/dist/admin/translations/en.json.mjs +1 -0
- package/dist/admin/translations/en.json.mjs.map +1 -1
- package/dist/admin/utils/attributes.js +17 -2
- package/dist/admin/utils/attributes.js.map +1 -1
- package/dist/admin/utils/attributes.mjs +17 -2
- package/dist/admin/utils/attributes.mjs.map +1 -1
- package/dist/admin/utils/layouts/normalizeContentManagerLayout.js +329 -0
- package/dist/admin/utils/layouts/normalizeContentManagerLayout.js.map +1 -0
- package/dist/admin/utils/layouts/normalizeContentManagerLayout.mjs +321 -0
- package/dist/admin/utils/layouts/normalizeContentManagerLayout.mjs.map +1 -0
- package/dist/server/controllers/collection-types.js +7 -2
- package/dist/server/controllers/collection-types.js.map +1 -1
- package/dist/server/controllers/collection-types.mjs +7 -2
- package/dist/server/controllers/collection-types.mjs.map +1 -1
- package/dist/server/src/controllers/collection-types.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -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 {\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,MAAMF,gBAAgB,CAAA;IAC5F,MAAM,EAAEG,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;AAC/B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,8BAAAA,EAAAA;AACpD,IAAA,MAAM,EAAEC,SAAAA,EAAWC,gBAAgB,EAAEC,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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;;;;;;;;"}
|
|
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';\nimport { normalizeContentManagerLayout } from '../utils/layouts/normalizeContentManagerLayout';\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\ntype ResolvedLayouts = {\n edit: EditLayout;\n list: ListLayout;\n listViewConversionContext: ListViewConversionContext;\n};\n\ntype ResolvedLayoutCacheEntry = {\n components: ComponentsDictionary;\n data: LayoutData;\n model: string;\n schema?: Schema;\n schemas: Schema[];\n value: ResolvedLayouts;\n};\n\nconst RESOLVED_LAYOUT_CACHE_LIMIT = 25;\n// Module-level cache keeps resolved layout object identities stable across hook instances\n// when RTK Query returns the same schema/configuration references.\nconst resolvedLayoutCache: ResolvedLayoutCacheEntry[] = [];\n\nconst getCachedResolvedLayouts = ({\n components,\n data,\n model,\n schema,\n schemas,\n}: Omit<ResolvedLayoutCacheEntry, 'value'>) => {\n return resolvedLayoutCache.find(\n (entry) =>\n entry.components === components &&\n entry.data === data &&\n entry.model === model &&\n entry.schema === schema &&\n entry.schemas === schemas\n )?.value;\n};\n\nconst setCachedResolvedLayouts = (entry: ResolvedLayoutCacheEntry) => {\n resolvedLayoutCache.unshift(entry);\n\n if (resolvedLayoutCache.length > RESOLVED_LAYOUT_CACHE_LIMIT) {\n resolvedLayoutCache.pop();\n }\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 cachedLayouts = getCachedResolvedLayouts({ components, data, model, schema, schemas });\n\n if (cachedLayouts) {\n return cachedLayouts;\n }\n\n const normalizedData = normalizeContentManagerLayout(data, { schemas, schema, components });\n const edit = formatEditLayout(normalizedData, { schemas, schema, components });\n const list = formatListLayout(normalizedData, { schemas, schema, components });\n const listViewConversionContext: ListViewConversionContext = {\n componentConfigurations: normalizedData.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n\n const layouts = { edit, list, listViewConversionContext };\n\n setCachedResolvedLayouts({ components, data, model, schema, schemas, value: layouts });\n\n return layouts;\n }, [data, isLoading, model, 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":["RESOLVED_LAYOUT_CACHE_LIMIT","resolvedLayoutCache","getCachedResolvedLayouts","components","data","model","schema","schemas","find","entry","value","setCachedResolvedLayouts","unshift","length","pop","DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","useContentTypeSchema","currentData","isLoadingConfigs","error","useGetContentTypeConfigurationQuery","isConfigResolvedForModel","contentType","uid","stableLayoutsByModelRef","React","useRef","Map","useEffect","type","message","resolvedLayouts","useMemo","cachedLayouts","normalizedData","normalizeContentManagerLayout","edit","formatEditLayout","list","formatListLayout","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","layouts","current","set","stableLayouts","get","editLayout","layout","metadatas","options","settings","listLayout","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuIA,MAAMA,2BAAAA,GAA8B,EAAA;AACpC;AACA;AACA,MAAMC,sBAAkD,EAAE;AAE1D,MAAMC,wBAAAA,GAA2B,CAAC,EAChCC,UAAU,EACVC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACiC,GAAA;IACxC,OAAON,mBAAAA,CAAoBO,IAAI,CAC7B,CAACC,KAAAA,GACCA,MAAMN,UAAU,KAAKA,UAAAA,IACrBM,KAAAA,CAAML,IAAI,KAAKA,QACfK,KAAAA,CAAMJ,KAAK,KAAKA,KAAAA,IAChBI,KAAAA,CAAMH,MAAM,KAAKA,MAAAA,IACjBG,KAAAA,CAAMF,OAAO,KAAKA,OAAAA,CAAAA,EACnBG,KAAAA;AACL,CAAA;AAEA,MAAMC,2BAA2B,CAACF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 +3,23 @@ import { useQueryParams, useStrapiApp, useNotification, useAPIErrorHandler } fro
|
|
|
3
3
|
import { HOOKS } from '../constants/hooks.mjs';
|
|
4
4
|
import { useGetContentTypeConfigurationQuery } from '../services/contentTypes.mjs';
|
|
5
5
|
import { getMainField } from '../utils/attributes.mjs';
|
|
6
|
+
import { normalizeContentManagerLayout } from '../utils/layouts/normalizeContentManagerLayout.mjs';
|
|
6
7
|
import { useContentTypeSchema } from './useContentTypeSchema.mjs';
|
|
7
8
|
import { useDocument, useDoc } from './useDocument.mjs';
|
|
8
9
|
|
|
10
|
+
const RESOLVED_LAYOUT_CACHE_LIMIT = 25;
|
|
11
|
+
// Module-level cache keeps resolved layout object identities stable across hook instances
|
|
12
|
+
// when RTK Query returns the same schema/configuration references.
|
|
13
|
+
const resolvedLayoutCache = [];
|
|
14
|
+
const getCachedResolvedLayouts = ({ components, data, model, schema, schemas })=>{
|
|
15
|
+
return resolvedLayoutCache.find((entry)=>entry.components === components && entry.data === data && entry.model === model && entry.schema === schema && entry.schemas === schemas)?.value;
|
|
16
|
+
};
|
|
17
|
+
const setCachedResolvedLayouts = (entry)=>{
|
|
18
|
+
resolvedLayoutCache.unshift(entry);
|
|
19
|
+
if (resolvedLayoutCache.length > RESOLVED_LAYOUT_CACHE_LIMIT) {
|
|
20
|
+
resolvedLayoutCache.pop();
|
|
21
|
+
}
|
|
22
|
+
};
|
|
9
23
|
/* -------------------------------------------------------------------------------------------------
|
|
10
24
|
* useDocumentLayout
|
|
11
25
|
* -----------------------------------------------------------------------------------------------*/ const DEFAULT_SETTINGS = {
|
|
@@ -68,29 +82,54 @@ import { useDocument, useDoc } from './useDocument.mjs';
|
|
|
68
82
|
if (!data || isLoading) {
|
|
69
83
|
return null;
|
|
70
84
|
}
|
|
71
|
-
const
|
|
85
|
+
const cachedLayouts = getCachedResolvedLayouts({
|
|
86
|
+
components,
|
|
87
|
+
data,
|
|
88
|
+
model,
|
|
89
|
+
schema,
|
|
90
|
+
schemas
|
|
91
|
+
});
|
|
92
|
+
if (cachedLayouts) {
|
|
93
|
+
return cachedLayouts;
|
|
94
|
+
}
|
|
95
|
+
const normalizedData = normalizeContentManagerLayout(data, {
|
|
96
|
+
schemas,
|
|
97
|
+
schema,
|
|
98
|
+
components
|
|
99
|
+
});
|
|
100
|
+
const edit = formatEditLayout(normalizedData, {
|
|
72
101
|
schemas,
|
|
73
102
|
schema,
|
|
74
103
|
components
|
|
75
104
|
});
|
|
76
|
-
const list = formatListLayout(
|
|
105
|
+
const list = formatListLayout(normalizedData, {
|
|
77
106
|
schemas,
|
|
78
107
|
schema,
|
|
79
108
|
components
|
|
80
109
|
});
|
|
81
110
|
const listViewConversionContext = {
|
|
82
|
-
componentConfigurations:
|
|
111
|
+
componentConfigurations: normalizedData.components,
|
|
83
112
|
componentSchemas: components,
|
|
84
113
|
contentTypeSchemas: schemas
|
|
85
114
|
};
|
|
86
|
-
|
|
115
|
+
const layouts = {
|
|
87
116
|
edit,
|
|
88
117
|
list,
|
|
89
118
|
listViewConversionContext
|
|
90
119
|
};
|
|
120
|
+
setCachedResolvedLayouts({
|
|
121
|
+
components,
|
|
122
|
+
data,
|
|
123
|
+
model,
|
|
124
|
+
schema,
|
|
125
|
+
schemas,
|
|
126
|
+
value: layouts
|
|
127
|
+
});
|
|
128
|
+
return layouts;
|
|
91
129
|
}, [
|
|
92
130
|
data,
|
|
93
131
|
isLoading,
|
|
132
|
+
model,
|
|
94
133
|
schemas,
|
|
95
134
|
schema,
|
|
96
135
|
components
|
|
@@ -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 {\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,EAA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AAA,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;;;;"}
|
|
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';\nimport { normalizeContentManagerLayout } from '../utils/layouts/normalizeContentManagerLayout';\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\ntype ResolvedLayouts = {\n edit: EditLayout;\n list: ListLayout;\n listViewConversionContext: ListViewConversionContext;\n};\n\ntype ResolvedLayoutCacheEntry = {\n components: ComponentsDictionary;\n data: LayoutData;\n model: string;\n schema?: Schema;\n schemas: Schema[];\n value: ResolvedLayouts;\n};\n\nconst RESOLVED_LAYOUT_CACHE_LIMIT = 25;\n// Module-level cache keeps resolved layout object identities stable across hook instances\n// when RTK Query returns the same schema/configuration references.\nconst resolvedLayoutCache: ResolvedLayoutCacheEntry[] = [];\n\nconst getCachedResolvedLayouts = ({\n components,\n data,\n model,\n schema,\n schemas,\n}: Omit<ResolvedLayoutCacheEntry, 'value'>) => {\n return resolvedLayoutCache.find(\n (entry) =>\n entry.components === components &&\n entry.data === data &&\n entry.model === model &&\n entry.schema === schema &&\n entry.schemas === schemas\n )?.value;\n};\n\nconst setCachedResolvedLayouts = (entry: ResolvedLayoutCacheEntry) => {\n resolvedLayoutCache.unshift(entry);\n\n if (resolvedLayoutCache.length > RESOLVED_LAYOUT_CACHE_LIMIT) {\n resolvedLayoutCache.pop();\n }\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 cachedLayouts = getCachedResolvedLayouts({ components, data, model, schema, schemas });\n\n if (cachedLayouts) {\n return cachedLayouts;\n }\n\n const normalizedData = normalizeContentManagerLayout(data, { schemas, schema, components });\n const edit = formatEditLayout(normalizedData, { schemas, schema, components });\n const list = formatListLayout(normalizedData, { schemas, schema, components });\n const listViewConversionContext: ListViewConversionContext = {\n componentConfigurations: normalizedData.components,\n componentSchemas: components,\n contentTypeSchemas: schemas,\n };\n\n const layouts = { edit, list, listViewConversionContext };\n\n setCachedResolvedLayouts({ components, data, model, schema, schemas, value: layouts });\n\n return layouts;\n }, [data, isLoading, model, 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":["RESOLVED_LAYOUT_CACHE_LIMIT","resolvedLayoutCache","getCachedResolvedLayouts","components","data","model","schema","schemas","find","entry","value","setCachedResolvedLayouts","unshift","length","pop","DEFAULT_SETTINGS","bulkable","filterable","searchable","pagination","defaultSortBy","defaultSortOrder","mainField","pageSize","relationOpenMode","useDocumentLayout","useDocument","collectionType","skip","query","useQueryParams","runHookWaterfall","useStrapiApp","state","toggleNotification","useNotification","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","isLoading","isLoadingSchemas","useContentTypeSchema","currentData","isLoadingConfigs","error","useGetContentTypeConfigurationQuery","isConfigResolvedForModel","contentType","uid","stableLayoutsByModelRef","React","useRef","Map","useEffect","type","message","resolvedLayouts","useMemo","cachedLayouts","normalizedData","normalizeContentManagerLayout","edit","formatEditLayout","list","formatListLayout","listViewConversionContext","componentConfigurations","componentSchemas","contentTypeSchemas","layouts","current","set","stableLayouts","get","editLayout","layout","metadatas","options","settings","listLayout","HOOKS","MUTATE_EDIT_VIEW_LAYOUT","useDocLayout","useDoc","currentPanelIndex","panelledEditAttributes","convertEditLayoutToFieldLayouts","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":";;;;;;;;;AAuIA,MAAMA,2BAAAA,GAA8B,EAAA;AACpC;AACA;AACA,MAAMC,sBAAkD,EAAE;AAE1D,MAAMC,wBAAAA,GAA2B,CAAC,EAChCC,UAAU,EACVC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,OAAO,EACiC,GAAA;IACxC,OAAON,mBAAAA,CAAoBO,IAAI,CAC7B,CAACC,KAAAA,GACCA,MAAMN,UAAU,KAAKA,UAAAA,IACrBM,KAAAA,CAAML,IAAI,KAAKA,QACfK,KAAAA,CAAMJ,KAAK,KAAKA,KAAAA,IAChBI,KAAAA,CAAMH,MAAM,KAAKA,MAAAA,IACjBG,KAAAA,CAAMF,OAAO,KAAKA,OAAAA,CAAAA,EACnBG,KAAAA;AACL,CAAA;AAEA,MAAMC,2BAA2B,CAACF,KAAAA,GAAAA;AAChCR,IAAAA,mBAAAA,CAAoBW,OAAO,CAACH,KAAAA,CAAAA;IAE5B,IAAIR,mBAAAA,CAAoBY,MAAM,GAAGb,2BAAAA,EAA6B;AAC5DC,QAAAA,mBAAAA,CAAoBa,GAAG,EAAA;AACzB,IAAA;AACF,CAAA;AAEA;;AAEkG,2GAE5FC,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,CAACpB,KAAAA,GAAAA;AAC5C,IAAA,MAAM,EAA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D,aAC7BA,UAAAA,CAAWqF,cAAc,CAACiB,SAAAA,CAAUO,SAAS,CAAC,EAAElC,QAAAA,IAAY,KAC7D,EAAC;QAEP,OAAO;AACL2B,YAAAA,SAAAA;YACAY,KAAAA,EAAOX,QAAAA,CAASW,KAAK,IAAI,EAAA;AACzB/F,YAAAA,SAAAA,EAAWgG,aAAab,SAAAA,EAAWC,QAAAA,CAASpF,SAAS,IAAIwD,QAAAA,CAASxD,SAAS,EAAE;AAC3Ef,gBAAAA,OAAAA;gBACAJ,UAAAA,EAAYA,UAAAA,EAAYI,WAAW;AACrC,aAAA,CAAA;YACAuG,IAAAA,EAAMA,IAAAA;YACN5F,UAAAA,EAAYwF,QAAAA,CAASxF,UAAU,IAAI,IAAA;YACnC+G,QAAAA,EAAUvB,QAAAA,CAASuB,QAAQ,IAAI;AACjC,SAAA;AACF,IAAA,CAAA,CAAA,CACCL,MAAM,CAAC,CAAC/B,KAAAA,GAAUA,KAAAA,KAAU,IAAA,CAAA;AACjC;;;;"}
|
|
@@ -46,7 +46,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
46
46
|
const { toggleNotification } = strapiAdmin.useNotification();
|
|
47
47
|
const { formatMessage } = reactIntl.useIntl();
|
|
48
48
|
const { _unstableFormatAPIError: formatAPIError } = strapiAdmin.useAPIErrorHandler();
|
|
49
|
-
const { components: components$1, fieldSizes, schema, error: errorSchema, isLoading: isLoadingSchema, isFetching: isFetchingSchema } = init.useGetInitialDataQuery(undefined, {
|
|
49
|
+
const { components: components$1, fieldSizes, schema, schemas, error: errorSchema, isLoading: isLoadingSchema, isFetching: isFetchingSchema } = init.useGetInitialDataQuery(undefined, {
|
|
50
50
|
selectFromResult: (res)=>{
|
|
51
51
|
const schema = res.data?.components.find((ct)=>ct.uid === model);
|
|
52
52
|
const componentsByKey = res.data?.components.reduce((acc, component)=>{
|
|
@@ -64,6 +64,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
64
64
|
error: res.error,
|
|
65
65
|
components,
|
|
66
66
|
schema,
|
|
67
|
+
schemas: res.data?.contentTypes ?? [],
|
|
67
68
|
fieldSizes
|
|
68
69
|
};
|
|
69
70
|
}
|
|
@@ -99,7 +100,8 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
99
100
|
*/ const isLoading = isLoadingConfig || isLoadingSchema || isFetchingConfig || isFetchingSchema;
|
|
100
101
|
const editLayout = React__namespace.useMemo(()=>data && !isLoading ? formatComponentConfigurationEditLayout.formatComponentConfigurationEditLayout(data, {
|
|
101
102
|
schema,
|
|
102
|
-
components: components$1
|
|
103
|
+
components: components$1,
|
|
104
|
+
schemas
|
|
103
105
|
}) : {
|
|
104
106
|
layout: [],
|
|
105
107
|
components: {},
|
|
@@ -110,7 +112,8 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
110
112
|
data,
|
|
111
113
|
isLoading,
|
|
112
114
|
schema,
|
|
113
|
-
components$1
|
|
115
|
+
components$1,
|
|
116
|
+
schemas
|
|
114
117
|
]);
|
|
115
118
|
const [updateConfiguration] = components.useUpdateComponentConfigurationMutation();
|
|
116
119
|
const handleSubmit = async (formData)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentConfigurationPage.js","sources":["../../../admin/src/pages/ComponentConfigurationPage.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Page, useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\n\nimport { TEMP_FIELD_NAME } from '../components/ConfigurationForm/Fields';\nimport { ConfigurationForm, ConfigurationFormProps } from '../components/ConfigurationForm/Form';\nimport { ComponentsDictionary, extractContentTypeComponents } from '../hooks/useContentTypeSchema';\nimport { DEFAULT_SETTINGS, EditLayout } from '../hooks/useDocumentLayout';\nimport { useTypedSelector } from '../modules/hooks';\nimport {\n useGetComponentConfigurationQuery,\n useUpdateComponentConfigurationMutation,\n} from '../services/components';\nimport { useGetInitialDataQuery } from '../services/init';\nimport { setIn } from '../utils/objects';\n\nimport { formatComponentConfigurationEditLayout } from './formatComponentConfigurationEditLayout';\n\nimport type { Component } from '../../../shared/contracts/components';\nimport type { Metadatas } from '../../../shared/contracts/content-types';\n\n/* -------------------------------------------------------------------------------------------------\n * ComponentConfigurationPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ComponentConfigurationPage = () => {\n /**\n * useDocumentLayout only works for documents, not components,\n * it feels weird to make that hook work for both when this is SUCH\n * a unique use case and we only do it here, so in short, we essentially\n * just extracted the logic to make an edit view layout and reproduced it here.\n */\n const { slug: model } = useParams<{ slug: string }>();\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const {\n components,\n fieldSizes,\n schema,\n error: errorSchema,\n isLoading: isLoadingSchema,\n isFetching: isFetchingSchema,\n } = useGetInitialDataQuery(undefined, {\n selectFromResult: (res) => {\n const schema = res.data?.components.find((ct) => ct.uid === model);\n\n const componentsByKey = res.data?.components.reduce<ComponentsDictionary>(\n (acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n },\n {}\n );\n\n const components = extractContentTypeComponents(schema?.attributes, componentsByKey);\n\n const fieldSizes = Object.entries(res.data?.fieldSizes ?? {}).reduce<\n ConfigurationFormProps['fieldSizes']\n >((acc, [attributeName, { default: size }]) => {\n acc[attributeName] = size;\n\n return acc;\n }, {});\n\n return {\n isFetching: res.isFetching,\n isLoading: res.isLoading,\n error: res.error,\n components,\n schema,\n fieldSizes,\n };\n },\n });\n\n React.useEffect(() => {\n if (errorSchema) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(errorSchema),\n });\n }\n }, [errorSchema, formatAPIError, toggleNotification]);\n\n const {\n data,\n isLoading: isLoadingConfig,\n isFetching: isFetchingConfig,\n error,\n } = useGetComponentConfigurationQuery(model ?? '');\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n /**\n * you **must** check if we're loading or fetching in case the component gets new props\n * but nothing was unmounted, it then becomes a fetch, not a load.\n */\n const isLoading = isLoadingConfig || isLoadingSchema || isFetchingConfig || isFetchingSchema;\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatComponentConfigurationEditLayout(data, { schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schema, components]\n );\n\n const [updateConfiguration] = useUpdateComponentConfigurationMutation();\n const handleSubmit: ConfigurationFormProps['onSubmit'] = async (formData) => {\n try {\n /**\n * We reconstruct the metadatas object by taking the existing list metadatas\n * and re-merging that by attribute name with the current list metadatas, whilst overwriting\n * the data from the form we've built.\n */\n const meta = Object.entries(data?.component.metadatas ?? {}).reduce<Metadatas>(\n (acc, [name, { edit, list }]) => {\n const {\n __temp_key__,\n size: _size,\n name: _name,\n ...editedMetadata\n } = formData.layout.flatMap((row) => row.children).find((field) => field.name === name) ??\n {};\n\n acc[name] = {\n edit: {\n ...edit,\n ...editedMetadata,\n },\n list,\n };\n\n return acc;\n },\n {}\n );\n\n const res = await updateConfiguration({\n layouts: {\n edit: formData.layout.map((row) =>\n row.children.reduce<Array<{ name: string; size: number }>>((acc, { name, size }) => {\n if (name !== TEMP_FIELD_NAME) {\n return [...acc, { name, size }];\n }\n\n return acc;\n }, [])\n ),\n list: data?.component.layouts.list,\n },\n settings: setIn(formData.settings, 'displayName', undefined),\n metadatas: meta,\n uid: model,\n });\n\n if ('data' in res) {\n toggleNotification({\n type: 'success',\n message: formatMessage({ id: 'notification.success.saved', defaultMessage: 'Saved' }),\n });\n } else {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(res.error),\n });\n }\n } catch {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occurred' }),\n });\n }\n };\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || errorSchema || !schema) {\n return <Page.Error />;\n }\n\n return (\n <>\n <Page.Title>{`Configure ${editLayout.settings.displayName} Edit View`}</Page.Title>\n <ConfigurationForm\n onSubmit={handleSubmit}\n attributes={schema.attributes}\n fieldSizes={fieldSizes}\n layout={editLayout}\n />\n </>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedComponentConfigurationPage = () => {\n const permissions = useTypedSelector(\n (state) => state.admin_app.permissions.contentManager?.componentsConfigurations\n );\n\n return (\n <Page.Protect permissions={permissions}>\n <ComponentConfigurationPage />\n </Page.Protect>\n );\n};\n\nexport { ComponentConfigurationPage, ProtectedComponentConfigurationPage };\n"],"names":["ComponentConfigurationPage","slug","model","useParams","toggleNotification","useNotification","formatMessage","useIntl","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","components","fieldSizes","schema","error","errorSchema","isLoading","isLoadingSchema","isFetching","isFetchingSchema","useGetInitialDataQuery","undefined","selectFromResult","res","data","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","entries","attributeName","default","size","React","useEffect","type","message","isLoadingConfig","isFetchingConfig","useGetComponentConfigurationQuery","editLayout","useMemo","formatComponentConfigurationEditLayout","layout","metadatas","options","settings","DEFAULT_SETTINGS","updateConfiguration","useUpdateComponentConfigurationMutation","handleSubmit","formData","meta","name","edit","list","__temp_key__","_size","_name","editedMetadata","flatMap","row","children","field","layouts","map","TEMP_FIELD_NAME","setIn","id","defaultMessage","_jsx","Page","Loading","Error","_jsxs","_Fragment","Title","displayName","ConfigurationForm","onSubmit","ProtectedComponentConfigurationPage","permissions","useTypedSelector","state","admin_app","contentManager","componentsConfigurations","Protect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;AAEkG,2GAE5FA,0BAAAA,GAA6B,IAAA;AACjC;;;;;AAKC,MAC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AA;AACF,QAAA;AACF,IAAA,CAAA;AAEA,IAAA,IAAI3D,SAAAA,EAAW;QACb,qBAAO4D,cAAA,CAACC,iBAAKC,OAAO,EAAA,EAAA,CAAA;AACtB,IAAA;IAEA,IAAIhE,KAAAA,IAASC,WAAAA,IAAe,CAACF,MAAAA,EAAQ;QACnC,qBAAO+D,cAAA,CAACC,iBAAKE,KAAK,EAAA,EAAA,CAAA;AACpB,IAAA;IAEA,qBACEC,eAAA,CAAAC,mBAAA,EAAA;;AACE,0BAAAL,cAAA,CAACC,iBAAKK,KAAK,EAAA;0BAAE,CAAC,UAAU,EAAEpC,UAAAA,CAAWM,QAAQ,CAAC+B,WAAW,CAAC,UAAU;;0BACpEP,cAAA,CAACQ,sBAAAA,EAAAA;gBACCC,QAAAA,EAAU7B,YAAAA;AACVvB,gBAAAA,UAAAA,EAAYpB,OAAOoB,UAAU;gBAC7BrB,UAAAA,EAAYA,UAAAA;gBACZqC,MAAAA,EAAQH;;;;AAIhB;AAEA;;AAEkG,2GAE5FwC,mCAAAA,GAAsC,IAAA;IAC1C,MAAMC,WAAAA,GAAcC,sBAAAA,CAClB,CAACC,KAAAA,GAAUA,KAAAA,CAAMC,SAAS,CAACH,WAAW,CAACI,cAAc,EAAEC,wBAAAA,CAAAA;IAGzD,qBACEhB,cAAA,CAACC,iBAAKgB,OAAO,EAAA;QAACN,WAAAA,EAAaA,WAAAA;AACzB,QAAA,QAAA,gBAAAX,cAAA,CAAC5E,0BAAAA,EAAAA,EAAAA;;AAGP;;;;;"}
|
|
1
|
+
{"version":3,"file":"ComponentConfigurationPage.js","sources":["../../../admin/src/pages/ComponentConfigurationPage.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Page, useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\n\nimport { TEMP_FIELD_NAME } from '../components/ConfigurationForm/Fields';\nimport { ConfigurationForm, ConfigurationFormProps } from '../components/ConfigurationForm/Form';\nimport { ComponentsDictionary, extractContentTypeComponents } from '../hooks/useContentTypeSchema';\nimport { DEFAULT_SETTINGS, EditLayout } from '../hooks/useDocumentLayout';\nimport { useTypedSelector } from '../modules/hooks';\nimport {\n useGetComponentConfigurationQuery,\n useUpdateComponentConfigurationMutation,\n} from '../services/components';\nimport { useGetInitialDataQuery } from '../services/init';\nimport { setIn } from '../utils/objects';\n\nimport { formatComponentConfigurationEditLayout } from './formatComponentConfigurationEditLayout';\n\nimport type { Component } from '../../../shared/contracts/components';\nimport type { Metadatas } from '../../../shared/contracts/content-types';\n\n/* -------------------------------------------------------------------------------------------------\n * ComponentConfigurationPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ComponentConfigurationPage = () => {\n /**\n * useDocumentLayout only works for documents, not components,\n * it feels weird to make that hook work for both when this is SUCH\n * a unique use case and we only do it here, so in short, we essentially\n * just extracted the logic to make an edit view layout and reproduced it here.\n */\n const { slug: model } = useParams<{ slug: string }>();\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const {\n components,\n fieldSizes,\n schema,\n schemas,\n error: errorSchema,\n isLoading: isLoadingSchema,\n isFetching: isFetchingSchema,\n } = useGetInitialDataQuery(undefined, {\n selectFromResult: (res) => {\n const schema = res.data?.components.find((ct) => ct.uid === model);\n\n const componentsByKey = res.data?.components.reduce<ComponentsDictionary>(\n (acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n },\n {}\n );\n\n const components = extractContentTypeComponents(schema?.attributes, componentsByKey);\n\n const fieldSizes = Object.entries(res.data?.fieldSizes ?? {}).reduce<\n ConfigurationFormProps['fieldSizes']\n >((acc, [attributeName, { default: size }]) => {\n acc[attributeName] = size;\n\n return acc;\n }, {});\n\n return {\n isFetching: res.isFetching,\n isLoading: res.isLoading,\n error: res.error,\n components,\n schema,\n schemas: res.data?.contentTypes ?? [],\n fieldSizes,\n };\n },\n });\n\n React.useEffect(() => {\n if (errorSchema) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(errorSchema),\n });\n }\n }, [errorSchema, formatAPIError, toggleNotification]);\n\n const {\n data,\n isLoading: isLoadingConfig,\n isFetching: isFetchingConfig,\n error,\n } = useGetComponentConfigurationQuery(model ?? '');\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n /**\n * you **must** check if we're loading or fetching in case the component gets new props\n * but nothing was unmounted, it then becomes a fetch, not a load.\n */\n const isLoading = isLoadingConfig || isLoadingSchema || isFetchingConfig || isFetchingSchema;\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatComponentConfigurationEditLayout(data, { schema, components, schemas })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schema, components, schemas]\n );\n\n const [updateConfiguration] = useUpdateComponentConfigurationMutation();\n const handleSubmit: ConfigurationFormProps['onSubmit'] = async (formData) => {\n try {\n /**\n * We reconstruct the metadatas object by taking the existing list metadatas\n * and re-merging that by attribute name with the current list metadatas, whilst overwriting\n * the data from the form we've built.\n */\n const meta = Object.entries(data?.component.metadatas ?? {}).reduce<Metadatas>(\n (acc, [name, { edit, list }]) => {\n const {\n __temp_key__,\n size: _size,\n name: _name,\n ...editedMetadata\n } = formData.layout.flatMap((row) => row.children).find((field) => field.name === name) ??\n {};\n\n acc[name] = {\n edit: {\n ...edit,\n ...editedMetadata,\n },\n list,\n };\n\n return acc;\n },\n {}\n );\n\n const res = await updateConfiguration({\n layouts: {\n edit: formData.layout.map((row) =>\n row.children.reduce<Array<{ name: string; size: number }>>((acc, { name, size }) => {\n if (name !== TEMP_FIELD_NAME) {\n return [...acc, { name, size }];\n }\n\n return acc;\n }, [])\n ),\n list: data?.component.layouts.list,\n },\n settings: setIn(formData.settings, 'displayName', undefined),\n metadatas: meta,\n uid: model,\n });\n\n if ('data' in res) {\n toggleNotification({\n type: 'success',\n message: formatMessage({ id: 'notification.success.saved', defaultMessage: 'Saved' }),\n });\n } else {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(res.error),\n });\n }\n } catch {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occurred' }),\n });\n }\n };\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || errorSchema || !schema) {\n return <Page.Error />;\n }\n\n return (\n <>\n <Page.Title>{`Configure ${editLayout.settings.displayName} Edit View`}</Page.Title>\n <ConfigurationForm\n onSubmit={handleSubmit}\n attributes={schema.attributes}\n fieldSizes={fieldSizes}\n layout={editLayout}\n />\n </>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedComponentConfigurationPage = () => {\n const permissions = useTypedSelector(\n (state) => state.admin_app.permissions.contentManager?.componentsConfigurations\n );\n\n return (\n <Page.Protect permissions={permissions}>\n <ComponentConfigurationPage />\n </Page.Protect>\n );\n};\n\nexport { ComponentConfigurationPage, ProtectedComponentConfigurationPage };\n"],"names":["ComponentConfigurationPage","slug","model","useParams","toggleNotification","useNotification","formatMessage","useIntl","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","components","fieldSizes","schema","schemas","error","errorSchema","isLoading","isLoadingSchema","isFetching","isFetchingSchema","useGetInitialDataQuery","undefined","selectFromResult","res","data","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","entries","attributeName","default","size","contentTypes","React","useEffect","type","message","isLoadingConfig","isFetchingConfig","useGetComponentConfigurationQuery","editLayout","useMemo","formatComponentConfigurationEditLayout","layout","metadatas","options","settings","DEFAULT_SETTINGS","updateConfiguration","useUpdateComponentConfigurationMutation","handleSubmit","formData","meta","name","edit","list","__temp_key__","_size","_name","editedMetadata","flatMap","row","children","field","layouts","map","TEMP_FIELD_NAME","setIn","id","defaultMessage","_jsx","Page","Loading","Error","_jsxs","_Fragment","Title","displayName","ConfigurationForm","onSubmit","ProtectedComponentConfigurationPage","permissions","useTypedSelector","state","admin_app","contentManager","componentsConfigurations","Protect"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA;;AAEkG,2GAE5FA,0BAAAA,GAA6B,IAAA;AACjC;;;;;AAKC,MACD,MAAM,EAAEC,IAAAA,EAAMC,KAAK,EAAE,GAAGC,wBAAAA,EAAAA;IACxB,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,2BAAAA,EAAAA;IAC/B,MAAM,EAAEC,aAAa,EAAE,GAAGC,iBAAAA,EAAAA;AAC1B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,8BAAAA,EAAAA;IAEpD,MAAM,cACJC,YAAU,EACVC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAAA,EAAOC,WAAW,EAClBC,SAAAA,EAAWC,eAAe,EAC1BC,UAAAA,EAAYC,gBAAgB,EAC7B,GAAGC,4BAAuBC,SAAAA,EAAW;AACpCC,QAAAA,gBAAAA,EAAkB,CAACC,GAAAA,GAAAA;YACjB,MAAMX,MAAAA,GAASW,GAAAA,CAAIC,IAAI,EAAEd,UAAAA,CAAWe,KAAK,CAACC,EAAAA,GAAOA,EAAAA,CAAGC,GAAG,KAAK1B,KAAAA,CAAAA;AAE5D,YAAA,MAAM2B,kBAAkBL,GAAAA,CAAIC,IAAI,EAAEd,UAAAA,CAAWmB,MAAAA,CAC3C,CAACC,GAAAA,EAAKC,SAAAA,GAAAA;AACJD,gBAAAA,GAAG,CAACC,SAAAA,CAAUJ,GAAG,CAAC,GAAGI,SAAAA;gBAErB,OAAOD,GAAAA;AACT,YAAA,CAAA,EACA,EAAC,CAAA;YAGH,MAAMpB,UAAAA,GAAasB,iDAAAA,CAA6BpB,MAAAA,EAAQqB,UAAAA,EAAYL,eAAAA,CAAAA;YAEpE,MAAMjB,UAAAA,GAAauB,OAAOC,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QAAA,QAAA,gBAAAX,cAAA,CAAC9E,0BAAAA,EAAAA,EAAAA;;AAGP;;;;;"}
|
|
@@ -25,7 +25,7 @@ import { formatComponentConfigurationEditLayout } from './formatComponentConfigu
|
|
|
25
25
|
const { toggleNotification } = useNotification();
|
|
26
26
|
const { formatMessage } = useIntl();
|
|
27
27
|
const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();
|
|
28
|
-
const { components, fieldSizes, schema, error: errorSchema, isLoading: isLoadingSchema, isFetching: isFetchingSchema } = useGetInitialDataQuery(undefined, {
|
|
28
|
+
const { components, fieldSizes, schema, schemas, error: errorSchema, isLoading: isLoadingSchema, isFetching: isFetchingSchema } = useGetInitialDataQuery(undefined, {
|
|
29
29
|
selectFromResult: (res)=>{
|
|
30
30
|
const schema = res.data?.components.find((ct)=>ct.uid === model);
|
|
31
31
|
const componentsByKey = res.data?.components.reduce((acc, component)=>{
|
|
@@ -43,6 +43,7 @@ import { formatComponentConfigurationEditLayout } from './formatComponentConfigu
|
|
|
43
43
|
error: res.error,
|
|
44
44
|
components,
|
|
45
45
|
schema,
|
|
46
|
+
schemas: res.data?.contentTypes ?? [],
|
|
46
47
|
fieldSizes
|
|
47
48
|
};
|
|
48
49
|
}
|
|
@@ -78,7 +79,8 @@ import { formatComponentConfigurationEditLayout } from './formatComponentConfigu
|
|
|
78
79
|
*/ const isLoading = isLoadingConfig || isLoadingSchema || isFetchingConfig || isFetchingSchema;
|
|
79
80
|
const editLayout = React.useMemo(()=>data && !isLoading ? formatComponentConfigurationEditLayout(data, {
|
|
80
81
|
schema,
|
|
81
|
-
components
|
|
82
|
+
components,
|
|
83
|
+
schemas
|
|
82
84
|
}) : {
|
|
83
85
|
layout: [],
|
|
84
86
|
components: {},
|
|
@@ -89,7 +91,8 @@ import { formatComponentConfigurationEditLayout } from './formatComponentConfigu
|
|
|
89
91
|
data,
|
|
90
92
|
isLoading,
|
|
91
93
|
schema,
|
|
92
|
-
components
|
|
94
|
+
components,
|
|
95
|
+
schemas
|
|
93
96
|
]);
|
|
94
97
|
const [updateConfiguration] = useUpdateComponentConfigurationMutation();
|
|
95
98
|
const handleSubmit = async (formData)=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ComponentConfigurationPage.mjs","sources":["../../../admin/src/pages/ComponentConfigurationPage.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Page, useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\n\nimport { TEMP_FIELD_NAME } from '../components/ConfigurationForm/Fields';\nimport { ConfigurationForm, ConfigurationFormProps } from '../components/ConfigurationForm/Form';\nimport { ComponentsDictionary, extractContentTypeComponents } from '../hooks/useContentTypeSchema';\nimport { DEFAULT_SETTINGS, EditLayout } from '../hooks/useDocumentLayout';\nimport { useTypedSelector } from '../modules/hooks';\nimport {\n useGetComponentConfigurationQuery,\n useUpdateComponentConfigurationMutation,\n} from '../services/components';\nimport { useGetInitialDataQuery } from '../services/init';\nimport { setIn } from '../utils/objects';\n\nimport { formatComponentConfigurationEditLayout } from './formatComponentConfigurationEditLayout';\n\nimport type { Component } from '../../../shared/contracts/components';\nimport type { Metadatas } from '../../../shared/contracts/content-types';\n\n/* -------------------------------------------------------------------------------------------------\n * ComponentConfigurationPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ComponentConfigurationPage = () => {\n /**\n * useDocumentLayout only works for documents, not components,\n * it feels weird to make that hook work for both when this is SUCH\n * a unique use case and we only do it here, so in short, we essentially\n * just extracted the logic to make an edit view layout and reproduced it here.\n */\n const { slug: model } = useParams<{ slug: string }>();\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const {\n components,\n fieldSizes,\n schema,\n error: errorSchema,\n isLoading: isLoadingSchema,\n isFetching: isFetchingSchema,\n } = useGetInitialDataQuery(undefined, {\n selectFromResult: (res) => {\n const schema = res.data?.components.find((ct) => ct.uid === model);\n\n const componentsByKey = res.data?.components.reduce<ComponentsDictionary>(\n (acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n },\n {}\n );\n\n const components = extractContentTypeComponents(schema?.attributes, componentsByKey);\n\n const fieldSizes = Object.entries(res.data?.fieldSizes ?? {}).reduce<\n ConfigurationFormProps['fieldSizes']\n >((acc, [attributeName, { default: size }]) => {\n acc[attributeName] = size;\n\n return acc;\n }, {});\n\n return {\n isFetching: res.isFetching,\n isLoading: res.isLoading,\n error: res.error,\n components,\n schema,\n fieldSizes,\n };\n },\n });\n\n React.useEffect(() => {\n if (errorSchema) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(errorSchema),\n });\n }\n }, [errorSchema, formatAPIError, toggleNotification]);\n\n const {\n data,\n isLoading: isLoadingConfig,\n isFetching: isFetchingConfig,\n error,\n } = useGetComponentConfigurationQuery(model ?? '');\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n /**\n * you **must** check if we're loading or fetching in case the component gets new props\n * but nothing was unmounted, it then becomes a fetch, not a load.\n */\n const isLoading = isLoadingConfig || isLoadingSchema || isFetchingConfig || isFetchingSchema;\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatComponentConfigurationEditLayout(data, { schema, components })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schema, components]\n );\n\n const [updateConfiguration] = useUpdateComponentConfigurationMutation();\n const handleSubmit: ConfigurationFormProps['onSubmit'] = async (formData) => {\n try {\n /**\n * We reconstruct the metadatas object by taking the existing list metadatas\n * and re-merging that by attribute name with the current list metadatas, whilst overwriting\n * the data from the form we've built.\n */\n const meta = Object.entries(data?.component.metadatas ?? {}).reduce<Metadatas>(\n (acc, [name, { edit, list }]) => {\n const {\n __temp_key__,\n size: _size,\n name: _name,\n ...editedMetadata\n } = formData.layout.flatMap((row) => row.children).find((field) => field.name === name) ??\n {};\n\n acc[name] = {\n edit: {\n ...edit,\n ...editedMetadata,\n },\n list,\n };\n\n return acc;\n },\n {}\n );\n\n const res = await updateConfiguration({\n layouts: {\n edit: formData.layout.map((row) =>\n row.children.reduce<Array<{ name: string; size: number }>>((acc, { name, size }) => {\n if (name !== TEMP_FIELD_NAME) {\n return [...acc, { name, size }];\n }\n\n return acc;\n }, [])\n ),\n list: data?.component.layouts.list,\n },\n settings: setIn(formData.settings, 'displayName', undefined),\n metadatas: meta,\n uid: model,\n });\n\n if ('data' in res) {\n toggleNotification({\n type: 'success',\n message: formatMessage({ id: 'notification.success.saved', defaultMessage: 'Saved' }),\n });\n } else {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(res.error),\n });\n }\n } catch {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occurred' }),\n });\n }\n };\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || errorSchema || !schema) {\n return <Page.Error />;\n }\n\n return (\n <>\n <Page.Title>{`Configure ${editLayout.settings.displayName} Edit View`}</Page.Title>\n <ConfigurationForm\n onSubmit={handleSubmit}\n attributes={schema.attributes}\n fieldSizes={fieldSizes}\n layout={editLayout}\n />\n </>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedComponentConfigurationPage = () => {\n const permissions = useTypedSelector(\n (state) => state.admin_app.permissions.contentManager?.componentsConfigurations\n );\n\n return (\n <Page.Protect permissions={permissions}>\n <ComponentConfigurationPage />\n </Page.Protect>\n );\n};\n\nexport { ComponentConfigurationPage, ProtectedComponentConfigurationPage };\n"],"names":["ComponentConfigurationPage","slug","model","useParams","toggleNotification","useNotification","formatMessage","useIntl","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","components","fieldSizes","schema","error","errorSchema","isLoading","isLoadingSchema","isFetching","isFetchingSchema","useGetInitialDataQuery","undefined","selectFromResult","res","data","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","entries","attributeName","default","size","React","useEffect","type","message","isLoadingConfig","isFetchingConfig","useGetComponentConfigurationQuery","editLayout","useMemo","formatComponentConfigurationEditLayout","layout","metadatas","options","settings","DEFAULT_SETTINGS","updateConfiguration","useUpdateComponentConfigurationMutation","handleSubmit","formData","meta","name","edit","list","__temp_key__","_size","_name","editedMetadata","flatMap","row","children","field","layouts","map","TEMP_FIELD_NAME","setIn","id","defaultMessage","_jsx","Page","Loading","Error","_jsxs","_Fragment","Title","displayName","ConfigurationForm","onSubmit","ProtectedComponentConfigurationPage","permissions","useTypedSelector","state","admin_app","contentManager","componentsConfigurations","Protect"],"mappings":";;;;;;;;;;;;;;;AAuBA;;AAEkG,2GAE5FA,0BAAAA,GAA6B,IAAA;AACjC;;;;;AAKC,MACD,MAAM,EAAEC,IAAAA,EAAMC,KAAK,EAAE,GAAGC,SAAAA,EAAAA;IACxB,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;IAC/B,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;AAC1B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,kBAAAA,EAAAA;AAEpD,IAAA,MAAM,EACJC,UAAU,EACVC,UAAU,EACVC,MAAM,EACNC,KAAAA,EAAOC,WAAW,EAClBC,SAAAA,EAAWC,eAAe,EAC1BC,UAAAA,EAAYC,gBAAgB,EAC7B,GAAGC,uBAAuBC,SAAAA,EAAW;AACpCC,QAAAA,gBAAAA,EAAkB,CAACC,GAAAA,GAAAA;YACjB,MAAMV,MAAAA,GAASU,GAAAA,CAAIC,IAAI,EAAEb,UAAAA,CAAWc,KAAK,CAACC,EAAAA,GAAOA,EAAAA,CAAGC,GAAG,KAAKzB,KAAAA,CAAAA;AAE5D,YAAA,MAAM0B,kBAAkBL,GAAAA,CAAIC,IAAI,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cC,gBAAAA,CAClB,CAACC,KAAAA,GAAUA,KAAAA,CAAMC,SAAS,CAACH,WAAW,CAACI,cAAc,EAAEC,wBAAAA,CAAAA;IAGzD,qBACEhB,GAAA,CAACC,KAAKgB,OAAO,EAAA;QAACN,WAAAA,EAAaA,WAAAA;AACzB,QAAA,QAAA,gBAAAX,GAAA,CAAC5E,0BAAAA,EAAAA,EAAAA;;AAGP;;;;"}
|
|
1
|
+
{"version":3,"file":"ComponentConfigurationPage.mjs","sources":["../../../admin/src/pages/ComponentConfigurationPage.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport { Page, useNotification, useAPIErrorHandler } from '@strapi/admin/strapi-admin';\nimport { useIntl } from 'react-intl';\nimport { useParams } from 'react-router-dom';\n\nimport { TEMP_FIELD_NAME } from '../components/ConfigurationForm/Fields';\nimport { ConfigurationForm, ConfigurationFormProps } from '../components/ConfigurationForm/Form';\nimport { ComponentsDictionary, extractContentTypeComponents } from '../hooks/useContentTypeSchema';\nimport { DEFAULT_SETTINGS, EditLayout } from '../hooks/useDocumentLayout';\nimport { useTypedSelector } from '../modules/hooks';\nimport {\n useGetComponentConfigurationQuery,\n useUpdateComponentConfigurationMutation,\n} from '../services/components';\nimport { useGetInitialDataQuery } from '../services/init';\nimport { setIn } from '../utils/objects';\n\nimport { formatComponentConfigurationEditLayout } from './formatComponentConfigurationEditLayout';\n\nimport type { Component } from '../../../shared/contracts/components';\nimport type { Metadatas } from '../../../shared/contracts/content-types';\n\n/* -------------------------------------------------------------------------------------------------\n * ComponentConfigurationPage\n * -----------------------------------------------------------------------------------------------*/\n\nconst ComponentConfigurationPage = () => {\n /**\n * useDocumentLayout only works for documents, not components,\n * it feels weird to make that hook work for both when this is SUCH\n * a unique use case and we only do it here, so in short, we essentially\n * just extracted the logic to make an edit view layout and reproduced it here.\n */\n const { slug: model } = useParams<{ slug: string }>();\n const { toggleNotification } = useNotification();\n const { formatMessage } = useIntl();\n const { _unstableFormatAPIError: formatAPIError } = useAPIErrorHandler();\n\n const {\n components,\n fieldSizes,\n schema,\n schemas,\n error: errorSchema,\n isLoading: isLoadingSchema,\n isFetching: isFetchingSchema,\n } = useGetInitialDataQuery(undefined, {\n selectFromResult: (res) => {\n const schema = res.data?.components.find((ct) => ct.uid === model);\n\n const componentsByKey = res.data?.components.reduce<ComponentsDictionary>(\n (acc, component) => {\n acc[component.uid] = component;\n\n return acc;\n },\n {}\n );\n\n const components = extractContentTypeComponents(schema?.attributes, componentsByKey);\n\n const fieldSizes = Object.entries(res.data?.fieldSizes ?? {}).reduce<\n ConfigurationFormProps['fieldSizes']\n >((acc, [attributeName, { default: size }]) => {\n acc[attributeName] = size;\n\n return acc;\n }, {});\n\n return {\n isFetching: res.isFetching,\n isLoading: res.isLoading,\n error: res.error,\n components,\n schema,\n schemas: res.data?.contentTypes ?? [],\n fieldSizes,\n };\n },\n });\n\n React.useEffect(() => {\n if (errorSchema) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(errorSchema),\n });\n }\n }, [errorSchema, formatAPIError, toggleNotification]);\n\n const {\n data,\n isLoading: isLoadingConfig,\n isFetching: isFetchingConfig,\n error,\n } = useGetComponentConfigurationQuery(model ?? '');\n\n React.useEffect(() => {\n if (error) {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(error),\n });\n }\n }, [error, formatAPIError, toggleNotification]);\n\n /**\n * you **must** check if we're loading or fetching in case the component gets new props\n * but nothing was unmounted, it then becomes a fetch, not a load.\n */\n const isLoading = isLoadingConfig || isLoadingSchema || isFetchingConfig || isFetchingSchema;\n\n const editLayout = React.useMemo(\n () =>\n data && !isLoading\n ? formatComponentConfigurationEditLayout(data, { schema, components, schemas })\n : ({\n layout: [],\n components: {},\n metadatas: {},\n options: {},\n settings: DEFAULT_SETTINGS,\n } as EditLayout),\n [data, isLoading, schema, components, schemas]\n );\n\n const [updateConfiguration] = useUpdateComponentConfigurationMutation();\n const handleSubmit: ConfigurationFormProps['onSubmit'] = async (formData) => {\n try {\n /**\n * We reconstruct the metadatas object by taking the existing list metadatas\n * and re-merging that by attribute name with the current list metadatas, whilst overwriting\n * the data from the form we've built.\n */\n const meta = Object.entries(data?.component.metadatas ?? {}).reduce<Metadatas>(\n (acc, [name, { edit, list }]) => {\n const {\n __temp_key__,\n size: _size,\n name: _name,\n ...editedMetadata\n } = formData.layout.flatMap((row) => row.children).find((field) => field.name === name) ??\n {};\n\n acc[name] = {\n edit: {\n ...edit,\n ...editedMetadata,\n },\n list,\n };\n\n return acc;\n },\n {}\n );\n\n const res = await updateConfiguration({\n layouts: {\n edit: formData.layout.map((row) =>\n row.children.reduce<Array<{ name: string; size: number }>>((acc, { name, size }) => {\n if (name !== TEMP_FIELD_NAME) {\n return [...acc, { name, size }];\n }\n\n return acc;\n }, [])\n ),\n list: data?.component.layouts.list,\n },\n settings: setIn(formData.settings, 'displayName', undefined),\n metadatas: meta,\n uid: model,\n });\n\n if ('data' in res) {\n toggleNotification({\n type: 'success',\n message: formatMessage({ id: 'notification.success.saved', defaultMessage: 'Saved' }),\n });\n } else {\n toggleNotification({\n type: 'danger',\n message: formatAPIError(res.error),\n });\n }\n } catch {\n toggleNotification({\n type: 'danger',\n message: formatMessage({ id: 'notification.error', defaultMessage: 'An error occurred' }),\n });\n }\n };\n\n if (isLoading) {\n return <Page.Loading />;\n }\n\n if (error || errorSchema || !schema) {\n return <Page.Error />;\n }\n\n return (\n <>\n <Page.Title>{`Configure ${editLayout.settings.displayName} Edit View`}</Page.Title>\n <ConfigurationForm\n onSubmit={handleSubmit}\n attributes={schema.attributes}\n fieldSizes={fieldSizes}\n layout={editLayout}\n />\n </>\n );\n};\n\n/* -------------------------------------------------------------------------------------------------\n * Header\n * -----------------------------------------------------------------------------------------------*/\n\nconst ProtectedComponentConfigurationPage = () => {\n const permissions = useTypedSelector(\n (state) => state.admin_app.permissions.contentManager?.componentsConfigurations\n );\n\n return (\n <Page.Protect permissions={permissions}>\n <ComponentConfigurationPage />\n </Page.Protect>\n );\n};\n\nexport { ComponentConfigurationPage, ProtectedComponentConfigurationPage };\n"],"names":["ComponentConfigurationPage","slug","model","useParams","toggleNotification","useNotification","formatMessage","useIntl","_unstableFormatAPIError","formatAPIError","useAPIErrorHandler","components","fieldSizes","schema","schemas","error","errorSchema","isLoading","isLoadingSchema","isFetching","isFetchingSchema","useGetInitialDataQuery","undefined","selectFromResult","res","data","find","ct","uid","componentsByKey","reduce","acc","component","extractContentTypeComponents","attributes","Object","entries","attributeName","default","size","contentTypes","React","useEffect","type","message","isLoadingConfig","isFetchingConfig","useGetComponentConfigurationQuery","editLayout","useMemo","formatComponentConfigurationEditLayout","layout","metadatas","options","settings","DEFAULT_SETTINGS","updateConfiguration","useUpdateComponentConfigurationMutation","handleSubmit","formData","meta","name","edit","list","__temp_key__","_size","_name","editedMetadata","flatMap","row","children","field","layouts","map","TEMP_FIELD_NAME","setIn","id","defaultMessage","_jsx","Page","Loading","Error","_jsxs","_Fragment","Title","displayName","ConfigurationForm","onSubmit","ProtectedComponentConfigurationPage","permissions","useTypedSelector","state","admin_app","contentManager","componentsConfigurations","Protect"],"mappings":";;;;;;;;;;;;;;;AAuBA;;AAEkG,2GAE5FA,0BAAAA,GAA6B,IAAA;AACjC;;;;;AAKC,MACD,MAAM,EAAEC,IAAAA,EAAMC,KAAK,EAAE,GAAGC,SAAAA,EAAAA;IACxB,MAAM,EAAEC,kBAAkB,EAAE,GAAGC,eAAAA,EAAAA;IAC/B,MAAM,EAAEC,aAAa,EAAE,GAAGC,OAAAA,EAAAA;AAC1B,IAAA,MAAM,EAAEC,uBAAAA,EAAyBC,cAAc,EAAE,GAAGC,kBAAAA,EAAAA;IAEpD,MAAM,EACJC,UAAU,EACVC,UAAU,EACVC,MAAM,EACNC,OAAO,EACPC,KAAAA,EAAOC,WAAW,EAClBC,SAAAA,EAAWC,eAAe,EAC1BC,UAAAA,EAAYC,gBAAgB,EAC7B,GAAGC,uBAAuBC,SAAAA,EAAW;AACpCC,QAAAA,gBAAAA,EAAkB,CAACC,GAAAA,GAA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