@wise/dynamic-flow-client 3.5.0-experimental-b041af5 → 3.5.0-experimental-63c768d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/common/errorBoundary/ErrorBoundary.js +44 -0
- package/build/common/errorBoundary/ErrorBoundaryAlert.js +12 -0
- package/build/common/makeHttpClient/makeHttpClient.spec.js +141 -0
- package/build/common/messages/external-confirmation.messages.js +23 -0
- package/build/i18n/de.json +46 -46
- package/build/i18n/en.json +46 -46
- package/build/i18n/es.json +46 -46
- package/build/i18n/fr.json +46 -46
- package/build/i18n/hu.json +46 -46
- package/build/i18n/id.json +46 -46
- package/build/i18n/index.js +36 -0
- package/build/i18n/it.json +46 -46
- package/build/i18n/ja.json +46 -46
- package/build/i18n/pl.json +46 -46
- package/build/i18n/pt.json +46 -46
- package/build/i18n/ro.json +46 -46
- package/build/i18n/ru.json +46 -46
- package/build/i18n/th.json +46 -46
- package/build/i18n/tr.json +46 -46
- package/build/i18n/zh_CN.json +46 -46
- package/build/i18n/zh_HK.json +46 -46
- package/build/index.js +10 -0
- package/build/legacy/common/contexts/eventsContext/EventsContext.spec.js +58 -0
- package/build/legacy/common/contexts/featureContext/FeatureContext.spec.js +41 -0
- package/build/legacy/common/contexts/logContext/LogContext.spec.js +54 -0
- package/build/legacy/common/hooks/useDebouncedFunction/useDebouncedFunction.spec.js +59 -0
- package/build/legacy/common/hooks/useExternal/useExternal.spec.js +236 -0
- package/build/legacy/common/hooks/useStepPolling/useStepPolling.spec.js +288 -0
- package/build/legacy/common/utils/debounce.spec.js +72 -0
- package/build/legacy/common/utils/file-utils.spec.js +69 -0
- package/build/legacy/common/utils/id-utils.spec.js +12 -0
- package/build/legacy/common/utils/is-equal.spec.js +88 -0
- package/build/legacy/common/utils/mobile-utils.spec.js +71 -0
- package/build/legacy/common/validators/models/model-utils.spec.js +45 -0
- package/build/legacy/common/validators/models/model-validators.spec.js +647 -0
- package/build/legacy/common/validators/schemas/schema-validators.spec.js +157 -0
- package/build/legacy/common/validators/types/type-validators.spec.js +147 -0
- package/build/legacy/common/validators/validationFailures/validation-failures.spec.js +198 -0
- package/build/legacy/common/validators/validationFailures/validation-failures.utils.spec.js +145 -0
- package/build/legacy/common/validators/values/value-validators.spec.js +22 -0
- package/build/legacy/dynamicFlow/BackButton.js +22 -0
- package/build/legacy/dynamicFlow/DynamicFlow.js +346 -0
- package/build/legacy/dynamicFlow/DynamicFlowStep.js +37 -0
- package/build/legacy/dynamicFlow/DynamicFlowTypes.js +1 -0
- package/build/legacy/dynamicFlow/index.js +1 -0
- package/build/legacy/dynamicFlow/stories/dev-tools/DynamicFlow.story.js +78 -0
- package/build/legacy/dynamicFlow/stories/dev-tools/ErrorResponses.story.js +124 -0
- package/build/legacy/dynamicFlow/stories/dev-tools/Examples.story.js +25 -0
- package/build/legacy/dynamicFlow/stories/dev-tools/Features.story.js +33 -0
- package/build/legacy/dynamicFlow/stories/dev-tools/JsonSchemaForm.story.js +31 -0
- package/build/legacy/dynamicFlow/stories/dev-tools/RefreshOnChange.story.js +194 -0
- package/build/legacy/dynamicFlow/stories/dev-tools/SearchFeature.story.js +114 -0
- package/build/legacy/dynamicFlow/stories/dev-tools/ServerTest.story.js +44 -0
- package/build/legacy/dynamicFlow/stories/dev-tools/Upload.story.js +212 -0
- package/build/legacy/dynamicFlow/stories/dev-tools/ValidationAsync.story.js +156 -0
- package/build/legacy/dynamicFlow/stories/examples/ObjectConst.story.js +150 -0
- package/build/legacy/dynamicFlow/stories/fixtureHttpClient.js +117 -0
- package/build/legacy/dynamicFlow/stories/visual-tests/VisualTests.story.js +43 -0
- package/build/legacy/dynamicFlow/tests/Actions.spec.js +185 -0
- package/build/legacy/dynamicFlow/tests/AllOfSchema.spec.js +196 -0
- package/build/legacy/dynamicFlow/tests/AutocompleteHints.spec.js +59 -0
- package/build/legacy/dynamicFlow/tests/DynamicFlow.BackButton.spec.js +179 -0
- package/build/legacy/dynamicFlow/tests/DynamicFlow.search.spec.js +475 -0
- package/build/legacy/dynamicFlow/tests/DynamicFlow.spec.js +559 -0
- package/build/legacy/dynamicFlow/tests/DynamicImage.spec.js +287 -0
- package/build/legacy/dynamicFlow/tests/DynamicInstructions.spec.js +49 -0
- package/build/legacy/dynamicFlow/tests/HiddenSchemas.spec.js +307 -0
- package/build/legacy/dynamicFlow/tests/ModalLayout.spec.js +252 -0
- package/build/legacy/dynamicFlow/tests/MultiSelect.spec.js +327 -0
- package/build/legacy/dynamicFlow/tests/MultipleFileUploadSchema.spec.js +401 -0
- package/build/legacy/dynamicFlow/tests/ObjectSchema.spec.js +295 -0
- package/build/legacy/dynamicFlow/tests/OneOfSchema.spec.js +773 -0
- package/build/legacy/dynamicFlow/tests/PersistAsync.blob-schema.spec.js +331 -0
- package/build/legacy/dynamicFlow/tests/PersistAsync.string-schema.spec.js +389 -0
- package/build/legacy/dynamicFlow/tests/RefreshStepOnChange.debouncing.spec.js +273 -0
- package/build/legacy/dynamicFlow/tests/RefreshStepOnChange.spec.js +567 -0
- package/build/legacy/dynamicFlow/tests/RepeatableSchema.spec.js +977 -0
- package/build/legacy/dynamicFlow/tests/StepModel.spec.js +119 -0
- package/build/legacy/dynamicFlow/tests/ValidationAsync.spec.js +484 -0
- package/build/legacy/dynamicFlow/tests/ssr.spec.js +47 -0
- package/build/legacy/dynamicFlow/utils/index.js +5 -0
- package/build/legacy/dynamicFlow/utils/responseParsers/response-parsers.js +185 -0
- package/build/legacy/dynamicFlow/utils/responseParsers/response-parsers.spec.js +463 -0
- package/build/legacy/dynamicFlow/utils/useDebouncedRefresh/useDebouncedRefresh.js +26 -0
- package/build/legacy/dynamicFlow/utils/useDynamicFlowState.js +137 -0
- package/build/legacy/dynamicFlow/utils/useLoader.js +22 -0
- package/build/legacy/formControl/Select.spec.js +104 -0
- package/build/legacy/formControl/utils/getAutocompleteString.spec.js +30 -0
- package/build/legacy/formControl/utils/value-utils.spec.js +158 -0
- package/build/legacy/jsonSchemaForm/JsonSchemaForm.end-to-end.spec.js +563 -0
- package/build/legacy/jsonSchemaForm/JsonSchemaForm.js +24 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/ArraySchema.js +25 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/ArrayListSchema.js +34 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/RepeatableSchema.js +134 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/RepeatableSchemaStep.js +85 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/utils/summary-utils.js +135 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/utils/summary-utils.spec.js +909 -0
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/genericSchema/GenericSchema.js +85 -0
- package/build/legacy/jsonSchemaForm/genericSchema/GenericSchema.rtl.spec.js +55 -0
- package/build/legacy/jsonSchemaForm/genericSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/index.js +1 -0
- package/build/legacy/jsonSchemaForm/objectSchema/ObjectSchema.js +77 -0
- package/build/legacy/jsonSchemaForm/objectSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/oneOfSchema/OneOfSchema.js +155 -0
- package/build/legacy/jsonSchemaForm/oneOfSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/oneOfSchema/utils.js +68 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/PersistAsyncSchema.js +26 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/PersistAsyncBlobSchema.js +131 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/UploadInputAdapter.js +31 -0
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBlobSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/PromotedOneOfSchema.js +72 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promoted-one-of-utils.js +8 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfCheckboxControl.js +27 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfControl.js +31 -0
- package/build/legacy/jsonSchemaForm/promotedOneOfSchema/promotedOneOfControl/PromotedOneOfRadioControl.js +32 -0
- package/build/legacy/jsonSchemaForm/readOnlySchema/ReadOnlySchema.js +54 -0
- package/build/legacy/jsonSchemaForm/readOnlySchema/ReadOnlySchema.messages.js +13 -0
- package/build/legacy/jsonSchemaForm/readOnlySchema/index.js +1 -0
- package/build/legacy/jsonSchemaForm/schemaFormControl/SchemaFormControl.spec.js +312 -0
- package/build/legacy/jsonSchemaForm/schemaFormControl/utils/mapping-utils.spec.js +231 -0
- package/build/legacy/jsonSchemaForm/validationAsyncSchema/ValidationAsyncSchema.js +150 -0
- package/build/legacy/jsonSchemaForm/validationAsyncSchema/index.js +1 -0
- package/build/legacy/layout/button/DynamicButton.spec.js +152 -0
- package/build/legacy/layout/button/utils.spec.js +50 -0
- package/build/legacy/layout/icon/DynamicIcon.spec.js +20 -0
- package/build/legacy/layout/list/DynamicStatusList.spec.js +111 -0
- package/build/legacy/layout/loadingIndicator/DynamicLoadingIndicator.spec.js +25 -0
- package/build/legacy/layout/markdown/DynamicMarkdown.spec.js +58 -0
- package/build/legacy/layout/review/DynamicReview.spec.js +152 -0
- package/build/legacy/step/cameraStep/CameraStep.js +124 -0
- package/build/legacy/step/cameraStep/cameraCapture/CameraCapture.js +161 -0
- package/build/legacy/step/cameraStep/cameraCapture/CameraCapture.spec.js +432 -0
- package/build/legacy/step/cameraStep/cameraCapture/hooks/useFullScreenOrientationLock.js +60 -0
- package/build/legacy/step/cameraStep/cameraCapture/hooks/useVideoConstraints.js +80 -0
- package/build/legacy/step/cameraStep/cameraCapture/index.js +1 -0
- package/build/legacy/step/cameraStep/cameraCapture/overlay/Overlay.js +77 -0
- package/build/legacy/step/cameraStep/cameraCapture/screens/cameraErrorScreen/CameraErrorScreen.js +18 -0
- package/build/legacy/step/cameraStep/cameraCapture/screens/index.js +1 -0
- package/build/legacy/step/cameraStep/cameraCapture/tracking/index.js +109 -0
- package/build/legacy/step/cameraStep/cameraCapture/utils/index.js +107 -0
- package/build/legacy/step/cameraStep/index.js +1 -0
- package/build/legacy/step/externalConfirmationStep/ExternalConfirmationStep.js +64 -0
- package/build/legacy/step/externalConfirmationStep/index.js +1 -0
- package/build/legacy/step/index.js +3 -0
- package/build/legacy/test-utils/DynamicFlowProviders.js +19 -0
- package/build/legacy/test-utils/index.js +4 -0
- package/build/legacy/test-utils/legacy-utils.js +69 -0
- package/build/legacy/test-utils/log-utils.js +9 -0
- package/build/main.js +6 -2
- package/build/main.min.js +1 -1
- package/build/main.mjs +6 -2
- package/build/revamp/DynamicFlowCore.js +299 -0
- package/build/revamp/DynamicFlowWise.js +69 -0
- package/build/revamp/DynamicFlowWise.spec.js +105 -0
- package/build/revamp/domain/components/AlertComponent.js +50 -0
- package/build/revamp/domain/components/AllOfComponent.js +72 -0
- package/build/revamp/domain/components/BooleanInputComponent.js +108 -0
- package/build/revamp/domain/components/BoxComponent.js +65 -0
- package/build/revamp/domain/components/ButtonComponent.js +50 -0
- package/build/revamp/domain/components/ColumnsComponent.js +74 -0
- package/build/revamp/domain/components/ConstComponent.js +50 -0
- package/build/revamp/domain/components/ContainerComponent.js +65 -0
- package/build/revamp/domain/components/DateInputComponent.js +127 -0
- package/build/revamp/domain/components/DecisionComponent.js +50 -0
- package/build/revamp/domain/components/DividerComponent.js +50 -0
- package/build/revamp/domain/components/FormComponent.js +65 -0
- package/build/revamp/domain/components/HeadingComponent.js +50 -0
- package/build/revamp/domain/components/ImageComponent.js +50 -0
- package/build/revamp/domain/components/InstructionsComponent.js +50 -0
- package/build/revamp/domain/components/IntegerInputComponent.js +125 -0
- package/build/revamp/domain/components/LoadingIndicatorComponent.js +50 -0
- package/build/revamp/domain/components/MarkdownComponent.js +50 -0
- package/build/revamp/domain/components/ModalComponent.js +65 -0
- package/build/revamp/domain/components/MultiUploadInputComponent.js +190 -0
- package/build/revamp/domain/components/NumberInputComponent.js +125 -0
- package/build/revamp/domain/components/ObjectComponent.js +104 -0
- package/build/revamp/domain/components/ParagraphComponent.js +50 -0
- package/build/revamp/domain/components/ReviewComponent.js +50 -0
- package/build/revamp/domain/components/SelectInputComponent.js +138 -0
- package/build/revamp/domain/components/StatusListComponent.js +50 -0
- package/build/revamp/domain/components/StepDomainComponent.js +93 -0
- package/build/revamp/domain/components/TextInputComponent.js +125 -0
- package/build/revamp/domain/components/UploadInputComponent.js +151 -0
- package/build/revamp/domain/components/repeatableComponent/RepeatableComponent.js +148 -0
- package/build/revamp/domain/components/repeatableComponent/RepeatableComponent.spec.js +145 -0
- package/build/revamp/domain/components/searchComponent/SearchComponent.js +108 -0
- package/build/revamp/domain/components/searchComponent/SearchComponent.spec.js +327 -0
- package/build/revamp/domain/components/utils/component-utils.js +18 -0
- package/build/revamp/domain/components/utils/debounce.js +38 -0
- package/build/revamp/domain/components/utils/debounce.spec.js +72 -0
- package/build/revamp/domain/components/utils/file-utils.js +46 -0
- package/build/revamp/domain/components/utils/getComponentForLocalValueKey.js +31 -0
- package/build/revamp/domain/components/utils/isPartialLocalValueMatch.js +40 -0
- package/build/revamp/domain/components/utils/isPartialLocalValueMatch.spec.js +108 -0
- package/build/revamp/domain/features/events.js +1 -0
- package/build/revamp/domain/features/persistAsync/getComponentPersistAsync.js +133 -0
- package/build/revamp/domain/features/persistAsync/getComponentPersistAsync.spec.js +199 -0
- package/build/revamp/domain/features/persistAsync/getInitialPersistedState.js +6 -0
- package/build/revamp/domain/features/persistAsync/getPerformPersistAsync.js +103 -0
- package/build/revamp/domain/features/persistAsync/getPerformPersistAsync.spec.js +280 -0
- package/build/revamp/domain/features/refresh/getPerformRefresh.js +53 -0
- package/build/revamp/domain/features/search/getPerformSearchFunction.js +104 -0
- package/build/revamp/domain/features/search/getPerformSearchFunction.spec.js +260 -0
- package/build/revamp/domain/features/summary/summary-utils.js +39 -0
- package/build/revamp/domain/features/summary/summary-utils.spec.js +110 -0
- package/build/revamp/domain/features/utils/http-utils.js +34 -0
- package/build/revamp/domain/features/utils/response-utils.js +9 -0
- package/build/revamp/domain/features/validation/spec-utils.js +16 -0
- package/build/revamp/domain/features/validation/validation-functions.js +12 -0
- package/build/revamp/domain/features/validation/validation-functions.spec.js +110 -0
- package/build/revamp/domain/features/validation/value-checks.js +111 -0
- package/build/revamp/domain/features/validation/value-checks.spec.js +204 -0
- package/build/revamp/domain/features/validationAsync/getComponentValidationAsync.js +94 -0
- package/build/revamp/domain/features/validationAsync/getComponentValidationAsync.spec.js +177 -0
- package/build/revamp/domain/features/validationAsync/getInitialValidationState.js +5 -0
- package/build/revamp/domain/features/validationAsync/getPerformValidationAsync.js +107 -0
- package/build/revamp/domain/features/validationAsync/getPerformValidationAsync.spec.js +266 -0
- package/build/revamp/domain/mappers/layout/alertLayoutToComponent.js +12 -0
- package/build/revamp/domain/mappers/layout/boxLayoutToComponents.js +15 -0
- package/build/revamp/domain/mappers/layout/buttonLayoutToComponent.js +64 -0
- package/build/revamp/domain/mappers/layout/columnsLayoutToComponent.js +18 -0
- package/build/revamp/domain/mappers/layout/decisionLayoutToComponent.js +36 -0
- package/build/revamp/domain/mappers/layout/dividerLayoutToComponent.js +5 -0
- package/build/revamp/domain/mappers/layout/formLayoutToComponent.js +27 -0
- package/build/revamp/domain/mappers/layout/headingLayoutToComponent.js +13 -0
- package/build/revamp/domain/mappers/layout/imageLayoutToComponent.js +12 -0
- package/build/revamp/domain/mappers/layout/infoLayoutToComponent.js +12 -0
- package/build/revamp/domain/mappers/layout/instructionsLayoutToComponent.js +18 -0
- package/build/revamp/domain/mappers/layout/listLayoutToComponent.js +30 -0
- package/build/revamp/domain/mappers/layout/loadingIndicatorLayoutToComponent.js +5 -0
- package/build/revamp/domain/mappers/layout/markdownLayoutToComponent.js +12 -0
- package/build/revamp/domain/mappers/layout/modalLayoutToComponent.js +17 -0
- package/build/revamp/domain/mappers/layout/paragraphLayoutToComponent.js +12 -0
- package/build/revamp/domain/mappers/layout/reviewLayoutToComponent.js +51 -0
- package/build/revamp/domain/mappers/layout/searchLayoutToComponent.js +14 -0
- package/build/revamp/domain/mappers/layout/statusListLayoutToComponent.js +11 -0
- package/build/revamp/domain/mappers/mapLayoutToComponent.js +63 -0
- package/build/revamp/domain/mappers/mapSchemaToComponent.js +84 -0
- package/build/revamp/domain/mappers/mapSchemaToComponent.spec.js +197 -0
- package/build/revamp/domain/mappers/mapStepToComponent.js +143 -0
- package/build/revamp/domain/mappers/mapStepToComponent.spec.js +184 -0
- package/build/revamp/domain/mappers/schema/allOfSchemaToComponent.js +29 -0
- package/build/revamp/domain/mappers/schema/arraySchemaToComponent/arraySchemaToComponent.js +35 -0
- package/build/revamp/domain/mappers/schema/arraySchemaToComponent/arraySchemaToMultiUploadComponent.js +63 -0
- package/build/revamp/domain/mappers/schema/arraySchemaToComponent/arraySchemaToRepeatableComponent.js +65 -0
- package/build/revamp/domain/mappers/schema/blobSchemaToComponent.js +30 -0
- package/build/revamp/domain/mappers/schema/booleanSchemaToComponent.js +38 -0
- package/build/revamp/domain/mappers/schema/constSchemaToComponent.js +14 -0
- package/build/revamp/domain/mappers/schema/integerSchemaToComponent.js +36 -0
- package/build/revamp/domain/mappers/schema/numberSchemaToComponent.js +35 -0
- package/build/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToComponent.js +41 -0
- package/build/revamp/domain/mappers/schema/objectSchemaToComponent/objectSchemaToComponent.spec.js +165 -0
- package/build/revamp/domain/mappers/schema/oneOfSchemaToComponent/oneOfSchemaToComponent.js +67 -0
- package/build/revamp/domain/mappers/schema/oneOfSchemaToComponent/oneOfSchemaToComponent.spec.js +316 -0
- package/build/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToComponent.js +14 -0
- package/build/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToComponent.spec.js +220 -0
- package/build/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToDateInputComponent.js +37 -0
- package/build/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToTextInputComponent.js +45 -0
- package/build/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToUploadInputComponent.js +32 -0
- package/build/revamp/domain/mappers/schema/tests/test-utils.js +27 -0
- package/build/revamp/domain/mappers/schema/types.js +1 -0
- package/build/revamp/domain/mappers/schema/utils/getPersistAsyncInitialState.js +35 -0
- package/build/revamp/domain/mappers/schema/utils/getValidationAsyncInitialState.js +25 -0
- package/build/revamp/domain/mappers/schema/utils/mapCommonSchemaProps.js +28 -0
- package/build/revamp/domain/mappers/types.js +1 -0
- package/build/revamp/domain/mappers/utils/getAutocompleteString.js +76 -0
- package/build/revamp/domain/mappers/utils/getAutocompleteString.spec.js +21 -0
- package/build/revamp/domain/mappers/utils/getRandomId.js +2 -0
- package/build/revamp/domain/mappers/utils/legacy-utils.js +53 -0
- package/build/revamp/domain/types.js +1 -0
- package/build/revamp/flow/executeRefresh.js +97 -0
- package/build/revamp/flow/executeSubmission.js +152 -0
- package/build/revamp/flow/getResponseType.js +76 -0
- package/build/revamp/flow/response-utils.js +88 -0
- package/build/revamp/renderers/CoreContainerRenderer.js +8 -0
- package/build/revamp/renderers/LoadingContext.js +7 -0
- package/build/revamp/renderers/getRenderFunction.js +55 -0
- package/build/revamp/renderers/getSchemaErrorMessageFunction.js +90 -0
- package/build/revamp/renderers/mappers/alertComponentToProps.js +4 -0
- package/build/revamp/renderers/mappers/allOfComponentToProps.js +11 -0
- package/build/revamp/renderers/mappers/booleanInputComponentToProps.js +16 -0
- package/build/revamp/renderers/mappers/boxComponentToProps.js +4 -0
- package/build/revamp/renderers/mappers/buttonComponentToProps.js +14 -0
- package/build/revamp/renderers/mappers/columnsComponentToProps.js +4 -0
- package/build/revamp/renderers/mappers/componentToRendererProps.js +105 -0
- package/build/revamp/renderers/mappers/containerComponentToProps.js +4 -0
- package/build/revamp/renderers/mappers/dateInputComponentToProps.js +13 -0
- package/build/revamp/renderers/mappers/decisionComponentToProps.js +4 -0
- package/build/revamp/renderers/mappers/dividerComponentToProps.js +4 -0
- package/build/revamp/renderers/mappers/formComponentToProps.js +4 -0
- package/build/revamp/renderers/mappers/headingComponentToProps.js +11 -0
- package/build/revamp/renderers/mappers/hiddenComponentToProps.js +3 -0
- package/build/revamp/renderers/mappers/imageComponentToProps.js +11 -0
- package/build/revamp/renderers/mappers/instructionsComponentToProps.js +10 -0
- package/build/revamp/renderers/mappers/integerInputComponentToProps.js +13 -0
- package/build/revamp/renderers/mappers/loadingIndicatorComponentToProps.js +9 -0
- package/build/revamp/renderers/mappers/markdownComponentToProps.js +10 -0
- package/build/revamp/renderers/mappers/modalComponentToProps.js +10 -0
- package/build/revamp/renderers/mappers/multiUploadInputComponentToProps.js +24 -0
- package/build/revamp/renderers/mappers/numberInputComponentToProps.js +13 -0
- package/build/revamp/renderers/mappers/objectComponentToProps.js +11 -0
- package/build/revamp/renderers/mappers/paragraphComponentToProps.js +10 -0
- package/build/revamp/renderers/mappers/repeatableComponentToProps.js +40 -0
- package/build/revamp/renderers/mappers/reviewComponentToProps.js +11 -0
- package/build/revamp/renderers/mappers/searchComponentToProps.js +49 -0
- package/build/revamp/renderers/mappers/selectInputComponentToProps.js +29 -0
- package/build/revamp/renderers/mappers/statusListComponentToProps.js +10 -0
- package/build/revamp/renderers/mappers/textInputComponentToProps.js +13 -0
- package/build/revamp/renderers/mappers/uploadInputComponentToProps.js +16 -0
- package/build/revamp/renderers/mappers/utils/inputComponentToProps.js +27 -0
- package/build/revamp/renderers/step/ExternalConfirmationDialog.js +31 -0
- package/build/revamp/renderers/step/StepRenderer.js +29 -0
- package/build/revamp/renderers/step/useExternal.js +15 -0
- package/build/revamp/renderers/stepComponentToProps.js +9 -0
- package/build/revamp/renderers/types.js +1 -0
- package/build/revamp/stories/dev-tools/DynamicFlowRevamp.story.js +304 -0
- package/build/revamp/stories/dev-tools/EditableStep.story.js +71 -0
- package/build/revamp/stories/dev-tools/ErrorHandling.story.js +149 -0
- package/build/revamp/stories/dev-tools/External.story.js +83 -0
- package/build/revamp/stories/dev-tools/OneOf.Inititalisation.story.js +123 -0
- package/build/revamp/stories/dev-tools/PersistAsync.story.js +168 -0
- package/build/revamp/stories/dev-tools/RefreshOnChange.story.js +309 -0
- package/build/revamp/stories/dev-tools/RefreshOnChange.with.PersistAsync.story.js +1004 -0
- package/build/revamp/stories/dev-tools/ServerTest.story.js +81 -0
- package/build/revamp/stories/dev-tools/Upload.story.js +221 -0
- package/build/revamp/stories/dev-tools/ValidationAsync.story.js +161 -0
- package/build/revamp/stories/examples/ObjectConst.story.js +153 -0
- package/build/revamp/stories/examples/OneOfInitialisation.story.js +102 -0
- package/build/revamp/stories/utils/fixtureHttpClient.js +130 -0
- package/build/revamp/stories/utils/mockSearchHandler.js +125 -0
- package/build/revamp/stories/visual-tests/VisualTests.story.js +111 -0
- package/build/revamp/test-utils/component-utils.js +19 -0
- package/build/revamp/test-utils/step-utils.js +6 -0
- package/build/revamp/tests/ImageRenderer.spec.js +108 -0
- package/build/revamp/tests/InitialAction.spec.js +281 -0
- package/build/revamp/tests/InitialStep.spec.js +104 -0
- package/build/revamp/tests/Logging.spec.js +112 -0
- package/build/revamp/tests/OneOfInitialisation.spec.js +654 -0
- package/build/revamp/tests/RefreshOnChange.ResponseHandling.spec.js +322 -0
- package/build/revamp/tests/RefreshOnChange.with.Tabs.spec.js +390 -0
- package/build/revamp/tests/RefreshOnChangePreserve.spec.js +218 -0
- package/build/revamp/tests/Submission.ResponseHandling.spec.js +697 -0
- package/build/revamp/tests/Submission.spec.js +399 -0
- package/build/revamp/tests/legacy/HiddenSchemas.spec.js +312 -0
- package/build/revamp/tests/legacy/MultipleFileUploadSchema.spec.js +447 -0
- package/build/revamp/tests/legacy/PersistAsync.blob-schema.spec.js +339 -0
- package/build/revamp/tests/legacy/PersistAsync.string-schema.spec.js +385 -0
- package/build/revamp/tests/legacy/RefreshStepOnChange.debouncing.spec.js +235 -0
- package/build/revamp/tests/legacy/RefreshStepOnChange.spec.js +623 -0
- package/build/revamp/tests/legacy/ValidationAsync.spec.js +452 -0
- package/build/revamp/tests/legacy/useExternal.spec.js +235 -0
- package/build/revamp/types.js +1 -0
- package/build/revamp/utils/component-utils.js +86 -0
- package/build/revamp/utils/component-utils.spec.js +385 -0
- package/build/revamp/utils/findComponent.js +29 -0
- package/build/revamp/utils/findComponent.spec.js +92 -0
- package/build/revamp/utils/type-utils.js +56 -0
- package/build/revamp/utils/type-validators.js +16 -0
- package/build/revamp/utils/type-validators.spec.js +163 -0
- package/build/revamp/utils/useStableCallback.js +21 -0
- package/build/revamp/wise/renderers/AlertRenderer.js +11 -0
- package/build/revamp/wise/renderers/BooleanInputRenderer.js +34 -0
- package/build/revamp/wise/renderers/BoxRenderer.js +30 -0
- package/build/revamp/wise/renderers/ButtonRenderer.js +64 -0
- package/build/revamp/wise/renderers/ColumnsRenderer.js +25 -0
- package/build/revamp/wise/renderers/DateInputRenderer.js +35 -0
- package/build/revamp/wise/renderers/DecisionRenderer.js +29 -0
- package/build/revamp/wise/renderers/DividerRenderer.js +10 -0
- package/build/revamp/wise/renderers/FormRenderer.js +21 -0
- package/build/revamp/wise/renderers/FormSectionRenderer.js +16 -0
- package/build/revamp/wise/renderers/HeadingRenderer.js +57 -0
- package/build/revamp/wise/renderers/ImageRenderer.js +111 -0
- package/build/revamp/wise/renderers/InstructionsRenderer.js +34 -0
- package/build/revamp/wise/renderers/IntegerInputRenderer.js +38 -0
- package/build/revamp/wise/renderers/LoadingIndicatorRenderer.js +11 -0
- package/build/revamp/wise/renderers/MarkdownRenderer.js +22 -0
- package/build/revamp/wise/renderers/ModalRenderer.js +25 -0
- package/build/revamp/wise/renderers/MultiUploadInputRenderer.js +74 -0
- package/build/revamp/wise/renderers/NumberInputRenderer.js +38 -0
- package/build/revamp/wise/renderers/ParagraphRenderer.js +44 -0
- package/build/revamp/wise/renderers/RepeatableRenderer.js +58 -0
- package/build/revamp/wise/renderers/ReviewRenderer.js +46 -0
- package/build/revamp/wise/renderers/SearchRenderer.js +63 -0
- package/build/revamp/wise/renderers/SelectInputRenderer/OptionMedia.js +27 -0
- package/build/revamp/wise/renderers/SelectInputRenderer/RadioInputRendererComponent.js +25 -0
- package/build/revamp/wise/renderers/SelectInputRenderer/SelectInputRenderer.js +30 -0
- package/build/revamp/wise/renderers/SelectInputRenderer/SelectInputRendererComponent.js +56 -0
- package/build/revamp/wise/renderers/SelectInputRenderer/SelectTriggerMedia.js +27 -0
- package/build/revamp/wise/renderers/SelectInputRenderer/TabInputRendererComponent.js +33 -0
- package/build/revamp/wise/renderers/StatusListRenderer.js +32 -0
- package/build/revamp/wise/renderers/TextInputRenderer.js +35 -0
- package/build/revamp/wise/renderers/UploadInputRenderer.js +136 -0
- package/build/revamp/wise/renderers/components/FieldInput.js +20 -0
- package/build/revamp/wise/renderers/components/Help.js +21 -0
- package/build/revamp/wise/renderers/components/LabelContentWithHelp.js +6 -0
- package/build/revamp/wise/renderers/components/UploadFieldInput.js +25 -0
- package/build/revamp/wise/renderers/components/VariableDateInput.js +30 -0
- package/build/revamp/wise/renderers/components/VariableTextInput.js +69 -0
- package/build/revamp/wise/renderers/components/icon/DynamicIcon.js +17 -0
- package/build/revamp/wise/renderers/components/icon/FlagIcon.js +198 -0
- package/build/revamp/wise/renderers/components/icon/NamedIcon.js +19 -0
- package/build/revamp/wise/renderers/components/icon/NavigationOptionMedia.js +31 -0
- package/build/revamp/wise/renderers/getWiseRenderers.js +57 -0
- package/build/revamp/wise/renderers/hooks/useSnackBarIfAvailable.js +6 -0
- package/build/revamp/wise/renderers/utils/file-utils.js +70 -0
- package/build/revamp/wise/renderers/utils/getRandomId.js +2 -0
- package/build/revamp/wise/renderers/utils/input-utils.js +6 -0
- package/build/revamp/wise/renderers/utils/layout-utils.js +31 -0
- package/build/revamp/wise/renderers/utils/value-utils.js +23 -0
- package/build/revamp/wise/renderers/utils/value-utils.spec.js +33 -0
- package/build/revamp/wise/renderers/validators/type-validators.js +15 -0
- package/build/test-utils/NeptuneProviders.js +23 -0
- package/build/test-utils/fetch-utils.js +104 -0
- package/build/test-utils/index.js +2 -0
- package/build/test-utils/rtl-utils.js +20 -0
- package/package.json +3 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './ArraySchema';
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { createElement as _createElement } from "react";
|
|
13
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import { useEffect } from 'react';
|
|
15
|
+
import { getSchemaType, isBasicError, isNullableBasicModel, isNullableObjectModel, isNullableArrayModel, isNullableStringModel, isObjectModel, isAllOfSchema, isOneOfSchema, isObjectSchema, isArraySchema, isPersistAsyncSchema, isValidationAsyncSchema, isBasicSchema, isOneOfObjectSchema, } from '../../common/utils';
|
|
16
|
+
import AllOfSchema from '../allOfSchema';
|
|
17
|
+
import ArraySchema from '../arrayTypeSchema';
|
|
18
|
+
import BasicTypeSchema from '../basicTypeSchema';
|
|
19
|
+
import ObjectSchema from '../objectSchema';
|
|
20
|
+
import OneOfSchema from '../oneOfSchema';
|
|
21
|
+
import PersistAsyncSchema from '../persistAsyncSchema';
|
|
22
|
+
import PromotedOneOfSchema from '../promotedOneOfSchema';
|
|
23
|
+
import ReadOnlySchema from '../readOnlySchema';
|
|
24
|
+
import ValidationAsyncSchema from '../validationAsyncSchema';
|
|
25
|
+
import { useLogger } from '../../common/contexts';
|
|
26
|
+
function GenericSchemaForm(props) {
|
|
27
|
+
var schema = props.schema, _a = props.model, model = _a === void 0 ? null : _a, _b = props.errors, errors = _b === void 0 ? null : _b, _c = props.hideTitle, hideTitle = _c === void 0 ? false : _c, _d = props.disabled, disabled = _d === void 0 ? false : _d;
|
|
28
|
+
var schemaProps = __assign(__assign({}, props), { model: model, errors: errors, hideTitle: hideTitle, disabled: disabled });
|
|
29
|
+
var type = getSchemaType(schema);
|
|
30
|
+
var log = useLogger();
|
|
31
|
+
useEffect(function () {
|
|
32
|
+
if (!isValidGenericSchema(schema, model, errors)) {
|
|
33
|
+
log.error('Invalid schema or model', "Schema of type ".concat(type || 'undefined', " requested, but schema did not pass validation."));
|
|
34
|
+
}
|
|
35
|
+
}, [JSON.stringify(schema), JSON.stringify(model), JSON.stringify(errors), type, log]);
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
37
|
+
switch (type) {
|
|
38
|
+
case 'readOnly':
|
|
39
|
+
return _jsx(ReadOnlySchema, __assign({}, schemaProps));
|
|
40
|
+
case 'persistAsync':
|
|
41
|
+
return _jsx(PersistAsyncSchema, __assign({}, schemaProps));
|
|
42
|
+
case 'validationAsync':
|
|
43
|
+
return _jsx(ValidationAsyncSchema, __assign({}, schemaProps));
|
|
44
|
+
case 'basic': {
|
|
45
|
+
var basicTypeProps = __assign({ infoMessage: null }, schemaProps);
|
|
46
|
+
return _jsx(BasicTypeSchema, __assign({}, basicTypeProps));
|
|
47
|
+
}
|
|
48
|
+
case 'object':
|
|
49
|
+
return _createElement(ObjectSchema, __assign({}, schemaProps, { key: JSON.stringify(schema) }));
|
|
50
|
+
case 'array':
|
|
51
|
+
return _jsx(ArraySchema, __assign({}, schemaProps));
|
|
52
|
+
case 'promotedOneOf':
|
|
53
|
+
return _jsx(PromotedOneOfSchema, __assign({}, schemaProps));
|
|
54
|
+
case 'oneOf':
|
|
55
|
+
return _jsx(OneOfSchema, __assign({}, schemaProps));
|
|
56
|
+
case 'allOf':
|
|
57
|
+
return _jsx(AllOfSchema, __assign({}, schemaProps));
|
|
58
|
+
}
|
|
59
|
+
return _jsx(_Fragment, {});
|
|
60
|
+
}
|
|
61
|
+
export default GenericSchemaForm;
|
|
62
|
+
// TODO: MC-3224 - We want to implement proper schema validation
|
|
63
|
+
var isValidGenericSchema = function (schema, model, errors) {
|
|
64
|
+
var type = getSchemaType(schema);
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
66
|
+
switch (type) {
|
|
67
|
+
case 'persistAsync':
|
|
68
|
+
return isPersistAsyncSchema(schema) && isNullableStringModel(model) && isBasicError(errors);
|
|
69
|
+
case 'validationAsync':
|
|
70
|
+
return isValidationAsyncSchema(schema) && isNullableBasicModel(model) && isBasicError(errors);
|
|
71
|
+
case 'basic':
|
|
72
|
+
return isBasicSchema(schema) && isNullableBasicModel(model) && isBasicError(errors);
|
|
73
|
+
case 'object':
|
|
74
|
+
return isObjectSchema(schema) && isNullableObjectModel(model);
|
|
75
|
+
case 'array':
|
|
76
|
+
return isArraySchema(schema) && isNullableArrayModel(model) && isBasicError(errors);
|
|
77
|
+
case 'promotedOneOf':
|
|
78
|
+
return isOneOfObjectSchema(schema) && isNullableObjectModel(model);
|
|
79
|
+
case 'oneOf':
|
|
80
|
+
return isOneOfSchema(schema);
|
|
81
|
+
case 'allOf':
|
|
82
|
+
return isAllOfSchema(schema) && isObjectModel(model);
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import * as loggingModule from '../../common/contexts/logContext/LogContext';
|
|
14
|
+
import { mockUseLogger, renderWithProviders } from '../../test-utils';
|
|
15
|
+
import GenericSchemaForm from './GenericSchema';
|
|
16
|
+
var mockLogger = mockUseLogger();
|
|
17
|
+
jest.spyOn(loggingModule, 'useLogger').mockImplementation(function () { return mockLogger; });
|
|
18
|
+
beforeEach(function () {
|
|
19
|
+
Object.values(mockLogger).forEach(function (logger) { return logger.mockClear(); });
|
|
20
|
+
});
|
|
21
|
+
describe('GenericSchema', function () {
|
|
22
|
+
var getProps = function () { return ({
|
|
23
|
+
schema: { type: 'string' },
|
|
24
|
+
model: null,
|
|
25
|
+
errors: null,
|
|
26
|
+
submitted: false,
|
|
27
|
+
onChange: jest.fn(),
|
|
28
|
+
onPersistAsync: jest.fn()
|
|
29
|
+
}); };
|
|
30
|
+
describe('when an invalid schema-model combination is supplied', function () {
|
|
31
|
+
var getSchema = function () { return ({
|
|
32
|
+
$id: 'id',
|
|
33
|
+
type: 'string',
|
|
34
|
+
title: 'String Schema A'
|
|
35
|
+
}); };
|
|
36
|
+
var getModel = function () { return ({ name: 'Bob' }); };
|
|
37
|
+
it('logs an error', function () {
|
|
38
|
+
var consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
39
|
+
renderWithProviders(_jsx(GenericSchemaForm, __assign({}, getProps(), { schema: getSchema(), model: getModel() })));
|
|
40
|
+
expect(mockLogger.error).toHaveBeenCalledWith('Invalid schema or model', expect.anything());
|
|
41
|
+
expect(mockLogger.error).toHaveBeenCalledTimes(1);
|
|
42
|
+
consoleWarnSpy.mockRestore();
|
|
43
|
+
});
|
|
44
|
+
describe('when the component is re-rendered with an identical schema', function () {
|
|
45
|
+
it('only logs an error one time', function () {
|
|
46
|
+
var consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation();
|
|
47
|
+
var rerender = renderWithProviders(_jsx(GenericSchemaForm, __assign({}, getProps(), { schema: getSchema(), model: getModel() }))).rerender;
|
|
48
|
+
expect(mockLogger.error).toHaveBeenCalledTimes(1);
|
|
49
|
+
rerender(_jsx(GenericSchemaForm, __assign({}, getProps(), { schema: getSchema(), model: getModel() })));
|
|
50
|
+
expect(mockLogger.error).toHaveBeenCalledTimes(1);
|
|
51
|
+
consoleWarnSpy.mockRestore();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './GenericSchema';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './JsonSchemaForm';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
22
|
+
import { Header } from '@transferwise/components';
|
|
23
|
+
import classNames from 'classnames';
|
|
24
|
+
import { useState, useEffect } from 'react';
|
|
25
|
+
import { isEqual } from '../../common/utils';
|
|
26
|
+
import { getValidObjectModelParts } from '../../common/validators';
|
|
27
|
+
import { DynamicAlert } from '../../layout';
|
|
28
|
+
import GenericSchema from '../genericSchema';
|
|
29
|
+
var getSchemaColumnClasses = function (width) { return ({
|
|
30
|
+
'col-xs-12': true,
|
|
31
|
+
'col-sm-6': width === 'md',
|
|
32
|
+
'col-sm-4': width === 'sm'
|
|
33
|
+
}); };
|
|
34
|
+
function ObjectSchema(props) {
|
|
35
|
+
var _a = useState(function () { return (__assign({}, getValidObjectModelParts(props.model, props.schema))); }), model = _a[0], setModel = _a[1];
|
|
36
|
+
var onChangeProperty = function (propertyName, onChangeProps) {
|
|
37
|
+
if (onChangeProps.model !== null) {
|
|
38
|
+
// FIXME we should not mutate the model here
|
|
39
|
+
model[propertyName] = onChangeProps.model;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
43
|
+
delete model[propertyName];
|
|
44
|
+
}
|
|
45
|
+
setModel(model);
|
|
46
|
+
props.onChange(__assign(__assign({}, onChangeProps), { model: model }));
|
|
47
|
+
};
|
|
48
|
+
var isRequired = function (propertyName) {
|
|
49
|
+
return props.schema.required && props.schema.required.includes(propertyName);
|
|
50
|
+
};
|
|
51
|
+
useEffect(function () {
|
|
52
|
+
// When the schema changes, only retain valid parts of the model
|
|
53
|
+
var newModel = getValidObjectModelParts(model, props.schema) || {};
|
|
54
|
+
setModel(newModel);
|
|
55
|
+
if (!isEqual(newModel, model)) {
|
|
56
|
+
props.onChange({
|
|
57
|
+
model: newModel,
|
|
58
|
+
triggerSchema: props.schema,
|
|
59
|
+
triggerModel: newModel
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, [props.schema]);
|
|
63
|
+
var allorderedPropertiesSet = new Set(__spreadArray(__spreadArray([], (props.schema.displayOrder || []), true), Object.keys(props.schema.properties), true));
|
|
64
|
+
var isPropertyDefined = function (propertyName) {
|
|
65
|
+
return typeof props.schema.properties[propertyName] !== 'undefined';
|
|
66
|
+
};
|
|
67
|
+
// eslint-disable-next-line unicorn/prefer-spread
|
|
68
|
+
var orderedPropertyNames = Array.from(allorderedPropertiesSet).filter(isPropertyDefined);
|
|
69
|
+
// TODO: LOW avoid type assertion -- what happens when props.errors is not an object?
|
|
70
|
+
var propsErrors = props.errors;
|
|
71
|
+
return (_jsxs(_Fragment, { children: [props.schema.alert && _jsx(DynamicAlert, { component: props.schema.alert }), _jsxs("fieldset", { children: [props.schema.title && !props.hideTitle && (_jsx(Header, { title: props.schema.title, as: "legend" })), props.schema.description && !props.hideTitle && _jsxs("p", { children: [" ", props.schema.description, " "] }), _jsx("div", __assign({ className: "row" }, { children: orderedPropertyNames.map(function (propertyName) { return (_jsx("div", __assign({ className: classNames(getSchemaColumnClasses(props.schema.properties[propertyName].width)) }, { children: _jsx(GenericSchema, { schema: props.schema.properties[propertyName], model: props.model && props.model[propertyName], errors: propsErrors === null || propsErrors === void 0 ? void 0 : propsErrors[propertyName], submitted: props.submitted, required: isRequired(propertyName), disabled: props.disabled, onChange: function (onChangeProps) { return onChangeProperty(propertyName, onChangeProps); }, onPersistAsync: props.onPersistAsync }) }), propertyName)); }) }))] })] }));
|
|
72
|
+
}
|
|
73
|
+
ObjectSchema.defaultProps = {
|
|
74
|
+
hideTitle: false,
|
|
75
|
+
disabled: false
|
|
76
|
+
};
|
|
77
|
+
export default ObjectSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './ObjectSchema';
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
22
|
+
import { Header } from '@transferwise/components';
|
|
23
|
+
import classNames from 'classnames';
|
|
24
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
25
|
+
import { useEventDispatcher } from '../../common/contexts';
|
|
26
|
+
import { useDebouncedFunction } from '../../common/hooks';
|
|
27
|
+
import { generateRandomId, isConstSchema, isNoNConstSchema } from '../../common/utils';
|
|
28
|
+
import { getValidModelParts, getValidationFailures, isArray, isEmpty, } from '../../common/validators';
|
|
29
|
+
import { DynamicAlert } from '../../layout';
|
|
30
|
+
import ControlFeedback from '../controlFeedback';
|
|
31
|
+
import GenericSchema from '../genericSchema';
|
|
32
|
+
import Help from '../help';
|
|
33
|
+
import SchemaFormControl from '../schemaFormControl';
|
|
34
|
+
import { getActiveSchemaIndex, getValidIndexFromValue } from './utils';
|
|
35
|
+
function OneOfSchema(props) {
|
|
36
|
+
var onEvent = useEventDispatcher();
|
|
37
|
+
var _a = useState(false), changed = _a[0], setChanged = _a[1];
|
|
38
|
+
var _b = useState(false), focused = _b[0], setFocused = _b[1];
|
|
39
|
+
var _c = useState(false), blurred = _c[0], setBlurred = _c[1];
|
|
40
|
+
var id = useMemo(function () { return props.schema.$id || generateRandomId(); }, [props.schema.$id]);
|
|
41
|
+
var _d = useState(getActiveSchemaIndex(props.schema, props.model)), schemaIndex = _d[0], setSchemaIndex = _d[1];
|
|
42
|
+
var _e = useState(getModelPartsForSchemas(props.model, props.schema.oneOf)), models = _e[0], setModels = _e[1];
|
|
43
|
+
var debouncedTrackEvent = useDebouncedFunction(onEvent, 200);
|
|
44
|
+
var onSearchChange = function (searchValue) {
|
|
45
|
+
debouncedTrackEvent('Dynamic Flow - OneOf Searched', {
|
|
46
|
+
oneOfId: props.schema.analyticsId,
|
|
47
|
+
searchValueLength: searchValue.length
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
// When the schema we receive from parent changes
|
|
51
|
+
useEffect(function () {
|
|
52
|
+
var modelIndex = getValidIndexFromValue(props.schema, props.model);
|
|
53
|
+
var defaultIndex = getValidIndexFromValue(props.schema, props.schema["default"]);
|
|
54
|
+
if (modelIndex === -1 && defaultIndex >= 0) {
|
|
55
|
+
onChooseNewSchema(defaultIndex, 'init');
|
|
56
|
+
}
|
|
57
|
+
}, [props.schema]);
|
|
58
|
+
if (!isArray(props.schema.oneOf)) {
|
|
59
|
+
// eslint-disable-next-line no-console
|
|
60
|
+
console.error('Incorrect format', props.schema);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
var onChildModelChange = function (index, onChangeParameters) {
|
|
64
|
+
setModels(__spreadArray(__spreadArray(__spreadArray([], models.slice(0, index), true), [onChangeParameters.model], false), models.slice(index + 1), true));
|
|
65
|
+
setChanged(true);
|
|
66
|
+
props.onChange(onChangeParameters);
|
|
67
|
+
};
|
|
68
|
+
var onFocus = function () {
|
|
69
|
+
setFocused(true);
|
|
70
|
+
};
|
|
71
|
+
var onBlur = function () {
|
|
72
|
+
setFocused(false);
|
|
73
|
+
setBlurred(true);
|
|
74
|
+
};
|
|
75
|
+
// TODO: LOW avoid type assertion
|
|
76
|
+
var onChooseNewSchema = function (index, type, metadata) {
|
|
77
|
+
setSchemaIndex(index);
|
|
78
|
+
var newSchema = props.schema.oneOf[index];
|
|
79
|
+
if (isConstSchema(newSchema)) {
|
|
80
|
+
// If new schema is a const we want to share the parent schema, not the const
|
|
81
|
+
var model = newSchema["const"];
|
|
82
|
+
props.onChange({
|
|
83
|
+
model: model,
|
|
84
|
+
triggerSchema: props.schema,
|
|
85
|
+
triggerModel: model,
|
|
86
|
+
type: type,
|
|
87
|
+
metadata: metadata
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
props.onChange({
|
|
92
|
+
model: models[index],
|
|
93
|
+
triggerSchema: newSchema,
|
|
94
|
+
triggerModel: models[index],
|
|
95
|
+
type: type,
|
|
96
|
+
metadata: metadata
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (type !== 'init' && props.schema.analyticsId) {
|
|
100
|
+
onEvent('Dynamic Flow - OneOf Selected', {
|
|
101
|
+
oneOfId: props.schema.analyticsId,
|
|
102
|
+
schemaId: newSchema === null || newSchema === void 0 ? void 0 : newSchema.analyticsId
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
var schemaForSelect = mapSchemasForSelect(props.schema);
|
|
107
|
+
var validations = getValidations(props, schemaIndex);
|
|
108
|
+
var formGroupClasses = {
|
|
109
|
+
'form-group': true,
|
|
110
|
+
'has-error': (!changed && props.errors && !isEmpty(props.errors)) ||
|
|
111
|
+
((props.submitted || (changed && blurred)) && validations.length)
|
|
112
|
+
};
|
|
113
|
+
var feedbackId = "".concat(id, "-feedback");
|
|
114
|
+
return (_jsxs(_Fragment, { children: [(props.schema.oneOf.length > 1 || isConstSchema(props.schema.oneOf[0])) && (_jsxs(_Fragment, { children: [props.schema.alert && _jsx(DynamicAlert, { component: props.schema.alert }), _jsxs("div", __assign({ className: classNames(formGroupClasses) }, { children: [getTitleAndHelp(props.schema, id), _jsx(SchemaFormControl, { id: id, schema: schemaForSelect, value: schemaIndex, disabled: props.disabled, describedBy: feedbackId, onChange: onChooseNewSchema, onFocus: onFocus, onBlur: onBlur, onSearchChange: onSearchChange }), _jsx(ControlFeedback, { id: feedbackId, changed: changed, focused: focused, blurred: blurred, submitted: props.submitted, errors: errorsToString(props.errors), schema: props.schema, validations: validations, infoMessage: null })] }))] })), isNoNConstSchema(props.schema.oneOf[schemaIndex]) && (_jsx(GenericSchema, { schema: props.schema.oneOf[schemaIndex], model: models[schemaIndex], errors: props.errors, submitted: props.submitted, hideTitle: true, disabled: props.disabled, onChange: function (parameters) { return onChildModelChange(schemaIndex, parameters); }, onPersistAsync: props.onPersistAsync }))] }));
|
|
115
|
+
}
|
|
116
|
+
function getTitleAndHelp(schema, forId) {
|
|
117
|
+
var _a;
|
|
118
|
+
var helpElement = schema.help ? _jsx(Help, { help: schema.help }) : null;
|
|
119
|
+
var titleElement = isConstSchema(schema.oneOf[0]) ? (_jsx("div", __assign({ className: "m-b-1" }, { children: _jsxs("label", __assign({ className: "control-label d-inline", htmlFor: forId }, { children: [schema.title, " ", helpElement] })) }))) : (_jsx(_Fragment, { children: helpElement ? (_jsxs("h4", __assign({ className: "m-b-2" }, { children: [schema.title, " ", helpElement] }))) : (_jsx(Header, { title: (_a = schema.title) !== null && _a !== void 0 ? _a : '' })) }));
|
|
120
|
+
return schema.title ? titleElement : helpElement;
|
|
121
|
+
}
|
|
122
|
+
function getValidations(props, schemaIndex) {
|
|
123
|
+
var selectedSchema = props.schema.oneOf[schemaIndex !== null && schemaIndex !== void 0 ? schemaIndex : -1];
|
|
124
|
+
if (isConstSchema(selectedSchema)) {
|
|
125
|
+
return getValidationFailures(selectedSchema["const"], props.schema, Boolean(props.required));
|
|
126
|
+
}
|
|
127
|
+
if (schemaIndex === null || schemaIndex < 0) {
|
|
128
|
+
return getValidationFailures(null, props.schema, Boolean(props.required));
|
|
129
|
+
}
|
|
130
|
+
return [];
|
|
131
|
+
}
|
|
132
|
+
function errorsToString(errors) {
|
|
133
|
+
// When oneOf represents a select, errors should be of type string
|
|
134
|
+
if (typeof errors === 'string') {
|
|
135
|
+
return errors;
|
|
136
|
+
}
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
function getModelPartsForSchemas(model, schemas) {
|
|
140
|
+
return schemas.map(function (schema) { return getValidModelParts(model, schema); });
|
|
141
|
+
}
|
|
142
|
+
// We want our model to be the index, so alter the oneOf schemas to be a const
|
|
143
|
+
function mapSchemasForSelect(schema) {
|
|
144
|
+
return __assign(__assign({}, schema), { oneOf: schema.oneOf.map(mapOneOfToConst) });
|
|
145
|
+
}
|
|
146
|
+
function mapOneOfToConst(schema, index) {
|
|
147
|
+
var title = schema.title, description = schema.description, _a = schema.disabled, disabled = _a === void 0 ? false : _a, icon = schema.icon, image = schema.image, keywords = schema.keywords;
|
|
148
|
+
// TODO LOW avoid type assertion below -- consider adding { type: 'integer' }
|
|
149
|
+
return { title: title, description: description, disabled: disabled, icon: icon, image: image, "const": index, keywords: keywords };
|
|
150
|
+
}
|
|
151
|
+
OneOfSchema.defaultProps = {
|
|
152
|
+
required: false,
|
|
153
|
+
disabled: false
|
|
154
|
+
};
|
|
155
|
+
export default OneOfSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './OneOfSchema';
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { isObjectModel, isOneOfObjectSchema, isConstSchema, isNoNConstSchema, } from '../../common/utils';
|
|
2
|
+
import { isValidSchema, isUndefined } from '../../common/validators';
|
|
3
|
+
export var getActiveSchemaIndex = function (schema, model) {
|
|
4
|
+
var indexFromModel = getValidIndexFromValue(schema, model);
|
|
5
|
+
// If our model satisfies one of the schemas, use that schema.
|
|
6
|
+
if (indexFromModel >= 0) {
|
|
7
|
+
return indexFromModel;
|
|
8
|
+
}
|
|
9
|
+
// If we have a non-const oneOf and there's only one, active index must be the first one
|
|
10
|
+
if (schema.oneOf.length === 1 && isNoNConstSchema(schema.oneOf[0])) {
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
if (isConstSchema(schema.oneOf[0])) {
|
|
14
|
+
var indexFromDefault = getValidIndexFromValue(schema, schema["default"]);
|
|
15
|
+
// If the default value satisfies one of the schemas, use that schema.
|
|
16
|
+
if (indexFromDefault >= 0) {
|
|
17
|
+
return indexFromDefault;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
if (isOneOfObjectSchema(schema) && isObjectModel(model) && Object.keys(model).length >= 1) {
|
|
21
|
+
// Even if the model does not satisfy any of the schemas, it may be closer to one of them.
|
|
22
|
+
return getBestMatchingSchemaIndexForValue(schema, model);
|
|
23
|
+
}
|
|
24
|
+
if (isOneOfObjectSchema(schema) &&
|
|
25
|
+
!isUndefined(schema["default"]) &&
|
|
26
|
+
isObjectModel(schema["default"]) &&
|
|
27
|
+
Object.keys(schema["default"]).length >= 1) {
|
|
28
|
+
// Even if the default value does not satisfy any of the schemas, it may be closer to one of them.
|
|
29
|
+
return getBestMatchingSchemaIndexForValue(schema, schema["default"]);
|
|
30
|
+
}
|
|
31
|
+
// Otherwise do not default
|
|
32
|
+
return null;
|
|
33
|
+
};
|
|
34
|
+
export var getValidIndexFromValue = function (schema, value) {
|
|
35
|
+
var predicate = function (childSchema) {
|
|
36
|
+
return !isUndefined(value) && isValidSchema(value, childSchema);
|
|
37
|
+
};
|
|
38
|
+
if (schema.oneOf.filter(predicate).length === 1) {
|
|
39
|
+
return schema.oneOf.findIndex(predicate);
|
|
40
|
+
}
|
|
41
|
+
return -1;
|
|
42
|
+
};
|
|
43
|
+
export function getBestMatchingSchemaIndexForValue(schema, value) {
|
|
44
|
+
if (value === null || value === undefined) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
var schemaPoints = schema.oneOf.map(function (childSchema) {
|
|
48
|
+
return getSchemaProperties(childSchema).reduce(function (total, _a) {
|
|
49
|
+
var key = _a[0], propertySchema = _a[1];
|
|
50
|
+
if (isConstSchema(propertySchema) && propertySchema["const"] === value[key]) {
|
|
51
|
+
return total + 2;
|
|
52
|
+
}
|
|
53
|
+
if (isNoNConstSchema(propertySchema) && typeof value[key] !== 'undefined') {
|
|
54
|
+
return total + 1;
|
|
55
|
+
}
|
|
56
|
+
return total;
|
|
57
|
+
}, 0);
|
|
58
|
+
});
|
|
59
|
+
if (schemaPoints.every(function (p) { return p === schemaPoints[0]; })) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
return schemaPoints.indexOf(Math.max.apply(Math, schemaPoints));
|
|
63
|
+
}
|
|
64
|
+
function getSchemaProperties(childSchema) {
|
|
65
|
+
return childSchema.properties !== null && typeof childSchema.properties === 'object'
|
|
66
|
+
? Object.entries(childSchema.properties)
|
|
67
|
+
: [];
|
|
68
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import PersistAsyncBasicSchema from './persistAsyncBasicSchema';
|
|
14
|
+
import PersistAsyncBlobSchema from './persistAsyncBlobSchema';
|
|
15
|
+
function PersistAsyncSchema(props) {
|
|
16
|
+
var schema = props.schema;
|
|
17
|
+
var persistAsyncSchemaType = schema.persistAsync.schema.type;
|
|
18
|
+
if (persistAsyncSchemaType === 'blob') {
|
|
19
|
+
return (_jsx(PersistAsyncBlobSchema, __assign({}, props)));
|
|
20
|
+
}
|
|
21
|
+
return _jsx(PersistAsyncBasicSchema, __assign({}, props));
|
|
22
|
+
}
|
|
23
|
+
PersistAsyncSchema.defaultProps = {
|
|
24
|
+
required: false
|
|
25
|
+
};
|
|
26
|
+
export default PersistAsyncSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './PersistAsyncSchema';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './PersistAsyncBasicSchema';
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
49
|
+
import classNames from 'classnames';
|
|
50
|
+
import { useEffect, useState } from 'react';
|
|
51
|
+
import { useEventDispatcher } from '../../../common/contexts';
|
|
52
|
+
import { isStatus422 } from '../../../common/utils';
|
|
53
|
+
import { getValidationFailures } from '../../../common/validators';
|
|
54
|
+
import ControlFeedback from '../../controlFeedback';
|
|
55
|
+
import { mapSchemaToUploadOptions } from '../../schemaFormControl/utils';
|
|
56
|
+
import { getIdFromResponse } from '../persistAsyncBasicSchema/PersistAsyncBasicSchema';
|
|
57
|
+
import { UploadInputAdapter } from './UploadInputAdapter';
|
|
58
|
+
import { useHttpClient } from '../../../../common/httpClientContext';
|
|
59
|
+
function PersistAsyncBlobSchema(props) {
|
|
60
|
+
var _this = this;
|
|
61
|
+
var model = props.model, schema = props.schema, submitted = props.submitted, required = props.required, errors = props.errors, onChange = props.onChange;
|
|
62
|
+
var _a = useState({}), persistAsyncValidationMessages = _a[0], setPersistAsyncValidationMessages = _a[1];
|
|
63
|
+
var _b = useState(null), persistAsyncValidations = _b[0], setPersistAsyncValidations = _b[1];
|
|
64
|
+
var _c = useState([]), validations = _c[0], setValidations = _c[1];
|
|
65
|
+
var _d = useState(false), changed = _d[0], setChanged = _d[1];
|
|
66
|
+
var httpClient = useHttpClient();
|
|
67
|
+
var onEvent = useEventDispatcher();
|
|
68
|
+
useEffect(function () {
|
|
69
|
+
if (submitted) {
|
|
70
|
+
setValidations(getValidationFailures(model, schema, Boolean(required)));
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
setValidations([]);
|
|
74
|
+
}
|
|
75
|
+
}, [model, schema, submitted, required]);
|
|
76
|
+
var onSuccess = function (httpResponse, _fileName) { return __awaiter(_this, void 0, void 0, function () {
|
|
77
|
+
var jsonResponse, id;
|
|
78
|
+
return __generator(this, function (_a) {
|
|
79
|
+
switch (_a.label) {
|
|
80
|
+
case 0: return [4 /*yield*/, httpResponse.json()];
|
|
81
|
+
case 1:
|
|
82
|
+
jsonResponse = (_a.sent());
|
|
83
|
+
id = getIdFromResponse(schema.persistAsync.idProperty, jsonResponse);
|
|
84
|
+
onChange({ model: id, triggerSchema: schema, triggerModel: id });
|
|
85
|
+
setChanged(true);
|
|
86
|
+
onEvent('Dynamic Flow - PersistAsync', { status: 'success', schemaId: schema.$id });
|
|
87
|
+
return [2 /*return*/];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}); };
|
|
91
|
+
var onFailure = function (errorResponse) { return __awaiter(_this, void 0, void 0, function () {
|
|
92
|
+
var jsonResponse;
|
|
93
|
+
return __generator(this, function (_a) {
|
|
94
|
+
switch (_a.label) {
|
|
95
|
+
case 0:
|
|
96
|
+
if (!(errorResponse.response && isStatus422(errorResponse.response.status))) return [3 /*break*/, 2];
|
|
97
|
+
return [4 /*yield*/, errorResponse.response.json()];
|
|
98
|
+
case 1:
|
|
99
|
+
jsonResponse = (_a.sent());
|
|
100
|
+
setPersistAsyncValidationMessages(jsonResponse.validation || {});
|
|
101
|
+
setPersistAsyncValidations([schema.persistAsync.param]);
|
|
102
|
+
_a.label = 2;
|
|
103
|
+
case 2:
|
|
104
|
+
onChange({ model: null, triggerSchema: schema, triggerModel: null });
|
|
105
|
+
setChanged(true);
|
|
106
|
+
onEvent('Dynamic Flow - PersistAsync', { status: 'failure', schemaId: schema.$id });
|
|
107
|
+
return [2 /*return*/];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}); };
|
|
111
|
+
var onCancel = function () {
|
|
112
|
+
setPersistAsyncValidations(null);
|
|
113
|
+
onChange({ model: null, triggerSchema: schema, triggerModel: null });
|
|
114
|
+
setChanged(true);
|
|
115
|
+
};
|
|
116
|
+
var _e = schema.persistAsync, url = _e.url, method = _e.method;
|
|
117
|
+
var combinedValidations = persistAsyncValidations || validations;
|
|
118
|
+
var formGroupClasses = {
|
|
119
|
+
'form-group': true,
|
|
120
|
+
'has-error': (submitted || changed) && Boolean(combinedValidations.length)
|
|
121
|
+
};
|
|
122
|
+
var id = schema.$id || schema.persistAsync.schema.$id || schema.persistAsync.idProperty;
|
|
123
|
+
var feedbackId = "".concat(id, "-feedback");
|
|
124
|
+
return (_jsxs("div", __assign({ className: classNames(formGroupClasses) }, { children: [_jsx("div", __assign({ "aria-describedby": feedbackId }, { children: _jsx(UploadInputAdapter, __assign({ id: id,
|
|
125
|
+
// TODO: LOW avoid type assertion -- model can be null, but fileId must be number | string -- or maybe make fileId: string| number | undefined
|
|
126
|
+
fileId: model, idProperty: schema.persistAsync.idProperty, animationDelay: 0, maxSize: schema.persistAsync.schema.maxSize, usLabel: schema.title || schema.persistAsync.schema.title, usPlaceholder: schema.description || schema.persistAsync.schema.description, httpOptions: { url: url, method: method, fileInputName: schema.persistAsync.param }, httpClient: httpClient, onSuccess: onSuccess, onFailure: onFailure, onCancel: onCancel }, mapSchemaToUploadOptions(schema.persistAsync.schema))) })), _jsx(ControlFeedback, { id: feedbackId, blurred: true, focused: false, changed: changed, submitted: submitted, errors: errors, schema: schema, validations: combinedValidations, validationMessages: __assign({ required: 'Value is required...' }, persistAsyncValidationMessages), infoMessage: null })] })));
|
|
127
|
+
}
|
|
128
|
+
PersistAsyncBlobSchema.defaultProps = {
|
|
129
|
+
required: false
|
|
130
|
+
};
|
|
131
|
+
export default PersistAsyncBlobSchema;
|