@payloadcms/ui 4.0.0-canary.4 → 4.0.0-canary.6
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/css/forms.css +6 -3
- package/dist/css/theme.css +2 -1
- package/dist/elements/AddNewRelation/index.css +1 -1
- package/dist/elements/ArrayAction/index.d.ts.map +1 -1
- package/dist/elements/ArrayAction/index.js +1 -0
- package/dist/elements/ArrayAction/index.js.map +1 -1
- package/dist/elements/Button/index.d.ts.map +1 -1
- package/dist/elements/Button/index.js +5 -0
- package/dist/elements/Button/index.js.map +1 -1
- package/dist/elements/ClipboardAction/index.d.ts.map +1 -1
- package/dist/elements/ClipboardAction/index.js +1 -0
- package/dist/elements/ClipboardAction/index.js.map +1 -1
- package/dist/elements/Collapsible/index.d.ts.map +1 -1
- package/dist/elements/Collapsible/index.js +2 -0
- package/dist/elements/Collapsible/index.js.map +1 -1
- package/dist/elements/DatePicker/index.css +1 -1
- package/dist/elements/DatePicker/index.js +1 -1
- package/dist/elements/DatePicker/index.js.map +1 -1
- package/dist/elements/DocumentControls/index.d.ts.map +1 -1
- package/dist/elements/DocumentControls/index.js +1 -0
- package/dist/elements/DocumentControls/index.js.map +1 -1
- package/dist/elements/DocumentFields/index.css +1 -0
- package/dist/elements/EditUpload/index.d.ts.map +1 -1
- package/dist/elements/EditUpload/index.js +4 -0
- package/dist/elements/EditUpload/index.js.map +1 -1
- package/dist/elements/Hierarchy/ColumnBrowser/Column/index.css +3 -1
- package/dist/elements/Hierarchy/ColumnBrowser/ColumnItem/index.css +1 -0
- package/dist/elements/Hierarchy/ColumnBrowser/types.d.ts +1 -1
- package/dist/elements/Hierarchy/ColumnBrowser/types.d.ts.map +1 -1
- package/dist/elements/Hierarchy/ColumnBrowser/types.js.map +1 -1
- package/dist/elements/Hierarchy/DocHeaderButton/index.js +12 -12
- package/dist/elements/Hierarchy/DocHeaderButton/index.js.map +1 -1
- package/dist/elements/Hierarchy/Field/index.client.js +14 -14
- package/dist/elements/Hierarchy/Field/index.client.js.map +1 -1
- package/dist/elements/Hierarchy/Modal/fetchAncestorPath.d.ts.map +1 -0
- package/dist/elements/Hierarchy/Modal/fetchAncestorPath.js.map +1 -0
- package/dist/elements/Hierarchy/Modal/index.css +88 -0
- package/dist/elements/Hierarchy/Modal/index.d.ts +20 -0
- package/dist/elements/Hierarchy/Modal/index.d.ts.map +1 -0
- package/dist/elements/Hierarchy/{Drawer → Modal}/index.js +105 -81
- package/dist/elements/Hierarchy/Modal/index.js.map +1 -0
- package/dist/elements/Hierarchy/{Drawer → Modal}/types.d.ts +22 -18
- package/dist/elements/Hierarchy/Modal/types.d.ts.map +1 -0
- package/dist/elements/Hierarchy/Modal/types.js.map +1 -0
- package/dist/elements/Hierarchy/Modal/useHierarchyModal.d.ts +30 -0
- package/dist/elements/Hierarchy/Modal/useHierarchyModal.d.ts.map +1 -0
- package/dist/elements/Hierarchy/{Drawer/useHierarchyDrawer.js → Modal/useHierarchyModal.js} +51 -50
- package/dist/elements/Hierarchy/Modal/useHierarchyModal.js.map +1 -0
- package/dist/elements/Hierarchy/MoveMany/index.d.ts +2 -2
- package/dist/elements/Hierarchy/MoveMany/index.d.ts.map +1 -1
- package/dist/elements/Hierarchy/MoveMany/index.js +9 -9
- package/dist/elements/Hierarchy/MoveMany/index.js.map +1 -1
- package/dist/elements/LivePreview/Toolbar/SizeInput/index.d.ts.map +1 -1
- package/dist/elements/LivePreview/Toolbar/SizeInput/index.js +1 -0
- package/dist/elements/LivePreview/Toolbar/SizeInput/index.js.map +1 -1
- package/dist/elements/LivePreview/Window/index.css +6 -0
- package/dist/elements/Popup/PopupTrigger/index.d.ts +1 -0
- package/dist/elements/Popup/PopupTrigger/index.d.ts.map +1 -1
- package/dist/elements/Popup/PopupTrigger/index.js +3 -0
- package/dist/elements/Popup/PopupTrigger/index.js.map +1 -1
- package/dist/elements/Popup/index.d.ts +6 -0
- package/dist/elements/Popup/index.d.ts.map +1 -1
- package/dist/elements/Popup/index.js +2 -0
- package/dist/elements/Popup/index.js.map +1 -1
- package/dist/elements/ReactSelect/DropdownIndicator/index.d.ts.map +1 -1
- package/dist/elements/ReactSelect/DropdownIndicator/index.js +19 -12
- package/dist/elements/ReactSelect/DropdownIndicator/index.js.map +1 -1
- package/dist/elements/ReactSelect/index.css +2 -2
- package/dist/elements/ReactSelect/index.js +1 -1
- package/dist/elements/ReactSelect/index.js.map +1 -1
- package/dist/elements/ReactSelect/types.d.ts +1 -0
- package/dist/elements/ReactSelect/types.d.ts.map +1 -1
- package/dist/elements/ReactSelect/types.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/Hierarchy/index.js +24 -24
- package/dist/elements/Table/DefaultCell/fields/Hierarchy/index.js.map +1 -1
- package/dist/elements/TimezonePicker/index.css +1 -1
- package/dist/exports/client/index.d.ts +3 -2
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +26 -26
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/rsc/index.d.ts +1 -0
- package/dist/exports/rsc/index.d.ts.map +1 -1
- package/dist/exports/rsc/index.js +1 -0
- package/dist/exports/rsc/index.js.map +1 -1
- package/dist/fields/Blocks/SectionTitle/index.d.ts.map +1 -1
- package/dist/fields/Blocks/SectionTitle/index.js +1 -0
- package/dist/fields/Blocks/SectionTitle/index.js.map +1 -1
- package/dist/fields/ConfirmPassword/index.d.ts +4 -0
- package/dist/fields/ConfirmPassword/index.d.ts.map +1 -1
- package/dist/fields/ConfirmPassword/index.js +37 -33
- package/dist/fields/ConfirmPassword/index.js.map +1 -1
- package/dist/fields/Number/Input.d.ts.map +1 -1
- package/dist/fields/Number/Input.js +29 -25
- package/dist/fields/Number/Input.js.map +1 -1
- package/dist/fields/Number/types.d.ts +4 -0
- package/dist/fields/Number/types.d.ts.map +1 -1
- package/dist/fields/Number/types.js.map +1 -1
- package/dist/fields/Password/input.d.ts.map +1 -1
- package/dist/fields/Password/input.js +33 -29
- package/dist/fields/Password/input.js.map +1 -1
- package/dist/fields/Password/types.d.ts +4 -0
- package/dist/fields/Password/types.d.ts.map +1 -1
- package/dist/fields/Password/types.js.map +1 -1
- package/dist/fields/Relationship/Input.d.ts.map +1 -1
- package/dist/fields/Relationship/Input.js +4 -0
- package/dist/fields/Relationship/Input.js.map +1 -1
- package/dist/fields/Relationship/types.d.ts +4 -0
- package/dist/fields/Relationship/types.d.ts.map +1 -1
- package/dist/fields/Relationship/types.js.map +1 -1
- package/dist/fields/Select/Input.d.ts +4 -0
- package/dist/fields/Select/Input.d.ts.map +1 -1
- package/dist/fields/Select/Input.js +45 -40
- package/dist/fields/Select/Input.js.map +1 -1
- package/dist/fields/Text/Input.d.ts.map +1 -1
- package/dist/fields/Text/Input.js +25 -21
- package/dist/fields/Text/Input.js.map +1 -1
- package/dist/fields/Text/types.d.ts +4 -0
- package/dist/fields/Text/types.d.ts.map +1 -1
- package/dist/fields/Text/types.js.map +1 -1
- package/dist/fields/Textarea/Input.d.ts.map +1 -1
- package/dist/fields/Textarea/Input.js +27 -23
- package/dist/fields/Textarea/Input.js.map +1 -1
- package/dist/fields/Textarea/index.css +1 -1
- package/dist/fields/Textarea/types.d.ts +4 -0
- package/dist/fields/Textarea/types.d.ts.map +1 -1
- package/dist/fields/Textarea/types.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/views/Dashboard/Default/ModularDashboard/WidgetConfigDrawer.d.ts.map +1 -1
- package/dist/views/Dashboard/Default/ModularDashboard/WidgetConfigDrawer.js +27 -23
- package/dist/views/Dashboard/Default/ModularDashboard/WidgetConfigDrawer.js.map +1 -1
- package/dist/views/Dashboard/Default/ModularDashboard/index.css +2 -0
- package/dist/views/Version/SelectComparison/index.d.ts.map +1 -1
- package/dist/views/Version/SelectComparison/index.js +1 -0
- package/dist/views/Version/SelectComparison/index.js.map +1 -1
- package/dist/widgets/CollectionQuery/SortField/index.d.ts +3 -0
- package/dist/widgets/CollectionQuery/SortField/index.d.ts.map +1 -0
- package/dist/widgets/CollectionQuery/SortField/index.js +118 -0
- package/dist/widgets/CollectionQuery/SortField/index.js.map +1 -0
- package/dist/widgets/CollectionQuery/getCollectionFieldPaths.d.ts +18 -0
- package/dist/widgets/CollectionQuery/getCollectionFieldPaths.d.ts.map +1 -0
- package/dist/widgets/CollectionQuery/getCollectionFieldPaths.js +91 -0
- package/dist/widgets/CollectionQuery/getCollectionFieldPaths.js.map +1 -0
- package/dist/widgets/CollectionQuery/getCollectionFieldPaths.spec.js +100 -0
- package/dist/widgets/CollectionQuery/getCollectionFieldPaths.spec.js.map +1 -0
- package/dist/widgets/CollectionQuery/index.css +206 -0
- package/dist/widgets/CollectionQuery/index.d.ts +17 -0
- package/dist/widgets/CollectionQuery/index.d.ts.map +1 -0
- package/dist/widgets/CollectionQuery/index.js +399 -0
- package/dist/widgets/CollectionQuery/index.js.map +1 -0
- package/package.json +4 -4
- package/dist/elements/Hierarchy/Drawer/fetchAncestorPath.d.ts.map +0 -1
- package/dist/elements/Hierarchy/Drawer/fetchAncestorPath.js.map +0 -1
- package/dist/elements/Hierarchy/Drawer/index.css +0 -90
- package/dist/elements/Hierarchy/Drawer/index.d.ts +0 -20
- package/dist/elements/Hierarchy/Drawer/index.d.ts.map +0 -1
- package/dist/elements/Hierarchy/Drawer/index.js.map +0 -1
- package/dist/elements/Hierarchy/Drawer/types.d.ts.map +0 -1
- package/dist/elements/Hierarchy/Drawer/types.js.map +0 -1
- package/dist/elements/Hierarchy/Drawer/useHierarchyDrawer.d.ts +0 -30
- package/dist/elements/Hierarchy/Drawer/useHierarchyDrawer.d.ts.map +0 -1
- package/dist/elements/Hierarchy/Drawer/useHierarchyDrawer.js.map +0 -1
- /package/dist/elements/Hierarchy/{Drawer → Modal}/fetchAncestorPath.d.ts +0 -0
- /package/dist/elements/Hierarchy/{Drawer → Modal}/fetchAncestorPath.js +0 -0
- /package/dist/elements/Hierarchy/{Drawer → Modal}/types.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WidgetConfigDrawer.d.ts","sourceRoot":"","sources":["../../../../../src/views/Dashboard/Default/ModularDashboard/WidgetConfigDrawer.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,SAAS,CAAA;AAEtD,OAAO,KAA4D,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"WidgetConfigDrawer.d.ts","sourceRoot":"","sources":["../../../../../src/views/Dashboard/Default/ModularDashboard/WidgetConfigDrawer.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAa,MAAM,SAAS,CAAA;AAEtD,OAAO,KAA4D,MAAM,OAAO,CAAA;AAiBhF,KAAK,uBAAuB,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;IAC/C,MAAM,EAAE,YAAY,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACrC,CAAA;AAMD,wBAAgB,kBAAkB,CAAC,EACjC,UAAU,EACV,MAAM,EACN,MAAM,EACN,UAAU,GACX,EAAE,uBAAuB,qBA0HzB"}
|
|
@@ -4,6 +4,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
4
4
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
5
|
import { v4 as uuid } from 'uuid';
|
|
6
6
|
import { Drawer } from '../../../../elements/Drawer/index.js';
|
|
7
|
+
import { Gutter } from '../../../../elements/Gutter/index.js';
|
|
7
8
|
import { useModal } from '../../../../elements/Modal/index.js';
|
|
8
9
|
import { ShimmerEffect } from '../../../../elements/ShimmerEffect/index.js';
|
|
9
10
|
import { Form } from '../../../../forms/Form/index.js';
|
|
@@ -106,30 +107,33 @@ export function WidgetConfigDrawer({
|
|
|
106
107
|
return /*#__PURE__*/_jsx(Drawer, {
|
|
107
108
|
slug: drawerSlug,
|
|
108
109
|
title: `${t('general:edit')} ${widgetLabel}`,
|
|
109
|
-
children:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
onChange: [onChange],
|
|
117
|
-
onSubmit: (_, data) => {
|
|
118
|
-
onSave(mergeLocaleData(widgetData ?? {}, data, localeCode, fields));
|
|
119
|
-
closeModal(drawerSlug);
|
|
120
|
-
},
|
|
121
|
-
uuid: formUUID,
|
|
122
|
-
children: [/*#__PURE__*/_jsx(RenderFields, {
|
|
110
|
+
children: /*#__PURE__*/_jsx(Gutter, {
|
|
111
|
+
className: "widget-config-drawer__content",
|
|
112
|
+
children: initialState === false ? /*#__PURE__*/_jsx(ShimmerEffect, {
|
|
113
|
+
height: "250px"
|
|
114
|
+
}) : /*#__PURE__*/_jsx(OperationProvider, {
|
|
115
|
+
operation: "update",
|
|
116
|
+
children: /*#__PURE__*/_jsxs(Form, {
|
|
123
117
|
fields: fields,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
children:
|
|
132
|
-
|
|
118
|
+
initialState: initialState,
|
|
119
|
+
onChange: [onChange],
|
|
120
|
+
onSubmit: (_, data) => {
|
|
121
|
+
onSave(mergeLocaleData(widgetData ?? {}, data, localeCode, fields));
|
|
122
|
+
closeModal(drawerSlug);
|
|
123
|
+
},
|
|
124
|
+
uuid: formUUID,
|
|
125
|
+
children: [/*#__PURE__*/_jsx(RenderFields, {
|
|
126
|
+
fields: fields,
|
|
127
|
+
forceRender: true,
|
|
128
|
+
parentIndexPath: "",
|
|
129
|
+
parentPath: "",
|
|
130
|
+
parentSchemaPath: widget.slug,
|
|
131
|
+
permissions: true,
|
|
132
|
+
readOnly: false
|
|
133
|
+
}), /*#__PURE__*/_jsx(FormSubmit, {
|
|
134
|
+
children: t('fields:saveChanges')
|
|
135
|
+
})]
|
|
136
|
+
})
|
|
133
137
|
})
|
|
134
138
|
})
|
|
135
139
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WidgetConfigDrawer.js","names":["React","useCallback","useEffect","useMemo","useRef","useState","v4","uuid","Drawer","useModal","ShimmerEffect","Form","RenderFields","FormSubmit","useLocale","OperationProvider","useServerFunctions","useTranslation","abortAndIgnore","extractLocaleData","mergeLocaleData","EMPTY_WIDGET_PREFERENCES","fields","WidgetConfigDrawer","drawerSlug","onSave","widget","widgetData","closeModal","modalState","getFormState","t","locale","localeCode","code","onChangeAbortControllerRef","initialState","setInitialState","isOpen","Boolean","formUUID","widgetLabel","label","slug","length","controller","AbortController","loadInitialState","localeFilteredData","state","data","docPermissions","docPreferences","operation","renderAllFields","schemaPath","signal","widgetSlug","onChange","formState","prevFormState","current","_jsx","title","height","_jsxs","onSubmit","_","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions","readOnly"],"sources":["../../../../../src/views/Dashboard/Default/ModularDashboard/WidgetConfigDrawer.tsx"],"sourcesContent":["'use client'\n\nimport type { ClientWidget, FormState } from 'payload'\n\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { v4 as uuid } from 'uuid'\n\nimport { Drawer } from '../../../../elements/Drawer/index.js'\nimport { useModal } from '../../../../elements/Modal/index.js'\nimport { ShimmerEffect } from '../../../../elements/ShimmerEffect/index.js'\nimport { Form } from '../../../../forms/Form/index.js'\nimport { RenderFields } from '../../../../forms/RenderFields/index.js'\nimport { FormSubmit } from '../../../../forms/Submit/index.js'\nimport { useLocale } from '../../../../providers/Locale/index.js'\nimport { OperationProvider } from '../../../../providers/Operation/index.js'\nimport { useServerFunctions } from '../../../../providers/ServerFunctions/index.js'\nimport { useTranslation } from '../../../../providers/Translation/index.js'\nimport { abortAndIgnore } from '../../../../utilities/abortAndIgnore.js'\nimport { extractLocaleData, mergeLocaleData } from './utils/localeUtils.js'\n\ntype WidgetConfigDrawerProps = {\n drawerSlug: string\n onSave: (data: Record<string, unknown>) => void\n widget: ClientWidget\n widgetData?: Record<string, unknown>\n}\n\nconst EMPTY_WIDGET_PREFERENCES = {\n fields: {},\n}\n\nexport function WidgetConfigDrawer({\n drawerSlug,\n onSave,\n widget,\n widgetData,\n}: WidgetConfigDrawerProps) {\n const { closeModal, modalState } = useModal()\n const { getFormState } = useServerFunctions()\n const { t } = useTranslation()\n const locale = useLocale()\n const localeCode = locale?.code ?? 'en'\n const onChangeAbortControllerRef = useRef<AbortController>(null)\n\n const [initialState, setInitialState] = useState<false | FormState | undefined>(false)\n\n const isOpen = Boolean(modalState?.[drawerSlug]?.isOpen)\n const formUUID = useMemo(() => uuid(), [])\n const widgetLabel = useMemo(\n () => (typeof widget.label === 'string' ? widget.label : widget.slug),\n [widget.label, widget.slug],\n )\n const fields = useMemo(() => widget.fields ?? [], [widget.fields])\n\n useEffect(() => {\n if (!isOpen || fields.length === 0) {\n setInitialState(false)\n return\n }\n\n const controller = new AbortController()\n\n const loadInitialState = async () => {\n const localeFilteredData = extractLocaleData(widgetData ?? {}, localeCode, fields)\n\n const { state } = await getFormState({\n data: localeFilteredData,\n docPermissions: {\n fields: true,\n },\n docPreferences: EMPTY_WIDGET_PREFERENCES,\n locale: localeCode,\n operation: 'update',\n renderAllFields: true,\n schemaPath: widget.slug,\n signal: controller.signal,\n widgetSlug: widget.slug,\n })\n\n if (state) {\n setInitialState(state)\n }\n }\n\n void loadInitialState()\n\n return () => {\n abortAndIgnore(controller)\n }\n }, [fields, getFormState, isOpen, localeCode, widget.slug, widgetData])\n\n const onChange = useCallback(\n async ({ formState: prevFormState }: { formState: FormState }) => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n\n const controller = new AbortController()\n onChangeAbortControllerRef.current = controller\n\n const { state } = await getFormState({\n docPermissions: {\n fields: true,\n },\n docPreferences: EMPTY_WIDGET_PREFERENCES,\n formState: prevFormState,\n operation: 'update',\n schemaPath: widget.slug,\n signal: controller.signal,\n widgetSlug: widget.slug,\n })\n\n if (!state) {\n return prevFormState\n }\n\n return state\n },\n [getFormState, widget.slug],\n )\n\n useEffect(() => {\n return () => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n }\n }, [])\n\n return (\n <Drawer slug={drawerSlug} title={`${t('general:edit')} ${widgetLabel}`}>\n {initialState === false ? (\n
|
|
1
|
+
{"version":3,"file":"WidgetConfigDrawer.js","names":["React","useCallback","useEffect","useMemo","useRef","useState","v4","uuid","Drawer","Gutter","useModal","ShimmerEffect","Form","RenderFields","FormSubmit","useLocale","OperationProvider","useServerFunctions","useTranslation","abortAndIgnore","extractLocaleData","mergeLocaleData","EMPTY_WIDGET_PREFERENCES","fields","WidgetConfigDrawer","drawerSlug","onSave","widget","widgetData","closeModal","modalState","getFormState","t","locale","localeCode","code","onChangeAbortControllerRef","initialState","setInitialState","isOpen","Boolean","formUUID","widgetLabel","label","slug","length","controller","AbortController","loadInitialState","localeFilteredData","state","data","docPermissions","docPreferences","operation","renderAllFields","schemaPath","signal","widgetSlug","onChange","formState","prevFormState","current","_jsx","title","className","height","_jsxs","onSubmit","_","forceRender","parentIndexPath","parentPath","parentSchemaPath","permissions","readOnly"],"sources":["../../../../../src/views/Dashboard/Default/ModularDashboard/WidgetConfigDrawer.tsx"],"sourcesContent":["'use client'\n\nimport type { ClientWidget, FormState } from 'payload'\n\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { v4 as uuid } from 'uuid'\n\nimport { Drawer } from '../../../../elements/Drawer/index.js'\nimport { Gutter } from '../../../../elements/Gutter/index.js'\nimport { useModal } from '../../../../elements/Modal/index.js'\nimport { ShimmerEffect } from '../../../../elements/ShimmerEffect/index.js'\nimport { Form } from '../../../../forms/Form/index.js'\nimport { RenderFields } from '../../../../forms/RenderFields/index.js'\nimport { FormSubmit } from '../../../../forms/Submit/index.js'\nimport { useLocale } from '../../../../providers/Locale/index.js'\nimport { OperationProvider } from '../../../../providers/Operation/index.js'\nimport { useServerFunctions } from '../../../../providers/ServerFunctions/index.js'\nimport { useTranslation } from '../../../../providers/Translation/index.js'\nimport { abortAndIgnore } from '../../../../utilities/abortAndIgnore.js'\nimport { extractLocaleData, mergeLocaleData } from './utils/localeUtils.js'\n\ntype WidgetConfigDrawerProps = {\n drawerSlug: string\n onSave: (data: Record<string, unknown>) => void\n widget: ClientWidget\n widgetData?: Record<string, unknown>\n}\n\nconst EMPTY_WIDGET_PREFERENCES = {\n fields: {},\n}\n\nexport function WidgetConfigDrawer({\n drawerSlug,\n onSave,\n widget,\n widgetData,\n}: WidgetConfigDrawerProps) {\n const { closeModal, modalState } = useModal()\n const { getFormState } = useServerFunctions()\n const { t } = useTranslation()\n const locale = useLocale()\n const localeCode = locale?.code ?? 'en'\n const onChangeAbortControllerRef = useRef<AbortController>(null)\n\n const [initialState, setInitialState] = useState<false | FormState | undefined>(false)\n\n const isOpen = Boolean(modalState?.[drawerSlug]?.isOpen)\n const formUUID = useMemo(() => uuid(), [])\n const widgetLabel = useMemo(\n () => (typeof widget.label === 'string' ? widget.label : widget.slug),\n [widget.label, widget.slug],\n )\n const fields = useMemo(() => widget.fields ?? [], [widget.fields])\n\n useEffect(() => {\n if (!isOpen || fields.length === 0) {\n setInitialState(false)\n return\n }\n\n const controller = new AbortController()\n\n const loadInitialState = async () => {\n const localeFilteredData = extractLocaleData(widgetData ?? {}, localeCode, fields)\n\n const { state } = await getFormState({\n data: localeFilteredData,\n docPermissions: {\n fields: true,\n },\n docPreferences: EMPTY_WIDGET_PREFERENCES,\n locale: localeCode,\n operation: 'update',\n renderAllFields: true,\n schemaPath: widget.slug,\n signal: controller.signal,\n widgetSlug: widget.slug,\n })\n\n if (state) {\n setInitialState(state)\n }\n }\n\n void loadInitialState()\n\n return () => {\n abortAndIgnore(controller)\n }\n }, [fields, getFormState, isOpen, localeCode, widget.slug, widgetData])\n\n const onChange = useCallback(\n async ({ formState: prevFormState }: { formState: FormState }) => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n\n const controller = new AbortController()\n onChangeAbortControllerRef.current = controller\n\n const { state } = await getFormState({\n docPermissions: {\n fields: true,\n },\n docPreferences: EMPTY_WIDGET_PREFERENCES,\n formState: prevFormState,\n operation: 'update',\n schemaPath: widget.slug,\n signal: controller.signal,\n widgetSlug: widget.slug,\n })\n\n if (!state) {\n return prevFormState\n }\n\n return state\n },\n [getFormState, widget.slug],\n )\n\n useEffect(() => {\n return () => {\n abortAndIgnore(onChangeAbortControllerRef.current)\n }\n }, [])\n\n return (\n <Drawer slug={drawerSlug} title={`${t('general:edit')} ${widgetLabel}`}>\n <Gutter className=\"widget-config-drawer__content\">\n {initialState === false ? (\n <ShimmerEffect height=\"250px\" />\n ) : (\n <OperationProvider operation=\"update\">\n <Form\n fields={fields}\n initialState={initialState}\n onChange={[onChange]}\n onSubmit={(_, data) => {\n onSave(mergeLocaleData(widgetData ?? {}, data, localeCode, fields))\n closeModal(drawerSlug)\n }}\n uuid={formUUID}\n >\n <RenderFields\n fields={fields}\n forceRender\n parentIndexPath=\"\"\n parentPath=\"\"\n parentSchemaPath={widget.slug}\n permissions={true}\n readOnly={false}\n />\n <FormSubmit>{t('fields:saveChanges')}</FormSubmit>\n </Form>\n </OperationProvider>\n )}\n </Gutter>\n </Drawer>\n )\n}\n"],"mappings":"AAAA;;;AAIA,OAAOA,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AACzE,SAASC,EAAA,IAAMC,IAAI,QAAQ;AAE3B,SAASC,MAAM,QAAQ;AACvB,SAASC,MAAM,QAAQ;AACvB,SAASC,QAAQ,QAAQ;AACzB,SAASC,aAAa,QAAQ;AAC9B,SAASC,IAAI,QAAQ;AACrB,SAASC,YAAY,QAAQ;AAC7B,SAASC,UAAU,QAAQ;AAC3B,SAASC,SAAS,QAAQ;AAC1B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,kBAAkB,QAAQ;AACnC,SAASC,cAAc,QAAQ;AAC/B,SAASC,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MACV,OAAOW,aAAA;IACT;IAEA,OAAOX,OAAA;EACT,GACA,CAACnB,YAAA,EAAcJ,MAAA,CAAOiB,IAAI,CAAC;EAG7B1C,SAAA,CAAU;IACR,OAAO;MACLiB,cAAA,CAAeiB,0BAAA,CAA2B0B,OAAO;IACnD;EACF,GAAG,EAAE;EAEL,oBACEC,IAAA,CAACvD,MAAA;IAAOoC,IAAA,EAAMnB,UAAA;IAAYuC,KAAA,EAAO,GAAGhC,CAAA,CAAE,mBAAmBU,WAAA,EAAa;cACpE,aAAAqB,IAAA,CAACtD,MAAA;MAAOwD,SAAA,EAAU;gBACf5B,YAAA,KAAiB,qBAChB0B,IAAA,CAACpD,aAAA;QAAcuD,MAAA,EAAO;wBAEtBH,IAAA,CAAC/C,iBAAA;QAAkBsC,SAAA,EAAU;kBAC3B,aAAAa,KAAA,CAACvD,IAAA;UACCW,MAAA,EAAQA,MAAA;UACRc,YAAA,EAAcA,YAAA;UACdsB,QAAA,EAAU,CAACA,QAAA,CAAS;UACpBS,QAAA,EAAUA,CAACC,CAAA,EAAGlB,IAAA;YACZzB,MAAA,CAAOL,eAAA,CAAgBO,UAAA,IAAc,CAAC,GAAGuB,IAAA,EAAMjB,UAAA,EAAYX,MAAA;YAC3DM,UAAA,CAAWJ,UAAA;UACb;UACAlB,IAAA,EAAMkC,QAAA;kCAENsB,IAAA,CAAClD,YAAA;YACCU,MAAA,EAAQA,MAAA;YACR+C,WAAW;YACXC,eAAA,EAAgB;YAChBC,UAAA,EAAW;YACXC,gBAAA,EAAkB9C,MAAA,CAAOiB,IAAI;YAC7B8B,WAAA,EAAa;YACbC,QAAA,EAAU;2BAEZZ,IAAA,CAACjD,UAAA;sBAAYkB,CAAA,CAAE;;;;;;AAO7B","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/SelectComparison/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAqC,MAAM,OAAO,CAAA;AAGzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAKvC,OAAO,aAAa,CAAA;AAKpB,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/SelectComparison/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAqC,MAAM,OAAO,CAAA;AAGzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAKvC,OAAO,aAAa,CAAA;AAKpB,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAqD3C,CAAA"}
|
|
@@ -48,6 +48,7 @@ export const SelectComparison = /*#__PURE__*/memo(props => {
|
|
|
48
48
|
return /*#__PURE__*/_jsxs("div", {
|
|
49
49
|
className: [fieldBaseClass, baseClass].filter(Boolean).join(' '),
|
|
50
50
|
children: [/*#__PURE__*/_jsx(ReactSelect, {
|
|
51
|
+
"aria-label": t('version:selectVersionToCompare'),
|
|
51
52
|
isClearable: false,
|
|
52
53
|
isSearchable: false,
|
|
53
54
|
onChange: onChange,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["React","memo","useCallback","useMemo","ReactSelect","fieldBaseClass","useTranslation","useVersionDrawer","baseClass","SelectComparison","props","collectionSlug","docID","globalSlug","onChange","onChangeFromProps","versionFromID","versionFromOptions","t","Drawer","openDrawer","options","label","_jsx","className","value","currentOption","find","option","val","_jsxs","filter","Boolean","join","isClearable","isSearchable","placeholder"],"sources":["../../../../src/views/Version/SelectComparison/index.tsx"],"sourcesContent":["'use client'\n\nimport React, { memo, useCallback, useMemo } from 'react'\n\nimport type { CompareOption } from '../Default/types.js'\nimport type { Props } from './types.js'\n\nimport { ReactSelect } from '../../../elements/ReactSelect/index.js'\nimport { fieldBaseClass } from '../../../fields/shared/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport './index.css'\nimport { useVersionDrawer } from './VersionDrawer/index.js'\n\nconst baseClass = 'compare-version'\n\nexport const SelectComparison: React.FC<Props> = memo((props) => {\n const {\n collectionSlug,\n docID,\n globalSlug,\n onChange: onChangeFromProps,\n versionFromID,\n versionFromOptions,\n } = props\n const { t } = useTranslation()\n\n const { Drawer, openDrawer } = useVersionDrawer({ collectionSlug, docID, globalSlug })\n\n const options = useMemo(() => {\n return [\n ...versionFromOptions,\n {\n label: <span className={`${baseClass}-moreVersions`}>{t('version:moreVersions')}</span>,\n value: 'more',\n },\n ]\n }, [t, versionFromOptions])\n\n const currentOption = useMemo(\n () => versionFromOptions.find((option) => option.value === versionFromID),\n [versionFromOptions, versionFromID],\n )\n\n const onChange = useCallback(\n (val: CompareOption) => {\n if (val.value === 'more') {\n openDrawer()\n return\n }\n onChangeFromProps(val)\n },\n [onChangeFromProps, openDrawer],\n )\n\n return (\n <div className={[fieldBaseClass, baseClass].filter(Boolean).join(' ')}>\n <ReactSelect\n isClearable={false}\n isSearchable={false}\n onChange={onChange}\n options={options}\n placeholder={t('version:selectVersionToCompare')}\n value={currentOption}\n />\n <Drawer />\n </div>\n )\n})\n"],"mappings":"AAAA;;;AAEA,OAAOA,KAAA,IAASC,IAAI,EAAEC,WAAW,EAAEC,OAAO,QAAQ;AAKlD,SAASC,WAAW,QAAQ;AAC5B,SAASC,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,OAAO;AACP,SAASC,gBAAgB,QAAQ;AAEjC,MAAMC,SAAA,GAAY;AAElB,OAAO,MAAMC,gBAAA,gBAAoCR,IAAA,CAAMS,KAAA;EACrD,MAAM;IACJC,cAAc;IACdC,KAAK;IACLC,UAAU;IACVC,QAAA,EAAUC,iBAAiB;IAC3BC,aAAa;IACbC;EAAkB,CACnB,GAAGP,KAAA;EACJ,MAAM;IAAEQ;EAAC,CAAE,GAAGZ,cAAA;EAEd,MAAM;IAAEa,MAAM;IAAEC;EAAU,CAAE,GAAGb,gBAAA,CAAiB;IAAEI,cAAA;IAAgBC,KAAA;IAAOC;EAAW;EAEpF,MAAMQ,OAAA,GAAUlB,OAAA,CAAQ;IACtB,OAAO,C,GACFc,kBAAA,EACH;MACEK,KAAA,eAAOC,IAAA,CAAC;QAAKC,SAAA,EAAW,GAAGhB,SAAA,eAAwB;kBAAGU,CAAA,CAAE;;MACxDO,KAAA,EAAO;IACT,EACD;EACH,GAAG,CAACP,CAAA,EAAGD,kBAAA,CAAmB;EAE1B,MAAMS,aAAA,GAAgBvB,OAAA,CACpB,MAAMc,kBAAA,CAAmBU,IAAI,CAAEC,MAAA,IAAWA,MAAA,CAAOH,KAAK,KAAKT,aAAA,GAC3D,CAACC,kBAAA,EAAoBD,aAAA,CAAc;EAGrC,MAAMF,QAAA,GAAWZ,WAAA,CACd2B,GAAA;IACC,IAAIA,GAAA,CAAIJ,KAAK,KAAK,QAAQ;MACxBL,UAAA;MACA;IACF;IACAL,iBAAA,CAAkBc,GAAA;EACpB,GACA,CAACd,iBAAA,EAAmBK,UAAA,CAAW;EAGjC,oBACEU,KAAA,CAAC;IAAIN,SAAA,EAAW,CAACnB,cAAA,EAAgBG,SAAA,CAAU,CAACuB,MAAM,CAACC,OAAA,EAASC,IAAI,CAAC;4BAC/DV,IAAA,CAACnB,WAAA;
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","memo","useCallback","useMemo","ReactSelect","fieldBaseClass","useTranslation","useVersionDrawer","baseClass","SelectComparison","props","collectionSlug","docID","globalSlug","onChange","onChangeFromProps","versionFromID","versionFromOptions","t","Drawer","openDrawer","options","label","_jsx","className","value","currentOption","find","option","val","_jsxs","filter","Boolean","join","isClearable","isSearchable","placeholder"],"sources":["../../../../src/views/Version/SelectComparison/index.tsx"],"sourcesContent":["'use client'\n\nimport React, { memo, useCallback, useMemo } from 'react'\n\nimport type { CompareOption } from '../Default/types.js'\nimport type { Props } from './types.js'\n\nimport { ReactSelect } from '../../../elements/ReactSelect/index.js'\nimport { fieldBaseClass } from '../../../fields/shared/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport './index.css'\nimport { useVersionDrawer } from './VersionDrawer/index.js'\n\nconst baseClass = 'compare-version'\n\nexport const SelectComparison: React.FC<Props> = memo((props) => {\n const {\n collectionSlug,\n docID,\n globalSlug,\n onChange: onChangeFromProps,\n versionFromID,\n versionFromOptions,\n } = props\n const { t } = useTranslation()\n\n const { Drawer, openDrawer } = useVersionDrawer({ collectionSlug, docID, globalSlug })\n\n const options = useMemo(() => {\n return [\n ...versionFromOptions,\n {\n label: <span className={`${baseClass}-moreVersions`}>{t('version:moreVersions')}</span>,\n value: 'more',\n },\n ]\n }, [t, versionFromOptions])\n\n const currentOption = useMemo(\n () => versionFromOptions.find((option) => option.value === versionFromID),\n [versionFromOptions, versionFromID],\n )\n\n const onChange = useCallback(\n (val: CompareOption) => {\n if (val.value === 'more') {\n openDrawer()\n return\n }\n onChangeFromProps(val)\n },\n [onChangeFromProps, openDrawer],\n )\n\n return (\n <div className={[fieldBaseClass, baseClass].filter(Boolean).join(' ')}>\n <ReactSelect\n aria-label={t('version:selectVersionToCompare')}\n isClearable={false}\n isSearchable={false}\n onChange={onChange}\n options={options}\n placeholder={t('version:selectVersionToCompare')}\n value={currentOption}\n />\n <Drawer />\n </div>\n )\n})\n"],"mappings":"AAAA;;;AAEA,OAAOA,KAAA,IAASC,IAAI,EAAEC,WAAW,EAAEC,OAAO,QAAQ;AAKlD,SAASC,WAAW,QAAQ;AAC5B,SAASC,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,OAAO;AACP,SAASC,gBAAgB,QAAQ;AAEjC,MAAMC,SAAA,GAAY;AAElB,OAAO,MAAMC,gBAAA,gBAAoCR,IAAA,CAAMS,KAAA;EACrD,MAAM;IACJC,cAAc;IACdC,KAAK;IACLC,UAAU;IACVC,QAAA,EAAUC,iBAAiB;IAC3BC,aAAa;IACbC;EAAkB,CACnB,GAAGP,KAAA;EACJ,MAAM;IAAEQ;EAAC,CAAE,GAAGZ,cAAA;EAEd,MAAM;IAAEa,MAAM;IAAEC;EAAU,CAAE,GAAGb,gBAAA,CAAiB;IAAEI,cAAA;IAAgBC,KAAA;IAAOC;EAAW;EAEpF,MAAMQ,OAAA,GAAUlB,OAAA,CAAQ;IACtB,OAAO,C,GACFc,kBAAA,EACH;MACEK,KAAA,eAAOC,IAAA,CAAC;QAAKC,SAAA,EAAW,GAAGhB,SAAA,eAAwB;kBAAGU,CAAA,CAAE;;MACxDO,KAAA,EAAO;IACT,EACD;EACH,GAAG,CAACP,CAAA,EAAGD,kBAAA,CAAmB;EAE1B,MAAMS,aAAA,GAAgBvB,OAAA,CACpB,MAAMc,kBAAA,CAAmBU,IAAI,CAAEC,MAAA,IAAWA,MAAA,CAAOH,KAAK,KAAKT,aAAA,GAC3D,CAACC,kBAAA,EAAoBD,aAAA,CAAc;EAGrC,MAAMF,QAAA,GAAWZ,WAAA,CACd2B,GAAA;IACC,IAAIA,GAAA,CAAIJ,KAAK,KAAK,QAAQ;MACxBL,UAAA;MACA;IACF;IACAL,iBAAA,CAAkBc,GAAA;EACpB,GACA,CAACd,iBAAA,EAAmBK,UAAA,CAAW;EAGjC,oBACEU,KAAA,CAAC;IAAIN,SAAA,EAAW,CAACnB,cAAA,EAAgBG,SAAA,CAAU,CAACuB,MAAM,CAACC,OAAA,EAASC,IAAI,CAAC;4BAC/DV,IAAA,CAACnB,WAAA;MACC,cAAYc,CAAA,CAAE;MACdgB,WAAA,EAAa;MACbC,YAAA,EAAc;MACdrB,QAAA,EAAUA,QAAA;MACVO,OAAA,EAASA,OAAA;MACTe,WAAA,EAAalB,CAAA,CAAE;MACfO,KAAA,EAAOC;qBAETH,IAAA,CAACJ,MAAA;;AAGP","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/widgets/CollectionQuery/SortField/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAgB,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAcrE,eAAO,MAAM,wBAAwB,EAAE,wBA6FtC,CAAA"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
4
|
+
import React, { useCallback, useMemo } from 'react';
|
|
5
|
+
import { SelectInput } from '../../../fields/Select/Input.js';
|
|
6
|
+
import { useField } from '../../../forms/useField/index.js';
|
|
7
|
+
import { useAuth } from '../../../providers/Auth/index.js';
|
|
8
|
+
import { useConfig } from '../../../providers/Config/index.js';
|
|
9
|
+
import { useTranslation } from '../../../providers/Translation/index.js';
|
|
10
|
+
import { reduceFieldsToOptions } from '../../../utilities/reduceFieldsToOptions.js';
|
|
11
|
+
import { getCollectionFieldPaths } from '../getCollectionFieldPaths.js';
|
|
12
|
+
const baseFieldValues = new Set(['createdAt', 'id', 'updatedAt']);
|
|
13
|
+
export const CollectionQuerySortField = ({
|
|
14
|
+
field,
|
|
15
|
+
path: pathFromProps,
|
|
16
|
+
readOnly
|
|
17
|
+
}) => {
|
|
18
|
+
const {
|
|
19
|
+
name,
|
|
20
|
+
admin,
|
|
21
|
+
label,
|
|
22
|
+
required
|
|
23
|
+
} = field;
|
|
24
|
+
const {
|
|
25
|
+
customComponents: {
|
|
26
|
+
AfterInput,
|
|
27
|
+
BeforeInput,
|
|
28
|
+
Description,
|
|
29
|
+
Error,
|
|
30
|
+
Label
|
|
31
|
+
} = {},
|
|
32
|
+
path,
|
|
33
|
+
setValue,
|
|
34
|
+
showError,
|
|
35
|
+
value
|
|
36
|
+
} = useField({
|
|
37
|
+
potentiallyStalePath: pathFromProps
|
|
38
|
+
});
|
|
39
|
+
const relatedCollectionField = useField({
|
|
40
|
+
path: 'relatedCollection'
|
|
41
|
+
});
|
|
42
|
+
const relatedCollection = relatedCollectionField.value;
|
|
43
|
+
const {
|
|
44
|
+
config
|
|
45
|
+
} = useConfig();
|
|
46
|
+
const {
|
|
47
|
+
permissions
|
|
48
|
+
} = useAuth();
|
|
49
|
+
const {
|
|
50
|
+
i18n,
|
|
51
|
+
t
|
|
52
|
+
} = useTranslation();
|
|
53
|
+
const collectionConfig = useMemo(() => {
|
|
54
|
+
if (!relatedCollection) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
return config.collections?.find(collection => collection.slug === relatedCollection) ?? null;
|
|
58
|
+
}, [config.collections, relatedCollection]);
|
|
59
|
+
const options = useMemo(() => {
|
|
60
|
+
if (!relatedCollection || !collectionConfig) {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
// Reuse the same sortable-path rules as the server widget so the dropdown only offers fields
|
|
64
|
+
// the API can actually sort by (e.g. excluding array sub-fields).
|
|
65
|
+
const {
|
|
66
|
+
sortableFieldPaths
|
|
67
|
+
} = getCollectionFieldPaths(collectionConfig.fields);
|
|
68
|
+
const fieldOptions = reduceFieldsToOptions({
|
|
69
|
+
fieldPermissions: permissions?.collections?.[relatedCollection]?.fields ?? true,
|
|
70
|
+
fields: collectionConfig.fields,
|
|
71
|
+
i18n
|
|
72
|
+
}).filter(({
|
|
73
|
+
fieldPath
|
|
74
|
+
}) => sortableFieldPaths.has(fieldPath) && !baseFieldValues.has(fieldPath)).map(({
|
|
75
|
+
fieldPath: fieldPath_0,
|
|
76
|
+
plainTextLabel
|
|
77
|
+
}) => ({
|
|
78
|
+
label: plainTextLabel ?? fieldPath_0,
|
|
79
|
+
value: fieldPath_0
|
|
80
|
+
}));
|
|
81
|
+
return [{
|
|
82
|
+
label: 'ID',
|
|
83
|
+
value: 'id'
|
|
84
|
+
}, {
|
|
85
|
+
label: t('general:createdAt'),
|
|
86
|
+
value: 'createdAt'
|
|
87
|
+
}, {
|
|
88
|
+
label: t('general:updatedAt'),
|
|
89
|
+
value: 'updatedAt'
|
|
90
|
+
}, ...fieldOptions];
|
|
91
|
+
}, [collectionConfig, i18n, permissions, relatedCollection, t]);
|
|
92
|
+
const onChange = useCallback(selectedOption => {
|
|
93
|
+
if (Array.isArray(selectedOption)) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
setValue(typeof selectedOption?.value === 'string' ? selectedOption.value : null);
|
|
97
|
+
}, [setValue]);
|
|
98
|
+
return /*#__PURE__*/_jsx(SelectInput, {
|
|
99
|
+
AfterInput: AfterInput,
|
|
100
|
+
BeforeInput: BeforeInput,
|
|
101
|
+
Description: Description,
|
|
102
|
+
description: admin?.description,
|
|
103
|
+
Error: Error,
|
|
104
|
+
isClearable: true,
|
|
105
|
+
Label: Label,
|
|
106
|
+
label: label,
|
|
107
|
+
name: name,
|
|
108
|
+
onChange: onChange,
|
|
109
|
+
options: options,
|
|
110
|
+
path: path,
|
|
111
|
+
placeholder: relatedCollection ? t('dashboard:widgetSelectSortField') : t('dashboard:widgetSelectCollectionFirst'),
|
|
112
|
+
readOnly: readOnly || !relatedCollection,
|
|
113
|
+
required: required,
|
|
114
|
+
showError: showError,
|
|
115
|
+
value: value
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","useCallback","useMemo","SelectInput","useField","useAuth","useConfig","useTranslation","reduceFieldsToOptions","getCollectionFieldPaths","baseFieldValues","Set","CollectionQuerySortField","field","path","pathFromProps","readOnly","name","admin","label","required","customComponents","AfterInput","BeforeInput","Description","Error","Label","setValue","showError","value","potentiallyStalePath","relatedCollectionField","relatedCollection","config","permissions","i18n","t","collectionConfig","collections","find","collection","slug","options","sortableFieldPaths","fields","fieldOptions","fieldPermissions","filter","fieldPath","has","map","plainTextLabel","onChange","selectedOption","Array","isArray","_jsx","description","isClearable","placeholder"],"sources":["../../../../src/widgets/CollectionQuery/SortField/index.tsx"],"sourcesContent":["'use client'\nimport type { OptionObject, TextFieldClientComponent } from 'payload'\n\nimport React, { useCallback, useMemo } from 'react'\n\nimport { SelectInput } from '../../../fields/Select/Input.js'\nimport { useField } from '../../../forms/useField/index.js'\nimport { useAuth } from '../../../providers/Auth/index.js'\nimport { useConfig } from '../../../providers/Config/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport { reduceFieldsToOptions } from '../../../utilities/reduceFieldsToOptions.js'\nimport { getCollectionFieldPaths } from '../getCollectionFieldPaths.js'\n\nconst baseFieldValues = new Set(['createdAt', 'id', 'updatedAt'])\n\nexport const CollectionQuerySortField: TextFieldClientComponent = ({\n field,\n path: pathFromProps,\n readOnly,\n}) => {\n const { name, admin, label, required } = field\n const {\n customComponents: { AfterInput, BeforeInput, Description, Error, Label } = {},\n path,\n setValue,\n showError,\n value,\n } = useField<string>({ potentiallyStalePath: pathFromProps })\n const relatedCollectionField = useField<string>({ path: 'relatedCollection' })\n const relatedCollection = relatedCollectionField.value\n const { config } = useConfig()\n const { permissions } = useAuth()\n const { i18n, t } = useTranslation()\n\n const collectionConfig = useMemo(() => {\n if (!relatedCollection) {\n return null\n }\n\n return config.collections?.find((collection) => collection.slug === relatedCollection) ?? null\n }, [config.collections, relatedCollection])\n\n const options = useMemo<OptionObject[]>(() => {\n if (!relatedCollection || !collectionConfig) {\n return []\n }\n\n // Reuse the same sortable-path rules as the server widget so the dropdown only offers fields\n // the API can actually sort by (e.g. excluding array sub-fields).\n const { sortableFieldPaths } = getCollectionFieldPaths(collectionConfig.fields)\n\n const fieldOptions = reduceFieldsToOptions({\n fieldPermissions: permissions?.collections?.[relatedCollection]?.fields ?? true,\n fields: collectionConfig.fields,\n i18n,\n })\n .filter(\n ({ fieldPath }) => sortableFieldPaths.has(fieldPath) && !baseFieldValues.has(fieldPath),\n )\n .map(({ fieldPath, plainTextLabel }) => ({\n label: plainTextLabel ?? fieldPath,\n value: fieldPath,\n }))\n\n return [\n { label: 'ID', value: 'id' },\n { label: t('general:createdAt'), value: 'createdAt' },\n { label: t('general:updatedAt'), value: 'updatedAt' },\n ...fieldOptions,\n ]\n }, [collectionConfig, i18n, permissions, relatedCollection, t])\n\n const onChange = useCallback(\n (selectedOption: OptionObject | OptionObject[]) => {\n if (Array.isArray(selectedOption)) {\n return\n }\n\n setValue(typeof selectedOption?.value === 'string' ? selectedOption.value : null)\n },\n [setValue],\n )\n\n return (\n <SelectInput\n AfterInput={AfterInput}\n BeforeInput={BeforeInput}\n Description={Description}\n description={admin?.description}\n Error={Error}\n isClearable\n Label={Label}\n label={label}\n name={name}\n onChange={onChange}\n options={options}\n path={path}\n placeholder={\n relatedCollection\n ? t('dashboard:widgetSelectSortField')\n : t('dashboard:widgetSelectCollectionFirst')\n }\n readOnly={readOnly || !relatedCollection}\n required={required}\n showError={showError}\n value={value}\n />\n )\n}\n"],"mappings":"AAAA;;;AAGA,OAAOA,KAAA,IAASC,WAAW,EAAEC,OAAO,QAAQ;AAE5C,SAASC,WAAW,QAAQ;AAC5B,SAASC,QAAQ,QAAQ;AACzB,SAASC,OAAO,QAAQ;AACxB,SAASC,SAAS,QAAQ;AAC1B,SAASC,cAAc,QAAQ;AAC/B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,uBAAuB,QAAQ;AAExC,MAAMC,eAAA,GAAkB,IAAIC,GAAA,CAAI,CAAC,aAAa,MAAM,YAAY;AAEhE,OAAO,MAAMC,wBAAA,GAAqDA,CAAC;EACjEC,KAAK;EACLC,IAAA,EAAMC,aAAa;EACnBC;AAAQ,CACT;EACC,MAAM;IAAEC,IAAI;IAAEC,KAAK;IAAEC,KAAK;IAAEC;EAAQ,CAAE,GAAGP,KAAA;EACzC,MAAM;IACJQ,gBAAA,EAAkB;MAAEC,UAAU;MAAEC,WAAW;MAAEC,WAAW;MAAEC,KAAK;MAAEC;IAAK,CAAE,GAAG,CAAC,CAAC;IAC7EZ,IAAI;IACJa,QAAQ;IACRC,SAAS;IACTC;EAAK,CACN,GAAGzB,QAAA,CAAiB;IAAE0B,oBAAA,EAAsBf;EAAc;EAC3D,MAAMgB,sBAAA,GAAyB3B,QAAA,CAAiB;IAAEU,IAAA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V,KAAA,EAAOiB,CAAA,CAAE;MAAsBP,KAAA,EAAO;IAAY,GACpD;MAAEV,KAAA,EAAOiB,CAAA,CAAE;MAAsBP,KAAA,EAAO;IAAY,G,GACjDgB,YAAA,CACJ;EACH,GAAG,CAACR,gBAAA,EAAkBF,IAAA,EAAMD,WAAA,EAAaF,iBAAA,EAAmBI,CAAA,CAAE;EAE9D,MAAMgB,QAAA,GAAWnD,WAAA,CACdoD,cAAA;IACC,IAAIC,KAAA,CAAMC,OAAO,CAACF,cAAA,GAAiB;MACjC;IACF;IAEA1B,QAAA,CAAS,OAAO0B,cAAA,EAAgBxB,KAAA,KAAU,WAAWwB,cAAA,CAAexB,KAAK,GAAG;EAC9E,GACA,CAACF,QAAA,CAAS;EAGZ,oBACE6B,IAAA,CAACrD,WAAA;IACCmB,UAAA,EAAYA,UAAA;IACZC,WAAA,EAAaA,WAAA;IACbC,WAAA,EAAaA,WAAA;IACbiC,WAAA,EAAavC,KAAA,EAAOuC,WAAA;IACpBhC,KAAA,EAAOA,KAAA;IACPiC,WAAW;IACXhC,KAAA,EAAOA,KAAA;IACPP,KAAA,EAAOA,KAAA;IACPF,IAAA,EAAMA,IAAA;IACNmC,QAAA,EAAUA,QAAA;IACVV,OAAA,EAASA,OAAA;IACT5B,IAAA,EAAMA,IAAA;IACN6C,WAAA,EACE3B,iBAAA,GACII,CAAA,CAAE,qCACFA,CAAA,CAAE;IAERpB,QAAA,EAAUA,QAAA,IAAY,CAACgB,iBAAA;IACvBZ,QAAA,EAAUA,QAAA;IACVQ,SAAA,EAAWA,SAAA;IACXC,KAAA,EAAOA;;AAGb","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ClientField, Field } from 'payload';
|
|
2
|
+
type QueryableField = ClientField | Field;
|
|
3
|
+
export type CollectionFieldPaths = {
|
|
4
|
+
/** Field paths that can be referenced in a `where` filter. */
|
|
5
|
+
filterableFieldPaths: Set<string>;
|
|
6
|
+
/** Field paths that point to another collection (relationship/upload/join). */
|
|
7
|
+
relationshipFieldPaths: Set<string>;
|
|
8
|
+
/** Field paths that the API can sort by. */
|
|
9
|
+
sortableFieldPaths: Set<string>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Builds the queryable field paths for a collection from either server or client field schemas.
|
|
13
|
+
* Sortability stays anchored on Payload's `sortableFieldTypes` so the widget follows core rules as
|
|
14
|
+
* field types evolve, while array sub-fields remain filter-only.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getCollectionFieldPaths(fields: QueryableField[]): CollectionFieldPaths;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=getCollectionFieldPaths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCollectionFieldPaths.d.ts","sourceRoot":"","sources":["../../../src/widgets/CollectionQuery/getCollectionFieldPaths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAIjD,KAAK,cAAc,GAAG,WAAW,GAAG,KAAK,CAAA;AAMzC,MAAM,MAAM,oBAAoB,GAAG;IACjC,8DAA8D;IAC9D,oBAAoB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACjC,+EAA+E;IAC/E,sBAAsB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACnC,4CAA4C;IAC5C,kBAAkB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAChC,CAAA;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,cAAc,EAAE,GAAG,oBAAoB,CAUtF"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { fieldAffectsData, sortableFieldTypes } from 'payload/shared';
|
|
2
|
+
const baseFieldPaths = ['createdAt', 'id', 'updatedAt'];
|
|
3
|
+
const sortableFieldTypeSet = new Set(sortableFieldTypes);
|
|
4
|
+
const relationshipFieldTypes = new Set(['join', 'relationship', 'upload']);
|
|
5
|
+
/**
|
|
6
|
+
* Builds the queryable field paths for a collection from either server or client field schemas.
|
|
7
|
+
* Sortability stays anchored on Payload's `sortableFieldTypes` so the widget follows core rules as
|
|
8
|
+
* field types evolve, while array sub-fields remain filter-only.
|
|
9
|
+
*/
|
|
10
|
+
export function getCollectionFieldPaths(fields) {
|
|
11
|
+
const paths = {
|
|
12
|
+
filterableFieldPaths: new Set(baseFieldPaths),
|
|
13
|
+
relationshipFieldPaths: new Set(),
|
|
14
|
+
sortableFieldPaths: new Set(baseFieldPaths)
|
|
15
|
+
};
|
|
16
|
+
addFieldPaths({
|
|
17
|
+
fields,
|
|
18
|
+
paths
|
|
19
|
+
});
|
|
20
|
+
return paths;
|
|
21
|
+
}
|
|
22
|
+
function addFieldPaths({
|
|
23
|
+
canSort = true,
|
|
24
|
+
fields,
|
|
25
|
+
parentPath,
|
|
26
|
+
paths
|
|
27
|
+
}) {
|
|
28
|
+
for (const field of fields) {
|
|
29
|
+
if ('virtual' in field && field.virtual === true) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (field.type === 'tabs' && 'tabs' in field) {
|
|
33
|
+
for (const tab of field.tabs) {
|
|
34
|
+
const path = 'name' in tab && tab.name ? joinPath(parentPath, tab.name) : parentPath;
|
|
35
|
+
addFieldPaths({
|
|
36
|
+
canSort,
|
|
37
|
+
fields: tab.fields,
|
|
38
|
+
parentPath: path,
|
|
39
|
+
paths
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
if ((field.type === 'collapsible' || field.type === 'row') && 'fields' in field) {
|
|
45
|
+
addFieldPaths({
|
|
46
|
+
canSort,
|
|
47
|
+
fields: field.fields,
|
|
48
|
+
parentPath,
|
|
49
|
+
paths
|
|
50
|
+
});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
// Groups are queryable by their child paths. Named groups prefix those paths.
|
|
54
|
+
if (field.type === 'group' && 'fields' in field) {
|
|
55
|
+
const path = fieldAffectsData(field) ? joinPath(parentPath, field.name) : parentPath;
|
|
56
|
+
addFieldPaths({
|
|
57
|
+
canSort,
|
|
58
|
+
fields: field.fields,
|
|
59
|
+
parentPath: path,
|
|
60
|
+
paths
|
|
61
|
+
});
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
// Array sub-fields can be filtered on, but the API cannot sort by them.
|
|
65
|
+
if (field.type === 'array' && 'fields' in field) {
|
|
66
|
+
addFieldPaths({
|
|
67
|
+
canSort: false,
|
|
68
|
+
fields: field.fields,
|
|
69
|
+
parentPath: joinPath(parentPath, field.name),
|
|
70
|
+
paths
|
|
71
|
+
});
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (field.type === 'blocks' || !fieldAffectsData(field)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const name = 'virtual' in field && typeof field.virtual === 'string' ? field.virtual : field.name;
|
|
78
|
+
const path = joinPath(parentPath, name);
|
|
79
|
+
paths.filterableFieldPaths.add(path);
|
|
80
|
+
if (relationshipFieldTypes.has(field.type)) {
|
|
81
|
+
paths.relationshipFieldPaths.add(path);
|
|
82
|
+
}
|
|
83
|
+
if (canSort && sortableFieldTypeSet.has(field.type)) {
|
|
84
|
+
paths.sortableFieldPaths.add(path);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
function joinPath(parentPath, path) {
|
|
89
|
+
return parentPath ? `${parentPath}.${path}` : path;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=getCollectionFieldPaths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCollectionFieldPaths.js","names":["fieldAffectsData","sortableFieldTypes","baseFieldPaths","sortableFieldTypeSet","Set","relationshipFieldTypes","getCollectionFieldPaths","fields","paths","filterableFieldPaths","relationshipFieldPaths","sortableFieldPaths","addFieldPaths","canSort","parentPath","field","virtual","type","tab","tabs","path","name","joinPath","add","has"],"sources":["../../../src/widgets/CollectionQuery/getCollectionFieldPaths.ts"],"sourcesContent":["import type { ClientField, Field } from 'payload'\n\nimport { fieldAffectsData, sortableFieldTypes } from 'payload/shared'\n\ntype QueryableField = ClientField | Field\n\nconst baseFieldPaths = ['createdAt', 'id', 'updatedAt']\nconst sortableFieldTypeSet = new Set<string>(sortableFieldTypes)\nconst relationshipFieldTypes = new Set<string>(['join', 'relationship', 'upload'])\n\nexport type CollectionFieldPaths = {\n /** Field paths that can be referenced in a `where` filter. */\n filterableFieldPaths: Set<string>\n /** Field paths that point to another collection (relationship/upload/join). */\n relationshipFieldPaths: Set<string>\n /** Field paths that the API can sort by. */\n sortableFieldPaths: Set<string>\n}\n\n/**\n * Builds the queryable field paths for a collection from either server or client field schemas.\n * Sortability stays anchored on Payload's `sortableFieldTypes` so the widget follows core rules as\n * field types evolve, while array sub-fields remain filter-only.\n */\nexport function getCollectionFieldPaths(fields: QueryableField[]): CollectionFieldPaths {\n const paths: CollectionFieldPaths = {\n filterableFieldPaths: new Set(baseFieldPaths),\n relationshipFieldPaths: new Set(),\n sortableFieldPaths: new Set(baseFieldPaths),\n }\n\n addFieldPaths({ fields, paths })\n\n return paths\n}\n\nfunction addFieldPaths({\n canSort = true,\n fields,\n parentPath,\n paths,\n}: {\n canSort?: boolean\n fields: QueryableField[]\n parentPath?: string\n paths: CollectionFieldPaths\n}) {\n for (const field of fields) {\n if ('virtual' in field && field.virtual === true) {\n continue\n }\n\n if (field.type === 'tabs' && 'tabs' in field) {\n for (const tab of field.tabs) {\n const path = 'name' in tab && tab.name ? joinPath(parentPath, tab.name) : parentPath\n\n addFieldPaths({ canSort, fields: tab.fields, parentPath: path, paths })\n }\n\n continue\n }\n\n if ((field.type === 'collapsible' || field.type === 'row') && 'fields' in field) {\n addFieldPaths({ canSort, fields: field.fields, parentPath, paths })\n\n continue\n }\n\n // Groups are queryable by their child paths. Named groups prefix those paths.\n if (field.type === 'group' && 'fields' in field) {\n const path = fieldAffectsData(field) ? joinPath(parentPath, field.name) : parentPath\n\n addFieldPaths({ canSort, fields: field.fields, parentPath: path, paths })\n\n continue\n }\n\n // Array sub-fields can be filtered on, but the API cannot sort by them.\n if (field.type === 'array' && 'fields' in field) {\n addFieldPaths({\n canSort: false,\n fields: field.fields,\n parentPath: joinPath(parentPath, field.name),\n paths,\n })\n\n continue\n }\n\n if (field.type === 'blocks' || !fieldAffectsData(field)) {\n continue\n }\n\n const name =\n 'virtual' in field && typeof field.virtual === 'string' ? field.virtual : field.name\n const path = joinPath(parentPath, name)\n\n paths.filterableFieldPaths.add(path)\n\n if (relationshipFieldTypes.has(field.type)) {\n paths.relationshipFieldPaths.add(path)\n }\n\n if (canSort && sortableFieldTypeSet.has(field.type)) {\n paths.sortableFieldPaths.add(path)\n }\n }\n}\n\nfunction joinPath(parentPath: string | undefined, path: string) {\n return parentPath ? `${parentPath}.${path}` : path\n}\n"],"mappings":"AAEA,SAASA,gBAAgB,EAAEC,kBAAkB,QAAQ;AAIrD,MAAMC,cAAA,GAAiB,CAAC,aAAa,MAAM,YAAY;AACvD,MAAMC,oBAAA,GAAuB,IAAIC,GAAA,CAAYH,kBAAA;AAC7C,MAAMI,sBAAA,GAAyB,IAAID,GAAA,CAAY,CAAC,QAAQ,gBAAgB,SAAS;AAWjF;;;;;AAKA,OAAO,SAASE,wBAAwBC,MAAwB;EAC9D,MAAMC,KAAA,GAA8B;IAClCC,oBAAA,EAAsB,IAAIL,GAAA,CAAIF,cAAA;IAC9BQ,sBAAA,EAAwB,IAAIN,GAAA;IAC5BO,kBAAA,EAAoB,IAAIP,GAAA,CAAIF,cAAA;EAC9B;EAEAU,aAAA,CAAc;IAAEL,MAAA;IAAQC;EAAM;EAE9B,OAAOA,KAAA;AACT;AAEA,SAASI,cAAc;EACrBC,OAAA,GAAU,IAAI;EACdN,MAAM;EACNO,UAAU;EACVN;AAAK,CAMN;EACC,KAAK,MAAMO,KAAA,IAASR,MAAA,EAAQ;IAC1B,IAAI,aAAaQ,KAAA,IA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Y,CAACjB,gBAAA,CAAiBe,KAAA,GAAQ;MACvD;IACF;IAEA,MAAMM,IAAA,GACJ,aAAaN,KAAA,IAAS,OAAOA,KAAA,CAAMC,OAAO,KAAK,WAAWD,KAAA,CAAMC,OAAO,GAAGD,KAAA,CAAMM,IAAI;IACtF,MAAMD,IAAA,GAAOE,QAAA,CAASR,UAAA,EAAYO,IAAA;IAElCb,KAAA,CAAMC,oBAAoB,CAACc,GAAG,CAACH,IAAA;IAE/B,IAAIf,sBAAA,CAAuBmB,GAAG,CAACT,KAAA,CAAME,IAAI,GAAG;MAC1CT,KAAA,CAAME,sBAAsB,CAACa,GAAG,CAACH,IAAA;IACnC;IAEA,IAAIP,OAAA,IAAWV,oBAAA,CAAqBqB,GAAG,CAACT,KAAA,CAAME,IAAI,GAAG;MACnDT,KAAA,CAAMG,kBAAkB,CAACY,GAAG,CAACH,IAAA;IAC/B;EACF;AACF;AAEA,SAASE,SAASR,UAA8B,EAAEM,IAAY;EAC5D,OAAON,UAAA,GAAa,GAAGA,UAAA,IAAcM,IAAA,EAAM,GAAGA,IAAA;AAChD","ignoreList":[]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getCollectionFieldPaths } from './getCollectionFieldPaths.js';
|
|
3
|
+
const fields = [{
|
|
4
|
+
name: 'title',
|
|
5
|
+
type: 'text'
|
|
6
|
+
}, {
|
|
7
|
+
name: 'status',
|
|
8
|
+
type: 'select',
|
|
9
|
+
options: [{
|
|
10
|
+
label: 'Draft',
|
|
11
|
+
value: 'draft'
|
|
12
|
+
}, {
|
|
13
|
+
label: 'Published',
|
|
14
|
+
value: 'published'
|
|
15
|
+
}]
|
|
16
|
+
}, {
|
|
17
|
+
name: 'isActive',
|
|
18
|
+
type: 'checkbox'
|
|
19
|
+
}, {
|
|
20
|
+
name: 'category',
|
|
21
|
+
type: 'relationship',
|
|
22
|
+
relationTo: 'categories'
|
|
23
|
+
}, {
|
|
24
|
+
name: 'meta',
|
|
25
|
+
type: 'group',
|
|
26
|
+
fields: [{
|
|
27
|
+
name: 'subtitle',
|
|
28
|
+
type: 'text'
|
|
29
|
+
}]
|
|
30
|
+
}, {
|
|
31
|
+
name: 'items',
|
|
32
|
+
type: 'array',
|
|
33
|
+
fields: [{
|
|
34
|
+
name: 'label',
|
|
35
|
+
type: 'text'
|
|
36
|
+
}]
|
|
37
|
+
}, {
|
|
38
|
+
type: 'tabs',
|
|
39
|
+
tabs: [{
|
|
40
|
+
name: 'seo',
|
|
41
|
+
fields: [{
|
|
42
|
+
name: 'keyword',
|
|
43
|
+
type: 'text'
|
|
44
|
+
}]
|
|
45
|
+
}, {
|
|
46
|
+
fields: [{
|
|
47
|
+
name: 'flat',
|
|
48
|
+
type: 'text'
|
|
49
|
+
}],
|
|
50
|
+
label: 'Layout'
|
|
51
|
+
}]
|
|
52
|
+
}, {
|
|
53
|
+
type: 'row',
|
|
54
|
+
fields: [{
|
|
55
|
+
name: 'rowField',
|
|
56
|
+
type: 'text'
|
|
57
|
+
}]
|
|
58
|
+
}];
|
|
59
|
+
describe('getCollectionFieldPaths', () => {
|
|
60
|
+
const {
|
|
61
|
+
filterableFieldPaths,
|
|
62
|
+
relationshipFieldPaths,
|
|
63
|
+
sortableFieldPaths
|
|
64
|
+
} = getCollectionFieldPaths(fields);
|
|
65
|
+
it('should always include base document fields', () => {
|
|
66
|
+
for (const path of ['createdAt', 'id', 'updatedAt']) {
|
|
67
|
+
expect(sortableFieldPaths.has(path)).toBe(true);
|
|
68
|
+
expect(filterableFieldPaths.has(path)).toBe(true);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
it('should mark top-level sortable field types as sortable', () => {
|
|
72
|
+
expect(sortableFieldPaths.has('title')).toBe(true);
|
|
73
|
+
expect(sortableFieldPaths.has('status')).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
it('should not mark non-sortable field types as sortable but keep them filterable', () => {
|
|
76
|
+
expect(sortableFieldPaths.has('isActive')).toBe(false);
|
|
77
|
+
expect(filterableFieldPaths.has('isActive')).toBe(true);
|
|
78
|
+
});
|
|
79
|
+
it('should treat relationships as filterable, flagged, and not sortable', () => {
|
|
80
|
+
expect(filterableFieldPaths.has('category')).toBe(true);
|
|
81
|
+
expect(relationshipFieldPaths.has('category')).toBe(true);
|
|
82
|
+
expect(sortableFieldPaths.has('category')).toBe(false);
|
|
83
|
+
});
|
|
84
|
+
it('should flatten group sub-fields into sortable and filterable paths', () => {
|
|
85
|
+
expect(sortableFieldPaths.has('meta.subtitle')).toBe(true);
|
|
86
|
+
expect(filterableFieldPaths.has('meta.subtitle')).toBe(true);
|
|
87
|
+
});
|
|
88
|
+
it('should keep array sub-fields filterable but never sortable', () => {
|
|
89
|
+
expect(filterableFieldPaths.has('items.label')).toBe(true);
|
|
90
|
+
expect(sortableFieldPaths.has('items.label')).toBe(false);
|
|
91
|
+
});
|
|
92
|
+
it('should prefix named tab sub-fields and inline unnamed tab sub-fields', () => {
|
|
93
|
+
expect(sortableFieldPaths.has('seo.keyword')).toBe(true);
|
|
94
|
+
expect(sortableFieldPaths.has('flat')).toBe(true);
|
|
95
|
+
});
|
|
96
|
+
it('should inline presentational row sub-fields', () => {
|
|
97
|
+
expect(sortableFieldPaths.has('rowField')).toBe(true);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=getCollectionFieldPaths.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCollectionFieldPaths.spec.js","names":["describe","expect","it","getCollectionFieldPaths","fields","name","type","options","label","value","relationTo","tabs","filterableFieldPaths","relationshipFieldPaths","sortableFieldPaths","path","has","toBe"],"sources":["../../../src/widgets/CollectionQuery/getCollectionFieldPaths.spec.ts"],"sourcesContent":["import type { Field } from 'payload'\n\nimport { describe, expect, it } from 'vitest'\n\nimport { getCollectionFieldPaths } from './getCollectionFieldPaths.js'\n\nconst fields: Field[] = [\n { name: 'title', type: 'text' },\n {\n name: 'status',\n type: 'select',\n options: [\n { label: 'Draft', value: 'draft' },\n { label: 'Published', value: 'published' },\n ],\n },\n { name: 'isActive', type: 'checkbox' },\n { name: 'category', type: 'relationship', relationTo: 'categories' },\n {\n name: 'meta',\n type: 'group',\n fields: [{ name: 'subtitle', type: 'text' }],\n },\n {\n name: 'items',\n type: 'array',\n fields: [{ name: 'label', type: 'text' }],\n },\n {\n type: 'tabs',\n tabs: [\n { name: 'seo', fields: [{ name: 'keyword', type: 'text' }] },\n { fields: [{ name: 'flat', type: 'text' }], label: 'Layout' },\n ],\n },\n {\n type: 'row',\n fields: [{ name: 'rowField', type: 'text' }],\n },\n]\n\ndescribe('getCollectionFieldPaths', () => {\n const { filterableFieldPaths, relationshipFieldPaths, sortableFieldPaths } =\n getCollectionFieldPaths(fields)\n\n it('should always include base document fields', () => {\n for (const path of ['createdAt', 'id', 'updatedAt']) {\n expect(sortableFieldPaths.has(path)).toBe(true)\n expect(filterableFieldPaths.has(path)).toBe(true)\n }\n })\n\n it('should mark top-level sortable field types as sortable', () => {\n expect(sortableFieldPaths.has('title')).toBe(true)\n expect(sortableFieldPaths.has('status')).toBe(true)\n })\n\n it('should not mark non-sortable field types as sortable but keep them filterable', () => {\n expect(sortableFieldPaths.has('isActive')).toBe(false)\n expect(filterableFieldPaths.has('isActive')).toBe(true)\n })\n\n it('should treat relationships as filterable, flagged, and not sortable', () => {\n expect(filterableFieldPaths.has('category')).toBe(true)\n expect(relationshipFieldPaths.has('category')).toBe(true)\n expect(sortableFieldPaths.has('category')).toBe(false)\n })\n\n it('should flatten group sub-fields into sortable and filterable paths', () => {\n expect(sortableFieldPaths.has('meta.subtitle')).toBe(true)\n expect(filterableFieldPaths.has('meta.subtitle')).toBe(true)\n })\n\n it('should keep array sub-fields filterable but never sortable', () => {\n expect(filterableFieldPaths.has('items.label')).toBe(true)\n expect(sortableFieldPaths.has('items.label')).toBe(false)\n })\n\n it('should prefix named tab sub-fields and inline unnamed tab sub-fields', () => {\n expect(sortableFieldPaths.has('seo.keyword')).toBe(true)\n expect(sortableFieldPaths.has('flat')).toBe(true)\n })\n\n it('should inline presentational row sub-fields', () => {\n expect(sortableFieldPaths.has('rowField')).toBe(true)\n })\n})\n"],"mappings":"AAEA,SAASA,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ;AAErC,SAASC,uBAAuB,QAAQ;AAExC,MAAMC,MAAA,GAAkB,CACtB;EAAEC,IAAA,EAAM;EAASC,IAAA,EAAM;AAAO,GAC9B;EACED,IAAA,EAAM;EACNC,IAAA,EAAM;EACNC,OAAA,EAAS,CACP;IAAEC,KAAA,EAAO;IAASC,KAAA,EAAO;EAAQ,GACjC;IAAED,KAAA,EAAO;IAAaC,KAAA,EAAO;EAAY;AAE7C,GACA;EAAEJ,IAAA,EAAM;EAAYC,IAAA,EAAM;AAAW,GACrC;EAAED,IAAA,EAAM;EAAYC,IAAA,EAAM;EAAgBI,UAAA,EAAY;AAAa,GACnE;EACEL,IAAA,EAAM;EACNC,IAAA,EAAM;EACNF,MAAA,EAAQ,CAAC;IAAEC,IAAA,EAAM;IAAYC,IAAA,EAAM;EAAO;AAC5C,GACA;EACED,IAAA,EAAM;EACNC,IAAA,EAAM;EACNF,MAAA,EAAQ,CAAC;IAAEC,IAAA,EAAM;IAASC,IAAA,EAAM;EAAO;AACzC,GACA;EACEA,IAAA,EAAM;EACNK,IAAA,EAAM,CACJ;IAAEN,IAAA,EAAM;IAAOD,MAAA,EAAQ,CAAC;MAAEC,IAAA,EAAM;MAAWC,IAAA,EAAM;IAAO;EAAG,GAC3D;IAAEF,MAAA,EAAQ,CAAC;MAAEC,IAAA,EAAM;MAAQC,IAAA,EAAM;IAAO,EAAE;IAAEE,KAAA,EAAO;EAAS;AAEhE,GACA;EACEF,IAAA,EAAM;EACNF,MAAA,EAAQ,CAAC;IAAEC,IAAA,EAAM;IAAYC,IAAA,EAAM;EAAO;AAC5C,EACD;AAEDN,QAAA,CAAS,2BAA2B;EAClC,MAAM;IAA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