Skip to content

Commit

Permalink
[#3688] Add option to map var to geometry attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Mar 8, 2024
1 parent 0ab225a commit 0146276
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const ObjectsApiOptionsFormFields = ({index, name, schema, formData, onChange})
draft.version = realVersion;
if (realVersion === 2) {
draft.variablesMapping = [];
draft.geometryVariableKey = '';
} else {
delete draft.variablesMapping;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {REGISTRATION_OBJECTS_TARGET_PATHS} from 'components/admin/form_design/co
import Field from 'components/admin/forms/Field';
import Fieldset from 'components/admin/forms/Fieldset';
import FormRow from 'components/admin/forms/FormRow';
import {TextInput} from 'components/admin/forms/Inputs';
import {Checkbox, TextInput} from 'components/admin/forms/Inputs';
import Select, {LOADING_OPTION} from 'components/admin/forms/Select';
import ErrorMessage from 'components/errors/ErrorMessage';
import {post} from 'utils/fetch';
Expand All @@ -25,6 +25,7 @@ import {asJsonSchema} from './utils';
* objecttype: string;
* objecttypeVersion: number;
* variablesMapping: {variableKey: string, targetPath: string[]}[];
* geometryVariableKey: string;
* }} ObjectsAPIRegistrationBackendOptions
*
* @param {Object} p
Expand All @@ -35,10 +36,11 @@ const ObjectsApiVariableConfigurationEditor = ({variable}) => {
const {csrftoken} = useContext(APIContext);

const [jsonSchemaVisible, toggleJsonSchemaVisible] = useToggle(false);
const {values: backendOptions, getFieldProps} = useFormikContext();
const {values: backendOptions, getFieldProps, setFieldValue} = useFormikContext();

/** @type {ObjectsAPIRegistrationBackendOptions} */
const {objecttype, objecttypeVersion, variablesMapping, version} = backendOptions;
const {objecttype, objecttypeVersion, geometryVariableKey, variablesMapping, version} =
backendOptions;
if (version !== 2) throw new Error('Not supported, must be config version 2.');

// get the index of our variable in the mapping, if it exists
Expand Down Expand Up @@ -110,6 +112,32 @@ const ObjectsApiVariableConfigurationEditor = ({variable}) => {
/>
</Field>
</FormRow>
<FormRow>
<Field
label={
<FormattedMessage
defaultMessage="Map to geometry field"
description="'Map to geometry field' checkbox label"
/>
}
helpText={
<FormattedMessage
description="'Map to geometry field' checkbox help text"
defaultMessage="Whether to map this variable to the {path} attribute"
values={{path: <code>record.geometry</code>}}
/>
}
name="geometryVariableKey"
disabled={!!mappedVariable.targetPath}
>
<Checkbox
onChange={event => {
const newValue = event.target.checked ? variable.key : undefined;
setFieldValue('geometryVariableKey', newValue);
}}
/>
</Field>
</FormRow>
<FormRow>
<Field
name={`${namePrefix}.targetPath`}
Expand All @@ -119,6 +147,7 @@ const ObjectsApiVariableConfigurationEditor = ({variable}) => {
description="'JSON Schema target' label"
/>
}
disabled={!!geometryVariableKey}
>
<TargetPathSelect
name={`${namePrefix}.targetPath`}
Expand Down

0 comments on commit 0146276

Please sign in to comment.