@orchestrator-ui/orchestrator-ui-components 0.3.1 → 0.5.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 (84) hide show
  1. package/.turbo/turbo-build.log +5 -5
  2. package/.turbo/turbo-lint.log +1 -1
  3. package/.turbo/turbo-test.log +11 -9
  4. package/CHANGELOG.md +19 -0
  5. package/dist/index.d.ts +332 -58
  6. package/dist/index.js +8487 -2415
  7. package/package.json +8 -9
  8. package/src/components/WfoBadges/WfoEngineStatusBadge/WfoEngineStatusBadge.tsx +8 -5
  9. package/src/components/WfoBadges/WfoEnvironmentBadge/WfoEnvironmentBadge.tsx +2 -1
  10. package/src/components/WfoForms/formFields/OrganisationField.tsx +11 -11
  11. package/src/components/WfoForms/formFields/SplitPrefix.tsx +11 -4
  12. package/src/components/WfoForms/formFields/SubscriptionField.tsx +1 -1
  13. package/src/components/WfoPageTemplate/WfoSidebar/WfoCopyright.tsx +22 -0
  14. package/src/components/WfoPageTemplate/WfoSidebar/WfoSidebar.tsx +10 -6
  15. package/src/components/WfoPageTemplate/WfoSidebar/styles.ts +17 -0
  16. package/src/components/WfoProcessList/WfoProcessesList.tsx +59 -25
  17. package/src/components/WfoProcessList/processListObjectMappers.ts +45 -1
  18. package/src/components/WfoSettings/WfoEngineStatusButton.tsx +11 -13
  19. package/src/components/WfoSettings/WfoFlushSettings.tsx +23 -35
  20. package/src/components/WfoSettings/WfoModifySettings.tsx +3 -16
  21. package/src/components/WfoSettings/WfoStatus.tsx +4 -9
  22. package/src/components/WfoSettings/index.ts +4 -1
  23. package/src/components/WfoSubscription/WfoSubscription.tsx +5 -2
  24. package/src/components/WfoSubscription/WfoSubscriptionDetailTree.tsx +1 -0
  25. package/src/components/WfoSubscription/WfoSubscriptionGeneral.tsx +1 -1
  26. package/src/components/WfoSubscription/subscriptionDetailTabs.tsx +36 -6
  27. package/src/components/WfoSubscriptionsList/WfoSubscriptionsList.tsx +42 -11
  28. package/src/components/WfoSubscriptionsList/index.ts +1 -1
  29. package/src/components/WfoSubscriptionsList/subscriptionListTabs.ts +1 -1
  30. package/src/components/WfoSubscriptionsList/{mapGraphQlSubscriptionsResultToSubscriptionListItems.ts → subscriptionResultMappers.ts} +6 -0
  31. package/src/components/WfoTable/WfoTableWithFilter/WfoTableWithFilter.tsx +12 -0
  32. package/src/components/WfoToastsList/WfoToastsList.tsx +11 -11
  33. package/src/components/WfoTree/WfoTreeNode.tsx +2 -0
  34. package/src/configuration/constants.ts +1 -0
  35. package/src/contexts/OrchestratorConfigContext.tsx +2 -4
  36. package/src/contexts/index.ts +0 -1
  37. package/src/graphqlQueries/index.ts +1 -1
  38. package/src/graphqlQueries/processListQuery.ts +29 -29
  39. package/src/graphqlQueries/subscriptionDetailQuery.ts +1 -1
  40. package/src/graphqlQueries/subscriptionsDropdownOptionsQuery.ts +1 -1
  41. package/src/hooks/index.ts +1 -2
  42. package/src/hooks/useCheckEngineStatus.ts +10 -9
  43. package/src/hooks/useOrchestratorConfig.ts +1 -16
  44. package/src/hooks/useQueryWithGraphql.ts +22 -0
  45. package/src/hooks/useShowToastMessage.ts +43 -0
  46. package/src/hooks/useStoredTableConfig.ts +5 -4
  47. package/src/icons/WfoCogFill.tsx +23 -25
  48. package/src/icons/WfoCubeSolid.tsx +33 -0
  49. package/src/icons/WfoPlayCircle.tsx +35 -0
  50. package/src/icons/WfoShare.tsx +35 -0
  51. package/src/icons/index.ts +3 -0
  52. package/src/index.ts +1 -0
  53. package/src/messages/en-GB.json +9 -5
  54. package/src/messages/nl-NL.json +8 -4
  55. package/src/pages/metadata/WfoProductBlocksPage.tsx +40 -6
  56. package/src/pages/metadata/WfoProductsPage.tsx +38 -9
  57. package/src/pages/metadata/WfoResourceTypesPage.tsx +36 -5
  58. package/src/pages/metadata/WfoWorkflowsPage.tsx +40 -9
  59. package/src/pages/settings/WfoSettingsPage.tsx +14 -23
  60. package/src/rtk/api.ts +40 -0
  61. package/src/rtk/endpoints/customers.ts +27 -0
  62. package/src/rtk/endpoints/index.ts +3 -0
  63. package/src/rtk/endpoints/processList.ts +89 -0
  64. package/src/rtk/endpoints/settings.ts +72 -0
  65. package/src/rtk/hooks.ts +7 -0
  66. package/src/rtk/index.ts +5 -0
  67. package/src/rtk/slices/index.ts +1 -0
  68. package/src/rtk/slices/orchestratorConfig.ts +16 -0
  69. package/src/rtk/slices/toastMessages.ts +56 -0
  70. package/src/rtk/store.ts +40 -0
  71. package/src/rtk/storeProvider.tsx +26 -0
  72. package/src/types/types.ts +33 -2
  73. package/src/utils/csvDownload.ts +83 -0
  74. package/src/utils/getDefaultTableConfig.ts +1 -3
  75. package/src/utils/getQueryVariablesForExport.spec.ts +19 -0
  76. package/src/utils/getQueryVariablesForExport.ts +11 -0
  77. package/src/utils/index.ts +1 -0
  78. package/src/utils/sortObjectKeys.spec.ts +34 -0
  79. package/src/utils/sortObjectKeys.ts +33 -0
  80. package/src/components/WfoSettings/WfoSettings.tsx +0 -40
  81. package/src/contexts/ToastContext.tsx +0 -136
  82. package/src/graphqlQueries/customersQuery.ts +0 -20
  83. package/src/hooks/useEngineStatusQuery.ts +0 -64
  84. package/src/hooks/useToastMessage.ts +0 -5
