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

👽 [#4693] Integrate Objects API prefill modal with backend #4799

Merged
merged 14 commits into from
Nov 22, 2024
Merged
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
4 changes: 2 additions & 2 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import '../src/openforms/scss/screen.scss';
import '../src/openforms/scss/admin/admin_overrides.scss';
import {withModalDecorator} from 'components/admin/form_design/story-decorators';
import {withModalDecorator, withReactSelectDecorator} from 'components/admin/form_design/story-decorators';
import {initialize, mswDecorator, mswLoader} from 'msw-storybook-addon';
import {reactIntl} from './reactIntl.js';
import ReactModal from 'react-modal';
Expand All @@ -15,7 +15,7 @@ initialize({
ReactModal.setAppElement(document.getElementById('storybook-root'));

export default {
decorators: [mswDecorator, withModalDecorator],
decorators: [mswDecorator, withModalDecorator, withReactSelectDecorator],
parameters: {
controls: {
matchers: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"trailingComma": "es5",
"useTabs": false,
"importOrder": [
"^((api-mocks|components|data|formio|hooks|map|story-utils|types|utils)/(.*)|(api|api-mocks|cache|Context|errors|headers|i18n|sdk|sentry|types))$",
"^((api-mocks|components|data|formio|hooks|map|story-utils|types|utils)/(.*)|(api|api-mocks|cache|Context|errors|headers|i18n|sdk|sentry|story-utils|types))$",
"^[./]"
],
"importOrderSeparation": true,
Expand Down
12 changes: 5 additions & 7 deletions src/openforms/forms/api/serializers/form_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,13 @@ def validate(self, attrs):
}
)

if (prefill_plugin and not prefill_attribute) or (
not prefill_plugin and prefill_attribute
if (prefill_plugin and not (prefill_attribute or prefill_options)) or (
not prefill_plugin and (prefill_attribute or prefill_options)
):
raise ValidationError(
{
"prefill_attribute": _(
"Prefill plugin and attribute must both be specified."
),
}
_(
"Prefill plugin must be specified with either prefill attribute or prefill options."
)
)

# check the specific validation options of the prefill plugin
Expand Down
32 changes: 31 additions & 1 deletion src/openforms/forms/tests/variables/test_viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,9 @@ def test_bulk_create_and_update_with_prefill_constraints(self):
self.assertEqual(response.json()["invalidParams"][0]["code"], "invalid")
self.assertEqual(
response.json()["invalidParams"][0]["reason"],
_("Prefill plugin and attribute must both be specified."),
_(
"Prefill plugin must be specified with either prefill attribute or prefill options."
),
)

with self.subTest(
Expand Down Expand Up @@ -1019,6 +1021,34 @@ def test_bulk_create_and_update_with_prefill_constraints(self):
),
)

with self.subTest(
"user_defined with prefill plugin and prefill options is allowed"
):
data = [
{
"form": form_url,
"form_definition": form_definition_url,
"key": "userdefined",
"name": "Test",
"service_fetch_configuration": None,
"data_type": FormVariableDataTypes.string,
"source": FormVariableSources.user_defined,
"prefill_plugin": "objects_api",
"prefill_attribute": "",
"prefill_options": {"foo": "bar"},
}
]

response = self.client.put(
reverse(
"api:form-variables",
kwargs={"uuid_or_slug": form.uuid},
),
data=data,
)

self.assertEqual(status.HTTP_200_OK, response.status_code)

def test_bulk_create_and_update_with_non_camel_case_initial_values(self):
user = StaffUserFactory.create(user_permissions=["change_form"])
self.client.force_authenticate(user)
Expand Down
60 changes: 54 additions & 6 deletions src/openforms/js/compiled-lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@
"value": "Regular expression for city"
}
],
"0EYS7D": [
{
"type": 0,
"value": "Objecttype"
}
],
"0FD2pY": [
{
"type": 0,
Expand Down Expand Up @@ -445,6 +451,12 @@
"value": "Maximum value"
}
],
"3SCiQR": [
{
"type": 0,
"value": "Copy configuration from registration"
}
],
"3W3Px9": [
{
"type": 0,
Expand Down Expand Up @@ -753,6 +765,12 @@
"value": "Key"
}
],
"6qPITC": [
{
"type": 0,
"value": "Something went wrong while retrieving the available object types."
}
],
"7/Bhpw": [
{
"type": 0,
Expand Down Expand Up @@ -1583,6 +1601,12 @@
"value": "Move down"
}
],
"DJ8XX2": [
{
"type": 0,
"value": "Select a registration backend and click the button to copy the configuration."
}
],
"DJWATl": [
{
"type": 0,
Expand Down Expand Up @@ -2079,6 +2103,12 @@
"value": "BRP Personen purpose limitation header value"
}
],
"HdRpKT": [
{
"type": 0,
"value": "Version"
}
],
"Hfdfv2": [
{
"type": 0,
Expand Down Expand Up @@ -4491,6 +4521,12 @@
"value": "Pricing logic"
}
],
"fQuLvm": [
{
"type": 0,
"value": "Copy configuration from registration backend"
}
],
"fRMCJI": [
{
"type": 0,
Expand Down Expand Up @@ -4943,6 +4979,12 @@
"value": "Edit complex variable"
}
],
"jU6W0l": [
{
"type": 0,
"value": "Copy"
}
],
"jUPlH5": [
{
"type": 0,
Expand Down Expand Up @@ -5091,12 +5133,6 @@
"value": "Subject of the email sent to the registration backend to notify a change in the payment status."
}
],
"kWw9qL": [
{
"type": 0,
"value": "This product will be send allong form submits."
}
],
"kg/eh1": [
{
"type": 0,
Expand Down Expand Up @@ -5283,6 +5319,12 @@
"value": "Is sensitive data"
}
],
"m83ECr": [
{
"type": 0,
"value": "Copying the configuration from the registration backend will clear the existing configuration. Are you sure you want to continue?"
}
],
"mCHS+l": [
{
"type": 0,
Expand Down Expand Up @@ -5499,6 +5541,12 @@
"value": "Whether to include the content of the confirmation page in the PDF."
}
],
"oqv4fM": [
{
"type": 0,
"value": "The prefill values will be taken from an object of the selected type."
}
],
"osSl3z": [
{
"type": 0,
Expand Down
60 changes: 54 additions & 6 deletions src/openforms/js/compiled-lang/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@
"value": "Patroon of waarde voor de stad"
}
],
"0EYS7D": [
{
"type": 0,
"value": "Objecttype"
}
],
"0FD2pY": [
{
"type": 0,
Expand Down Expand Up @@ -445,6 +451,12 @@
"value": "Maximale waarde"
}
],
"3SCiQR": [
{
"type": 0,
"value": "Copy configuration from registration"
}
],
"3W3Px9": [
{
"type": 0,
Expand Down Expand Up @@ -753,6 +765,12 @@
"value": "Sleutel"
}
],
"6qPITC": [
{
"type": 0,
"value": "Something went wrong while retrieving the available object types."
}
],
"7/Bhpw": [
{
"type": 0,
Expand Down Expand Up @@ -1604,6 +1622,12 @@
"value": "Verplaats omlaag"
}
],
"DJ8XX2": [
{
"type": 0,
"value": "Select a registration backend and click the button to copy the configuration."
}
],
"DJWATl": [
{
"type": 0,
Expand Down Expand Up @@ -2100,6 +2124,12 @@
"value": "BRP Personen 'doelbinding' header-waarde"
}
],
"HdRpKT": [
{
"type": 0,
"value": "Version"
}
],
"Hfdfv2": [
{
"type": 0,
Expand Down Expand Up @@ -4513,6 +4543,12 @@
"value": "Prijslogica"
}
],
"fQuLvm": [
{
"type": 0,
"value": "Copy configuration from registration backend"
}
],
"fRMCJI": [
{
"type": 0,
Expand Down Expand Up @@ -4965,6 +5001,12 @@
"value": "Wijzig complexe waarde"
}
],
"jU6W0l": [
{
"type": 0,
"value": "Copy"
}
],
"jUPlH5": [
{
"type": 0,
Expand Down Expand Up @@ -5113,12 +5155,6 @@
"value": "Subject of the email sent to the registration backend to notify a change in the payment status."
}
],
"kWw9qL": [
{
"type": 0,
"value": "Dit product wordt met inzendingen meegestuurd."
}
],
"kg/eh1": [
{
"type": 0,
Expand Down Expand Up @@ -5305,6 +5341,12 @@
"value": "(Privacy)gevoelige gegevens"
}
],
"m83ECr": [
{
"type": 0,
"value": "Copying the configuration from the registration backend will clear the existing configuration. Are you sure you want to continue?"
}
],
"mCHS+l": [
{
"type": 0,
Expand Down Expand Up @@ -5521,6 +5563,12 @@
"value": "Vink aan om de inhoud toe te voegen aan de PDF die mensen op het eind kunnen downloaden."
}
],
"oqv4fM": [
{
"type": 0,
"value": "The prefill values will be taken from an object of the selected type."
}
],
"osSl3z": [
{
"type": 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {expect, fn, screen, userEvent, waitFor, within} from '@storybook/test';
import selectEvent from 'react-select-event';

import {mockProcessDefinitionsGet} from 'components/admin/form_design/registrations/camunda/mocks';
import {
Expand All @@ -17,6 +16,7 @@ import {
FormDecorator,
ValidationErrorsDecorator,
} from 'components/admin/form_design/story-decorators';
import {rsSelect} from 'utils/storybookTestHelpers';

import RegistrationFields from './RegistrationFields';

Expand Down Expand Up @@ -729,7 +729,7 @@ export const ObjectsAPI = {
await userEvent.click(within(fieldsetTitle).getByRole('link', {name: '(Tonen)'}));

const catalogueSelect = modal.getByLabelText('Catalogus');
await selectEvent.select(catalogueSelect, 'Catalogus 2');
await rsSelect(catalogueSelect, 'Catalogus 2');
});

await step('Submit the form', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {expect, fireEvent, fn, userEvent, waitFor, within} from '@storybook/test';
import selectEvent from 'react-select-event';

import {
mockDMNDecisionDefinitionVersionsGet,
Expand All @@ -8,7 +7,7 @@ import {
} from 'components/admin/form_design/mocks';
import {FormDecorator} from 'components/admin/form_design/story-decorators';
import {serializeValue} from 'components/admin/forms/VariableMapping';
import {getReactSelectContainer} from 'utils/storybookTestHelpers';
import {getReactSelectContainer, rsSelect} from 'utils/storybookTestHelpers';

import DMNActionConfig from './DMNActionConfig';

Expand Down Expand Up @@ -232,7 +231,7 @@ export const Empty = {

const [formVarsDropdowns, dmnVarsDropdown] = dropdowns;

await selectEvent.select(formVarsDropdowns, 'Name');
await rsSelect(formVarsDropdowns, 'Name');
// this is super flaky for some reason on both Chromium and Firefox :/
await waitFor(async () => {
await userEvent.selectOptions(dmnVarsDropdown, 'Camunda variable');
Expand Down
Loading
Loading