@axinom/mosaic-ui 0.39.1-feat-gs.2 → 0.40.0-rc.0

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.
Files changed (70) hide show
  1. package/dist/components/FormStation/Create/Create.d.ts +1 -1
  2. package/dist/components/FormStation/Create/Create.d.ts.map +1 -1
  3. package/dist/components/FormStation/Details/Details.d.ts +2 -2
  4. package/dist/components/FormStation/Details/Details.d.ts.map +1 -1
  5. package/dist/components/FormStation/FormStation.d.ts +15 -8
  6. package/dist/components/FormStation/FormStation.d.ts.map +1 -1
  7. package/dist/components/FormStation/FormStation.models.d.ts +3 -17
  8. package/dist/components/FormStation/FormStation.models.d.ts.map +1 -1
  9. package/dist/components/FormStation/StationErrorStateType.d.ts +5 -0
  10. package/dist/components/FormStation/StationErrorStateType.d.ts.map +1 -0
  11. package/dist/components/FormStation/index.d.ts +1 -1
  12. package/dist/components/FormStation/index.d.ts.map +1 -1
  13. package/dist/components/FormStation/{helpers/useValidationError.d.ts → useValidationError.d.ts} +1 -1
  14. package/dist/components/FormStation/useValidationError.d.ts.map +1 -0
  15. package/dist/components/Utils/Postgraphile/getArrayDiff.d.ts.map +1 -1
  16. package/dist/components/Utils/Postgraphile/getFormDiff.d.ts.map +1 -1
  17. package/dist/helpers/testing.d.ts +1 -4
  18. package/dist/helpers/testing.d.ts.map +1 -1
  19. package/dist/index.es.js +4 -4
  20. package/dist/index.es.js.map +1 -1
  21. package/dist/index.js +4 -4
  22. package/dist/index.js.map +1 -1
  23. package/package.json +4 -3
  24. package/src/components/Actions/Action/Action.scss +0 -1
  25. package/src/components/FormElements/Tags/Tags.tsx +3 -3
  26. package/src/components/FormStation/Create/Create.stories.tsx +9 -1
  27. package/src/components/FormStation/Create/Create.tsx +1 -4
  28. package/src/components/FormStation/Details/Details.tsx +2 -5
  29. package/src/components/FormStation/FormStation.models.ts +3 -29
  30. package/src/components/FormStation/FormStation.scss +70 -0
  31. package/src/components/FormStation/FormStation.spec.tsx +1 -2
  32. package/src/components/FormStation/FormStation.stories.tsx +1 -20
  33. package/src/components/FormStation/FormStation.tsx +403 -68
  34. package/src/components/FormStation/StationErrorStateType.tsx +5 -0
  35. package/src/components/FormStation/index.ts +5 -1
  36. package/src/components/FormStation/{helpers/useValidationError.tsx → useValidationError.tsx} +1 -1
  37. package/src/components/Utils/Postgraphile/getArrayDiff.ts +6 -7
  38. package/src/components/Utils/Postgraphile/getFormDiff.ts +1 -2
  39. package/dist/components/FormStation/FormContentWrapper/FormContentWrapper.d.ts +0 -11
  40. package/dist/components/FormStation/FormContentWrapper/FormContentWrapper.d.ts.map +0 -1
  41. package/dist/components/FormStation/FormStationActions/FormStationActions.d.ts +0 -21
  42. package/dist/components/FormStation/FormStationActions/FormStationActions.d.ts.map +0 -1
  43. package/dist/components/FormStation/FormStationContext/FormStationContext.d.ts +0 -13
  44. package/dist/components/FormStation/FormStationContext/FormStationContext.d.ts.map +0 -1
  45. package/dist/components/FormStation/FormStationContext/FormStationContextProvider.d.ts +0 -10
  46. package/dist/components/FormStation/FormStationContext/FormStationContextProvider.d.ts.map +0 -1
  47. package/dist/components/FormStation/FormStationHeader/FormStationHeader.d.ts +0 -12
  48. package/dist/components/FormStation/FormStationHeader/FormStationHeader.d.ts.map +0 -1
  49. package/dist/components/FormStation/helpers/mergeData.d.ts +0 -7
  50. package/dist/components/FormStation/helpers/mergeData.d.ts.map +0 -1
  51. package/dist/components/FormStation/helpers/useChangeSets.d.ts +0 -12
  52. package/dist/components/FormStation/helpers/useChangeSets.d.ts.map +0 -1
  53. package/dist/components/FormStation/helpers/useDataProvider.d.ts +0 -14
  54. package/dist/components/FormStation/helpers/useDataProvider.d.ts.map +0 -1
  55. package/dist/components/FormStation/helpers/useDebouncedFormikValues.d.ts +0 -7
  56. package/dist/components/FormStation/helpers/useDebouncedFormikValues.d.ts.map +0 -1
  57. package/dist/components/FormStation/helpers/useUndo.d.ts +0 -6
  58. package/dist/components/FormStation/helpers/useUndo.d.ts.map +0 -1
  59. package/dist/components/FormStation/helpers/useValidationError.d.ts.map +0 -1
  60. package/src/components/FormStation/FormContentWrapper/FormContentWrapper.scss +0 -66
  61. package/src/components/FormStation/FormContentWrapper/FormContentWrapper.tsx +0 -77
  62. package/src/components/FormStation/FormStationActions/FormStationActions.tsx +0 -132
  63. package/src/components/FormStation/FormStationContext/FormStationContext.ts +0 -22
  64. package/src/components/FormStation/FormStationContext/FormStationContextProvider.tsx +0 -86
  65. package/src/components/FormStation/FormStationHeader/FormStationHeader.tsx +0 -85
  66. package/src/components/FormStation/helpers/mergeData.ts +0 -26
  67. package/src/components/FormStation/helpers/useChangeSets.ts +0 -70
  68. package/src/components/FormStation/helpers/useDataProvider.ts +0 -169
  69. package/src/components/FormStation/helpers/useDebouncedFormikValues.ts +0 -22
  70. package/src/components/FormStation/helpers/useUndo.ts +0 -43
