@evoke-platform/ui-components 1.1.0-testing.10 → 1.1.0-testing.12

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.
@@ -2,40 +2,77 @@ import { ApiServices, Obj, ObjectInstance, UserAccount } from '@evoke-platform/c
2
2
  import { ReactComponent } from '@formio/react';
3
3
  import React from 'react';
4
4
  import '../../../../styles/form-component.css';
5
- import { Document, ObjectPropertyInputProps } from '../types';
5
+ import { Address, Document, ObjectPropertyInputProps } from '../types';
6
6
  type OnSaveResponse = {
7
7
  isSuccessful: boolean;
8
8
  error?: Record<string, unknown>;
9
9
  };
10
10
  export type FormProps = {
11
- formKey?: number;
12
- object?: Obj;
13
- instance?: ObjectInstance;
14
- document?: Document;
15
- user?: UserAccount;
16
- onSave?: (data: Record<string, unknown>, setSubmitting?: (value: boolean) => void) => Promise<OnSaveResponse>;
17
- submitButtonLabel?: string;
18
- isReadOnly?: boolean;
19
- apiServices?: ApiServices | undefined;
20
- navigateTo?: (path: string) => void;
21
- closeModal?: () => void;
22
- clearable?: boolean;
23
- objectInputCommonProps?: ObjectPropertyInputProps;
11
+ /** An optional identifier for the action associated with the form. */
24
12
  actionId?: string;
25
- onAutoSave?: (data: Record<string, unknown>) => Promise<{
26
- isSuccessful: boolean;
27
- error?: Record<string, unknown>;
28
- }>;
13
+ /** The type of action associated with the form. */
29
14
  actionType?: string;
15
+ /** Optional API services for the form. */
16
+ apiServices?: ApiServices | undefined;
17
+ /** An object representing an associated object with optional `instanceId` and `propertyId` properties. */
30
18
  associatedObject?: {
31
19
  instanceId?: string;
32
20
  propertyId?: string;
33
21
  };
34
- queryAddresses?: unknown;
22
+ /**
23
+ * Whether the form can be cleared.
24
+ * @default false
25
+ * */
26
+ clearable?: boolean;
27
+ /** An optional document related to the form. */
28
+ document?: Document;
29
+ /** Defines the height of the fields in the form. */
35
30
  fieldHeight?: 'small' | 'medium';
31
+ /** An optional unique identifier for the form instance. */
32
+ formKey?: number;
33
+ /**
34
+ * A reference to the form for direct manipulation.
35
+ * i.e: formRef.current.submit({data: formRef.current.data}, 'submit', (error?: Record<string, unknown>) => {...}, (value: boolean) => {...})
36
+ * */
37
+ formRef?: React.MutableRefObject<FormRef | undefined>;
38
+ /** A React component used as a rich text editor. */
36
39
  richTextEditor?: typeof ReactComponent;
40
+ /**
41
+ * Whether to hide the buttons in the form.
42
+ * @default false
43
+ * */
37
44
  hideButtons?: boolean;
38
- formRef?: React.MutableRefObject<FormRef | undefined>;
45
+ /** An optional instance of an object associated with the form. */
46
+ instance?: ObjectInstance;
47
+ /**
48
+ * Whether the form is in read-only mode.
49
+ * @default false
50
+ * */
51
+ isReadOnly?: boolean;
52
+ /** An optional object associated with the form. */
53
+ object?: Obj;
54
+ /** Common properties for object input fields. */
55
+ objectInputCommonProps?: ObjectPropertyInputProps;
56
+ /** An optional user account associated with the form. */
57
+ user?: UserAccount;
58
+ /**
59
+ * The label for the submit button.
60
+ * @default Submit
61
+ * */
62
+ submitButtonLabel?: string;
63
+ /** A function to close a modal if the form is in one. */
64
+ closeModal?: () => void;
65
+ /** A function to navigate to a different path. */
66
+ navigateTo?: (path: string) => void;
67
+ /** A callback function to save draft the form data. */
68
+ onAutoSave?: (data: Record<string, unknown>) => Promise<{
69
+ isSuccessful: boolean;
70
+ error?: Record<string, unknown>;
71
+ }>;
72
+ /** A callback function to save the form data. It returns a promise with a response. */
73
+ onSave?: (data: Record<string, unknown>, setSubmitting?: (value: boolean) => void) => Promise<OnSaveResponse>;
74
+ /** A function to query addresses related to the form. */
75
+ queryAddresses?: (query: string) => Promise<Address[]>;
39
76
  };
