From 5affccb168dae1d72dbe10a8d92c5ea841a203c9 Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Mon, 23 Sep 2024 12:26:46 +0200 Subject: [PATCH] :sparkles: [#4608] Bring prefill modal in line with backend --- .../js/components/admin/form_design/mocks.js | 6 +-- .../variables/VariablesEditor.stories.js | 42 +++++++++---------- .../prefill/PrefillConfigurationForm.js | 14 ++++--- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/openforms/js/components/admin/form_design/mocks.js b/src/openforms/js/components/admin/form_design/mocks.js index 48d4760c98..d3a18f722f 100644 --- a/src/openforms/js/components/admin/form_design/mocks.js +++ b/src/openforms/js/components/admin/form_design/mocks.js @@ -64,10 +64,10 @@ export const mockPrefillAttributesGet = pluginAttributes => export const mockObjectsAPIPrefillAttributesGet = pluginAttributes => rest.get( - `${API_BASE_URL}/api/v2/prefill/plugins/:plugin/:uuid/versions/:version/attributes`, + `${API_BASE_URL}/api/v2/prefill/plugins/objects-api/objecttypes/:uuid/versions/:version/properties`, (req, res, ctx) => { - const {plugin, uuid, version} = req.params; - const attributeList = pluginAttributes[plugin][uuid][version] || []; + const {uuid, version} = req.params; + const attributeList = pluginAttributes[uuid][version] || []; return res(ctx.json(attributeList)); } ); diff --git a/src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.js b/src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.js index e9d97658ce..8b5f501916 100644 --- a/src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.js +++ b/src/openforms/js/components/admin/form_design/variables/VariablesEditor.stories.js @@ -7,13 +7,7 @@ import { import {BACKEND_OPTIONS_FORMS} from 'components/admin/form_design/registrations'; import {mockTargetPathsPost} from 'components/admin/form_design/registrations/objectsapi/mocks'; -import { - mockCataloguesGet, - mockDocumentTypesGet, - mockObjecttypeVersionsGet, - mockObjecttypesError, - mockObjecttypesGet, -} from '../registrations/objectsapi/mocks'; +import {mockObjecttypeVersionsGet, mockObjecttypesGet} from '../registrations/objectsapi/mocks'; import {FormDecorator} from '../story-decorators'; import VariablesEditor from './VariablesEditor'; @@ -173,21 +167,25 @@ export default { ], }), mockObjectsAPIPrefillAttributesGet({ - objects_api: { - '2c77babf-a967-4057-9969-0200320d23f2': { - 1: [ - {id: 'firstName', label: 'First name'}, - {id: 'lastName', label: 'Last name'}, - {id: 'age', label: 'Age'}, - ], - }, - '2c77babf-a967-4057-9969-0200320d23f1': { - 1: [{id: 'height', label: 'Height'}], - 2: [ - {id: 'height', label: 'Height'}, - {id: 'species', label: 'Species'}, - ], - }, + '2c77babf-a967-4057-9969-0200320d23f2': { + 1: [ + { + targetPath: ['firstName'], + jsonSchema: {type: 'string', description: 'First name'}, + }, + { + targetPath: ['lastName'], + jsonSchema: {type: 'string', description: 'Last name'}, + }, + {targetPath: ['age'], jsonSchema: {type: 'integer', description: 'Age'}}, + ], + }, + '2c77babf-a967-4057-9969-0200320d23f1': { + 1: [{targetPath: ['height'], jsonSchema: {type: 'integer', description: 'Height'}}], + 2: [ + {targetPath: ['height'], jsonSchema: {type: 'integer', description: 'Height'}}, + {targetPath: ['species'], jsonSchema: {type: 'string', description: 'Species'}}, + ], }, }), mockObjecttypesGet([ diff --git a/src/openforms/js/components/admin/form_design/variables/prefill/PrefillConfigurationForm.js b/src/openforms/js/components/admin/form_design/variables/prefill/PrefillConfigurationForm.js index 43991ba463..490a602c1e 100644 --- a/src/openforms/js/components/admin/form_design/variables/prefill/PrefillConfigurationForm.js +++ b/src/openforms/js/components/admin/form_design/variables/prefill/PrefillConfigurationForm.js @@ -217,7 +217,7 @@ const ObjectsAPIPrefillFields = ({values, errors}) => { defaultMessage: 'Prefill attribute', }); - const {objecttype, objecttypeVersion} = values.prefillOptions; + const {objecttype, objecttypeVersion, objectsApiGroup} = values.prefillOptions; // Load the possible prefill attributes // XXX: this would benefit from client-side caching @@ -226,14 +226,16 @@ const ObjectsAPIPrefillFields = ({values, errors}) => { value = [], error, } = useAsync(async () => { - if (!plugin || !objecttype || !objecttypeVersion) return []; + if (!plugin || !objecttype || !objecttypeVersion || !objectsApiGroup) return []; - const endpoint = `/api/v2/prefill/plugins/${plugin}/${objecttype}/versions/${objecttypeVersion}/attributes`; + const endpoint = `/api/v2/prefill/plugins/objects-api/objecttypes/${objecttype}/versions/${objecttypeVersion}/properties`; + const params = new URLSearchParams({objects_api_group: objectsApiGroup}); // XXX: clean up error handling here at some point... - const response = await get(endpoint); + const response = await get(`${endpoint}?${params.toString()}`); if (!response.ok) throw response.data; - return response.data.map(attribute => [attribute.id, attribute.label]); - }, [plugin, objecttype, objecttypeVersion]); + console.log(response.data); + return response.data.map(attribute => [attribute.targetPath, attribute.targetPath.join(' > ')]); + }, [plugin, objecttype, objecttypeVersion, objectsApiGroup]); // throw errors to the nearest error boundary if (error) throw error;