Skip to content

Commit

Permalink
🪟🎉 Connector form: Respect default value for oneOf properties (#20588)
Browse files Browse the repository at this point in the history
* improve some types

* improve further

* clean up a bit more

* refactor loading state

* move loading state up

* remove isLoading references

* remove unused props and make fetch connector error work

* remove special component for name

* remove top level state for unifinished flows

* start removing uiwidget

* Update airbyte-webapp/src/views/Connector/ConnectorCard/ConnectorCard.module.scss

Co-authored-by: Tim Roes <tim@airbyte.io>

* remove undefined option for selected id

* remove unused prop

* fix types

* remove uiwidget state

* clean up

* adjust comment

* handle errors in a nice way

* do not respect default on oneOf fields

* rename to formblock

* reduce re-renders

* pass error to secure inputs

* simplify and improve styling

* align top

* code review

* remove comment

* review comments

* rename file

* be strict about boolean values

* add example

* track form error in error boundary

* review comments

* handle unexpected cases better

* respect default value for oneOf properties

* enrich error with connector id

* rename prop

Co-authored-by: Tim Roes <tim@airbyte.io>
  • Loading branch information
Joe Reuter and Tim Roes authored Jan 4, 2023
1 parent 0f26915 commit 966c13f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions airbyte-webapp/src/views/Connector/ConnectorForm/useBuildForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ function setDefaultValues(
setDefaultValues(property, values[property.fieldKey] as Record<string, unknown>, options);
break;
case "formCondition":
// implicitly select the first option (do not respect a potential default value)
values[property.fieldKey] =
options.respectExistingValues && values[property.fieldKey] ? values[property.fieldKey] : {};
setDefaultValues(property.conditions[0], values[property.fieldKey] as Record<string, unknown>, options);
values[property.fieldKey] = {};
let chosenCondition = property.conditions[0];
// if default is set, try to find it in the list of possible selection const values.
// if there is a match, default to this condition.
// In all other cases, go with the first one.
if (property.default) {
const matchingConditionIndex = property.selectionConstValues.indexOf(property.default);
if (matchingConditionIndex !== -1) {
chosenCondition = property.conditions[matchingConditionIndex];
}
}

setDefaultValues(chosenCondition, values[property.fieldKey] as Record<string, unknown>);
}
});
}
Expand Down

0 comments on commit 966c13f

Please sign in to comment.