@axinom/mosaic-ui 0.33.0-rc.9 → 0.34.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 (89) hide show
  1. package/dist/components/DynamicDataList/DynamicDataList.d.ts.map +1 -1
  2. package/dist/components/DynamicDataList/DynamicListRow/DynamicListRow.d.ts +3 -1
  3. package/dist/components/DynamicDataList/DynamicListRow/DynamicListRow.d.ts.map +1 -1
  4. package/dist/components/FormElements/CustomTags/CustomTags.d.ts.map +1 -1
  5. package/dist/components/FormElements/FileUploadControl/FileUploadControl.d.ts.map +1 -1
  6. package/dist/components/FormElements/Radio/Radio.d.ts.map +1 -1
  7. package/dist/components/FormElements/Tags/Tags.d.ts.map +1 -1
  8. package/dist/components/FormElements/formStoryHelper.d.ts.map +1 -1
  9. package/dist/components/FormStation/FormStation.d.ts.map +1 -1
  10. package/dist/components/InfoPanel/InfoImage/InfoImage.d.ts.map +1 -1
  11. package/dist/components/List/List.d.ts.map +1 -1
  12. package/dist/components/Loaders/ImageLoader/ImageLoader.d.ts +2 -0
  13. package/dist/components/Loaders/ImageLoader/ImageLoader.d.ts.map +1 -1
  14. package/dist/components/index.d.ts +1 -1
  15. package/dist/components/index.d.ts.map +1 -1
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.es.js +3 -3
  19. package/dist/index.es.js.map +1 -1
  20. package/dist/index.js +3 -3
  21. package/dist/index.js.map +1 -1
  22. package/dist/initialize.d.ts +7 -4
  23. package/dist/initialize.d.ts.map +1 -1
  24. package/dist/utils/ErrorMapper/ApolloClient/ApolloErrorMapper.d.ts +9 -0
  25. package/dist/utils/ErrorMapper/ApolloClient/ApolloErrorMapper.d.ts.map +1 -0
  26. package/dist/utils/ErrorMapper/ErrorMapper.d.ts +15 -0
  27. package/dist/utils/ErrorMapper/ErrorMapper.d.ts.map +1 -0
  28. package/dist/utils/ErrorMapper/ErrorMapper.type.d.ts +11 -0
  29. package/dist/utils/ErrorMapper/ErrorMapper.type.d.ts.map +1 -0
  30. package/dist/utils/ErrorMapper/index.d.ts +4 -0
  31. package/dist/utils/ErrorMapper/index.d.ts.map +1 -0
  32. package/dist/utils/ErrorTypeToStationError.d.ts +1 -1
  33. package/dist/utils/ErrorTypeToStationError.d.ts.map +1 -1
  34. package/package.json +3 -3
  35. package/src/components/Accordion/Accordion.scss +1 -1
  36. package/src/components/Accordion/AccordionItem/AccordionItem.scss +1 -1
  37. package/src/components/Actions/Action/Action.scss +0 -2
  38. package/src/components/Buttons/Button/Button.scss +66 -20
  39. package/src/components/Buttons/CompositeButton/CompositeButton.scss +50 -18
  40. package/src/components/Buttons/TextButton/TextButton.scss +45 -16
  41. package/src/components/DateTime/DatePicker/DatePicker.scss +15 -6
  42. package/src/components/DateTime/DateTimePicker.scss +6 -2
  43. package/src/components/DynamicDataList/DynamicDataList.tsx +1 -0
  44. package/src/components/DynamicDataList/DynamicListDataEntry/DynamicListDataEntry.scss +15 -5
  45. package/src/components/DynamicDataList/DynamicListDataEntry/Renderers/createInputRenderer/createInputRenderer.tsx +1 -1
  46. package/src/components/DynamicDataList/DynamicListDataEntry/Renderers/createSelectRenderer/createSelectRenderer.scss +36 -12
  47. package/src/components/DynamicDataList/DynamicListDataEntry/Renderers/createSelectRenderer/createSelectRenderer.tsx +2 -2
  48. package/src/components/DynamicDataList/DynamicListRow/DynamicListRow.scss +26 -0
  49. package/src/components/DynamicDataList/DynamicListRow/DynamicListRow.tsx +7 -1
  50. package/src/components/Filters/Filter/Filter.scss +8 -2
  51. package/src/components/Filters/SelectionTypes/DateTimeFilter/DateTimeFilter.scss +4 -1
  52. package/src/components/FormElements/Checkbox/Checkbox.scss +20 -0
  53. package/src/components/FormElements/CustomTags/CustomTags.scss +24 -0
  54. package/src/components/FormElements/CustomTags/CustomTags.tsx +8 -2
  55. package/src/components/FormElements/DateTimeField/DateTimeText.spec.tsx +1 -1
  56. package/src/components/FormElements/DateTimeField/DateTimeText.tsx +1 -1
  57. package/src/components/FormElements/FileUploadControl/FileUploadControl.scss +4 -2
  58. package/src/components/FormElements/FileUploadControl/FileUploadControl.tsx +12 -3
  59. package/src/components/FormElements/Radio/Radio.scss +18 -3
  60. package/src/components/FormElements/Radio/Radio.tsx +2 -2
  61. package/src/components/FormElements/Select/Select.scss +10 -0
  62. package/src/components/FormElements/SingleLineText/SingleLineText.spec.tsx +2 -2
  63. package/src/components/FormElements/SingleLineText/SingleLineText.tsx +1 -1
  64. package/src/components/FormElements/Tags/Tags.scss +14 -0
  65. package/src/components/FormElements/Tags/Tags.tsx +5 -1
  66. package/src/components/FormElements/TextArea/TextArea.spec.tsx +2 -2
  67. package/src/components/FormElements/TextArea/TextArea.tsx +1 -1
  68. package/src/components/FormElements/formStoryHelper.tsx +163 -97
  69. package/src/components/FormStation/FormStation.spec.tsx +13 -3
  70. package/src/components/FormStation/FormStation.tsx +13 -3
  71. package/src/components/InfoPanel/InfoImage/InfoImage.scss +8 -3
  72. package/src/components/InfoPanel/InfoImage/InfoImage.tsx +1 -0
  73. package/src/components/List/List.tsx +3 -1
  74. package/src/components/List/ListCheckBox/ListCheckBox.scss +8 -3
  75. package/src/components/List/ListRow/ListRow.scss +0 -4
  76. package/src/components/Loaders/ImageLoader/ImageLoader.tsx +5 -0
  77. package/src/components/PageHeader/PageHeaderAction/PageHeaderAction.scss +0 -1
  78. package/src/components/index.ts +1 -1
  79. package/src/index.ts +1 -0
  80. package/src/initialize.ts +15 -12
  81. package/src/styles/variables.scss +32 -2
  82. package/src/utils/ErrorMapper/ApolloClient/ApolloErrorMapper.spec.ts +32 -0
  83. package/src/utils/ErrorMapper/ApolloClient/ApolloErrorMapper.tsx +33 -0
  84. package/src/utils/ErrorMapper/ErrorMapper.spec.ts +67 -0
  85. package/src/utils/ErrorMapper/ErrorMapper.ts +31 -0
  86. package/src/utils/ErrorMapper/ErrorMapper.type.ts +11 -0
  87. package/src/utils/ErrorMapper/index.ts +3 -0
  88. package/src/utils/ErrorTypeToStationError.spec.tsx +12 -0
  89. package/src/utils/ErrorTypeToStationError.tsx +5 -1