@@ -0,0 +1,34 @@
1
+ import { sortObjectKeys } from './sortObjectKeys';
2
+
3
+ describe('sortObjectKeys', () => {
4
+ it('sorts the keys of an object', () => {
5
+ const testObject = {
6
+ a: 1,
7
+ b: 2,
8
+ c: 3,
9
+ };
10
+ const sortedObject = sortObjectKeys(testObject, ['b', 'a', 'c']);
11
+
12
+ // Verifies order of keys
13
+ expect(Object.keys(sortedObject).join('-')).toEqual('b-a-c');
14
+
15
+ // Verifies values
16
+ expect(sortedObject).toEqual({ a: 1, b: 2, c: 3 });
17
+ });
18
+
19
+ it('handles missing keys in the keyOrder array', () => {
20
+ const testObject = {
21
+ a: 1,
22
+ b: 2,
23
+ c: 3,
24
+ d: 4,
25
+ };
26
+ const sortedObject = sortObjectKeys(testObject, ['d', 'a']);
27
+
28
+ // Verifies order of keys
29
+ expect(Object.keys(sortedObject).join('-')).toEqual('d-a-b-c');
30
+
31
+ // Verifies values
32
+ expect(sortedObject).toEqual({ a: 1, b: 2, c: 3, d: 4 });
33
+ });
34
+ });
@@ -0,0 +1,33 @@
1
+ // Some components in this project need the keys of an object to be in a certain order
2
+ // This function sorts the keys of an object based on an array of strings
3
+ // Keys that do not exist in the object will be ignored
4
+ export const sortObjectKeys = <T extends object>(
5
+ inputObject: T,
6
+ keyOrder: string[],
7
+ ): T => {
8
+ const allInputObjectKeys = Object.keys(inputObject) as Array<keyof T>;
9
+ allInputObjectKeys.sort((left, right) => {
10
+ const leftIndex = keyOrder.indexOf(left.toString());
11
+ const rightIndex = keyOrder.indexOf(right.toString());
12
+
13
+ if (leftIndex === -1 && rightIndex === -1) {
14
+ return 0;
15
+ }
16
+
17
+ if (leftIndex === -1) {
18
+ return 1;
19
+ }
20
+
21
+ if (rightIndex === -1) {
22
+ return -1;
23
+ }
24
+
25
+ return leftIndex - rightIndex;
26
+ });
27
+
28
+ // Using all keys from the input object means the result will contain all keys of T, meaning the type is T
29
+ return allInputObjectKeys.reduce((acc, key) => {
30
+ acc[key] = inputObject[key];
31
+ return acc;
32
+ }, {} as T);
33
+ };
@@ -1,40 +0,0 @@
1
- import React from 'react';
2
-
3
- import { EuiHorizontalRule, EuiPageHeader, EuiSpacer } from '@elastic/eui';
4
-
5
- import { EngineStatus } from '@/types';
6
-
7
- import { WfoFlushSettings } from './WfoFlushSettings';
8
- import { WfoModifySettings } from './WfoModifySettings';
9
- import { WfoStatus } from './WfoStatus';
10
-
11
- interface WfoSettingsProps {
12
- currentEngineStatus: EngineStatus | undefined;
13
- currentRunningProcesses: number | undefined;
14
- changeEngineStatus: () => void;
15
- }
16
- export const WfoSettings = ({
17
- currentEngineStatus,
18
- currentRunningProcesses,
19
- changeEngineStatus,
20
- }: WfoSettingsProps) => {
21
- return (
22
- <>
23
- <EuiSpacer />
24
-
25
- <EuiPageHeader pageTitle="Settings" />
26
- <EuiHorizontalRule />
27
- <WfoFlushSettings />
28
- <EuiSpacer />
29
- <WfoModifySettings
30
- engineStatus={currentEngineStatus}
31
- changeEngineStatus={changeEngineStatus}
32
- />
33
- <EuiSpacer />
34
- <WfoStatus
35
- engineStatus={currentEngineStatus || EngineStatus.PAUSED}
36
- runningProcesses={currentRunningProcesses}
37
- />
38
- </>
39
- );
40
- };
@@ -1,136 +0,0 @@
1
- import React, { createContext, useReducer } from 'react';
2
- import type { ReactElement, ReactNode, Reducer } from 'react';
3
-
4
- import type { Toast } from '@elastic/eui/src/components/toast/global_toast_list';
5
-
6
- export enum ToastTypes {
7
- ERROR = 'ERROR',
8
- SUCCESS = 'SUCCESS',
9
- }
10
-
11
- enum ToastActionTypes {
12
- ADD = 'ADD',
13
- REMOVE = 'REMOVE',
14
- }
15
-
16
- type ToastAddAction = {
17
- type: ToastActionTypes.ADD;
18
- payload: Toast; // From eui
19
- };
20
-
21
- type ToastRemoveAction = {
22
- type: ToastActionTypes.REMOVE;
23
- payload: {
24
- id: string;
25
- };
26
- };
27
-
28
- type ToastsState = {
29
- toasts: Toast[];
30
- };
31
-
32
- export interface ToastContextProps {
33
- addToast: (
34
- type: ToastTypes,
35
- text: ReactElement | string,
36
- title: string,
37
- ) => void;
38
- removeToast: (id: string) => void;
39
- toasts: Toast[];
40
- }
41
-
42
- export const ToastContext = createContext<ToastContextProps>({
43
- addToast: () => {},
44
- removeToast: () => {},
45
- toasts: [],
46
- });
47
-
48
- interface ToastsContextProviderProps {
49
- children: ReactNode;
50
- }
51
-
52
- const toastsReducer = (
53
- state: ToastsState,
54
- action: ToastAddAction | ToastRemoveAction,
55
- ): ToastsState => {
56
- switch (action.type) {
57
- case ToastActionTypes.ADD:
58
- return {
59
- toasts: [...state.toasts, action.payload],
60
- };
61
- case ToastActionTypes.REMOVE:
62
- const toasts = state.toasts.filter(
63
- (toast) => toast.id !== action.payload.id,
64
- );
65
- return {
66
- toasts: [...toasts],
67
- };
68
-
69
- default:
70
- throw new Error('Unhandled notification action type');
71
- }
72
- };
73
-
74
- export const ToastsContextProvider = ({
75
- children,
76
- }: ToastsContextProviderProps) => {
77
- const initialState: ToastsState = {
78
- toasts: [],
79
- };
80
-
81
- const [state, dispatch] = useReducer<
82
- Reducer<ToastsState, ToastAddAction | ToastRemoveAction>
83
- >(toastsReducer, initialState);
84
-
85
- const getTypeProps = (type: ToastTypes): Partial<Toast> => {
86
- switch (type) {
87
- case ToastTypes.ERROR:
88
- return {
89
- color: 'danger',
90
- iconType: 'warning',
91
- };
92
- case ToastTypes.SUCCESS:
93
- return {
94
- color: 'success',
95
- iconType: 'check',
96
- };
97
- }
98
- };
99
-
100
- const addToast = (
101
- type: ToastTypes,
102
- text: ReactElement | string,
103
- title: string,
104
- ) => {
105
- const typeProps = getTypeProps(type);
106
- const id = Math.floor(Math.random() * 10000000).toString();
107
- dispatch({
108
- type: ToastActionTypes.ADD,
109
- payload: {
110
- id,
111
- text,
112
- title,
113
- ...typeProps,
114
- },
115
- });
116
- };
117
-
118
- const removeToast = (id: string) => {
119
- dispatch({
120
- type: ToastActionTypes.REMOVE,
121
- payload: { id },
122
- });
123
- };
124
-
125
- return (
126
- <ToastContext.Provider
127
- value={{
128
- addToast,
129
- removeToast,
130
- toasts: state.toasts,
131
- }}
132
- >
133
- {children}
134
- </ToastContext.Provider>
135
- );
136
- };
@@ -1,20 +0,0 @@
1
- import { parse } from 'graphql';
2
- import { gql } from 'graphql-request';
3
-
4
- import { TypedDocumentNode } from '@graphql-typed-document-node/core';
5
-
6
- import { CustomersResult } from '../types';
7
-
8
- // Avoiding pagination by passing a large number to first. TODO: Fix this better
9
- export const GET_CUSTOMER_GRAPHQL_QUERY: TypedDocumentNode<CustomersResult> =
10
- parse(gql`
11
- query Customers {
12
- customers(first: 1000000, after: 0) {
13
- page {
14
- fullname
15
- identifier
16
- shortcode
17
- }
18
- }
19
- }
20
- `);
@@ -1,64 +0,0 @@
1
- import { useContext } from 'react';
2
- import { useMutation, useQueryClient } from 'react-query';
3
-
4
- import { OrchestratorConfigContext } from '@/contexts';
5
- import { EngineStatus } from '@/types';
6
-
7
- import { useQueryWithFetch } from './useQueryWithFetch';
8
- import { useSessionWithToken } from './useSessionWithToken';
9
-
10
- export interface EngineStatusReturnValue {
11
- global_lock: boolean;
12
- running_processes: number;
13
- global_status: EngineStatus;
14
- }
15
-
16
- interface EngineStatusPayload {
17
- global_lock: boolean;
18
- }
19
-
20
- export const useEngineStatusQuery = () => {
21
- const { engineStatusEndpoint } = useContext(OrchestratorConfigContext);
22
-
23
- return useQueryWithFetch<EngineStatusReturnValue, Record<string, never>>(
24
- engineStatusEndpoint,
25
- {},
26
- 'engineStatus',
27
- );
28
- };
29
-
30
- export const useEngineStatusMutation = () => {
31
- const { engineStatusEndpoint } = useContext(OrchestratorConfigContext);
32
- const queryClient = useQueryClient();
33
- const { session } = useSessionWithToken();
34
- let requestHeaders = {};
35
-
36
- if (session) {
37
- const { accessToken } = session;
38
-
39
- requestHeaders = {
40
- Authorization: `Bearer ${accessToken}`,
41
- };
42
- }
43
-
44
- const setEngineStatus = async (data: EngineStatusPayload) => {
45
- const response = await fetch(engineStatusEndpoint, {
46
- method: 'PUT',
47
- body: JSON.stringify(data),
48
- headers: {
49
- 'Content-Type': 'application/json',
50
- ...requestHeaders,
51
- },
52
- });
53
- return (await response.json()) as EngineStatusReturnValue;
54
- };
55
-
56
- return useMutation('engineStatus', setEngineStatus, {
57
- onMutate: () => {
58
- queryClient.setQueryData(['engineStatus'], null); // Set loading state of the button
59
- },
60
- onSuccess: (data: EngineStatusReturnValue) => {
61
- queryClient.setQueryData(['engineStatus'], data); // Set global status
62
- },
63
- });
64
- };
@@ -1,5 +0,0 @@
1
- import { useContext } from 'react';
2
-
3
- import { ToastContext } from '../contexts/ToastContext';
4
-
5
- export const useToastMessage = () => useContext(ToastContext);