@@ -1,23 +1,51 @@
1
1
  import clsx from 'clsx';
2
- import { Formik, FormikValues } from 'formik';
3
- import React, { PropsWithChildren } from 'react';
2
+ import {
3
+ Form,
4
+ Formik,
5
+ FormikHelpers,
6
+ FormikValues,
7
+ useFormikContext,
8
+ } from 'formik';
9
+ import React, {
10
+ PropsWithChildren,
11
+ useCallback,
12
+ useEffect,
13
+ useMemo,
14
+ useRef,
15
+ useState,
16
+ } from 'react';
17
+ import { useHistory } from 'react-router-dom';
4
18
  import { OptionalObjectSchema } from 'yup/lib/object';
5
- import type { Data } from '../../types/data';
6
- import type { StationMessage } from '../models';
7
- import { FormContentWrapper } from './FormContentWrapper/FormContentWrapper';
8
- import type {
9
- FormActionData,
10
- InitialFormData,
11
- ObjectSchemaDefinition,
12
- SaveDataFunction,
13
- } from './FormStation.models';
19
+ import { SaveIndicatorType, setSaveIndicator } from '../../initialize';
20
+ import { Data } from '../../types/data';
21
+ import { ErrorTypeToStationError } from '../../utils/ErrorTypeToStationError';
22
+ import { Actions, ActionsProps } from '../Actions';
23
+ import { isNavigationAction } from '../Actions/Action/Action';
24
+ import { IconName } from '../Icons';
25
+ import { MessageBar } from '../MessageBar';
26
+ import {
27
+ PageHeader,
28
+ PageHeaderActionType,
29
+ PageHeaderProps,
30
+ } from '../PageHeader';
31
+ import { ErrorType, StationMessage } from '../models';
32
+ import { FormActionData, InitialFormData } from './FormStation.models';
14
33
  import classes from './FormStation.scss';
15
- import { FormStationActions } from './FormStationActions/FormStationActions';
16
- import { FormStationContextProvider } from './FormStationContext/FormStationContextProvider';
17
- import { FormStationHeader } from './FormStationHeader/FormStationHeader';
18
34
  import { SaveOnNavigate } from './SaveOnNavigate/SaveOnNavigate';
