@headless-adminapp/app 0.0.17-alpha.14 → 0.0.17-alpha.15

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.
@@ -2,6 +2,7 @@ import { EntityMainFormCommandItemExperience } from '@headless-adminapp/core/exp
2
2
  import { EntityMainGridCommandItemExperience, SubGridCommandItemExperience } from '@headless-adminapp/core/experience/view';
3
3
  import { Localized } from '@headless-adminapp/core/types';
4
4
  import { Icon } from '@headless-adminapp/icons';
5
+ import { FormCommandBuilder } from './FormCommandBuilder';
5
6
  import { ViewCommandBuilder } from './ViewCommandBuilder';
6
7
  export declare namespace DefaultCommandBuilder {
7
8
  interface CreateDefaultViewCommandStrings {
@@ -33,12 +34,15 @@ export declare namespace DefaultCommandBuilder {
33
34
  save: string;
34
35
  saveAndClose: string;
35
36
  refresh: string;
37
+ delete: string;
38
+ deleteRecordCommandStringSet: FormCommandBuilder.DeleteRecordCommandStringSet;
36
39
  }
37
40
  interface CreateDefaultFormCommandOptions {
38
41
  icons: {
39
42
  Save: Icon;
40
43
  SaveAndClose: Icon;
41
44
  Refresh: Icon;
45
+ Delete: Icon;
42
46
  };
43
47
  strings?: CreateDefaultFormCommandStrings;
44
48
  localizedSrings?: Localized<CreateDefaultFormCommandStrings>;
@@ -77,6 +77,8 @@ var DefaultCommandBuilder;
77
77
  save: 'Save',
78
78
  saveAndClose: 'Save & Close',
79
79
  refresh: 'Refresh',
80
+ delete: 'Delete',
81
+ deleteRecordCommandStringSet: FormCommandBuilder_1.FormCommandBuilder.defaultDeleteRecordStringSet,
80
82
  };
81
83
  function createDefaultFormCommands({ icons, strings = DefaultCommandBuilder.defaultFormCommandStrings, localizedSrings, }) {
82
84
  return [
@@ -96,6 +98,13 @@ var DefaultCommandBuilder;
96
98
  text: strings.refresh,
97
99
  localizedTexts: extractLocalizedStrings(localizedSrings, (x) => x.refresh),
98
100
  }),
101
+ FormCommandBuilder_1.FormCommandBuilder.createDeleteCommand({
102
+ Icon: icons.Delete,
103
+ text: 'Delete',
104
+ localizedTexts: extractLocalizedStrings(localizedSrings, (x) => x.delete),
105
+ stringSet: strings.deleteRecordCommandStringSet,
106
+ localizedStringSet: extractLocalizedStrings(localizedSrings, (x) => x.deleteRecordCommandStringSet),
107
+ }),
99
108
  ],
100
109
  ];
101
110
  }
@@ -1,12 +1,13 @@
1
1
  import { EntityFormCommandContext, EntityMainFormCommandItemExperience } from '@headless-adminapp/core/experience/form';
2
+ import { Localized } from '@headless-adminapp/core/types';
2
3
  import { Icon } from '@headless-adminapp/icons';