@@ -0,0 +1,32 @@
1
+ import { ErrorType } from '../../../components';
2
+ import { ApolloErrorMapper } from './ApolloErrorMapper';
3
+
4
+ describe('ApolloErrorMapper', () => {
5
+ const mockError: ErrorType = {
6
+ name: 'ApolloError',
7
+ networkError: { message: 'Network connection lost' },
8
+ };
9
+
10
+ it('should map an Apollo error with a network error', () => {
11
+ const mappedError = ApolloErrorMapper(mockError);
12
+ expect(mappedError).toEqual({
13
+ title: 'A network error occurred',
14
+ body: expect.any(Object), // You can modify the expectation here based on your needs
15
+ });
16
+ });
17
+
18
+ it('should not map an error if already mapped by a previous error mapper', () => {
19
+ const previousMappedError: ErrorType = {
20
+ title: 'Previous Error',
21
+ body: 'Previous error message',
22
+ };
23
+ const mappedError = ApolloErrorMapper(mockError, previousMappedError);
24
+ expect(mappedError).toBeUndefined();
25
+ });
26
+
27
+ it('should return undefined if it does not match the conditions', () => {
28
+ const error: ErrorType = new Error('Some other error');
29
+ const mappedError = ApolloErrorMapper(error);
30
+ expect(mappedError).toBeUndefined();
31
+ });
32
+ });
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import { ErrorMapper } from '../ErrorMapper.type';
3
+
4
+ /**
5
+ * An error mapper that maps errors from the Apollo Client to more user friendly errors.
6
+ * @param error The error to map
7
+ * @param mappedError The error that was mapped by a previous error mapper
8
+ * @returns The mapped error or undefined if the error could not be mapped
9
+ */
10
+ export const ApolloErrorMapper: ErrorMapper = (error, mappedError) => {
11
+ if (!mappedError) {
12
+ const apolloError = error as {
13
+ networkError?: { message: string };
14
+ name?: string;
15
+ };
16
+
17
+ if (apolloError.name === 'ApolloError' && apolloError.networkError) {
18
+ return {
19
+ title: 'A network error occurred',
20
+ body: (
21
+ <>
22
+ <p>Please check your internet connection and try again.</p>
23
+ <>
24
+ <i>Original Error:</i>
25
+ <pre>{JSON.stringify(error, undefined, 2)}</pre>
26
+ </>
27
+ </>
28
+ ),
29
+ };
30
+ }
31
+ return undefined;
32
+ }
33
+ };
@@ -0,0 +1,67 @@
1
+ import { ErrorType } from '../../components/models';
2
+ import { mapError, setErrorMappers } from './ErrorMapper';
3
+ import { ErrorMapper } from './ErrorMapper.type';
4
+
5
+ describe('mapError', () => {
6
+ const errorMapper1: ErrorMapper = (error) => {
7
+ if (typeof error === 'string') {
8
+ return { title: 'String Error', body: error };
9
+ }
10
+ return undefined;
11
+ };
12
+
13
+ const errorMapper2: ErrorMapper = (error) => {
14
+ if (typeof error === 'number') {
15
+ return { title: 'Number Error', body: error.toString() };
16
+ }
17
+ return undefined;
18
+ };
19
+
20
+ const errorMapper3: ErrorMapper = (error) => {
21
+ if (error instanceof Error) {
22
+ return { title: 'Custom Error', body: error.message };
23
+ }
24
+ return undefined;
25
+ };
26
+
27
+ beforeEach(() => {
28
+ setErrorMappers([errorMapper1, errorMapper2, errorMapper3]);
29
+ });
30
+
31
+ afterEach(() => {
32
+ setErrorMappers([]);
33
+ });
34
+
35
+ it('should map a string error', () => {
36
+ const error: ErrorType = 'Something went wrong';
37
+ const mappedError = mapError(error);
38
+ expect(mappedError).toEqual({
39
+ title: 'String Error',
40
+ body: 'Something went wrong',
41
+ });
42
+ });
43
+
44
+ it('should map a number error', () => {
45
+ const error: ErrorType = 42;
46
+ const mappedError = mapError(error);
47
+ expect(mappedError).toEqual({ title: 'Number Error', body: '42' });
48
+ });
49
+
50
+ it('should map a custom error', () => {
51
+ const error: ErrorType = new Error('Custom error message');
52
+ const mappedError = mapError(error);
53
+ expect(mappedError).toEqual({
54
+ title: 'Custom Error',
55
+ body: 'Custom error message',
56
+ });
57
+ });
58
+
59
+ it('should return the original error if no mapper can map it', () => {
60
+ const error: ErrorType = {
61
+ title: 'Unknown Error',
62
+ body: 'Something unexpected happened',
63
+ };
64
+ const mappedError = mapError(error);
65
+ expect(mappedError).toBe(error);
66
+ });
67
+ });
@@ -0,0 +1,31 @@
1
+ import { ApolloErrorMapper } from './ApolloClient/ApolloErrorMapper';
2
+ import { ErrorMapper } from './ErrorMapper.type';
3
+
4
+ let ErrorMappers: ErrorMapper[] = [ApolloErrorMapper];
5
+
6
+ /**
7
+ * Sets the error mappers to use for mapping errors.
8
+ * By default the `ApolloErrorMapper` is registered.
9
+ * @param mappers an array of error mappers that should be used
10
+ */
11
+ export const setErrorMappers = (mappers: ErrorMapper[]): void => {
12
+ ErrorMappers = mappers;
13
+ };
14
+
15
+ /**
16
+ * Uses the currently registered error mappers to map the given error.
17
+ * To register error mappers use the `setErrorMappers` function.
18
+ * @param error the error to map
19
+ * @returns the mapped error or the original error if no mapper was able to map the error
20
+ */
21
+ export const mapError: ErrorMapper = (error) => {
22
+ const originalError = error;
23
+ let mappedError = undefined;
24
+ for (const mapper of ErrorMappers) {
25
+ const mappingResult = mapper(originalError, mappedError);
26
+ if (mappingResult !== undefined && mappingResult !== originalError) {
27
+ mappedError = mappingResult;
28
+ }
29
+ }
30
+ return mappedError ?? originalError;
31
+ };
@@ -0,0 +1,11 @@
1
+ import { ErrorType } from '../../components/models';
2
+
3
+ export interface ErrorMapper {
4
+ /**
5
+ * Maps the given error to a new error.
6
+ * @param error the error to map
7
+ * @param currentlyMappedError the error that was mapped by a previous error mapper
8
+ * @returns the mapped error or undefined if the error could not be mapped
9
+ */
10
+ (error: ErrorType, currentlyMappedError?: ErrorType): ErrorType | undefined;
11
+ }
@@ -0,0 +1,3 @@
1
+ export * from './ApolloClient/ApolloErrorMapper';
2
+ export * from './ErrorMapper';
3
+ export * from './ErrorMapper.type';
@@ -55,4 +55,16 @@ describe('ErrorTypeToStationError', () => {
55
55
  const result = ErrorTypeToStationError(error, 'custom title');
56
56
  expect(result.title).toBe('custom title');
57
57
  });