19
- import { useDataProvider } from './helpers/useDataProvider';
20
- import { useValidationError } from './helpers/useValidationError';
35
+ import { StationErrorStateType } from './StationErrorStateType';
36
+ import { useValidationError } from './useValidationError';
37
+
38
+ export type ObjectSchemaDefinition<
39
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
+ T extends Data | null = any,
41
+ > = {
42
+ // TODO: Adding 'any' here since there are a couple of open issues regarding generics in the latest version of yup.
43
+ // https://github.com/jquense/yup/issues/1159
44
+ // https://github.com/jquense/yup/issues/1247
45
+ // Consider revisiting once 'yup' has addressed these issues.
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ [field in keyof T]: any;
48
+ };
21
49
 
22
50
  export interface FormStationProps<
23
51
  TValues extends Data = FormikValues,
@@ -61,11 +89,28 @@ export interface FormStationProps<
61
89
  * Called whenever the form needs to be saved.
62
90
  * This method needs to throw an exception in case the saving did not succeed.
63
91
  */
64
- saveData: SaveDataFunction<TValues, TSubmitResponse>;
92
+ saveData: (
93
+ /** The current values of the form */
94
+ values: TValues,
95
+ /** The initial values of the form */
96
+ initialData: InitialFormData<TValues>,
97
+ /** The Formik state helpers */
98
+ formikHelpers: FormikHelpers<TValues>,
99
+ ) => Promise<TSubmitResponse> | void;
65
100
  /** CSS Class name for additional styles */
66
101
  className?: string;
67
- /** Periodically calls saveData when the form values change */
68
- autosave?: boolean;
102
+ }
103
+
104
+ interface FormActionProps<T, Y> extends Omit<ActionsProps, 'actions'> {
105
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
106
+ validationSchema?: OptionalObjectSchema<ObjectSchemaDefinition<any>>;
107
+ actions?: FormActionData<T, Y>[];
108
+ setStationError: (error: StationErrorStateType) => void;
109
+ setValidationError: () => void;
110
+ submitResponse?: React.MutableRefObject<Y | undefined>;
111
+ alwaysSubmitBeforeAction?: boolean;
112
+ className?: string;
113
+ isFormSubmitting?: boolean;
69
114
  }
70
115
 
