@axinom/mosaic-ui 0.39.1-feat-gs.3 → 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,169 +0,0 @@
1
- import { FormikHelpers } from 'formik';
2
- import {
3
- Dispatch,
4
- SetStateAction,
5
- useCallback,
6
- useEffect,
7
- useRef,
8
- useState,
9
- } from 'react';
10
- import { SaveIndicatorType, setSaveIndicator } from '../../../initialize';
11
- import { Data } from '../../../types';
12
- import { ErrorTypeToStationError } from '../../../utils/ErrorTypeToStationError';
13
- import { getFormDiff } from '../../Utils';
14
- import type { ErrorType } from '../../models';
15
- import type {
16
- InitialFormData,
17
- SaveDataFunction,
18
- StationErrorStateType,
19
- } from '../FormStation.models';
20
- import { mergeData } from './mergeData';
21
-
22
- export type FormStationDataProvider = <TValues extends Data, TSubmitResponse>(
23
- initialData: InitialFormData<TValues>,
24
- saveData: SaveDataFunction<TValues, TSubmitResponse>,
25
- currentDataRef: React.MutableRefObject<TValues>,
26
- ) => {
27
- onSubmit: (
28
- values: TValues,
29
- formikHelpers: FormikHelpers<TValues>,
30
- initialFormData?: InitialFormData<TValues>,
31
- ) => Promise<TSubmitResponse> | void;
32
- stationError?: StationErrorStateType;
33
- setStationError: Dispatch<SetStateAction<StationErrorStateType | undefined>>;
34
- isFormSubmitting: boolean;
35
- lastSubmittedResponse: React.MutableRefObject<TSubmitResponse | undefined>;
36
- initialValues: TValues | null | undefined;
37
- };
38
-
39
- export const useDataProvider: FormStationDataProvider = <
40
- TValues extends Data,
41
- TSubmitResponse,
42
- >(
43
- initialData: InitialFormData<TValues>,
44
- saveData: SaveDataFunction<TValues, TSubmitResponse>,
45
- currentDataRef: React.MutableRefObject<TValues>,
46
- ) => {
47
- const [stationError, setStationError] = useState<StationErrorStateType>();
48
- const [isFormSubmitting, setIsFormSubmitting] = useState<boolean>(false);
49
- const lastSubmittedResponse = useRef<TSubmitResponse>();
50
- const [initialValues, setInitialValues] = useState(
51
- initialData.data ?? ({} as TValues),
52
- );
53
-
54
- useEffect(() => {
55
- if (
56
- !initialData.loading &&
57
- initialData.data !== null &&
58
- initialData.data !== undefined
59
- ) {
60
- // Form Station tends to re-render when the initialData prop changes even though there are no changes to the data.
61
- // This check is there to prevent these unnecessary re-renders.
62
- const diff = getFormDiff(initialData.data as TValues, initialValues);
63
- if (diff && Object.keys(diff).length > 0) {
64
- setInitialValues(initialData.data as TValues);
65
- }
66
- }
67
- // eslint-disable-next-line react-hooks/exhaustive-deps
68
- }, [initialData.data]);
69
-
70
- useEffect(() => {
71
- if (
72
- initialData.error ||
73
- (initialData.data === null && !initialData.loading) ||
74
- initialData.entityNotFound
75
- ) {
76
- setStationError({
77
- ...ErrorTypeToStationError(
78
- initialData.error,
79
- 'An error occurred when trying to load data.',
80
- 'Entity not found',
81
- ),
82
- type: 'loading',
83
- });
84
- } else {
85
- if (stationError?.type === 'loading') {
86
- // Only clear the error if it is a loading error, which now seems to be cleared.
87
- setStationError(undefined);
88
- }
89
- }
90
- }, [
91
- initialData.loading,
92
- initialData.error,
93
- initialData.entityNotFound,
94
- initialData.data,
95
- stationError?.type,
96
- ]);
97
-
98
- const onSubmit = useCallback(
99
- async (
100
- values: TValues,
101
- formikHelpers: FormikHelpers<TValues>,
102
- initialFormData: InitialFormData<TValues> = initialData,
103
- ) => {
104
- if (isFormSubmitting) {
105
- // TODO: Handle this case. Throw an error maybe?
106
- return undefined as TSubmitResponse;
107
- }
108
-
109
- try {
110
- setIsFormSubmitting(true);
111
- setSaveIndicator(SaveIndicatorType.Saving);
112
- setStationError(undefined);
113
- if (!initialFormData.loading && saveData) {
114
- const result = await saveData(
115
- values,
116
- { ...initialFormData, data: initialValues },
117
- formikHelpers,
118
- );
119
-
120
- if (result) {
121
- lastSubmittedResponse.current = result;
122
- }
123
-
124
- const {
125
- newCurrentValues,
126
- newInitialValues,
127
- shouldUpdateCurrentValues,
128
- } = mergeData<TValues>(values, currentDataRef.current, result ?? {});
129
-
130
- formikHelpers.resetForm({ values: newInitialValues });
131
- setInitialValues(newInitialValues);
132
-
133
- if (shouldUpdateCurrentValues) {
134
- formikHelpers.setValues(newCurrentValues);
135
- }
136
-
137
- return lastSubmittedResponse.current as TSubmitResponse;
138
- }
139
- } catch (error) {
140
- setStationError(
141
- ErrorTypeToStationError(
142
- error as ErrorType,
143
- 'An error occurred when trying to save data.',
144
- ),
145
- );
146
-
147
- // We still throw the error, to make sure that navigation or action execution
148
- // will not continue after a failed save.
149
- throw error;
150
- } finally {
151
- formikHelpers.setSubmitting(false);
152
- setIsFormSubmitting(false);
153
- setSaveIndicator(SaveIndicatorType.Inactive);
154
- }
155
-
156
- return undefined as TSubmitResponse;
157
- },
158
- [currentDataRef, initialData, initialValues, isFormSubmitting, saveData],
159
- );
160
-
161
- return {
162
- onSubmit,
163
- stationError,
164
- setStationError,
165
- isFormSubmitting,
166
- lastSubmittedResponse,
167
- initialValues,
168
- };
169
- };
@@ -1,22 +0,0 @@
1
- import { FormikContextType, useFormikContext } from 'formik';
2
- import { useEffect } from 'react';
3
- import { useDebounce } from '../../../hooks';
4
-
5
- export const useDebouncedFormikValues = <TValues>(
6
- autosaveDelay?: number,
7
- ): {
8
- debouncedValues: TValues;
9
- } & FormikContextType<TValues> => {
10
- const formikContext = useFormikContext<TValues>();
11
-
12
- const [debouncedValues, setValues] = useDebounce(
13
- formikContext.initialValues,
14
- autosaveDelay ?? 500,
15
- );
16
-
17
- useEffect(() => {
18
- setValues(formikContext.values);
19
- }, [setValues, formikContext.values]);
20
-
21
- return { debouncedValues, ...formikContext };
22
- };
@@ -1,43 +0,0 @@
1
- import { FormikValues, useFormikContext } from 'formik';
2
- import React, { useCallback } from 'react';
3
- import { FormStationContext } from '../FormStationContext/FormStationContext';
4
-
5
- export const useUndo = (): {
6
- undoOnce: () => void;
7
- undoAll: () => void;
8
- showUndo: boolean;
9
- } => {
10
- const {
11
- changeSets,
12
- popChangeSet,
13
- clearChangeSets,
14
- lastUndoneValue,
15
- autosave,
16
- } = React.useContext(FormStationContext);
17
- const { values, setValues, submitForm } = useFormikContext<FormikValues>();
18
-
19
- const undoAll = useCallback((): void => {
20
- lastUndoneValue.current = clearChangeSets();
21
- setValues(lastUndoneValue.current);
22
- if (autosave) {
23
- submitForm();
24
- }
25
- }, [autosave, clearChangeSets, lastUndoneValue, setValues, submitForm]);
26
-
27
- const undoOnce = useCallback((): void => {
28
- const lastChangeSet = popChangeSet();
29
-
30
- lastUndoneValue.current = {
31
- ...values,
32
- ...lastChangeSet?.prev,
33
- };
34
-
35
- setValues(lastUndoneValue.current);
36
-
37
- if (autosave) {
38
- submitForm();
39
- }
40
- }, [autosave, lastUndoneValue, popChangeSet, setValues, submitForm, values]);
41
-
42
- return { undoOnce, undoAll, showUndo: changeSets.length > 0 };
43
- };