Merge pull request #2272 from automatisch/AUT-1409

feat: accept falsy default values
This commit is contained in:
Ali BARIN
2025-01-27 16:39:07 +01:00
committed by GitHub
6 changed files with 40 additions and 19 deletions

View File

@@ -12,7 +12,7 @@ test.describe('Webhook flow', () => {
test('Create a new flow with a sync Webhook step then a Webhook step', async ({
flowEditorPage,
page,
request
request,
}) => {
await flowEditorPage.flowName.click();
await flowEditorPage.flowNameInput.fill('syncWebhook');
@@ -23,10 +23,11 @@ test.describe('Webhook flow', () => {
await expect(flowEditorPage.continueButton).toHaveCount(1);
await expect(flowEditorPage.continueButton).not.toBeEnabled();
await page
.getByTestId('parameters.statusCode-power-input')
.locator('[contenteditable]')
.fill('200');
await expect(
page
.getByTestId('parameters.statusCode-power-input')
.locator('[contenteditable]')
).toHaveText('200');
await flowEditorPage.clickAway();
await expect(flowEditorPage.continueButton).toHaveCount(1);
await expect(flowEditorPage.continueButton).not.toBeEnabled();
@@ -36,7 +37,9 @@ test.describe('Webhook flow', () => {
.locator('[contenteditable]')
.fill('response from webhook');
await flowEditorPage.clickAway();
await expect(page.getByTestId("parameters.headers.0.key-power-input")).toBeVisible();
await expect(
page.getByTestId('parameters.headers.0.key-power-input')
).toBeVisible();
await expect(flowEditorPage.continueButton).toBeEnabled();
await flowEditorPage.continueButton.click();
@@ -52,7 +55,7 @@ test.describe('Webhook flow', () => {
test('Create a new flow with an async Webhook step then a Webhook step', async ({
flowEditorPage,
page,
request
request,
}) => {
await flowEditorPage.flowName.click();
await flowEditorPage.flowNameInput.fill('asyncWebhook');
@@ -75,7 +78,9 @@ test.describe('Webhook flow', () => {
.locator('[contenteditable]')
.fill('response from webhook');
await flowEditorPage.clickAway();
await expect(page.getByTestId("parameters.headers.0.key-power-input")).toBeVisible();
await expect(
page.getByTestId('parameters.headers.0.key-power-input')
).toBeVisible();
await expect(flowEditorPage.continueButton).toBeEnabled();
await flowEditorPage.continueButton.click();

View File

@@ -14,7 +14,7 @@ function CodeEditor(props) {
required,
name,
label,
defaultValue,
defaultValue = '',
shouldUnregister = false,
disabled,
'data-test': dataTest,
@@ -39,7 +39,7 @@ function CodeEditor(props) {
<Controller
rules={{ required }}
name={name}
defaultValue={defaultValue || ''}
defaultValue={defaultValue}
control={control}
shouldUnregister={shouldUnregister}
render={({ field }) => (

View File

@@ -53,7 +53,7 @@ function ControlledAutocomplete(props) {
<Controller
rules={{ required }}
name={name}
defaultValue={defaultValue || ''}
defaultValue={defaultValue}
control={control}
shouldUnregister={shouldUnregister}
render={({

View File

@@ -23,12 +23,29 @@ function DynamicField(props) {
return fields.reduce((previousValue, field) => {
return {
...previousValue,
[field.key]: '',
[field.key]: field.value ?? '',
__id: uuidv4(),
};
}, {});
}, [fields]);
const generateDefaultValue = React.useCallback(() => {
if (defaultValue?.length > 0) {
return defaultValue.map((item) => {
return fields.reduce((previousValue, field) => {
return {
...previousValue,
// if field value is different than null or undefined - use it,
// otherwise use the parent default value
[field.key]: field.value ?? item[field.key] ?? '',
};
}, {});
});
} else {
return [createEmptyItem()];
}
}, [defaultValue, fields, createEmptyItem]);
const addItem = React.useCallback(() => {
const values = getValues(name);
if (!values) {
@@ -52,13 +69,11 @@ function DynamicField(props) {
React.useEffect(
function addInitialGroupWhenEmpty() {
const fieldValues = getValues(name);
if (!fieldValues && defaultValue) {
setValue(name, defaultValue);
} else if (!fieldValues) {
setValue(name, [createEmptyItem()]);
if (!fieldValues) {
setValue(name, generateDefaultValue());
}
},
[createEmptyItem, defaultValue],
[generateDefaultValue],
);
return (

View File

@@ -162,6 +162,7 @@ function InputCreator(props) {
required={required}
disabled={disabled}
shouldUnregister={shouldUnregister}
defaultValue={value}
/>
{isDynamicFieldsLoading && !additionalFields?.length && (

View File

@@ -23,7 +23,7 @@ function TextField(props) {
const {
required,
name,
defaultValue,
defaultValue = '',
shouldUnregister = false,
clickToCopy = false,
readOnly = false,
@@ -38,7 +38,7 @@ function TextField(props) {
<Controller
rules={{ required }}
name={name}
defaultValue={defaultValue || ''}
defaultValue={defaultValue}
control={control}
shouldUnregister={shouldUnregister}
render={({