58
+
59
+ it('uses the apollo mapper by default', () => {
60
+ const error = {
61
+ name: 'ApolloError',
62
+ networkError: { message: 'test error' },
63
+ };
64
+ const result = ErrorTypeToStationError(error);
65
+ expect(result.title).toBe('A network error occurred');
66
+ const wrapper = render(<>{result.body}</>);
67
+
68
+ expect(wrapper.toString()).toContain('test error');
69
+ });
58
70
  });
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
2
  import { ErrorType, StationError } from '../components/models';
3
+ import { mapError } from './ErrorMapper/ErrorMapper';
3
4
 
4
5
  /**
5
6
  * Converts an `ErrorType` object into a station error.
@@ -9,10 +10,13 @@ import { ErrorType, StationError } from '../components/models';
9
10
  * @returns A station error object
10
11
  */
11
12
  export const ErrorTypeToStationError = (
12
- error?: ErrorType,
13
+ originalError?: ErrorType,
13
14
  defaultTitle = 'An error occurred.',
14
15
  defaultBody?: string,
15
16
  ): StationError => {
17
+ const error = mapError(
18
+ originalError ?? { title: defaultTitle, body: defaultBody },
19
+ );
16
20
  let stationError: StationError;
17
21
  if (isStationError(error)) {
18
22
  // we already got a station error