Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Objects API sets #4332

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/openforms/fixtures/admin_index_unlisted.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"qmatic.QmaticConfig",
"registrations_email.EmailConfig",
"registrations_microsoft_graph.MSGraphRegistrationConfig",
"registrations_objects_api.ObjectsAPIGroupConfig",
"registrations_objects_api.ObjectsAPIConfig",
"stuf.StufService",
"stuf_bg.StufBGConfig",
Expand Down
12 changes: 12 additions & 0 deletions src/openforms/js/compiled-lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1893,6 +1893,12 @@
"value": "Decision definition ID"
}
],
"Ijrbrp": [
{
"type": 0,
"value": "Which Objects API group to use. If not provided, the default Objects API group will be used."
}
],
"Ika4IH": [
{
"type": 0,
Expand Down Expand Up @@ -4499,6 +4505,12 @@
"value": "House number"
}
],
"mgs/Xe": [
{
"type": 0,
"value": "Objects API group"
}
],
"mpzdoT": [
{
"type": 0,
Expand Down
12 changes: 12 additions & 0 deletions src/openforms/js/compiled-lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,12 @@
"value": "Beslisdefinitie-ID"
}
],
"Ijrbrp": [
{
"type": 0,
"value": "Which Objects API group to use. If not provided, the default Objects API group will be used."
}
],
"Ika4IH": [
{
"type": 0,
Expand Down Expand Up @@ -4504,6 +4510,12 @@
"value": "Huisnummer"
}
],
"mgs/Xe": [
{
"type": 0,
"value": "Objects API group"
}
],
"mpzdoT": [
{
"type": 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import {useIntl} from 'react-intl';

import {CustomFieldTemplate} from 'components/admin/RJSFWrapper';
import {Checkbox, NumberInput, TextArea, TextInput} from 'components/admin/forms/Inputs';
import Select from 'components/admin/forms/Select';
import {ValidationErrorContext} from 'components/admin/forms/ValidationErrors';

import {getErrorMarkup, getFieldErrors} from './utils';
import {getChoicesFromSchema, getErrorMarkup, getFieldErrors} from './utils';

const LegacyConfigFields = ({index, name, formData, onChange}) => {
const LegacyConfigFields = ({index, name, schema, formData, onChange}) => {
const intl = useIntl();
const validationErrors = useContext(ValidationErrorContext);

const {
objectsApiGroup = '',
objecttype = '',
objecttypeVersion = '',
productaanvraagType = '',
Expand All @@ -32,6 +34,33 @@ const LegacyConfigFields = ({index, name, formData, onChange}) => {

return (
<>
<CustomFieldTemplate
id="root_objectsApiGroup"
label={intl.formatMessage({
defaultMessage: 'Objects API group',
description: 'Objects API group',
})}
rawDescription={intl.formatMessage({
description: 'Objects API group selection',
defaultMessage:
'Which Objects API group to use. If not provided, the default Objects API group will be used.',
})}
Viicos marked this conversation as resolved.
Show resolved Hide resolved
rawErrors={null}
errors={null}
displayLabel
>
<Select
id="root_objectsApiGroup"
name="objectsApiGroup"
choices={getChoicesFromSchema(
schema?.properties?.objectsApiGroup?.enum,
schema?.properties?.objectsApiGroup?.enumNames
)}
value={objectsApiGroup}
onChange={onChange}
allowBlank
/>
</CustomFieldTemplate>
<CustomFieldTemplate
id="root_objecttype"
label={intl.formatMessage({
Expand Down Expand Up @@ -269,7 +298,9 @@ const LegacyConfigFields = ({index, name, formData, onChange}) => {
LegacyConfigFields.propTypes = {
index: PropTypes.number,
name: PropTypes.string,
schema: PropTypes.any,
formData: PropTypes.shape({
objectsApiGroup: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
version: PropTypes.number,
objecttype: PropTypes.string,
objecttypeVersion: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const getObjecttypeVersionsEndpoint = objecttype => {
};

const ObjectTypeVersionSelect = ({
objectsApiGroup,
availableObjecttypes = [],
selectedObjecttype,
selectedVersion,
Expand All @@ -31,13 +32,15 @@ const ObjectTypeVersionSelect = ({
// no match -> no versions to retrieve;
if (!objecttype) return [];

const response = await get(getObjecttypeVersionsEndpoint(objecttype));
const params = {};
if (objectsApiGroup) params.objects_api_group = objectsApiGroup;
const response = await get(getObjecttypeVersionsEndpoint(objecttype), params);
if (!response.ok) {
throw new Error('Loading available object types failed');
}
const versions = response.data;
return versions.sort((v1, v2) => v2.version - v1.version);
}, [selectedObjecttype, objecttypeUrls]);
}, [selectedObjecttype, objecttypeUrls, objectsApiGroup]);

const choices =
loading || error
Expand Down Expand Up @@ -76,6 +79,7 @@ const ObjectTypeVersionSelect = ({
};

ObjectTypeVersionSelect.propTypes = {
objectsApiGroup: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
availableObjecttypes: PropTypes.array,
selectedObjecttype: PropTypes.string.isRequired,
selectedVersion: PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const ObjectsApiOptionsFormFields = ({index, name, schema, formData, onChange})
<LegacyConfigFields
index={index}
name={name}
schema={schema}
formData={formData}
onChange={onFieldChange}
/>
Expand All @@ -111,6 +112,7 @@ const ObjectsApiOptionsFormFields = ({index, name, schema, formData, onChange})
<V2ConfigFields
index={index}
name={name}
schema={schema}
formData={formData}
onChange={onFieldChange}
/>
Expand All @@ -126,6 +128,7 @@ ObjectsApiOptionsFormFields.propTypes = {
name: PropTypes.string,
schema: PropTypes.any,
formData: PropTypes.shape({
objectsApiGroup: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
version: PropTypes.number,
objecttype: PropTypes.string,
objecttypeVersion: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,21 @@ import {FormattedMessage, useIntl} from 'react-intl';

import {CustomFieldTemplate} from 'components/admin/RJSFWrapper';
import {Checkbox, TextInput} from 'components/admin/forms/Inputs';
import Select from 'components/admin/forms/Select';
import {ValidationErrorContext} from 'components/admin/forms/ValidationErrors';
import ErrorMessage from 'components/errors/ErrorMessage';

import ObjectTypeSelect from './ObjectTypeSelect';
import ObjectTypeVersionSelect from './ObjectTypeVersionSelect';
import {useGetAvailableObjectTypes} from './hooks';
import {getErrorMarkup, getFieldErrors} from './utils';
import {getChoicesFromSchema, getErrorMarkup, getFieldErrors} from './utils';

const V2ConfigFields = ({index, name, formData, onChange}) => {
const V2ConfigFields = ({index, name, schema, formData, onChange}) => {
const intl = useIntl();
const validationErrors = useContext(ValidationErrorContext);

// Track available object types and versions in this component so the state can be
// shared.
const availableObjectTypesState = useGetAvailableObjectTypes();

const {
objectsApiGroup = '',
objecttype = '',
objecttypeVersion = '',
informatieobjecttypeSubmissionReport = '',
Expand All @@ -30,6 +28,10 @@ const V2ConfigFields = ({index, name, formData, onChange}) => {
organisatieRsin = '',
} = formData;

// Track available object types and versions in this component so the state can be
// shared.
const availableObjectTypesState = useGetAvailableObjectTypes(objectsApiGroup);

const buildErrorsComponent = field => {
const rawErrors = getFieldErrors(name, index, validationErrors, field);
return rawErrors ? getErrorMarkup(rawErrors) : null;
Expand All @@ -49,6 +51,33 @@ const V2ConfigFields = ({index, name, formData, onChange}) => {

return (
<>
<CustomFieldTemplate
id="root_objectsApiGroup"
label={intl.formatMessage({
defaultMessage: 'Objects API group',
description: 'Objects API group',
})}
rawDescription={intl.formatMessage({
description: 'Objects API group selection',
defaultMessage:
'Which Objects API group to use. If not provided, the default Objects API group will be used.',
})}
Viicos marked this conversation as resolved.
Show resolved Hide resolved
rawErrors={null}
errors={null}
displayLabel
>
<Select
id="root_objectsApiGroup"
name="objectsApiGroup"
choices={getChoicesFromSchema(
schema?.properties?.objectsApiGroup?.enum,
schema?.properties?.objectsApiGroup?.enumNames
)}
value={objectsApiGroup}
onChange={onChange}
allowBlank
/>
</CustomFieldTemplate>
<CustomFieldTemplate
id="root_objecttype"
label={intl.formatMessage({
Expand Down Expand Up @@ -89,6 +118,7 @@ const V2ConfigFields = ({index, name, formData, onChange}) => {
>
{/* TODO: fallback to legacy UI if there are loading errors */}
<ObjectTypeVersionSelect
objectsApiGroup={objectsApiGroup}
availableObjecttypes={availableObjectTypesState.availableObjecttypes}
selectedObjecttype={objecttype}
selectedVersion={objecttypeVersion}
Expand Down Expand Up @@ -226,7 +256,9 @@ const V2ConfigFields = ({index, name, formData, onChange}) => {
V2ConfigFields.propTypes = {
index: PropTypes.number,
name: PropTypes.string,
schema: PropTypes.any,
formData: PropTypes.shape({
objectsApiGroup: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
version: PropTypes.number,
objecttype: PropTypes.string,
objecttypeVersion: PropTypes.string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,20 @@ import useAsync from 'react-use/esm/useAsync';
import {REGISTRATION_OBJECTTYPES_ENDPOINT} from 'components/admin/form_design/constants';
import {get} from 'utils/fetch';

export const useGetAvailableObjectTypes = () => {
export const useGetAvailableObjectTypes = objectsApiGroup => {
const {
loading,
value: availableObjecttypes = [],
error,
} = useAsync(
async () => {
const response = await get(REGISTRATION_OBJECTTYPES_ENDPOINT);
if (!response.ok) {
throw new Error('Loading available object types failed');
}
return response.data;
},
// available object types only need to be loaded once when the component mounts
[]
);
} = useAsync(async () => {
const params = {};
if (objectsApiGroup) params.objects_api_group = objectsApiGroup;
const response = await get(REGISTRATION_OBJECTTYPES_ENDPOINT, params);
if (!response.ok) {
throw new Error('Loading available object types failed');
}
return response.data;
Viicos marked this conversation as resolved.
Show resolved Hide resolved
}, [objectsApiGroup]);

return {
loading,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ import React from 'react';
// TODO This is duplicated from the ZGW registration, but will be cleaned up
// with the backend UI refactor.

const getChoicesFromSchema = (enums, enumNames) => {
let finalChoices = {};
Object.keys(enums).forEach(key => {
finalChoices[enums[key]] = enumNames[key];
});

return finalChoices;
};
Viicos marked this conversation as resolved.
Show resolved Hide resolved

const getFieldErrors = (name, index, errors, field) => {
const errorMessages = [];

Expand Down Expand Up @@ -30,6 +39,8 @@ const getErrorMarkup = errorMessages => {
);
};

// End TODO

const VARIABLE_TYPE_MAP = {
boolean: 'boolean',
int: 'integer',
Expand Down Expand Up @@ -89,4 +100,4 @@ const asJsonSchema = (variable, components) => {
};
};

export {getErrorMarkup, getFieldErrors, asJsonSchema};
export {getChoicesFromSchema, getErrorMarkup, getFieldErrors, asJsonSchema};
1 change: 1 addition & 0 deletions src/openforms/js/components/form/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const getInformatieObjectTypen = async (backend, options) => {
}
case 'objects_api':
return await get('/api/v2/registration/informatieobjecttypen', {
objects_api_group: options.objectsApiGroup,
registration_backend: backend,
});
default:
Expand Down
10 changes: 10 additions & 0 deletions src/openforms/js/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,11 @@
"description": "Decision definition ID label",
"originalDefault": "Decision definition ID"
},
"Ijrbrp": {
"defaultMessage": "Which Objects API group to use. If not provided, the default Objects API group will be used.",
"description": "Objects API group selection",
"originalDefault": "Which Objects API group to use. If not provided, the default Objects API group will be used."
},
"Ika4IH": {
"defaultMessage": "Submissions will be deleted",
"description": "delete_permanently removal method option label",
Expand Down Expand Up @@ -2079,6 +2084,11 @@
"description": "JSON variable type \"Form field\" representation",
"originalDefault": "Form field"
},
"mgs/Xe": {
"defaultMessage": "Objects API group",
"description": "Objects API group",
"originalDefault": "Objects API group"
},
"myvtu0": {
"defaultMessage": "Manage process variables",
"description": "Open manage camunda process vars modal button",
Expand Down
10 changes: 10 additions & 0 deletions src/openforms/js/lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,11 @@
"description": "Decision definition ID label",
"originalDefault": "Decision definition ID"
},
"Ijrbrp": {
"defaultMessage": "Which Objects API group to use. If not provided, the default Objects API group will be used.",
"description": "Objects API group selection",
"originalDefault": "Which Objects API group to use. If not provided, the default Objects API group will be used."
},
"Ika4IH": {
"defaultMessage": "Inzendingen worden permanent verwijderd",
"description": "delete_permanently removal method option label",
Expand Down Expand Up @@ -2093,6 +2098,11 @@
"description": "JSON variable type \"Form field\" representation",
"originalDefault": "Form field"
},
"mgs/Xe": {
"defaultMessage": "Objects API group",
"description": "Objects API group",
"originalDefault": "Objects API group"
},
"myvtu0": {
"defaultMessage": "Beheer procesvariabelen",
"description": "Open manage camunda process vars modal button",
Expand Down
Loading
Loading