@genesislcap/blank-app-seed 5.4.0-prerelease.24 → 5.4.0-prerelease.26

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.
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/blank-app-seed-config",
3
3
  "description": "Genesis Blank App Seed Configuration",
4
- "version": "5.4.0-prerelease.24",
4
+ "version": "5.4.0-prerelease.26",
5
5
  "license": "Apache-2.0",
6
6
  "scripts": {
7
7
  "lint": "eslint .",
@@ -0,0 +1,40 @@
1
+ import { type CustomAction, CrudMenuPosition, UiSchema } from '@genesislcap/foundation-entity-management';
2
+
3
+ {{#each tile.config.customEvents}}
4
+ {{#if this.hasForm}}
5
+ export const {{camelCase this.name}}FormSchema: UiSchema = {{{this.uischema}}};
6
+ {{/if}}
7
+ {{/each}}
8
+
9
+ export const customActions: CustomAction[] = [
10
+ {{#each tile.config.customEvents}}
11
+ {
12
+ name: '{{this.name}}',
13
+ action: {
14
+ type: 'event',
15
+ event: 'EVENT_{{this.baseEvent}}',
16
+ hasForm: {{this.hasForm}},
17
+ {{#if this.hasForm}}
18
+ uiSchema: {{camelCase this.name}}FormSchema,
19
+ {{/if}}
20
+ defaultValues: {{{this.defaultValues}}},
21
+ },
22
+ {{#if this.position}}
23
+ position: CrudMenuPosition.{{{pascalCase this.position}}},
24
+ {{/if}}
25
+ {{#if this.icon}}
26
+ icon: '{{this.icon}}',
27
+ {{/if}}
28
+ {{#if this.tooltip}}
29
+ tooltip: '{{this.tooltip}}',
30
+ {{/if}}
31
+ {{#if this.confirmSubmit}}
32
+ confirmSubmit: {
33
+ state: '{{this.confirmSubmit.state}}',
34
+ message: '{{this.confirmSubmit.message}}'
35
+ },
36
+ {{/if}}
37
+ requiresSelection: true,
38
+ },
39
+ {{/each}}
40
+ ];
@@ -4,9 +4,7 @@ import { getUser } from '@genesislcap/foundation-user';
4
4
  import { ErrorMessageComponent } from '../../../components/error-message/error-message.component';
5
5
  import { getViewUpdateRightComponent } from '../../../utils';
6
6
  {{#if tile.config.customEvents}}
7
- import { getConnect } from '@genesislcap/foundation-comms';
8
- import type { ActionRendererParams } from '@genesislcap/rapid-grid-pro';
9
- import { RapidAgActionRenderer } from '@genesislcap/rapid-grid-pro';
7
+ import { customActions as emCustomActions } from './{{kebabCase tile.title}}.events.config';
10
8
  {{/if}}
11
9
  {{#if tile.config.gridOptions}}
12
10
  import { GridOptionsConfig } from "@genesislcap/rapid-grid-pro";
@@ -56,33 +54,6 @@ export class {{pascalCase tile.componentName}} {
56
54
  reqrep = { pollingInterval: 5000, requestAutoSetup: false };{{/if}}{{#if tile.config.columns}}
57
55
  columnDefs = [
58
56
  ...columnDefs,
59
- {{#if tile.config.customEvents}}
60
- /**
61
- * TODO: Update the action button's icon under `contentTemplate` below.
62
- * More information about rapid-icon can be found at: https://docs.genesis.global/docs/develop/client-capabilities/presentation/client-presentation-icon/
63
- **/
64
- {{#each tile.config.customEvents}}
65
- {
66
- field: '',
67
- headerName: '',
68
- minWidth: 50,
69
- maxWidth: 50,
70
- pinned: 'right',
71
- cellRenderer: RapidAgActionRenderer,
72
- cellRendererParams: <ActionRendererParams>{
73
- actionClick: async (rowData) => {
74
- const { ROW_REF, ...DETAILS } = rowData;
75
- const response = await getConnect().commitEvent("EVENT_{{this}}", {
76
- DETAILS,
77
- });
78
- },
79
- contentTemplate: `
80
- <rapid-icon name="cog"></rapid-icon>
81
- `,
82
- },
83
- },
84
- {{/each}}
85
- {{/if}}
86
57
  ];{{/if}}{{#if tile.config.type}}
87
58
  chartConfig = { {{#ifEquals tile.config.type 'pie'}}
88
59
  "radius": 0.75,
@@ -90,6 +61,6 @@ export class {{pascalCase tile.componentName}} {
90
61
  "colorField": "groupBy",{{else}}
91
62
  "xField": "groupBy",
92
63
  "yField": "value",{{/ifEquals}}
93
- };{{/if}}
94
-
64
+ };{{/if}}{{#if tile.config.customEvents}}
65
+ customActions = emCustomActions;{{/if}}
95
66
  }
@@ -48,6 +48,9 @@
48
48
  {{#if config.enableSearchBar}}
49
49
  enable-search-bar
50
50
  {{/if}}
51
+ {{#if config.customEvents}}
52
+ [customActions]="customActions"
53
+ {{/if}}
51
54
  ></entity-management>
52
55
  </ng-container>{{#if config.permissions.viewRight}}
53
56
 
@@ -1,5 +1,4 @@
1
- import { CustomEventHandler } from "../../../utils/customEvents";
2
- import { UiSchema } from '@genesislcap/foundation-forms';
1
+ import { type CustomAction, CrudMenuPosition, UiSchema } from '@genesislcap/foundation-entity-management';
3
2
 
4
3
  {{#each tile.config.customEvents}}
5
4
  {{#if this.hasForm}}
@@ -7,27 +6,35 @@ export const {{camelCase this.name}}FormSchema: UiSchema = {{{this.uischema}}};
7
6
  {{/if}}
8
7
  {{/each}}
9
8
 
10
- export const customEventFormSchemas = {
11
- {{#each tile.config.customEvents}}
12
- {{#if this.hasForm}}
13
- '{{this.name}}': {{camelCase this.name}}FormSchema,
14
- {{/if}}
15
- {{/each}}
16
- };
17
-
18
- export const customEvents: CustomEventHandler[] = [
9
+ export const customActions: CustomAction[] = [
19
10
  {{#each tile.config.customEvents}}
20
11
  {
21
- baseEvent: '{{this.baseEvent}}',
22
12
  name: '{{this.name}}',
23
- hasForm: {{this.hasForm}},
13
+ action: {
14
+ type: 'event',
15
+ event: 'EVENT_{{this.baseEvent}}',
16
+ hasForm: {{this.hasForm}},
17
+ {{#if this.hasForm}}
18
+ uiSchema: {{camelCase this.name}}FormSchema,
19
+ {{/if}}
20
+ defaultValues: {{{this.defaultValues}}},
21
+ },
22
+ {{#if this.position}}
23
+ position: CrudMenuPosition.{{{pascalCase this.position}}},
24
+ {{/if}}
25
+ {{#if this.icon}}
26
+ icon: '{{this.icon}}',
27
+ {{/if}}
28
+ {{#if this.tooltip}}
29
+ tooltip: '{{this.tooltip}}',
30
+ {{/if}}
24
31
  {{#if this.confirmSubmit}}
25
32
  confirmSubmit: {
26
33
  state: '{{this.confirmSubmit.state}}',
27
34
  message: '{{this.confirmSubmit.message}}'
28
35
  },
29
36
  {{/if}}
30
- defaultValues: {{{this.defaultValues}}},
37
+ requiresSelection: true,
31
38
  },
32
39
  {{/each}}
33
40
  ];
@@ -1,9 +1,6 @@
1
1
  {{#if tile.config.permissions.viewRight~}}
2
2
  import { getUser } from '@genesislcap/foundation-user';
3
- {{#if tile.config.customEvents}}
4
- import { customEvent } from '@genesislcap/foundation-events';
5
- {{/if}}
6
- import { getViewUpdateRightComponent{{#if tile.config.customEvents}}, submitFailureNotification{{/if}} } from '../../../utils';
3
+ import { getViewUpdateRightComponent } from '../../../utils';
7
4
  import ErrorMessage from '../../../components/ErrorMessage/ErrorMessage';
8
5
  {{else if tile.config.permissions.updateRight~}}
9
6
  import { getUser } from '@genesislcap/foundation-user';
@@ -14,14 +11,7 @@ import { getViewUpdateRightComponent{{#if tile.config.customEvents}}, submitFail
14
11
  import ErrorMessage from '../../../components/ErrorMessage/ErrorMessage';
15
12
  {{/if}}
16
13
  {{#if tile.config.customEvents}}
17
- import { useState, useRef, useEffect } from 'react';
18
- import { createPortal } from 'react-dom';
19
- import { getConnect } from '@genesislcap/foundation-comms';
20
- import type { ActionRendererParams } from '@genesislcap/rapid-grid-pro';
21
- import { RapidAgActionRenderer } from '@genesislcap/rapid-grid-pro';
22
- import { UiSchema } from '@genesislcap/foundation-forms';
23
- import { customEvents, customEventFormSchemas } from './{{pascalCase tile.title}}EventsConfig';
24
- import { useCustomEvent, type CustomEventState } from '../../../utils/customEvents';
14
+ import { customActions } from './{{pascalCase tile.title}}EventsConfig';
25
15
  {{/if}}
26
16
  {{#if tile.config.createFormUiSchema~}}
27
17
  import { createFormSchema as createFormSchemaTile } from './{{pascalCase tile.title}}CreateFormSchema';
@@ -66,48 +56,7 @@ export const {{pascalCase tile.componentName}}: React.FC = () => {
66
56
  const updateFormSchema: typeof updateFormSchemaTile = updateFormSchemaTile;
67
57
  {{/if}}
68
58
  {{#if tile.config.columns~}}
69
- const columnDefs: typeof columnDefsTile = [
70
- ...columnDefsTile,
71
- {{#if tile.config.customEvents}}
72
- /**
73
- * TODO: Update the action button's icon under `contentTemplate` below.
74
- * More information about rapid-icon can be found at: https://docs.genesis.global/docs/develop/client-capabilities/presentation/client-presentation-icon/
75
- **/
76
- {{#each tile.config.customEvents}}
77
- {
78
- headerName: '',
79
- minWidth: 50,
80
- maxWidth: 50,
81
- headerTooltip: '{{this.tooltip}}',
82
- pinned: 'right',
83
- suppressCellFlash: true,
84
- cellRenderer: RapidAgActionRenderer,
85
- cellRendererParams: {
86
- actionClick: async (rowData) => {
87
- setIsModalVisible(false);
88
-
89
- const customEvent = customEvents.find(e => e.name === '{{this.name}}');
90
- if (customEvent) {
91
- const handleCustomEvent = useCustomEvent(
92
- customEvent,
93
- rowData,
94
- setCustomEventFormData,
95
- setActiveCustomEvent,
96
- setResourceName,
97
- setUiSchema,
98
- customEventFormSchemas
99
- );
100
- await handleCustomEvent();
101
- }
102
- },
103
- contentTemplate: `
104
- <rapid-icon name="{{this.icon}}" title="{{this.name}}"></rapid-icon>
105
- `,
106
- } as ActionRendererParams,
107
- },
108
- {{/each}}
109
- {{/if}}
110
- ];
59
+ const columnDefs: typeof columnDefsTile = [...columnDefsTile];
111
60
  {{/if}}
112
61
  {{#if tile.config.gridOptions~}}
113
62
  const deferredGridOptions: { onRowClicked: GridOptionsConfig.onRowClicked } = { onRowClicked: gridOptionsTile?.onRowClicked }
@@ -137,44 +86,6 @@ export const {{pascalCase tile.componentName}}: React.FC = () => {
137
86
  };
138
87
  {{/if}}
139
88
 
140
- {{#if tile.config.customEvents}}
141
- const [activeCustomEvent, setActiveCustomEvent] = useState<CustomEventState | null>(null);
142
- const [customEventFormData, setCustomEventFormData] = useState<Record<string, any>>({});
143
- const [resourceName, setResourceName] = useState<string>('');
144
- const [uiSchema, setUiSchema] = useState<UiSchema | null>(null);
145
- const [isModalVisible, setIsModalVisible] = useState<boolean>(false);
146
-
147
- function confirmationMessage() {
148
- if (!activeCustomEvent) return null;
149
- const event = customEvents.find(e => e.name === activeCustomEvent.name);
150
- return event?.confirmSubmit?.state === 'enabled' ? event.confirmSubmit.message : null;
151
- }
152
-
153
- useEffect(() => {
154
- if (activeCustomEvent) {
155
- setIsModalVisible(true);
156
- }
157
- }, [activeCustomEvent]);
158
-
159
- const renderFormModal = () => {
160
- if (!activeCustomEvent) return null;
161
-
162
- return createPortal(
163
- <smart-form-modal
164
- entityLabel="{{ tile.config.entityName }}"
165
- modal-position="{{ tile.config.modalPosition }}"
166
- modalFormType={isModalVisible && 'update'}
167
- editModalVisible={isModalVisible}
168
- formResourceName={resourceName}
169
- formUiSchema={uiSchema}
170
- editedEntity={customEventFormData}
171
- confirmationMessage={confirmationMessage()}
172
- ></smart-form-modal>,
173
- document.querySelector('rapid-design-system-provider')!
174
- );
175
- };
176
- {{/if}}
177
-
178
89
  return (
179
90
  {{> (lookup tile 'type') tile}}
180
91
  );
@@ -61,10 +61,10 @@ hasUserPermission('{{config.permissions.viewRight}}') ? (
61
61
  {{#if config.enableSearchBar~}}
62
62
  enable-search-bar
63
63
  {{/if}}
64
+ {{#if config.customEvents}}
65
+ customActions={customActions}
66
+ {{/if}}
64
67
  ></entity-management>
65
- {{#if config.customEvents}}
66
- {renderFormModal()}
67
- {{/if}}
68
68
  </>
69
69
  {{#if config.permissions.viewRight~}}
70
70
  ) : (
@@ -1,32 +1,40 @@
1
- import { CustomEventHandler } from "../../../utils/customEvents";
1
+ import { type CustomAction, CrudMenuPosition, UiSchema } from '@genesislcap/foundation-entity-management';
2
2
 
3
3
  {{#each tile.config.customEvents}}
4
4
  {{#if this.hasForm}}
5
- export const {{camelCase this.name}}FormSchema = {{{this.uischema}}};
5
+ export const {{camelCase this.name}}FormSchema: UiSchema = {{{this.uischema}}};
6
6
  {{/if}}
7
7
  {{/each}}
8
8
 
9
- export const customEventFormSchemas = {
10
- {{#each tile.config.customEvents}}
11
- {{#if this.hasForm}}
12
- '{{this.name}}': {{camelCase this.name}}FormSchema,
13
- {{/if}}
14
- {{/each}}
15
- };
16
-
17
- export const customEvents: CustomEventHandler[] = [
9
+ export const customActions: CustomAction[] = [
18
10
  {{#each tile.config.customEvents}}
19
11
  {
20
- baseEvent: '{{this.baseEvent}}',
21
12
  name: '{{this.name}}',
22
- hasForm: {{this.hasForm}},
13
+ action: {
14
+ type: 'event',
15
+ event: 'EVENT_{{this.baseEvent}}',
16
+ hasForm: {{this.hasForm}},
17
+ {{#if this.hasForm}}
18
+ uiSchema: {{camelCase this.name}}FormSchema,
19
+ {{/if}}
20
+ defaultValues: {{{this.defaultValues}}},
21
+ },
22
+ {{#if this.position}}
23
+ position: CrudMenuPosition.{{{pascalCase this.position}}},
24
+ {{/if}}
25
+ {{#if this.icon}}
26
+ icon: '{{this.icon}}',
27
+ {{/if}}
28
+ {{#if this.tooltip}}
29
+ tooltip: '{{this.tooltip}}',
30
+ {{/if}}
23
31
  {{#if this.confirmSubmit}}
24
32
  confirmSubmit: {
25
33
  state: '{{this.confirmSubmit.state}}',
26
34
  message: '{{this.confirmSubmit.message}}'
27
35
  },
28
36
  {{/if}}
29
- defaultValues: {{{this.defaultValues}}},
37
+ requiresSelection: true,
30
38
  },
31
39
  {{/each}}
32
- ];
40
+ ];
@@ -7,12 +7,6 @@ import { {{pascalCase tile.title}}Template as template } from './{{kebabCase til
7
7
  import { columnDefs } from './{{kebabCase tile.title}}.column.defs';
8
8
  import { ColDef } from '@ag-grid-community/core';
9
9
  {{/if}}
10
- {{#if tile.config.customEvents}}
11
- import type { ActionRendererParams } from '@genesislcap/rapid-grid-pro';
12
- import { RapidAgActionRenderer } from '@genesislcap/rapid-grid-pro';
13
- import { customEvents, customEventFormSchemas } from './{{kebabCase tile.title}}.events.config';
14
- import { handleFormCustomEvent, handleNonFormCustomEvent, showCustomEventConfirmation, type CustomEventHandler, type CustomEventState } from '../../../utils/customEvents';
15
- {{/if}}
16
10
 
17
11
  {{#ifAny tile.metadata.comment tile.metadata.todo}}
18
12
  /**
@@ -32,70 +26,9 @@ export class {{pascalCase tile.componentName}} extends GenesisElement {
32
26
  @User user: User;
33
27
  @Connect connect!: Connect;
34
28
 
35
- {{#if tile.config.customEvents}}
36
- @observable customEvents: CustomEventHandler[] = customEvents;
37
- @observable activeCustomEvent: CustomEventState | null = null;
38
- @observable customEventFormData: Record<string, any> = {};
39
-
40
- async handleCustomEventClick(eventName: string, rowData: any) {
41
- const customEvent = this.customEvents.find((e) => e.name === eventName);
42
- if (!customEvent) return;
43
-
44
- if (customEvent.hasForm) {
45
- handleFormCustomEvent(
46
- customEvent,
47
- rowData,
48
- (data) => (this.customEventFormData = data),
49
- (event) => (this.activeCustomEvent = event),
50
- );
51
- } else {
52
- await handleNonFormCustomEvent(this.connect, customEvent, rowData, (onConfirm) =>
53
- showCustomEventConfirmation(customEvent, onConfirm),
54
- );
55
- }
56
- }
57
-
58
- getActiveCustomEvent() {
59
- if (!this.activeCustomEvent) return null;
60
- return this.customEvents.find(e => e.name === this.activeCustomEvent.name);
61
- }
62
-
63
- getCustomEventResourceName() {
64
- if (!this.activeCustomEvent) return '';
65
- return `EVENT_${this.activeCustomEvent.event}`;
66
- }
67
-
68
- getCustomEventUiSchema() {
69
- const customEvent = this.getActiveCustomEvent();
70
- if (!customEvent) return null;
71
- return customEventFormSchemas[customEvent.name];
72
- }
73
- {{/if}}
74
-
75
29
  {{#if tile.config.columns}}
76
30
  @observable columns: ColDef[] = [
77
31
  ...columnDefs,
78
- {{#if tile.config.customEvents}}
79
- {{#each tile.config.customEvents}}
80
- {
81
- headerName: '',
82
- minWidth: 50,
83
- maxWidth: 50,
84
- headerTooltip: '{{this.tooltip}}',
85
- pinned: 'right',
86
- suppressCellFlash: true,
87
- cellRenderer: RapidAgActionRenderer,
88
- cellRendererParams: <ActionRendererParams>{
89
- actionClick: async (rowData) => {
90
- await this.handleCustomEventClick('{{this.name}}', rowData);
91
- },
92
- contentTemplate: `
93
- <rapid-icon name="{{this.icon}}" title="{{this.name}}"></rapid-icon>
94
- `,
95
- },
96
- },
97
- {{/each}}
98
- {{/if}}
99
32
  ];
100
33
  {{/if}}
101
34
  }
@@ -10,6 +10,9 @@ import { createFormSchema } from './{{kebabCase tile.title}}.create.form.schema'
10
10
  {{#if tile.config.updateFormUiSchema}}
11
11
  import { updateFormSchema } from './{{kebabCase tile.title}}.update.form.schema';
12
12
  {{/if}}
13
+ {{#if tile.config.customEvents}}
14
+ import { customActions } from './{{kebabCase tile.title}}.events.config';
15
+ {{/if}}
13
16
  {{#if tile.config.gridOptions}}
14
17
  import { gridOptions } from './{{kebabCase tile.title}}.gridOptions';
15
18
  {{/if}}
@@ -49,19 +49,10 @@ ${whenElse(
49
49
  {{#if config.enableSearchBar}}
50
50
  enable-search-bar
51
51
  {{/if}}
52
+ {{#if config.customEvents}}
53
+ :customActions=${() => customActions}
54
+ {{/if}}
52
55
  ></entity-management>
53
- {{#if config.customEvents}}
54
- <smart-form-modal
55
- entityLabel="{{ config.entityName }}"
56
- modal-position="{{ config.modalPosition }}"
57
- :modalFormType=${(x) => !!x.activeCustomEvent && 'update'}
58
- :editModalVisible=${(x) => !!x.activeCustomEvent}
59
- :formResourceName=${(x) => x.getCustomEventResourceName()}
60
- :formUiSchema=${(x) => x.getCustomEventUiSchema()}
61
- :editedEntity=${(x) => x.customEventFormData}
62
- confirmation-message="${(x) => x.getActiveCustomEvent()?.confirmSubmit?.state === 'enabled' ? x.getActiveCustomEvent().confirmSubmit.message : null}"
63
- ></smart-form-modal>
64
- {{/if}}
65
56
  `,
66
57
  html`
67
58
  <not-permitted-component></not-permitted-component>
@@ -1,5 +1,5 @@
1
1
  {
2
- "UI": "14.310.2",
3
- "GSF": "8.14.0-beta3",
2
+ "UI": "14.333.0",
3
+ "GSF": "8.14.0-beta4",
4
4
  "Auth": "8.14.0-beta3"
5
5
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [5.4.0-prerelease.26](https://github.com/genesiscommunitysuccess/blank-app-seed/compare/v5.4.0-prerelease.25...v5.4.0-prerelease.26) (2025-10-06)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * updating server version information for GSF [PSD-0](https://github.com/genesiscommunitysuccess/blank-app-seed/issues/0) 56405a7
9
+
10
+ ## [5.4.0-prerelease.25](https://github.com/genesiscommunitysuccess/blank-app-seed/compare/v5.4.0-prerelease.24...v5.4.0-prerelease.25) (2025-10-06)
11
+
12
+
13
+ ### Features
14
+
15
+ * add position + customEvents in angular GENC-1213 38ddcf4
16
+ * handle custom actions by entity-management GENC-1213 b78bf5d
17
+ * handle custom actions by entity-management GENC-1213 (#519) e96b445
18
+
3
19
  ## [5.4.0-prerelease.24](https://github.com/genesiscommunitysuccess/blank-app-seed/compare/v5.4.0-prerelease.23...v5.4.0-prerelease.24) (2025-10-02)
4
20
 
5
21
 
@@ -1,4 +1,3 @@
1
- export * from './customEvents';
2
1
  export * from './fdc3';
3
2
  export * from './getLayoutNameByRoute';
4
3
  export * from './layout';
@@ -1,4 +1,3 @@
1
- export * from './customEvents';
2
1
  export * from './fdc3';
3
2
  export * from './layout';
4
3
  export * from './logger';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@genesislcap/blank-app-seed",
3
3
  "description": "Genesis Blank App Seed",
4
- "version": "5.4.0-prerelease.24",
4
+ "version": "5.4.0-prerelease.26",
5
5
  "license": "Apache-2.0",
6
6
  "scripts": {
7
7
  "release": "semantic-release"
@@ -1,187 +0,0 @@
1
- import { getConnect } from '@genesislcap/foundation-comms';
2
- import { UiSchema } from '@genesislcap/foundation-forms';
3
- import { showNotification, showNotificationDialog } from '@genesislcap/foundation-notifications';
4
-
5
- interface ConfirmSubmit {
6
- state: 'enabled' | 'disabled';
7
- message: string;
8
- }
9
-
10
- interface CustomEventError {
11
- errors: {
12
- message?: string;
13
- CODE: string;
14
- TEXT: string;
15
- }[];
16
- }
17
-
18
- export interface CustomEventHandler {
19
- baseEvent: string;
20
- name: string;
21
- hasForm: boolean;
22
- confirmSubmit?: ConfirmSubmit;
23
- defaultValues?: Record<string, any>;
24
- }
25
-
26
- export interface CustomEventState {
27
- name: string;
28
- event: string;
29
- rowData: any;
30
- }
31
-
32
- interface RecordTypeValue {
33
- type: 'record';
34
- mapping?: string;
35
- }
36
-
37
- type DefaultValue = string | number | boolean | null | RecordTypeValue;
38
-
39
- interface DefaultValues {
40
- [key: string]: DefaultValue;
41
- }
42
-
43
- export const mapDefaultValues = (
44
- defaultValues: DefaultValues,
45
- rowData: any
46
- ): Record<string, any> =>
47
- Object.entries(defaultValues).reduce(
48
- (acc, [key, value]) => ({
49
- ...acc,
50
- [key]:
51
- typeof value === 'object' &&
52
- value !== null &&
53
- 'type' in value &&
54
- value.type === 'record'
55
- ? rowData[(value as RecordTypeValue).mapping || key]
56
- : value,
57
- }),
58
- {}
59
- );
60
-
61
- export const executeCustomEvent = async (
62
- customEventHandler: CustomEventHandler,
63
- rowData: any
64
- ): Promise<void> => {
65
- const payload = customEventHandler.defaultValues
66
- ? mapDefaultValues(customEventHandler.defaultValues, rowData)
67
- : {};
68
-
69
- const res = await getConnect().commitEvent(
70
- `EVENT_${customEventHandler.baseEvent}`,
71
- { DETAILS: payload }
72
- );
73
-
74
- if (res.MESSAGE_TYPE === 'EVENT_NACK') {
75
- const err: CustomEventError = {
76
- errors:
77
- res?.ERROR?.map((e) => ({
78
- TEXT: e.TEXT,
79
- CODE: e.STATUS_CODE ?? '0 Unknown Error',
80
- message:
81
- 'PATH' in e && typeof e.PATH === 'string' && 'FIELD' in e && typeof e.FIELD === 'string'
82
- ? e.TEXT.replace(e.PATH, e.FIELD)
83
- : undefined,
84
- })) ?? [],
85
- };
86
- submitFailureNotification(new CustomEvent('Error', { detail: err }));
87
- }
88
- };
89
-
90
- export const showCustomEventConfirmation = (
91
- customEvent: CustomEventHandler,
92
- onConfirm: () => Promise<void>
93
- ): void => {
94
- showNotificationDialog(
95
- {
96
- title: customEvent.name,
97
- body: customEvent.confirmSubmit!.message,
98
- dialog: {
99
- confirmingActions: [
100
- {
101
- label: 'Confirm',
102
- action: onConfirm,
103
- },
104
- ],
105
- dismissingAction: {
106
- label: 'Cancel',
107
- action: () => {},
108
- },
109
- },
110
- },
111
- 'rapid',
112
- );
113
- };
114
-
115
- export const submitFailureNotification = (e: CustomEvent<CustomEventError>) => {
116
- e.detail.errors.forEach((submitFailureError) => {
117
- if (submitFailureError.CODE === 'OPTIMISTIC_CONCURRENCY_ERROR') {
118
- showNotification(
119
- {
120
- title: 'Warning',
121
- body: "You're editing an old revision. Please close the form and try editing again",
122
- config: {
123
- snackbar: {
124
- type: 'error',
125
- },
126
- },
127
- },
128
- 'rapid',
129
- );
130
- } else {
131
- showNotification(
132
- {
133
- title: 'Error submitting form',
134
- body:
135
- submitFailureError.message ??
136
- (submitFailureError.CODE + ': ' + submitFailureError.TEXT).toString(),
137
- config: {
138
- snackbar: {
139
- type: 'error',
140
- },
141
- },
142
- },
143
- 'rapid',
144
- );
145
- }
146
- });
147
- };
148
-
149
- export const useCustomEvent =
150
- (
151
- customEvent: CustomEventHandler,
152
- rowData: any,
153
- setFormData: (data: Record<string, any>) => void,
154
- setActiveEvent: (event: CustomEventState | null) => void,
155
- setResourceName?: (name: string) => void,
156
- setUiSchema?: (schema: UiSchema) => void,
157
- customEventFormSchemas?: Record<string, UiSchema>
158
- ) =>
159
- async () => {
160
- if (customEvent.hasForm) {
161
- const defaultValues = customEvent.defaultValues || {};
162
- const formData = mapDefaultValues(defaultValues, rowData);
163
- setFormData(formData);
164
- setActiveEvent({
165
- name: customEvent.name,
166
- event: customEvent.baseEvent,
167
- rowData,
168
- });
169
-
170
- if (setResourceName) {
171
- setResourceName(`EVENT_${customEvent.baseEvent}`);
172
- }
173
-
174
- if (setUiSchema && customEventFormSchemas) {
175
- const uiSchema = customEventFormSchemas[customEvent.name];
176
- setUiSchema(uiSchema || null);
177
- }
178
- } else {
179
- if (customEvent.confirmSubmit?.state === 'enabled') {
180
- showCustomEventConfirmation(customEvent, () =>
181
- executeCustomEvent(customEvent, rowData)
182
- );
183
- } else {
184
- await executeCustomEvent(customEvent, rowData);
185
- }
186
- }
187
- };
@@ -1,166 +0,0 @@
1
- import { Connect } from '@genesislcap/foundation-comms';
2
- import { showNotification, showNotificationDialog } from '@genesislcap/foundation-notifications';
3
-
4
- interface ConfirmSubmit {
5
- state: 'enabled' | 'disabled';
6
- message: string;
7
- }
8
-
9
- interface CustomEventError {
10
- errors: {
11
- message?: string;
12
- CODE: string;
13
- TEXT: string;
14
- }[];
15
- }
16
-
17
- export interface CustomEventHandler {
18
- baseEvent: string;
19
- name: string;
20
- hasForm: boolean;
21
- confirmSubmit?: ConfirmSubmit;
22
- defaultValues?: Record<string, any>;
23
- }
24
-
25
- export interface CustomEventState {
26
- name: string;
27
- event: string;
28
- rowData: any;
29
- }
30
-
31
- interface RecordTypeValue {
32
- type: 'record';
33
- mapping?: string;
34
- }
35
-
36
- type DefaultValue = string | number | boolean | null | RecordTypeValue;
37
-
38
- interface DefaultValues {
39
- [key: string]: DefaultValue;
40
- }
41
-
42
- export const mapDefaultValues = (defaultValues: DefaultValues, rowData: any): Record<string, any> =>
43
- Object.entries(defaultValues).reduce(
44
- (acc, [key, value]) => ({
45
- ...acc,
46
- [key]:
47
- typeof value === 'object' && value !== null && 'type' in value && value.type === 'record'
48
- ? rowData[(value as RecordTypeValue).mapping || key]
49
- : value,
50
- }),
51
- {},
52
- );
53
-
54
- export const executeCustomEvent = async (
55
- connect: Connect,
56
- customEvent: CustomEventHandler,
57
- rowData: any,
58
- ): Promise<void> => {
59
- const payload = customEvent.defaultValues
60
- ? mapDefaultValues(customEvent.defaultValues, rowData)
61
- : {};
62
-
63
- const res = await connect.commitEvent(`EVENT_${customEvent.baseEvent}`, {
64
- DETAILS: payload,
65
- });
66
-
67
- if (res.MESSAGE_TYPE === 'EVENT_NACK') {
68
- const err: CustomEventError = {
69
- errors:
70
- res?.ERROR?.map((e) => ({
71
- TEXT: e.TEXT,
72
- CODE: e.STATUS_CODE ?? '0 Unknown Error',
73
- message:
74
- 'PATH' in e && typeof e.PATH === 'string' && 'FIELD' in e && typeof e.FIELD === 'string'
75
- ? e.TEXT.replace(e.PATH, e.FIELD)
76
- : undefined,
77
- })) ?? [],
78
- };
79
- submitFailureNotification(new CustomEvent('Error', { detail: err }));
80
- }
81
- };
82
-
83
- export const showCustomEventConfirmation = (
84
- customEvent: CustomEventHandler,
85
- onConfirm: () => Promise<void>,
86
- ): void => {
87
- showNotificationDialog(
88
- {
89
- title: customEvent.name,
90
- body: customEvent.confirmSubmit!.message,
91
- dialog: {
92
- confirmingActions: [
93
- {
94
- label: 'Confirm',
95
- action: onConfirm,
96
- },
97
- ],
98
- dismissingAction: {
99
- label: 'Cancel',
100
- action: () => {},
101
- },
102
- },
103
- },
104
- 'rapid',
105
- );
106
- };
107
-
108
- export const submitFailureNotification = (e: CustomEvent<CustomEventError>) => {
109
- e.detail.errors.forEach((submitFailureError) => {
110
- if (submitFailureError.CODE === 'OPTIMISTIC_CONCURRENCY_ERROR') {
111
- showNotification(
112
- {
113
- title: 'Warning',
114
- body: "You're editing an old revision. Please close the form and try editing again",
115
- config: {
116
- snackbar: {
117
- type: 'error',
118
- },
119
- },
120
- },
121
- 'rapid',
122
- );
123
- } else {
124
- showNotification(
125
- {
126
- title: 'Error submitting form',
127
- body:
128
- submitFailureError.message ??
129
- (submitFailureError.CODE + ': ' + submitFailureError.TEXT).toString(),
130
- config: {
131
- snackbar: {
132
- type: 'error',
133
- },
134
- },
135
- },
136
- 'rapid',
137
- );
138
- }
139
- });
140
- };
141
-
142
- export const handleFormCustomEvent = (
143
- customEvent: CustomEventHandler,
144
- rowData: any,
145
- setFormData: (data: Record<string, any>) => void,
146
- setActiveEvent: (event: CustomEventState) => void,
147
- ): void => {
148
- const defaultValues = customEvent.defaultValues || {};
149
- const formData = mapDefaultValues(defaultValues, rowData);
150
-
151
- setFormData(formData);
152
- setActiveEvent({ name: customEvent.name, event: customEvent.baseEvent, rowData });
153
- };
154
-
155
- export const handleNonFormCustomEvent = async (
156
- connect: Connect,
157
- customEvent: CustomEventHandler,
158
- rowData: any,
159
- showConfirmation: (onConfirm: () => Promise<void>) => void,
160
- ): Promise<void> => {
161
- if (customEvent.confirmSubmit?.state === 'enabled') {
162
- showConfirmation(() => executeCustomEvent(connect, customEvent, rowData));
163
- } else {
164
- await executeCustomEvent(connect, customEvent, rowData);
165
- }
166
- };