Skip to content

Commit

Permalink
✨ [#4608] Bring prefill modal in line with backend
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Sep 23, 2024
1 parent d03a8a6 commit 5affccb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions src/openforms/js/components/admin/form_design/mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 5affccb

Please sign in to comment.