3
4
  export declare namespace FormCommandBuilder {
4
- export function createSaveCommand({ Icon, text, localizedTexts, }: {
5
+ function createSaveCommand({ Icon, text, localizedTexts, }: {
5
6
  Icon: Icon;
6
7
  text: string;
7
8
  localizedTexts?: Record<string, string>;
8
9
  }): EntityMainFormCommandItemExperience;
9
- export function createSaveAndCloseCommand({ Icon, text, localizedTexts, }: {
10
+ function createSaveAndCloseCommand({ Icon, text, localizedTexts, }: {
10
11
  Icon: Icon;
11
12
  text: string;
12
13
  localizedTexts?: Record<string, string>;
@@ -29,17 +30,17 @@ export declare namespace FormCommandBuilder {
29
30
  title: string;
30
31
  };
31
32
  }
32
- export const defaultDeleteRecordStringSet: DeleteRecordCommandStringSet;
33
- export function createDeleteCommand({ Icon, text, localizedTexts, stringSet, }: {
33
+ const defaultDeleteRecordStringSet: DeleteRecordCommandStringSet;
34
+ function createDeleteCommand({ Icon, text, localizedTexts, stringSet, }: {
34
35
  Icon: Icon;
35
36
  text: string;
36
37
  localizedTexts?: Record<string, string>;
37
38
  stringSet: DeleteRecordCommandStringSet | ((context: EntityFormCommandContext) => DeleteRecordCommandStringSet);
39
+ localizedStringSet?: Localized<DeleteRecordCommandStringSet | ((context: EntityFormCommandContext) => DeleteRecordCommandStringSet)>;
38
40
  }): EntityMainFormCommandItemExperience;
39
- export function createRefreshCommand({ Icon, text, localizedTexts, }: {
41
+ function createRefreshCommand({ Icon, text, localizedTexts, }: {
40
42
  Icon: Icon;
41
43
  text: string;
42
44
  localizedTexts?: Record<string, string>;
43
45
  }): EntityMainFormCommandItemExperience;
44
- export {};
45
46
  }
@@ -10,6 +10,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.FormCommandBuilder = void 0;
13
+ var EnabledRules;
14
+ (function (EnabledRules) {
15
+ function HasCreatePermisssion(context) {
16
+ var _a;
17
+ return !((_a = context.primaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableCreate);
18
+ }
19
+ EnabledRules.HasCreatePermisssion = HasCreatePermisssion;
20
+ function HasUpdatePermission(context) {
21
+ var _a;
22
+ return !((_a = context.primaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableUpdate);
23
+ }
24
+ EnabledRules.HasUpdatePermission = HasUpdatePermission;
25
+ function HasDeletePermission(context) {
26
+ var _a;
27
+ return !((_a = context.primaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableDelete);
28
+ }
29
+ EnabledRules.HasDeletePermission = HasDeletePermission;
30
+ })(EnabledRules || (EnabledRules = {}));
13
31
  var FormCommandBuilder;
14
32
  (function (FormCommandBuilder) {
15
33
  function createSaveCommand({ Icon, text, localizedTexts, }) {
@@ -22,12 +40,19 @@ var FormCommandBuilder;
22
40
  onClick: (context) => __awaiter(this, void 0, void 0, function* () {
23
41
  yield context.primaryControl.save('save');
24
42
  }),
25
- hidden: (context) => {
26
- if (context.primaryControl.readonly) {
27
- return true;
28
- }
29
- return false;
30
- },
43
+ hidden: [
44
+ (context) => {
45
+ if (context.primaryControl.readonly) {
46
+ return true;
47
+ }
48
+ if (context.primaryControl.recordId) {
49
+ return !EnabledRules.HasUpdatePermission(context);
50
+ }
51
+ else {
52
+ return !EnabledRules.HasCreatePermisssion(context);
53
+ }
54
+ },
55
+ ],
31
56
  };
32
57
  }
33
58
  FormCommandBuilder.createSaveCommand = createSaveCommand;
@@ -40,12 +65,19 @@ var FormCommandBuilder;
40
65
  onClick: (context) => __awaiter(this, void 0, void 0, function* () {
41
66
  yield context.primaryControl.save('saveandclose');
42
67
  }),
43
- hidden: (context) => {
44
- if (context.primaryControl.readonly) {
45
- return true;
46
- }
47
- return false;
48
- },
68
+ hidden: [
69
+ (context) => {
70
+ if (context.primaryControl.readonly) {
71
+ return true;
72
+ }
73
+ if (context.primaryControl.recordId) {
74
+ return !EnabledRules.HasUpdatePermission(context);
75
+ }
76
+ else {
77
+ return !EnabledRules.HasCreatePermisssion(context);
78
+ }
79
+ },
80
+ ],
49
81
  };
50
82
  }
51
83
  FormCommandBuilder.createSaveAndCloseCommand = createSaveAndCloseCommand;
@@ -75,14 +107,10 @@ var FormCommandBuilder;
75
107
  localizedText: localizedTexts,
76
108
  danger: true,
77
109
  hidden: (context) => {
78
- var _a;
79
110
  if (!context.primaryControl.recordId) {
80
111
  return true;
81
112
  }
82
- if ((_a = context.primaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableDelete) {
83
- return true;
84
- }
85
- return false;
113
+ return !EnabledRules.HasDeletePermission(context);
86
114
  },
87
115
  onClick: (context) => __awaiter(this, void 0, void 0, function* () {
88
116
  const recordId = context.primaryControl.recordId;
@@ -103,17 +131,13 @@ var FormCommandBuilder;
103
131
  return;
104
132
  }
105
133
  context.utility.showProgressIndicator(stringSet.status.deleting + '...');
106
- yield new Promise((resolve) => setTimeout(resolve, 2000));
107
- // await context.dataService.deleteRecord(
108
- // context.primaryControl.logicalName,
109
- // recordId
110
- // );
134
+ yield context.dataService.deleteRecord(context.primaryControl.logicalName, recordId);
111
135
  context.utility.showNotification({
112
136
  title: stringSet.successNotification.title,
113
137
  text: stringSet.successNotification.text,
114
138
  type: 'success',
115
139
  });
116
- // context.primaryControl.close();
140
+ context.primaryControl.close();
117
141
  }
118
142
  catch (error) {
119
143
  context.utility.showNotification({
@@ -10,7 +10,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.SubgridCommandBuilder = void 0;
13
- const utils_1 = require("./utils");
13
+ const utils_1 = require("../utils");
14
+ const utils_2 = require("./utils");
15
+ var EnabledRules;
16
+ (function (EnabledRules) {
17
+ function HasCreatePermisssion(context) {
18
+ var _a;
19
+ return !((_a = context.secondaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableCreate);
20
+ }
21
+ EnabledRules.HasCreatePermisssion = HasCreatePermisssion;
22
+ function HasUpdatePermission(context) {
23
+ var _a;
24
+ return !((_a = context.secondaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableUpdate);
25
+ }
26
+ EnabledRules.HasUpdatePermission = HasUpdatePermission;
27
+ function HasDeletePermission(context) {
28
+ var _a;
29
+ return !((_a = context.secondaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableDelete);
30
+ }
31
+ EnabledRules.HasDeletePermission = HasDeletePermission;
32
+ function HasSingleRecordSelected(context) {
33
+ return context.secondaryControl.selectedIds.length === 1;
34
+ }
35
+ EnabledRules.HasSingleRecordSelected = HasSingleRecordSelected;
36
+ function HasAtLeastOneRecordSelected(context) {
37
+ return context.secondaryControl.selectedIds.length > 0;
38
+ }
39
+ EnabledRules.HasAtLeastOneRecordSelected = HasAtLeastOneRecordSelected;
40
+ })(EnabledRules || (EnabledRules = {}));
14
41
  var SubgridCommandBuilder;
15
42
  (function (SubgridCommandBuilder) {
16
43
  function createNewRecordCommand({ Icon, text, localizedTexts, }) {
@@ -20,13 +47,25 @@ var SubgridCommandBuilder;
20
47
  text,
21
48
  localizedText: localizedTexts,
22
49
  onClick: (context) => {
23
- console.log('New record', context);
24
- },
25
- hidden: (context) => {
26
- console.log(context);
27
- // TODO: Implement logic to hide the button
28
- return false;
50
+ if (context.secondaryControl.associated) {
51
+ context.navigation.openForm({
52
+ logicalName: context.primaryControl.schema.logicalName,
53
+ parameters: {
54
+ [context.secondaryControl.associated.refAttributeName]: {
55
+ id: context.secondaryControl.associated.id,
56
+ logicalName: context.secondaryControl.associated.logicalName,
57
+ name: context.secondaryControl.associated.name,
58
+ },
59
+ },
60
+ });
61
+ }
62
+ else {
63
+ context.navigation.openForm({
64
+ logicalName: context.primaryControl.schema.logicalName,
65
+ });
66
+ }
29
67
  },
68
+ hidden: (context) => !EnabledRules.HasCreatePermisssion(context),
30
69
  };
31
70
  }
32
71
  SubgridCommandBuilder.createNewRecordCommand = createNewRecordCommand;
@@ -38,13 +77,9 @@ var SubgridCommandBuilder;
38
77
  localizedText: localizedTexts,
39
78
  isContextMenu: true,
40
79
  onClick: (context) => {
41
- console.log('Edit record', context);
42
- },
43
- // hidden: (context) => context.secondaryControl.selectedIds.length !== 1, // TODO: check permissions
44
- hidden: (context) => {
45
- console.log('temp.', context);
46
- return context.secondaryControl.selectedIds.length !== 1;
80
+ context.secondaryControl.openRecord(context.secondaryControl.selectedIds[0]);
47
81
  },
82
+ hidden: [(context) => !EnabledRules.HasSingleRecordSelected(context)],
48
83
  };
49
84
  }
50
85
  SubgridCommandBuilder.createEditRecordCommand = createEditRecordCommand;
@@ -86,13 +121,12 @@ var SubgridCommandBuilder;
86
121
  localizedText,
87
122
  danger: true,
88
123
  isContextMenu: true,
89
- hidden: [(context) => context.secondaryControl.selectedIds.length === 0], // TODO: check permissions
90
124
  onClick: (context) => __awaiter(this, void 0, void 0, function* () {
91
125
  const recordIds = context.secondaryControl.selectedIds;
92
126
  if (!recordIds.length) {
93
127
  return;
94
128
  }
95
- const localizeSelector = (0, utils_1.createLocalizedSelector)(stringSet, localizedStringSet, context.locale.language);
129
+ const localizeSelector = (0, utils_2.createLocalizedSelector)(stringSet, localizedStringSet, context.locale.language);
96
130
  try {
97
131
  const confirmResult = yield context.utility.openConfirmDialog({
98
132
  title: plurialize(recordIds.length, localizeSelector((s) => s.confirmation.title)),
@@ -104,7 +138,9 @@ var SubgridCommandBuilder;
104
138
  return;
105
139
  }
106
140
  context.utility.showProgressIndicator(plurialize(recordIds.length, localizeSelector((s) => s.status.deleting)) + '...');
107
- yield new Promise((resolve) => setTimeout(resolve, 2000));
141
+ for (const recordId of recordIds) {
142
+ yield context.dataService.deleteRecord(context.primaryControl.logicalName, recordId);
143
+ }
108
144
  context.utility.showNotification({
109
145
  title: plurialize(recordIds.length, localizeSelector((s) => s.successNotification.title)),
110
146
  text: plurialize(recordIds.length, localizeSelector((s) => s.successNotification.text)),
@@ -123,6 +159,10 @@ var SubgridCommandBuilder;
123
159
  context.utility.hideProgressIndicator();
124
160
  }
125
161
  }),
162
+ hidden: [
163
+ (context) => !EnabledRules.HasAtLeastOneRecordSelected(context),
164
+ (context) => !EnabledRules.HasDeletePermission(context),
165
+ ],
126
166
  };
127
167
  }
128
168
  SubgridCommandBuilder.createDeleteRecordCommand = createDeleteRecordCommand;
@@ -150,17 +190,67 @@ var SubgridCommandBuilder;
150
190
  Icon: excel.Icon,
151
191
  text: excel.text,
152
192
  localizedTexts: excel.localizedTexts,
153
- onClick: (context) => {
154
- console.log('Export to Excel', context);
155
- },
193
+ onClick: (context) => __awaiter(this, void 0, void 0, function* () {
194
+ context.utility.showProgressIndicator('Exporting to Excel...');
195
+ try {
196
+ const result = yield (0, utils_1.retriveRecords)({
197
+ columnFilters: context.secondaryControl.columnFilter,
198
+ dataService: context.dataService,
199
+ gridColumns: context.secondaryControl.gridColumns,
200
+ schema: context.secondaryControl.schema,
201
+ schemaStore: context.stores.schemaStore,
202
+ view: context.secondaryControl.view,
203
+ search: context.secondaryControl.searchText,
204
+ extraFilter: context.secondaryControl.extraFilter,
205
+ sorting: context.secondaryControl.sorting,
206
+ skip: 0,
207
+ limit: 5000,
208
+ });
209
+ yield (0, utils_1.exportRecordsXLS)({
210
+ fileName: context.secondaryControl.view.name + '.xlsx',
211
+ gridColumns: context.secondaryControl.gridColumns,
212
+ records: result.records,
213
+ schema: context.secondaryControl.schema,
214
+ schemaStore: context.stores.schemaStore,
215
+ });
216
+ }
217
+ finally {
218
+ context.utility.hideProgressIndicator();
219
+ }
220
+ }),
156
221
  },
157
222
  {
158
223
  Icon: csv.Icon,
159
224
  text: csv.text,
160
225
  localizedTexts: csv.localizedTexts,
161
- onClick: (context) => {
162
- console.log('Export to CSV', context);
163
- },
226
+ onClick: (context) => __awaiter(this, void 0, void 0, function* () {
227
+ context.utility.showProgressIndicator('Exporting to CSV...');
228
+ try {
229
+ const result = yield (0, utils_1.retriveRecords)({
230
+ columnFilters: context.secondaryControl.columnFilter,
231
+ dataService: context.dataService,
232
+ gridColumns: context.secondaryControl.gridColumns,
233
+ schema: context.secondaryControl.schema,
234
+ schemaStore: context.stores.schemaStore,
235
+ view: context.secondaryControl.view,
236
+ search: context.secondaryControl.searchText,
237
+ extraFilter: context.secondaryControl.extraFilter,
238
+ sorting: context.secondaryControl.sorting,
239
+ skip: 0,
240
+ limit: 5000,
241
+ });
242
+ yield (0, utils_1.exportRecordsCSV)({
243
+ fileName: context.secondaryControl.view.name + '.csv',
244
+ gridColumns: context.secondaryControl.gridColumns,
245
+ records: result.records,
246
+ schema: context.secondaryControl.schema,
247
+ schemaStore: context.stores.schemaStore,
248
+ });
249
+ }
250
+ finally {
251
+ context.utility.hideProgressIndicator();
252
+ }
253
+ }),
164
254
  },
165
255
  ],
166
256
  ],
@@ -46,12 +46,12 @@ var ViewCommandBuilder;
46
46
  Icon,
47
47
  text,
48
48
  localizedText: localizedTexts,
49
- onClick: context => {
49
+ onClick: (context) => {
50
50
  context.navigation.openForm({
51
51
  logicalName: context.primaryControl.schema.logicalName,
52
52
  });
53
53
  },
54
- hidden: context => {
54
+ hidden: (context) => {
55
55
  if (!EnabledRules.HasCreatePermisssion(context)) {
56
56
  return true;
57
57
  }
@@ -67,18 +67,10 @@ var ViewCommandBuilder;
67
67
  text,
68
68
  localizedText: localizedTexts,
69
69
  isContextMenu: true,
70
- onClick: context => {
70
+ onClick: (context) => {
71
71
  context.primaryControl.openRecord(context.primaryControl.selectedIds[0]);
72
72
  },
73
- hidden: context => {
74
- if (!EnabledRules.HasUpdatePermission(context)) {
75
- return true;
76
- }
77
- if (!EnabledRules.HasSingleRecordSelected(context)) {
78
- return true;
79
- }
80
- return false;
81
- },
73
+ hidden: [(context) => !EnabledRules.HasSingleRecordSelected(context)],
82
74
  };
83
75
  }
84
76
  ViewCommandBuilder.createEditRecordCommand = createEditRecordCommand;
@@ -119,28 +111,28 @@ var ViewCommandBuilder;
119
111
  const localizeSelector = (0, utils_2.createLocalizedSelector)(stringSet, localizedStringSet, context.locale.language);
120
112
  try {
121
113
  const confirmResult = yield context.utility.openConfirmDialog({
122
- title: (0, utils_2.plurialize)(recordIds.length, localizeSelector(s => s.confirmation.title)),
123
- text: (0, utils_2.plurialize)(recordIds.length, localizeSelector(s => s.confirmation.text)),
124
- cancelButtonLabel: localizeSelector(s => s.confirmation.buttonCancel),
125
- confirmButtonLabel: localizeSelector(s => s.confirmation.buttonConfirm),
114
+ title: (0, utils_2.plurialize)(recordIds.length, localizeSelector((s) => s.confirmation.title)),
115
+ text: (0, utils_2.plurialize)(recordIds.length, localizeSelector((s) => s.confirmation.text)),
116
+ cancelButtonLabel: localizeSelector((s) => s.confirmation.buttonCancel),
117
+ confirmButtonLabel: localizeSelector((s) => s.confirmation.buttonConfirm),
126
118
  });
127
119
  if (!(confirmResult === null || confirmResult === void 0 ? void 0 : confirmResult.confirmed)) {
128
120
  return;
129
121
  }
130
- context.utility.showProgressIndicator((0, utils_2.plurialize)(recordIds.length, localizeSelector(s => s.status.deleting)) + '...');
122
+ context.utility.showProgressIndicator((0, utils_2.plurialize)(recordIds.length, localizeSelector((s) => s.status.deleting)) + '...');
131
123
  for (const recordId of recordIds) {
132
124
  yield context.dataService.deleteRecord(context.primaryControl.logicalName, recordId);
133
125
  }
134
126
  context.utility.showNotification({
135
- title: (0, utils_2.plurialize)(recordIds.length, localizeSelector(s => s.successNotification.title)),
136
- text: (0, utils_2.plurialize)(recordIds.length, localizeSelector(s => s.successNotification.text)),
127
+ title: (0, utils_2.plurialize)(recordIds.length, localizeSelector((s) => s.successNotification.title)),
128
+ text: (0, utils_2.plurialize)(recordIds.length, localizeSelector((s) => s.successNotification.text)),
137
129
  type: 'success',
138
130
  });
139
131
  context.primaryControl.refresh();
140
132
  }
141
133
  catch (error) {
142
134
  context.utility.showNotification({
143
- title: localizeSelector(s => s.errorNotification.title),
135
+ title: localizeSelector((s) => s.errorNotification.title),
144
136
  text: error.message,
145
137
  type: 'error',
146
138
  });
@@ -150,8 +142,8 @@ var ViewCommandBuilder;
150
142
  }
151
143
  }),
152
144
  hidden: [
153
- context => !EnabledRules.HasAtLeastOneRecordSelected(context),
154
- context => !EnabledRules.HasDeletePermission(context),
145
+ (context) => !EnabledRules.HasAtLeastOneRecordSelected(context),
146
+ (context) => !EnabledRules.HasDeletePermission(context),
155
147
  ],
156
148
  };
157
149
  }
@@ -162,7 +154,7 @@ var ViewCommandBuilder;
162
154
  Icon,
163
155
  text,
164
156
  localizedText: localizedTexts,
165
- onClick: context => {
157
+ onClick: (context) => {
166
158
  context.primaryControl.refresh();
167
159
  },
168
160
  };
@@ -214,7 +206,7 @@ var ViewCommandBuilder;
214
206
  text: csv.text,
215
207
  localizedTexts: csv.localizedTexts,
216
208
  onClick: (context) => __awaiter(this, void 0, void 0, function* () {
217
- context.utility.showProgressIndicator('Exporting to Excel...');
209
+ context.utility.showProgressIndicator('Exporting to CSV...');
218
210
  try {
219
211
  const result = yield (0, utils_1.retriveRecords)({
220
212
  columnFilters: context.primaryControl.columnFilter,
@@ -12,6 +12,11 @@ export interface DataGridProviderProps<S extends SchemaAttributes = SchemaAttrib
12
12
  commands: CommandItemExperience<CommandContext>[][];
13
13
  onChangeView?: (viewId: string) => void;
14
14
  isSubGrid?: boolean;
15
+ associated?: false | {
16
+ logicalName: string;
17
+ id: string;
18
+ refAttributeName: string;
19
+ };
15
20
  allowViewSelection?: boolean;
16
21
  maxRecords?: number;
17
22
  }
@@ -45,6 +45,7 @@ function DataGridProvider(props) {
45
45
  isSubGrid: (_b = props.isSubGrid) !== null && _b !== void 0 ? _b : false,
46
46
  allowViewSelection: (_c = props.allowViewSelection) !== null && _c !== void 0 ? _c : false,
47
47
  maxRecords: props.maxRecords,
48
+ associated: props.associated,
48
49
  });
49
50
  (0, react_1.useEffect)(() => {
50
51
  var _a;
@@ -74,5 +75,12 @@ function DataGridProvider(props) {
74
75
  commands: props.commands,
75
76
  });
76
77
  }, [props.commands, contextValue]);
78
+ (0, react_1.useEffect)(() => {
79
+ var _a;
80
+ contextValue.setValue({
81
+ isSubGrid: (_a = props.isSubGrid) !== null && _a !== void 0 ? _a : false,
82
+ associated: props.associated,
83
+ });
84
+ }, [props.isSubGrid, props.associated, contextValue]);
77
85
  return ((0, jsx_runtime_1.jsxs)(context_2.GridContext.Provider, { value: contextValue, children: [(0, jsx_runtime_1.jsx)(DataResolver_1.DataResolver, {}), props.children] }));
78
86
  }
@@ -13,6 +13,11 @@ export interface GridContextState<S extends SchemaAttributes = SchemaAttributes,
13
13
  extraFilter?: Filter;
14
14
  commands?: CommandItemExperience<CommandContext>[][];
15
15
  maxRecords?: number;
16
+ associated?: false | {
17
+ logicalName: string;
18
+ id: string;
19
+ refAttributeName: string;
20
+ };
16
21
  columns: TransformedViewColumn<S>[];
17
22
  searchText: string;
18
23
  columnFilters: Partial<Record<keyof S, ColumnCondition>>;
@@ -4,54 +4,26 @@ exports.useSubGridCommandHandlerContext = useSubGridCommandHandlerContext;
4
4
  exports.useSubGridCommands = useSubGridCommands;
5
5
  exports.useSubGridContextCommands = useSubGridContextCommands;
6
6
  const app_1 = require("@headless-adminapp/app/app");
7
+ const dataform_1 = require("@headless-adminapp/app/dataform");
7
8
  const mutable_1 = require("@headless-adminapp/app/mutable");
8
- const react_1 = require("react");
9
9
  const command_1 = require("../../command");
10
10
  const useMainFormCommands_1 = require("../../dataform/hooks/useMainFormCommands");
11
11
  const context_1 = require("../context");
12
- const useGridColumnFilter_1 = require("./useGridColumnFilter");
13
- const useGridData_1 = require("./useGridData");
14
- const useGridExtraFilter_1 = require("./useGridExtraFilter");
15
- const useGridRefresh_1 = require("./useGridRefresh");
16
- const useGridSchema_1 = require("./useGridSchema");
17
- const useGridSelection_1 = require("./useGridSelection");
18
- const useSearchText_1 = require("./useSearchText");
19
- const useSelectedView_1 = require("./useSelectedView");
12
+ const useMainGridCommands_1 = require("./useMainGridCommands");
20
13
  function useSubGridCommandHandlerContext() {
21
14
  const baseHandlerContext = (0, command_1.useBaseCommandHandlerContext)();
22
- const data = (0, useGridData_1.useGridData)();
23
- const schema = (0, useGridSchema_1.useDataGridSchema)();
24
- const view = (0, useSelectedView_1.useSelectedView)();
25
- const [searchText] = (0, useSearchText_1.useSearchText)();
26
- const [selectedIds] = (0, useGridSelection_1.useGridSelection)();
27
- const selectedIdsObj = (0, react_1.useMemo)(() => {
28
- const obj = {};
29
- selectedIds.forEach((id) => {
30
- obj[id] = true;
31
- });
32
- return obj;
33
- }, [selectedIds]);
34
- const selectedRecords = (0, react_1.useMemo)(() => {
35
- var _a;
36
- return ((_a = data === null || data === void 0 ? void 0 : data.records) !== null && _a !== void 0 ? _a : []).filter((record) => selectedIdsObj[record[schema.idAttribute]]);
37
- }, [data, schema, selectedIdsObj]);
38
- const [columnFilter] = (0, useGridColumnFilter_1.useGridColumnFilter)();
39
- const extraFilter = (0, useGridExtraFilter_1.useGridExtraFilter)();
40
- const refresh = (0, useGridRefresh_1.useGridRefresh)();
41
15
  const mainFormHandlerContext = (0, useMainFormCommands_1.useMainFormCommandHandlerContext)();
42
- return Object.assign(Object.assign({}, baseHandlerContext), { primaryControl: mainFormHandlerContext.primaryControl, secondaryControl: {
43
- data,
44
- logicalName: schema.logicalName,
45
- schema,
46
- refresh,
47
- searchText,
48
- selectedIds,
49
- selectedRecords,
50
- view,
51
- viewId: view.id,
52
- columnFilter,
53
- extraFilter,
54
- } });
16
+ const gridControl = (0, useMainGridCommands_1.useGridControlContext)();
17
+ const associated = (0, mutable_1.useContextSelector)(context_1.GridContext, (state) => state.associated);
18
+ const recordTitle = (0, dataform_1.useRecordTitle)();
19
+ return Object.assign(Object.assign({}, baseHandlerContext), { primaryControl: mainFormHandlerContext.primaryControl, secondaryControl: Object.assign(Object.assign({}, gridControl), { associated: !associated
20
+ ? false
21
+ : {
22
+ id: associated.id,
23
+ logicalName: associated.logicalName,
24
+ name: recordTitle,
25
+ refAttributeName: associated.refAttributeName,
26
+ } }) });
55
27
  }
56
28
  const emptyCommands = [];
57
29
  function useGridCommands() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/app",
3
- "version": "0.0.17-alpha.14",
3
+ "version": "0.0.17-alpha.15",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -39,5 +39,5 @@
39
39
  "react-hook-form": "7.52.2",
40
40
  "yup": "^1.4.0"
41
41
  },
42
- "gitHead": "ff55ee185a483fa8f3eb4acb5e7a628a4513a460"
42
+ "gitHead": "bfd82e4fa1f3abaca7f1c59dc01ee248f2611a1e"
43
43
  }