@genesislcap/pbc-notify-ui 15.14.0 → 15.14.1

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 (16) hide show
  1. package/dist/custom-elements.json +1332 -1348
  2. package/dist/dts/components/foundation-notification-dashboard/components/templates/template-dialog/template-condition-builder/template-condition-builder.d.ts +2 -1
  3. package/dist/dts/components/foundation-notification-dashboard/components/templates/template-dialog/template-condition-builder/template-condition-builder.d.ts.map +1 -1
  4. package/dist/dts/components/foundation-notification-dashboard/components/templates/template-dialog/template-dialog.d.ts +1 -0
  5. package/dist/dts/components/foundation-notification-dashboard/components/templates/template-dialog/template-dialog.d.ts.map +1 -1
  6. package/dist/dts/react.d.ts +28 -28
  7. package/dist/dts/services/system.service.d.ts.map +1 -1
  8. package/dist/esm/components/foundation-notification-dashboard/components/templates/template-dialog/template-condition-builder/template-condition-builder.js +4 -4
  9. package/dist/esm/components/foundation-notification-dashboard/components/templates/template-dialog/template-dialog.js +27 -13
  10. package/dist/esm/services/system.service.js +37 -12
  11. package/dist/react.cjs +30 -30
  12. package/dist/react.mjs +27 -27
  13. package/package.json +23 -23
  14. package/src/components/foundation-notification-dashboard/components/templates/template-dialog/template-condition-builder/template-condition-builder.ts +5 -4
  15. package/src/components/foundation-notification-dashboard/components/templates/template-dialog/template-dialog.ts +27 -14
  16. package/src/services/system.service.ts +39 -12
@@ -64,6 +64,7 @@ export class TemplateDialog extends AlertSoundAttachmentMixin(GenesisElement) {
64
64
  @observable resources: Array<string> = [];
65
65
  @observable fields: Array<Field> = [];
66
66
  @observable topics: Array<string> = [];
67
+ private hydrating = false;
67
68
 
68
69
  private requiredFields = () => [this.name, this.description, this.header, this.message];
69
70
 
@@ -82,23 +83,31 @@ export class TemplateDialog extends AlertSoundAttachmentMixin(GenesisElement) {
82
83
  }
83
84
 
84
85
  public async openDialog(params: any) {
85
- this.topics = await this.notifyService.getNotifyRouteTopics();
86
- this.resources = await this.systemService.getResources(); // TODO: Tables + Views
87
86
  this.templateDialogMode = params.mode;
87
+ this.hydrating = true;
88
+ this.dialog.show();
88
89
 
89
- switch (params.mode) {
90
- case TemplateDialogMode.CREATE:
91
- await this.createTemplate();
92
- break;
93
- case TemplateDialogMode.EDIT:
94
- await this.editTemplate(params.data);
95
- break;
96
- default:
97
- logger.error('Error on TemplateDialogMode');
98
- break;
90
+ try {
91
+ this.topics = await this.notifyService.getNotifyRouteTopics();
92
+ this.resources = await this.systemService.getResources(); // TODO: Tables + Views
93
+
94
+ switch (params.mode) {
95
+ case TemplateDialogMode.CREATE:
96
+ await this.createTemplate();
97
+ break;
98
+ case TemplateDialogMode.EDIT:
99
+ await this.editTemplate(params.data);
100
+ break;
101
+ default:
102
+ logger.error('Error on TemplateDialogMode');
103
+ break;
104
+ }
105
+ } catch (error) {
106
+ logger.error('Failed to initialize template dialog', error);
107
+ this.close();
108
+ } finally {
109
+ this.hydrating = false;
99
110
  }
100
-
101
- this.dialog.show();
102
111
  }
103
112
 
104
113
  close() {
@@ -262,6 +271,10 @@ export class TemplateDialog extends AlertSoundAttachmentMixin(GenesisElement) {
262
271
  }
263
272
 
264
273
  async resourceChanged() {
274
+ if (this.hydrating) {
275
+ return;
276
+ }
277
+
265
278
  this.conditions = [DynamicRuleUtils.createEmptyCondition()];
266
279
  this.fields = await this.systemService.getFields(this.resource);
267
280
  this.refreshExpressionPreview();
@@ -12,6 +12,27 @@ export interface SystemService {
12
12
  getFields(resource: string): Promise<Field[]>;
13
13
  }
14
14
 
15
+ function schemaDefinitionToField(name: string, def: unknown): Field {
16
+ const raw = def && typeof def === 'object' ? (def as Record<string, unknown>) : {};
17
+ const oneOf = Array.isArray(raw.oneOf) ? raw.oneOf : [];
18
+ const concrete =
19
+ (oneOf.find((option) => {
20
+ if (!option || typeof option !== 'object') {
21
+ return false;
22
+ }
23
+ return (option as Record<string, unknown>).type !== 'null';
24
+ }) as Record<string, unknown> | undefined) ?? raw;
25
+ const genesisType = typeof concrete.genesisType === 'string' ? concrete.genesisType : undefined;
26
+ const jsonType = typeof concrete.type === 'string' ? concrete.type : undefined;
27
+ const enumValues = Array.isArray(concrete.enum) ? concrete.enum.map(String) : null;
28
+
29
+ return {
30
+ FIELD_NAME: name,
31
+ FIELD_TYPE: (genesisType ?? jsonType ?? 'STRING').toUpperCase(),
32
+ FIELD_VALUES: enumValues,
33
+ };
34
+ }
35
+
15
36
  class SystemServiceImpl implements SystemService {
16
37
  @Connect private connect: Connect;
17
38
 
@@ -27,18 +48,24 @@ class SystemServiceImpl implements SystemService {
27
48
  return [];
28
49
  }
29
50
 
30
- const response = await this.connect.request('SYSTEM_ENTITY_FIELDS', {
31
- REQUEST: {
32
- ENTITY_NAME: resource,
33
- },
34
- });
35
- return response.REPLY.sort((a, b) => a.NAME.localeCompare(b.NAME)).map((entity) => ({
36
- FIELD_NAME: entity.NAME,
37
- FIELD_TYPE: entity.TYPE,
38
- // Enum fields expose their allowed values (space-separated) so the condition
39
- // builder can render a multiselect for them.
40
- FIELD_VALUES: entity.VALUES ? entity.VALUES.split(' ').filter((v: string) => v.length) : null,
41
- }));
51
+ try {
52
+ const schema = await this.connect.getJSONSchema(resource);
53
+ const reply = schema?.OUTBOUND?.properties?.REPLY;
54
+ if (!reply || typeof reply === 'boolean') {
55
+ return [];
56
+ }
57
+
58
+ const items = Array.isArray(reply.items) ? reply.items[0] : reply.items;
59
+ if (!items || typeof items === 'boolean' || !items.properties) {
60
+ return [];
61
+ }
62
+
63
+ return Object.entries(items.properties)
64
+ .map(([name, def]) => schemaDefinitionToField(name, def))
65
+ .sort((a, b) => a.FIELD_NAME.localeCompare(b.FIELD_NAME));
66
+ } catch {
67
+ return [];
68
+ }
42
69
  }
43
70
  }
44
71