Skip to content

Commit

Permalink
Bal 3478 (#2993)
Browse files Browse the repository at this point in the history
* feat: added initial validator boilerplate & utilities & tests

* feat: implmeneted validate method & tests

* fix: test

* feat: implemented conditional validation rule apply & custom validators

* feat: implemented useValidate & tests

* feat: finalized validator component

* feat: added story for validator

* feat: added renderer & tests & dynamic form boilerplate

* feat: added rule engine

* feat: implemented dynamic form context logic & tests & types

* feat: finalized core form logic & finalized field list & tests

* fix: tests

* fix: build

* feat: added input boilerplates(unfinished) & field layout & tests

* feat: added fields (wip)

* fix: fixed build & tests

* feat: implemented events & fixed tests

* feat: implemented fields extend & removed elementsMap

* feat: added select field & fixed types & tests

* feat: added initial demo & bugfixes & updated tests

* feat: added phone field & tests & updated storybook

* feat: added file field & added tests & minor fixes

* feat: added clear value on input hide & updates tests

* feat: fixed onMount & onUnmount events & updated tests

* feat: added configurable file upload

* feat: added task runner & tests

* feat: implemented file upload on submit & tests

* feat: added more form stories & tests update

* feat: added custom validators & custom inputs examples

* feat: added radio field & tests

* feat: added tags input & tests & config fixes

* feat: added v2 adapters for custom fields & updated exports from ui & added tests (#2913)

* feat: added field descriptions & updated tests (#2914)

* feat: reworked ui elements for v2 & added tests (#2930)

* feat: reworked ui elements for v2 & added tests

* feat: added validate on blur

* feat: added initial rendering of UI V2

* feat: updated exports

* feat: implemented events provider

* feat: updated exports

* fix: listeners reinitialize

* feat: implemented document field

* feat: added document validator

* fix: fixed types

* fix: fixed tests & typo

* fix: fixed touched issue with non field definitions in form

* fix: updated validation params & cleanup

* fix: better violation names on statistics page (BAL-3294) (#2932)

* feat: better violation names on statistics page

* fix: CodeRabbit comments

---------

Co-authored-by: Alon Peretz <[email protected]>

* fix: renamed property in applyWhen rule

* feat: added url format & refactor

* Bal 3242 (#2939)

* feat: fixed types & exports & verbose logging & submit event

* feat: implemented plugins runner

* feat: updated types & minor adjustments to format string

* fix: document validator fixes & updated metadata

* feat: added submit button lock while tasks running

* feat: added metadata to useField & useElement & added missing format validator

* feat: added ref to form & fixed types & tests

* fix: fixed plugins context update & added plugin listeners

* feat: updated en translations

* fix: fixed kyb tests

* Bal 2977 (#2942)

* fix: css fixes & rule engine fixes

* feat: implemented sync

* feat: added classnames to row & column

* fix: submit button styles

* Bal 3330 (#2949)

* feat: added formatting for rules & updated tests

* feat: added transformer plugin

* fix: lock file

* feat: implemented priority fields & bug fixes & tests (#2950)

* fix: fixed build

* feat: implemented default data insertion on field list (#2951)

* feat: added support of html tags in descriptions

* feat: added useControl hook

* fix: reworked revision

* fix: fixed renderer stories

* Bal 3356 (WIP) (#2967)

* feat: implemented document field in ui package

* feat: finalized documentfield

* fix: fixed build

* fix: cleanup

* fix: fixed fieldlist

* feat: updated tests

* feat: added clear value for edge cases as documents

* fix: fixed tests & plugins

* fix: fixed fields extraction from definition

* fix: fixed infinite call of useRules due to default array value

* feat: enabled sync rules execution for controls disable and elements hiding

* feat: reworked cleanup

* feat: updated tests

* fix: added handling of dynamic indexes for useRquired & bugfixes

* fix: fixed types

* feat: added version to ui definition & added version resolving to kyb

* feat: reorganize

* feat: removed v1

* fix: post merge fixes & tests & reorganized folders

* fix: fixed state step tracking on submit

* fix: state sync fix

* fix: fixed tests

* feat: ui bump

* fix: fixed bug where dynamic indexes was not resolved in validation

* fix: bugfixes

* fix: cleanup

---------

Co-authored-by: Alon Peretz <[email protected]>
Co-authored-by: Sasha <[email protected]>
  • Loading branch information
3 people authored Jan 28, 2025
1 parent 4121a89 commit d6f7267
Show file tree
Hide file tree
Showing 529 changed files with 22,009 additions and 489 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// vite.config.ts
import react from 'file:///Users/ilyarudnev/Documents/Backend/ballerine/node_modules/.pnpm/@[email protected][email protected]/node_modules/@vitejs/plugin-react-swc/index.mjs';
import { defineConfig } from 'file:///Users/ilyarudnev/Documents/Backend/ballerine/node_modules/.pnpm/[email protected]_@[email protected][email protected]/node_modules/vitest/dist/config.js';
import terminal from 'file:///Users/ilyarudnev/Documents/Backend/ballerine/node_modules/.pnpm/[email protected][email protected]/node_modules/vite-plugin-terminal/dist/index.mjs';
import tsconfigPaths from 'file:///Users/ilyarudnev/Documents/Backend/ballerine/node_modules/.pnpm/[email protected][email protected][email protected]/node_modules/vite-tsconfig-paths/dist/index.js';
import topLevelAwait from 'file:///Users/ilyarudnev/Documents/Backend/ballerine/node_modules/.pnpm/[email protected][email protected]/node_modules/vite-plugin-top-level-await/exports/import.mjs';
var vite_config_default = defineConfig(configEnv => {
const isDevelopment = configEnv.mode === 'development';
return {
server: {
open: true,
host: true,
port: 5137,
// port: 443,
// https: true,
},
preview: {
port: 5137,
},
plugins: [
topLevelAwait({
promiseExportName: '__tla',
promiseImportName: i => `__tla_${i}`,
}),
terminal({
output: ['console', 'terminal'],
strip: false,
}),
react(),
tsconfigPaths(),
// mkcert(),
],
css: {
modules: {
generateScopedName: isDevelopment ? '[name]__[local]__[hash:base64:5]' : '[hash:base64:5]',
},
},
test: {
exclude: ['e2e', 'node_modules'],
environment: 'jsdom',
setupFiles: ['./src/tests-setup.ts'],
},
build: {
sourcemap: true,
},
};
});
export { vite_config_default as default };
//# sourceMappingURL=data:application/json;base64,ewogICJ2ZXJzaW9uIjogMywKICAic291cmNlcyI6IFsidml0ZS5jb25maWcudHMiXSwKICAic291cmNlc0NvbnRlbnQiOiBbImNvbnN0IF9fdml0ZV9pbmplY3RlZF9vcmlnaW5hbF9kaXJuYW1lID0gXCIvVXNlcnMvaWx5YXJ1ZG5ldi9Eb2N1bWVudHMvQmFja2VuZC9iYWxsZXJpbmUvYXBwcy9iYWNrb2ZmaWNlLXYyXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2ZpbGVuYW1lID0gXCIvVXNlcnMvaWx5YXJ1ZG5ldi9Eb2N1bWVudHMvQmFja2VuZC9iYWxsZXJpbmUvYXBwcy9iYWNrb2ZmaWNlLXYyL3ZpdGUuY29uZmlnLnRzXCI7Y29uc3QgX192aXRlX2luamVjdGVkX29yaWdpbmFsX2lt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FDbkIsbUJBQW1CLE9BQUssU0FBUyxDQUFDO0FBQUEsTUFDcEMsQ0FBQztBQUFBLE1BQ0QsU0FBUztBQUFBLFFBQ1AsUUFBUSxDQUFDLFdBQVcsVUFBVTtBQUFBLFFBQzlCLE9BQU87QUFBQSxNQUNULENBQUM7QUFBQSxNQUNELE1BQU07QUFBQSxNQUNOLGNBQWM7QUFBQTtBQUFBLElBRWhCO0FBQUEsSUFDQSxLQUFLO0FBQUEsTUFDSCxTQUFTO0FBQUEsUUFDUCxvQkFBb0IsZ0JBQWdCLHFDQUFxQztBQUFBLE1BQzNFO0FBQUEsSUFDRjtBQUFBLElBQ0EsTUFBTTtBQUFBLE1BQ0osU0FBUyxDQUFDLE9BQU8sY0FBYztBQUFBLE1BQy9CLGFBQWE7QUFBQSxNQUNiLFlBQVksQ0FBQyxzQkFBc0I7QUFBQSxJQUNyQztBQUFBLElBQ0EsT0FBTztBQUFBLE1BQ0wsV0FBVztBQUFBLElBQ2I7QUFBQSxFQUNGO0FBQ0YsQ0FBQzsiLAogICJuYW1lcyI6IFtdCn0K
7 changes: 7 additions & 0 deletions apps/kyb-app/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# kyb-app

## 0.3.117

### Patch Changes

- Updated dependencies
- @ballerine/ui@0.5.68

## 0.3.116

### Patch Changes
Expand Down
5 changes: 3 additions & 2 deletions apps/kyb-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ballerine/kyb-app",
"private": true,
"version": "0.3.116",
"version": "0.3.117",
"type": "module",
"scripts": {
"dev": "vite",
Expand All @@ -19,7 +19,7 @@
"@ballerine/blocks": "0.2.34",
"@ballerine/common": "^0.9.70",
"@ballerine/workflow-browser-sdk": "0.6.89",
"@ballerine/ui": "0.5.67",
"@ballerine/ui": "0.5.68",
"@lukemorales/query-key-factory": "^1.0.3",
"@radix-ui/react-icons": "^1.3.0",
"@rjsf/core": "^5.9.0",
Expand All @@ -46,6 +46,7 @@
"i18next-http-backend": "^2.1.1",
"jmespath": "^0.16.0",
"json-logic-js": "^2.0.2",
"jsonata": "^2.0.6",
"ky": "^0.33.3",
"lodash": "^4.17.21",
"lucide-react": "^0.144.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LoadingScreen } from '@/common/components/molecules/LoadingScreen';
import { InvalidAccessTokenError } from '@/common/errors/invalid-access-token';
import { useCustomerQuery } from '@/hooks/useCustomerQuery';
import { useFlowContextQuery } from '@/hooks/useFlowContextQuery';
import { LoadingScreen } from '@/pages/CollectionFlow/components/atoms/LoadingScreen';
import { HTTPError } from 'ky';
import { FunctionComponent, useEffect, useMemo, useState } from 'react';
import { getJsonErrors, isShouldIgnoreErrors } from './helpers';
Expand Down
10 changes: 5 additions & 5 deletions apps/kyb-app/src/components/organisms/DynamicUI/DynamicUI.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { PageResolver } from '@/components/organisms/DynamicUI/PageResolver';
import { StateManager } from '@/components/organisms/DynamicUI/StateManager/StateManager';
import { AnyChildren } from '@ballerine/ui';
import { dynamicUIContext } from './dynamic-ui.context';
import { useDynamicUIContextComposer } from '@/components/organisms/DynamicUI/hooks/useDynamicUIContextComposer';
import { TransitionListener } from '@/components/organisms/DynamicUI/TransitionListener';
import { UIState } from '@/components/organisms/DynamicUI/hooks/useUIStateLogic/types';
import { Page } from '@/components/organisms/DynamicUI/Page';
import { PageResolver } from '@/components/organisms/DynamicUI/PageResolver';
import { ActionsHandler } from '@/components/organisms/DynamicUI/StateManager/components/ActionsHandler';
import { StateManager } from '@/components/organisms/DynamicUI/StateManager/StateManager';
import { TransitionListener } from '@/components/organisms/DynamicUI/TransitionListener';
import { AnyChildren } from '@ballerine/ui';
import { dynamicUIContext } from './dynamic-ui.context';

const { Provider } = dynamicUIContext;

Expand Down
6 changes: 3 additions & 3 deletions apps/kyb-app/src/components/organisms/DynamicUI/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export const Page = ({ page, children }: PageProps) => {
[page],
);

const { payload } = useStateManagerContext();
const { state } = useDynamicUIContext();
const rulesResult = useRuleExecutor(payload, rules, definition, state);
const { payload, state } = useStateManagerContext();
const { state: _uiState } = useDynamicUIContext();
const rulesResult = useRuleExecutor(payload, rules, definition, _uiState);
const fieldErrors = useMemo(
() =>
rulesResult.reduce(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

import { ErrorField } from '@/components/organisms/DynamicUI/rule-engines';
import { findDocumentDefinitionById } from '@/components/organisms/UIRenderer/elements/JSONForm/helpers/findDefinitionByName';
import { Document, UIElement, UIPage } from '@/domains/collection-flow';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@ import { useStateManagerContext } from '@/components/organisms/DynamicUI/StateMa
import { useDynamicUIContext } from '@/components/organisms/DynamicUI/hooks/useDynamicUIContext';
import { useUIElementToolsLogic } from '@/components/organisms/DynamicUI/hooks/useUIStateLogic/hooks/useUIElementsStateLogic/hooks/useUIElementToolsLogic';
import { ErrorField } from '@/components/organisms/DynamicUI/rule-engines';
import { DocumentValueDestinationParser } from '@/components/organisms/UIRenderer/elements/JSONForm/components/DocumentField/helpers/document-value-destination-parser';
import { serializeDocumentId } from '@/components/organisms/UIRenderer/elements/JSONForm/components/DocumentField/helpers/serialize-document-id';
import { FileUploaderField } from '@/components/organisms/UIRenderer/elements/JSONForm/components/FileUploaderField';
import { useFileRepository } from '@/components/organisms/UIRenderer/elements/JSONForm/components/FileUploaderField/hooks/useFileRepository';
import { UploadFileFn } from '@/components/organisms/UIRenderer/elements/JSONForm/components/FileUploaderField/hooks/useFileUploading/types';
import { useUIElementErrors } from '@/components/organisms/UIRenderer/hooks/useUIElementErrors/useUIElementErrors';
import { useUIElementState } from '@/components/organisms/UIRenderer/hooks/useUIElementState';
import { Document, UIElement } from '@/domains/collection-flow';
import { fetchFile, uploadFile } from '@/domains/storage/storage.api';
import { collectionFlowFileStorage } from '@/pages/CollectionFlow/collection-flow.file-storage';
import { collectionFlowFileStorage } from '@/pages/CollectionFlow/versions/v1/collection-flow.file-storage';
import { findDocumentSchemaByTypeAndCategory } from '@ballerine/common';
import { AnyObject, ErrorsList, RJSFInputProps } from '@ballerine/ui';
import { HTTPError } from 'ky';
import get from 'lodash/get';
import set from 'lodash/set';
import { useCallback, useLayoutEffect, useMemo, useRef, useState } from 'react';
import { serializeDocumentId } from './helpers/serialize-document-id';

export interface DocumentFieldParams {
documentData: Partial<Document>;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,69 @@ describe('DocumentValueDestinationParser', () => {
});
});
});
describe('DocumentValueDestinationParser', () => {
describe('.extractRootPath', () => {
describe('when path is valid', () => {
describe.each([
['some.root.path.documents[0].pages[0]', 'some.root.path.documents'],
['documents[0].pages[0]', 'documents'],
])('will extract root path from %s', (input, expected) => {
test(`returns ${expected}`, () => {
const parser = new DocumentValueDestinationParser(input);

expect(parser.extractRootPath()).toBe(expected);
});
});
});

describe('otherwise', () => {
it('will be null', () => {
const parser = new DocumentValueDestinationParser(
'some.random.broken.path[3433434].test.99.1221',
);

expect(parser.extractRootPath()).toBe(null);
});
});
});

describe('.extractPagePath', () => {
describe('when path is valid', () => {
it('will extract path to document page', () => {
const parser = new DocumentValueDestinationParser(
'some.path.to.documents[0].page.nested.pages[1].file.id',
);

expect(parser.extractPagePath()).toBe('page.nested.pages[1]');
});
});

describe('otherwise', () => {
it('will be null', () => {
const parser = new DocumentValueDestinationParser('brokenpath');

expect(parser.extractPagePath()).toBe(null);
});
});
});

describe('.extractFileIdPath', () => {
describe('when path is valid', () => {
it('will extract path to fileId', () => {
const parser = new DocumentValueDestinationParser(
'context.documents[1].additionalInfo.pages[0].path.to.file.id',
);

expect(parser.extractFileIdPath()).toBe('path.to.file.id');
});
});

describe('otherwise', () => {
it('will be null', () => {
const parser = new DocumentValueDestinationParser('some-broken.path-pages[1121]');

expect(parser.extractFileIdPath()).toBe(null);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { serializeDocumentId } from '@/components/organisms/UIRenderer/elements/JSONForm/components/DocumentField/helpers/serialize-document-id';
import { serializeDocumentId } from './serialize-document-id';

describe('serializeDocumentId', () => {
it('will populate INDEX placeholder with index', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ export const serializeDocumentId = (baseId: string, index: number): string => {

export const deserializeDocumentId = (id: string): string => {
const result = id.replace(/\[index:\d+\]/g, '[{INDEX}]');

return result;
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ts-nocheck
import { UIElement } from '@/domains/collection-flow';
import {
Chip,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { deserializeDocumentId } from '@/components/organisms/UIRenderer/elements/JSONForm/components/DocumentField/helpers/serialize-document-id';
import { UIElement } from '@/domains/collection-flow';
import { AnyObject } from '@ballerine/ui';

const deserializeDocumentId = (id: string) => {
return id;
};

export const findDefinitionByName = (
name: string,
elements: Array<UIElement<AnyObject>>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//@ts-nocheck
import { CheckboxList } from '@/components/organisms/UIRenderer/elements/JSONForm/components/CheckboxList';
import { CountryPicker } from '@/components/organisms/UIRenderer/elements/JSONForm/components/CountryPicker';
import { DocumentField } from '@/components/organisms/UIRenderer/elements/JSONForm/components/DocumentField';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
Breadcrumbs,
} from '@/components/atoms/Stepper/components/atoms/Breadcrumbs';
import { VerticalLayout } from '@/components/atoms/Stepper/layouts/Vertical';
import { usePageContext } from '@/components/organisms/DynamicUI/Page';
import { usePageResolverContext } from '@/components/organisms/DynamicUI/PageResolver/hooks/usePageResolverContext';
import { useStateManagerContext } from '@/components/organisms/DynamicUI/StateManager/components/StateProvider';
import { useDynamicUIContext } from '@/components/organisms/DynamicUI/hooks/useDynamicUIContext';
Expand All @@ -14,16 +13,18 @@ import { UIPage } from '@/domains/collection-flow';
import { CollectionFlowContext } from '@/domains/collection-flow/types/flow-context.types';
import { isPageCompleted } from '@/helpers/prepareInitialUIState';
import { ScrollArea, ScrollBar } from '@ballerine/ui';
import { useEffect, useMemo, useState } from 'react';
import { FunctionComponent, useEffect, useMemo, useState } from 'react';

export const StepperUI = () => {
interface IStepperUIProps {
revisionStateNames: string[];
}

export const StepperUI: FunctionComponent<IStepperUIProps> = ({ revisionStateNames }) => {
const { state: uiState } = useDynamicUIContext();
const { pages, currentPage } = usePageResolverContext();
const { payload } = useStateManagerContext();
const { pageErrors } = usePageContext();

const computeStepStatus = ({
pageError,
page,
context,
uiElementState,
Expand All @@ -34,7 +35,7 @@ export const StepperUI = () => {
currentPage: UIPage;
context: CollectionFlowContext;
}) => {
if (Object.values(pageError || {}).some(error => error.type === 'warning')) return 'warning';
if (revisionStateNames?.includes(page.stateName)) return 'warning';

if (isPageCompleted(page, context) || uiElementState?.isCompleted) return 'completed';

Expand All @@ -48,8 +49,6 @@ export const StepperUI = () => {
const stepStatus = computeStepStatus({
// @ts-ignore
uiElementState: uiState.elements[page.stateName],
// @ts-ignore
pageError: pageErrors?.[page.stateName],
page,
context: initialContext,
currentPage: currentPage as UIPage,
Expand All @@ -63,7 +62,7 @@ export const StepperUI = () => {

return step;
});
}, [pages, uiState, pageErrors, initialContext, currentPage]);
}, [pages, uiState, initialContext, currentPage]);

const activeStep = useMemo(() => {
const activeStep = steps.find(step => step.id === currentPage?.stateName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// @ts-nocheck

import { ARRAY_VALUE_INDEX_PLACEHOLDER } from '@/common/consts/consts';
import { DocumentFieldParams } from '@/components/organisms/UIRenderer/elements/JSONForm/components/DocumentField';
import { UIElement, UIPage } from '@/domains/collection-flow';
Expand All @@ -12,7 +14,7 @@ export const getElementByValueDestination = (

const findByElementDefinitionByDestination = (
targetDestination: string,
elements: UIElement<AnyObject>[],
elements: Array<UIElement<AnyObject>>,
): UIElement<AnyObject> | null => {
for (const element of elements) {
if (element.valueDestination === targetDestination) return element;
Expand All @@ -22,6 +24,7 @@ export const getElementByValueDestination = (
targetDestination,
element.elements,
);

if (foundElement) return foundElement;
}
}
Expand All @@ -36,26 +39,25 @@ export const getElementByValueDestination = (
);

const element = findByElementDefinitionByDestination(originArrayDestinationPath, page.elements);

return element;
}

return findByElementDefinitionByDestination(destination, page.elements);
};

export const getDocumentElementByDocumentError = (
id: string,
page: UIPage,
): UIElement<AnyObject> | null => {
export const getDocumentElementByDocumentError = (id: string, page: any): any => {
const findElement = (
id: string,
elements: UIElement<AnyObject>[],
elements: Array<UIElement<AnyObject>>,
): UIElement<DocumentFieldParams> | null => {
for (const element of elements) {
//@ts-ignore
if (element.options?.documentData?.id === id.replace('document-error-', '')) return element;

if (element.elements) {
const foundInElements = findElement(id, element.elements);

if (foundInElements) return foundInElements;
}
}
Expand Down
Loading

0 comments on commit d6f7267

Please sign in to comment.