40
77
  export type FormRef = {
41
78
  submit: (submission: Record<string, unknown>, type: 'submit' | 'draft', setError: (error?: Record<string, unknown>) => void, setSubmitting?: (value: boolean) => void) => void;
@@ -445,7 +445,7 @@ export function Form(props) {
445
445
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
446
446
  , {
447
447
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
448
- onChange: (e) => setFormData(e.data), key: closeModal ? undefined : formKey, form: {
448
+ onChange: (e) => !isEqual(e.data, formData) && setFormData(e.data), key: closeModal ? undefined : formKey, form: {
449
449
  display: 'form',
450
450
  components: componentProps,
451
451
  }, formReady: handleFormReady })) : (React.createElement(Box, null,
@@ -21,11 +21,10 @@ type ButtonProps = {
21
21
  };
22
22
  export declare class ButtonComponent extends ReactComponent {
23
23
  [x: string]: any;
24
- component: ButtonComponentProps;
25
24
  componentRoot?: Root;
26
25
  constructor(component: ButtonComponentProps, options: any, data: any);
27
26
  setError(error?: Record<string, unknown>): void;
28
- getButton: (buttonAction: 'cancel' | 'submit' | 'save-draft') => Button | undefined;
27
+ getButton: (buttonAction: 'cancel' | 'submit' | 'save-draft') => any;
29
28
  handleCancel: (event: any) => void;
30
29
  handleSaveDraft: (setSubmitting: (value: boolean) => void) => void;
31
30
  handleSubmit: (setSubmitting: (value: boolean) => void) => void;
@@ -1,10 +1,9 @@
1
1
  import { ReactComponent } from '@formio/react';
2
2
  import { Root } from 'react-dom/client';
3
- import { BaseFormComponentProps, SavedDocumentReference } from '../../types';
3
+ import { SavedDocumentReference } from '../../types';
4
4
  export declare class DocumentComponent extends ReactComponent {
5
5
  [x: string]: any;
6
6
  static schema: any;
7
- component: BaseFormComponentProps;
8
7
  errorDetails: any;
9
8
  componentRoot?: Root;
10
9
  constructor(component: any, options: any, data: any);
@@ -15,7 +15,6 @@ type FormFieldComponentProps = Omit<BaseFormComponentProps, 'property'> & {
15
15
  export declare class FormFieldComponent extends ReactComponent {
16
16
  [x: string]: any;
17
17
  static schema: any;
18
- component: FormFieldComponentProps;
19
18
  errorDetails: any;
20
19
  /**
21
20
  * Called when the component has been instantiated. This is useful to define
@@ -4,9 +4,6 @@ import { BaseFormComponentProps } from '../../types';
4
4
  export declare class ImageComponent extends ReactComponent {
5
5
  [x: string]: any;
6
6
  static schema: any;
7
- component: BaseFormComponentProps & {
8
- initialValue?: string;
9
- };
10
7
  errorDetails: any;
11
8
  componentRoot?: Root;
12
9
  constructor(component: BaseFormComponentProps, options: any, data: any);
@@ -12,7 +12,6 @@ export declare class ObjectComponent extends ReactComponent {
12
12
  relatedObject?: Obj;
13
13
  [x: string]: any;
14
14
  static schema: any;
15
- component: ObjectComponentProps;
16
15
  errorDetails: any;
17
16
  componentRoot?: Root;
18
17
  criteria?: Record<string, unknown>;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { Action, ApiServices, Obj, Property, UserAccount } from '@evoke-platform/context';
3
- import { ObjectPropertyInputProps } from '../../types';
3
+ import { Address, ObjectPropertyInputProps } from '../../types';
4
4
  export type ActionDialogProps = {
5
5
  open: boolean;
6
6
  onClose: () => void;
@@ -15,7 +15,7 @@ export type ActionDialogProps = {
15
15
  instanceId?: string;
16
16
  relatedProperty?: Property;
17
17
  apiServices: ApiServices;
18
- queryAddresses?: unknown;
18
+ queryAddresses?: (query: string) => Promise<Address[]>;
19
19
  user?: UserAccount;
20
20
  };
21
21
  export declare const ActionDialog: (props: ActionDialogProps) => JSX.Element;
@@ -1,11 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import { ApiServices, ObjectInstance, Property, UserAccount, ViewLayoutEntityReference } from '@evoke-platform/context';
3
+ import { Address } from '../../types';
3
4
  export type ObjectPropertyInputProps = {
4
5
  property: Property;
5
6
  instance: ObjectInstance;
6
7
  canUpdateProperty: boolean;
7
8
  apiServices: ApiServices;
8
- queryAddresses?: unknown;
9
+ queryAddresses?: (query: string) => Promise<Address[]>;
9
10
  user?: UserAccount;
10
11
  viewLayout?: ViewLayoutEntityReference;
11
12
  };
@@ -10,7 +10,6 @@ type RepeatableFieldComponentProps = BaseFormComponentProps & {
10
10
  export declare class RepeatableFieldComponent extends ReactComponent {
11
11
  [x: string]: any;
12
12
  static schema: any;
13
- component: RepeatableFieldComponentProps;
14
13
  criteria: Record<string, any> | undefined;
15
14
  updatedCriteria: Record<string, any>;
16
15
  constructor(component: RepeatableFieldComponentProps, options: any, data: any);
@@ -6,9 +6,6 @@ export declare class UserComponent extends ReactComponent {
6
6
  [x: string]: any;
7
7
  static schema: any;
8
8
  errorDetails: any;
9
- component: BaseFormComponentProps & {
10
- initialValue?: string;
11
- };
12
9
  componentRoot?: Root;
13
10
  criteria: Record<string, unknown> | undefined;
14
11
  updatedCriteria: Record<string, unknown>;
@@ -2,7 +2,7 @@ import { ActionInput, ActionInputType, ApiServices, FormEntry, InputParameter, I
2
2
  import { ReactComponent } from '@formio/react';
3
3
  import { LocalDateTime } from '@js-joda/core';
4
4
  import { AutocompleteOption } from '../../core';
5
- import { ObjectPropertyInputProps } from './types';
5
+ import { Address, ObjectPropertyInputProps } from './types';
6
6
  export declare function determineComponentType(properties: Property[], parameter?: InputParameter): ActionInputType | undefined;
7
7
  export declare function determineParameterType(componentType: string): PropertyType;
8
8
  export declare function getFlattenEntries(entries: FormEntry[]): InputParameterReference[];
@@ -21,9 +21,9 @@ export declare function getMiddleObject(instance: ObjectInstance, property: Prop
21
21
  } | undefined;
22
22
  export declare function getMiddleInstance(instanceId: string, property: Property, middleObjectInstances: ObjectInstance[]): ObjectInstance | undefined;
23
23
  export declare function getPrefixedUrl(url: string): string;
24
- export declare function addObjectPropertiesToComponentProps(properties: Property[], formComponents: any[], instance?: ObjectInstance, objectPropertyInputProps?: ObjectPropertyInputProps, autoSave?: (data: Record<string, unknown>) => void, readOnly?: boolean, defaultPages?: Record<string, string>, navigateTo?: (path: string) => void, queryAddresses?: unknown, apiServices?: ApiServices, isModal?: boolean, fieldHeight?: 'small' | 'medium', richTextEditor?: typeof ReactComponent): Promise<ActionInput[]>;
24
+ export declare function addObjectPropertiesToComponentProps(properties: Property[], formComponents: any[], instance?: ObjectInstance, objectPropertyInputProps?: ObjectPropertyInputProps, autoSave?: (data: Record<string, unknown>) => void, readOnly?: boolean, defaultPages?: Record<string, string>, navigateTo?: (path: string) => void, queryAddresses?: (query: string) => Promise<Address[]>, apiServices?: ApiServices, isModal?: boolean, fieldHeight?: 'small' | 'medium', richTextEditor?: typeof ReactComponent): Promise<ActionInput[]>;
25
25
  export declare function getDefaultValue(initialValue: unknown, selectOptions?: AutocompleteOption[]): unknown;
26
- export declare const buildComponentPropsFromObjectProperties: (properties: Property[], objectId: string, instance?: ObjectInstance, objectPropertyInputProps?: ObjectPropertyInputProps, hasActionPermissions?: boolean, autoSave?: ((data: Record<string, unknown>) => void) | undefined, readOnly?: boolean, queryAddresses?: unknown, isModal?: boolean, fieldHeight?: 'small' | 'medium', richTextEditor?: typeof ReactComponent) => unknown[];
26
+ export declare const buildComponentPropsFromObjectProperties: (properties: Property[], objectId: string, instance?: ObjectInstance, objectPropertyInputProps?: ObjectPropertyInputProps, hasActionPermissions?: boolean, autoSave?: ((data: Record<string, unknown>) => void) | undefined, readOnly?: boolean, queryAddresses?: ((query: string) => Promise<Address[]>) | undefined, isModal?: boolean, fieldHeight?: 'small' | 'medium', richTextEditor?: typeof ReactComponent) => unknown[];
27
27
  export declare const buildComponentPropsFromDocumentProperties: (documentProperties: [string, unknown][], readOnly?: boolean, autoSave?: ((data: Record<string, unknown>) => void) | undefined, fieldHeight?: 'small' | 'medium') => {
28
28
  type: string;
29
29
  key: string;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { CriteriaBuilder as BuildCriteria } from '../index';
3
3
  export default {
4
- title: 'Input/CriteriaBuilder',
4
+ title: 'Custom/CriteriaBuilder',
5
5
  component: BuildCriteria,
6
6
  };
7
7
  const defaultProperties = [
@@ -0,0 +1,6 @@
1
+ import { ComponentMeta, ComponentStory } from '@storybook/react';
2
+ import { Form } from '../index';
3
+ declare const _default: ComponentMeta<typeof Form>;
4
+ export default _default;
5
+ export declare const FormWithButtons: ComponentStory<typeof Form>;
6
+ export declare const FormWithNoButtons: ComponentStory<typeof Form>;
@@ -0,0 +1,82 @@
1
+ import React from 'react';
2
+ import { Button, Form } from '../index';
3
+ export default {
4
+ title: 'Custom/Form',
5
+ component: Form,
6
+ };
7
+ const object = {
8
+ id: 'test',
9
+ name: 'Test',
10
+ properties: [
11
+ {
12
+ id: 'name',
13
+ name: 'Name',
14
+ type: 'string',
15
+ required: true,
16
+ },
17
+ {
18
+ id: 'decimal',
19
+ name: 'Decimal',
20
+ type: 'number',
21
+ },
22
+ {
23
+ id: 'integer',
24
+ name: 'Integer',
25
+ type: 'integer',
26
+ },
27
+ ],
28
+ actions: [
29
+ {
30
+ id: '_create',
31
+ name: 'Create Test',
32
+ type: 'create',
33
+ outputEvent: 'Test Created',
34
+ },
35
+ {
36
+ id: '_update',
37
+ name: 'Update Test',
38
+ type: 'update',
39
+ outputEvent: 'Test Updated',
40
+ },
41
+ {
42
+ id: '_delete',
43
+ name: 'Delete Test',
44
+ type: 'delete',
45
+ inputProperties: [],
46
+ outputEvent: 'Test Deleted',
47
+ },
48
+ ],
49
+ };
50
+ const FormWithButtonsTemplate = (args) => {
51
+ return React.createElement(Form, { ...args });
52
+ };
53
+ export const FormWithButtons = FormWithButtonsTemplate.bind({});
54
+ FormWithButtons.args = {
55
+ actionId: '_update',
56
+ actionType: 'update',
57
+ object: object,
58
+ instance: { id: 'id', objectId: 'test', name: 'test', integer: 12, decimal: 12.5 },
59
+ };
60
+ const FormWithNoButtonsTemplate = (args) => {
61
+ return (React.createElement("div", null,
62
+ React.createElement(Form, { ...args }),
63
+ React.createElement(Button, { onClick: () => {
64
+ console.log(args.formRef?.current?.data);
65
+ args.formRef?.current?.data &&
66
+ args.formRef.current.submit({ data: args.formRef.current.data }, 'submit', (error) => {
67
+ console.log(error);
68
+ });
69
+ } },
70
+ ' ',
71
+ "Submit",
72
+ ' ')));
73
+ };
74
+ export const FormWithNoButtons = FormWithNoButtonsTemplate.bind({});
75
+ FormWithNoButtons.args = {
76
+ actionId: '_update',
77
+ actionType: 'update',
78
+ object: object,
79
+ instance: { id: 'id', objectId: 'test', name: 'test', integer: 12, decimal: 12.5 },
80
+ hideButtons: true,
81
+ formRef: { current: {} },
82
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evoke-platform/ui-components",
3
- "version": "1.1.0-testing.10",
3
+ "version": "1.1.0-testing.12",
4
4
  "description": "",
5
5
  "main": "dist/published/index.js",
6
6
  "module": "dist/published/index.js",