71
116
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -86,30 +131,141 @@ export const FormStation = <TValues extends Data, TSubmitResponse = unknown>({
86
131
  alwaysSubmitBeforeAction = false,
87
132
  stationMessage,
88
133
  className = '',
89
- autosave = false,
90
134
  }: PropsWithChildren<
91
135
  FormStationProps<TValues, TSubmitResponse>
92
136
  >): JSX.Element => {
93
- const currentValuesRef = React.useRef<TValues>({} as TValues);
137
+ const [stationError, setStationError] = useState<StationErrorStateType>();
94
138
 
95
- const {
96
- onSubmit,
139
+ const { setValidationError, validationWatcher } = useValidationError(
97
140
  stationError,
98
141
  setStationError,
99
- isFormSubmitting,
100
- lastSubmittedResponse,
101
- initialValues,
102
- } = useDataProvider<TValues, TSubmitResponse>(
103
- initialData,
104
- saveData,
105
- currentValuesRef,
106
142
  );
107
143
 
108
- const { setValidationError, validationWatcher } = useValidationError(
109
- stationError,
110
- setStationError,
144
+ const submitResponse = useRef<TSubmitResponse>();
145
+ const [isFormSubmitting, setIsFormSubmitting] = useState<boolean>(false);
146
+
147
+ const onSubmit = useCallback(
148
+ async (
149
+ values: TValues,
150
+ formikHelpers: FormikHelpers<TValues>,
151
+ ): Promise<void> => {
152
+ if (isFormSubmitting) {
153
+ return;
154
+ }
155
+
156
+ try {
157
+ setIsFormSubmitting(true);
158
+ setSaveIndicator(SaveIndicatorType.Saving);
159
+ setStationError(undefined);
160
+ if (!initialData.loading && saveData) {
161
+ const response = await saveData(values, initialData, formikHelpers);
162
+ if (response) {
163
+ submitResponse.current = response;
164
+ }
165
+ }
166
+ } catch (error) {
167
+ setStationError(
168
+ ErrorTypeToStationError(
169
+ error as ErrorType,
170
+ 'An error occurred when trying to save data.',
171
+ ),
172
+ );
173
+
174
+ setSaveIndicator(SaveIndicatorType.Dirty);
175
+
176
+ // We still throw the error, to make sure that navigation or action execution
177
+ // will not continue after a failed save.
178
+ throw error;
179
+ } finally {
180
+ formikHelpers.setSubmitting(false);
181
+ setIsFormSubmitting(false);
182
+ }
183
+ },
184
+ [isFormSubmitting, initialData, saveData, setStationError],
111
185
  );
112
186
 
187
+ useEffect(() => {
188
+ if (
189
+ initialData.error ||
190
+ (initialData.data === null && !initialData.loading) ||
191
+ initialData.entityNotFound
192
+ ) {
193
+ const stationError = {
194
+ ...ErrorTypeToStationError(
195
+ initialData.error,
196
+ 'An error occurred when trying to load data.',
197
+ 'Entity not found',
198
+ ),
199
+ type: 'loading',
200
+ };
201
+
202
+ setStationError(stationError);
203
+ } else {
204
+ if (stationError?.type === 'loading') {
205
+ // Only clear the error if it is a loading error, which now seems to be cleared.
206
+ setStationError(undefined);
207
+ }
208
+ }
209
+ }, [
210
+ initialData.loading,
211
+ initialData.error,
212
+ initialData.entityNotFound,
213
+ initialData.data,
214
+ stationError?.type,
215
+ ]);
216
+
217
+ const getContent = (): JSX.Element | undefined => {
218
+ if (initialData.loading) {
219
+ // TODO: Loading skeleton of the page
220
+ return;
221
+ }
222
+
223
+ if (
224
+ initialData.error ||
225
+ initialData.data === null ||
226
+ initialData.entityNotFound
227
+ ) {
228
+ // Error on loading - we can't show the form
229
+ return <div className={classes.loadingError}></div>;
230
+ }
231
+
232
+ // Loading successful
233
+ return (
234
+ <>
235
+ <SaveOnNavigate
236
+ isSubmitting={isFormSubmitting}
237
+ onNavigationCancelled={setValidationError}
238
+ />
239
+ <div className={classes.main}>
240
+ <div
241
+ className={clsx(classes.formWrapper, {
242
+ [classes.hasMessage]: stationMessage,
243
+ })}
244
+ >
245
+ {stationMessage && (
246
+ <MessageBar {...stationMessage}>{stationMessage.body}</MessageBar>
247
+ )}
248
+ <div
249
+ className={clsx(classes.formContainer, {
250
+ [classes.paddedContent]: !edgeToEdgeContent,
251
+ })}
252
+ >
253
+ <Form>
254
+ <>
255
+ {children}
256
+ {/* Adding a invisible text input here to prevent the browser from submitting on "Enter" when there is only a single text input field in the form
257
+ See: https://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2 */}
258
+ <input type="text" style={{ display: 'none' }} />
259
+ </>
260
+ </Form>
261
+ </div>
262
+ </div>
263
+ {infoPanel}
264
+ </div>
265
+ </>
266
+ );
267
+ };
268
+
113
269
  return (
114
270
  <div
115
271
  className={clsx(
@@ -122,50 +278,229 @@ export const FormStation = <TValues extends Data, TSubmitResponse = unknown>({
122
278
  )}
123
279
  >
124
280
  <Formik
125
- initialValues={initialValues ?? ({} as TValues)}
281
+ initialValues={initialData.data ?? ({} as TValues)}
126
282
  validationSchema={validationSchema}
127
283
  onSubmit={onSubmit}
128
284
  enableReinitialize={true}
129
285
  >
130
286
  <>
131
287
  {validationWatcher}
132
- <SaveOnNavigate isSubmitting={isFormSubmitting} />
133
- <FormStationContextProvider<TValues>
134
- autosave={autosave}
135
- currentValuesRef={currentValuesRef}
136
- >
137
- <FormStationHeader
138
- titleProperty={titleProperty as string}
139
- defaultTitle={defaultTitle}
140
- subtitle={subtitle}
141
- cancelNavigationUrl={cancelNavigationUrl}
142
- isFormSubmitting={isFormSubmitting}
143
- />
144
- <FormContentWrapper
145
- stationMessage={stationMessage}
146
- edgeToEdgeContent={edgeToEdgeContent}
147
- infoPanel={infoPanel}
148
- initialData={initialData}
149
- stationError={stationError}
288
+ <FormStationHeader
289
+ titleProperty={titleProperty as string}
290
+ defaultTitle={defaultTitle}
291
+ subtitle={subtitle}
292
+ cancelNavigationUrl={cancelNavigationUrl}
293
+ />
294
+ {stationError && (
295
+ <div className={classes.errorMessage}>
296
+ <MessageBar
297
+ type="error"
298
+ title={String(stationError.title)}
299
+ onClose={() => setStationError(undefined)}
300
+ >
301
+ {stationError?.body}
302
+ </MessageBar>
303
+ </div>
304
+ )}
305
+ <div className={classes.children}>{getContent()}</div>
306
+ {alwaysShowActionsPanel || (actions?.length ?? 0) > 0 ? (
307
+ <FormStationAction<TValues, TSubmitResponse>
308
+ actions={actions}
309
+ width={actionsWidth}
310
+ validationSchema={validationSchema}
150
311
  setStationError={setStationError}
151
- >
152
- {children}
153
- </FormContentWrapper>
154
- {alwaysShowActionsPanel || (actions?.length ?? 0) > 0 ? (
155
- <FormStationActions<TValues, TSubmitResponse>
156
- actions={actions}
157
- width={actionsWidth}
158
- validationSchema={validationSchema}
159
- setStationError={setStationError}
160
- setValidationError={setValidationError}
161
- submitResponse={lastSubmittedResponse}
162
- alwaysSubmitBeforeAction={alwaysSubmitBeforeAction}
163
- className={classes.actionsPanel}
164
- />
165
- ) : null}
166
- </FormStationContextProvider>
312
+ setValidationError={setValidationError}
313
+ submitResponse={submitResponse}
314
+ alwaysSubmitBeforeAction={alwaysSubmitBeforeAction}
315
+ className={classes.actionsPanel}
316
+ />
317
+ ) : null}
167
318
  </>
168
319
  </Formik>
169
320
  </div>
170
321
  );
171
322
  };
323
+
324
+ /**
325
+ * Saves the form before the action is performed.
326
+ */
327
+ const FormStationAction = <T, Y>(
328
+ props: PropsWithChildren<FormActionProps<T, Y>>,
329
+ ): JSX.Element => {
330
+ const {
331
+ actions,
332
+ validationSchema,
333
+ setStationError,
334
+ setValidationError,
335
+ submitResponse,
336
+ alwaysSubmitBeforeAction,
337
+ className = '',
338
+ } = props;
339
+ const {
340
+ submitForm,
341
+ resetForm,
342
+ values,
343
+ validateForm,
344
+ isValid,
345
+ dirty,
346
+ isSubmitting,
347
+ } = useFormikContext<T>();
348
+
349
+ const updatedActions = useMemo(() => {
350
+ return actions?.map((action) => {
351
+ const { onActionSelected } = action;
352
+
353
+ return isNavigationAction(action)
354
+ ? action
355
+ : {
356
+ ...action,
357
+ isDisabled: action.isDisabled || isSubmitting,
358
+ onActionSelected: () => {
359
+ (async () => {
360
+ //TODO: Busy indicator (disable form?)
361
+ if (dirty || alwaysSubmitBeforeAction) {
362
+ // We can't rely on 'isValid' alone, since that will only evaluate if the form is touched or 'submitForm' is called.
363
+ // On a create station though the from might not be touched but still being invalid.
364
+ // Also the validation on submitForm in here will not help, since the value of isValid is already bound to that method and will not change
365
+ // anymore while this method executes - even if it changes on the context!
366
+ if (
367
+ !isValid ||
368
+ (await validationSchema?.isValid(values)) === false
369
+ ) {
370
+ setValidationError();
371
+ // Making sure that the fields will actually show the validation messages (they won't if the from was not touched yet - e.g. on a create station)
372
+ validateForm();
373
+ return;
374
+ }
375
+
376
+ try {
377
+ await submitForm();
378
+
379
+ // Committing the changed values to the form to get the current version as the new "reset" state.
380
+ resetForm({ values });
381
+ } catch (error) {
382
+ // we will abort the action if saving is not successful
383
+ // a station error is already set by the "onSubmit"
384
+ return;
385
+ }
386
+ }
387
+
388
+ try {
389
+ const result =
390
+ onActionSelected &&
391
+ (await onActionSelected({
392
+ values,
393
+ submitResponse: submitResponse?.current,
394
+ }));
395
+ if (result !== undefined) {
396
+ setStationError(
397
+ ErrorTypeToStationError(
398
+ result,
399
+ 'An error occurred when trying to execute the action.',
400
+ ),
401
+ );
402
+ }
403
+ } catch (error) {
404
+ const stationError = ErrorTypeToStationError(
405
+ error as ErrorType,
406
+ 'An error occurred when trying to execute the action.',
407
+ );
408
+ setStationError(stationError);
409
+ }
410
+ })();
411
+ },
412
+ };
413
+ });
414
+ }, [
415
+ actions,
416
+ alwaysSubmitBeforeAction,
417
+ dirty,
418
+ isSubmitting,
419
+ isValid,
420
+ resetForm,
421
+ setStationError,
422
+ setValidationError,
423
+ submitForm,
424
+ submitResponse,
425
+ validateForm,
426
+ validationSchema,
427
+ values,
428
+ ]);
429
+
430
+ return (
431
+ <div className={className}>
432
+ <Actions actions={updatedActions} />
433
+ </div>
434
+ );
435
+ };
436
+
437
+ /**
438
+ * Handles showRefresh and cancel buttons based on form states
439
+ */
440
+ const FormStationHeader: React.FC<
441
+ Omit<PageHeaderProps, 'title'> & {
442
+ titleProperty?: string;
443
+ defaultTitle?: string;
444
+ cancelNavigationUrl?: string;
445
+ }
446
+ > = ({ titleProperty, defaultTitle, subtitle, cancelNavigationUrl }) => {
447
+ const { dirty, resetForm, values } = useFormikContext<FormikValues>();
448
+
449
+ useEffect(() => {
450
+ // Set the save indicator to dirty depending on the form state
451
+ if (dirty) {
452
+ setSaveIndicator(SaveIndicatorType.Dirty);
453
+ } else {
454
+ setSaveIndicator(SaveIndicatorType.Inactive);
455
+ }
456
+ return () => {
457
+ // The form is not always considered "not dirty" after the save
458
+ // so this code will make sure that the indicator is set to inactive
459
+ // when the station is left.
460
+ setSaveIndicator(SaveIndicatorType.Inactive);
461
+ };
462
+ }, [dirty]);
463
+
464
+ const history = useHistory();
465
+
466
+ const title =
467
+ titleProperty && values[titleProperty] !== ''
468
+ ? values[titleProperty]
469
+ : defaultTitle ?? '';
470
+
471
+ return (
472
+ <PageHeader
473
+ title={title}
474
+ subtitle={subtitle}
475
+ actions={[
476
+ ...(dirty === true // add undo action if form as been altered
477
+ ? [
478
+ {
479
+ label: 'Undo Changes',
480
+ icon: IconName.Undo,
481
+ actionType: PageHeaderActionType.Context,
482
+ onClick: () => {
483
+ resetForm();
484
+ },
485
+ },
486
+ ]
487
+ : []),
488
+ ...(cancelNavigationUrl // add cancel action if applicable
489
+ ? [
490
+ {
491
+ label: 'Cancel',
492
+ icon: IconName.X,
493
+ onClick: () => {
494
+ resetForm();
495
+ // If the form has errors, Navigation needs to be wrapped in a promise or timeout.
496
+ Promise.resolve().then(() =>
497
+ history.push(cancelNavigationUrl),
498
+ );
499
+ },
500
+ },
501
+ ]
502
+ : []),
503
+ ]}
504
+ />
505
+ );
506
+ };
@@ -0,0 +1,5 @@
1
+ import { StationError } from '../models';
2
+
3
+ export interface StationErrorStateType extends StationError {
4
+ type?: string;
5
+ }
@@ -1,4 +1,8 @@
1
1
  export { Create, CreateProps } from './Create/Create';
2
2
  export { Details, DetailsProps } from './Details/Details';
3
- export { FormStation, FormStationProps } from './FormStation';
3
+ export {
4
+ FormStation,
5
+ FormStationProps,
6
+ ObjectSchemaDefinition,
7
+ } from './FormStation';
4
8
  export * from './FormStation.models';
@@ -1,6 +1,6 @@
1
1
  import { useFormikContext } from 'formik';
2
2
  import React, { useCallback, useEffect, useState } from 'react';
3
- import type { StationErrorStateType } from '../FormStation.models';
3
+ import { StationErrorStateType } from './StationErrorStateType';
4
4
 
5
5
  /**
6
6
  * Component that watches for changes in the form validation state
@@ -1,4 +1,3 @@
1
- import { isEqual } from 'lodash';
2
1
  /**
3
2
  * Compares two arrays and returns an object holding an array for the added and another one for the removed items.
4
3
  *
@@ -54,9 +53,9 @@ export function getArrayDiff<T>(
54
53
  (x: T) =>
55
54
  !originalArray.find((e) => {
56
55
  if (key) {
57
- return isEqual(e[key], x[key]);
56
+ return e[key] === x[key];
58
57
  }
59
- return isEqual(e, x);
58
+ return e === x;
60
59
  }),
61
60
  );
62
61
 
@@ -64,9 +63,9 @@ export function getArrayDiff<T>(
64
63
  (x: T) =>
65
64
  !currentArray.find((e) => {
66
65
  if (key && typeof key === 'string') {
67
- return isEqual(e[key], x[key]);
66
+ return e[key] === x[key];
68
67
  }
69
- return isEqual(e, x);
68
+ return e === x;
70
69
  }),
71
70
  );
72
71
 
@@ -75,7 +74,7 @@ export function getArrayDiff<T>(
75
74
  if (key && typeof key === 'string') {
76
75
  updated.push(
77
76
  ...currentArray.filter((x: T) =>
78
- originalArray.find((e) => isEqual(e[key], x[key]) && isUpdated(e, x)),
77
+ originalArray.find((e) => e[key] === x[key] && isUpdated(e, x)),
79
78
  ),
80
79
  );
81
80
  }
@@ -88,7 +87,7 @@ function isUpdated<U>(x: U, y: U): boolean {
88
87
 
89
88
  if (isObject(x) && isObject(y)) {
90
89
  Object.keys(x).forEach((key) => {
91
- if (!isEqual(x[key], y[key])) {
90
+ if (x[key] !== y[key]) {
92
91
  value = true;
93
92
  }
94
93
  });
@@ -1,5 +1,4 @@
1
1
  import { FormikValues } from 'formik';
2
- import { isEqual } from 'lodash';
3
2
 
4
3
  /**
5
4
  * Returns an object only containing the differences between the two FormikValues.
@@ -20,7 +19,7 @@ export function getFormDiff<T extends FormikValues>(
20
19
  ): Partial<T> {
21
20
  const updateData = initial
22
21
  ? Object.keys(current).reduce<T>((result, value) => {
23
- if (!isEqual(current[value], initial[value])) {
22
+ if (current[value] !== initial[value]) {
24
23
  result[value as keyof T] = current[value];
25
24
  }
26
25
  return result;
@@ -1,11 +0,0 @@
1
- import React from 'react';
2
- import type { Data } from '../../../types';
3
- import type { FormStationProps } from '../FormStation';
4
- import type { StationErrorStateType } from '../FormStation.models';
5
- interface FormContentWrapperProps extends Pick<FormStationProps<Data>, 'stationMessage' | 'edgeToEdgeContent' | 'infoPanel' | 'initialData'> {
6
- stationError?: StationErrorStateType;
7
- setStationError: React.Dispatch<React.SetStateAction<StationErrorStateType | undefined>>;
8
- }
9
- export declare const FormContentWrapper: React.FC<FormContentWrapperProps>;
10
- export {};
11
- //# sourceMappingURL=FormContentWrapper.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormContentWrapper.d.ts","sourceRoot":"","sources":["../../../../src/components/FormStation/FormContentWrapper/FormContentWrapper.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAGnE,UAAU,uBACR,SAAQ,IAAI,CACV,gBAAgB,CAAC,IAAI,CAAC,EACtB,gBAAgB,GAAG,mBAAmB,GAAG,WAAW,GAAG,aAAa,CACrE;IACD,YAAY,CAAC,EAAE,qBAAqB,CAAC;IACrC,eAAe,EAAE,KAAK,CAAC,QAAQ,CAC7B,KAAK,CAAC,cAAc,CAAC,qBAAqB,GAAG,SAAS,CAAC,CACxD,CAAC;CACH;AAED,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAwDhE,CAAC"}
@@ -1,21 +0,0 @@
1
- import React, { PropsWithChildren } from 'react';
2
- import { OptionalObjectSchema } from 'yup/lib/object';
3
- import { ActionsProps } from '../../Actions';
4
- import { StationError } from '../../models';
5
- import { FormActionData, ObjectSchemaDefinition } from '../FormStation.models';
6
- interface FormActionProps<T, Y> extends Omit<ActionsProps, 'actions'> {
7
- validationSchema?: OptionalObjectSchema<ObjectSchemaDefinition<any>>;
8
- actions?: FormActionData<T, Y>[];
9
- setStationError: (error: StationError) => void;
10
- setValidationError: () => void;
11
- submitResponse?: React.MutableRefObject<Y | undefined>;
12
- alwaysSubmitBeforeAction?: boolean;
13
- className?: string;
14
- isFormSubmitting?: boolean;
15
- }
16
- /**
17
- * Saves the form before the action is performed.
18
- */
19
- export declare const FormStationActions: <T, Y>(props: React.PropsWithChildren<FormActionProps<T, Y>>) => JSX.Element;
20
- export {};
21
- //# sourceMappingURL=FormStationActions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormStationActions.d.ts","sourceRoot":"","sources":["../../../../src/components/FormStation/FormStationActions/FormStationActions.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,iBAAiB,EAAW,MAAM,OAAO,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAW,YAAY,EAAE,MAAM,eAAe,CAAC;AAEtD,OAAO,EAAa,YAAY,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/E,UAAU,eAAe,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC;IAEnE,gBAAgB,CAAC,EAAE,oBAAoB,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAC,CAAC;IACrE,OAAO,CAAC,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;IACjC,eAAe,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IAC/C,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAC/B,cAAc,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC;IACvD,wBAAwB,CAAC,EAAE,OAAO,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED;;GAEG;AACH,eAAO,MAAM,kBAAkB,mEAE5B,WAyGF,CAAC"}
@@ -1,13 +0,0 @@
1
- import type { FormikValues } from 'formik';
2
- import React from 'react';
3
- import { ChangeSet } from '../helpers/useChangeSets';
4
- export interface FormStationContextType {
5
- changeSets: ChangeSet<FormikValues>[];
6
- pushChangeSet: (value: never) => void;
7
- popChangeSet: () => ChangeSet<FormikValues> | undefined;
8
- clearChangeSets: () => FormikValues;
9
- lastUndoneValue: React.MutableRefObject<FormikValues>;
10
- autosave: boolean;
11
- }
12
- export declare const FormStationContext: React.Context<FormStationContextType>;
13
- //# sourceMappingURL=FormStationContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormStationContext.d.ts","sourceRoot":"","sources":["../../../../src/components/FormStation/FormStationContext/FormStationContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAC3C,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAErD,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,SAAS,CAAC,YAAY,CAAC,EAAE,CAAC;IACtC,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACtC,YAAY,EAAE,MAAM,SAAS,CAAC,YAAY,CAAC,GAAG,SAAS,CAAC;IACxD,eAAe,EAAE,MAAM,YAAY,CAAC;IACpC,eAAe,EAAE,KAAK,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC;IACtD,QAAQ,EAAE,OAAO,CAAC;CACnB;AAED,eAAO,MAAM,kBAAkB,uCAO7B,CAAC"}
@@ -1,10 +0,0 @@
1
- import React, { PropsWithChildren } from 'react';
2
- import { Data } from '../../../types';
3
- interface FormStationContextProviderProps<TValues extends Data> {
4
- autosave?: boolean;
5
- autosaveDelay?: number;
6
- currentValuesRef?: React.MutableRefObject<Partial<TValues>>;
7
- }
8
- export declare const FormStationContextProvider: <TValues extends Data>({ children, autosave, autosaveDelay, currentValuesRef, }: React.PropsWithChildren<FormStationContextProviderProps<TValues>>) => JSX.Element;
9
- export {};
10
- //# sourceMappingURL=FormStationContextProvider.d.ts.map