@headless-adminapp/app 1.4.43 → 1.4.44
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.
- package/builders/CommandBuilder.d.ts +176 -0
- package/builders/CommandBuilder.js +474 -0
- package/metadata/hooks/useAppStore.d.ts +1 -0
- package/metadata/hooks/useAppStore.js +8 -0
- package/package.json +2 -2
- package/store/ClientAppStore.d.ts +7 -0
- package/store/ClientAppStore.js +30 -0
- package/widget/context.d.ts +2 -0
- package/widget/context.js +5 -0
- package/widget/hooks/index.d.ts +3 -0
- package/widget/hooks/index.js +8 -0
- package/widget/index.d.ts +1 -0
- package/widget/index.js +5 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { EntityFormCommandContext, EntityMainFormCommandItemExperience } from '@headless-adminapp/core/experience/form';
|
|
2
|
+
import { EntityMainGridCommandItemExperience, SubGridCommandItemExperience } from '@headless-adminapp/core/experience/view';
|
|
3
|
+
import { Localized } from '@headless-adminapp/core/types';
|
|
4
|
+
import { Icon } from '@headless-adminapp/icons';
|
|
5
|
+
export declare function localizedLabel<T extends {
|
|
6
|
+
label: string;
|
|
7
|
+
localizedLabels?: Localized<string>;
|
|
8
|
+
}>(language: string, value: T, fallback?: T): string;
|
|
9
|
+
export declare function createLocalizedSelector<T>(stringSet: T, localizedStringSet: Localized<T> | undefined, language: string): <U>(selector: (stringSet: T) => U) => U;
|
|
10
|
+
export declare namespace CommandBuilder {
|
|
11
|
+
namespace View {
|
|
12
|
+
export function createNewRecordCommand({ Icon, text, localizedTexts, }: {
|
|
13
|
+
Icon: Icon;
|
|
14
|
+
text: string;
|
|
15
|
+
localizedTexts?: Record<string, string>;
|
|
16
|
+
}): EntityMainGridCommandItemExperience;
|
|
17
|
+
export function createEditRecordCommand({ Icon, text, localizedTexts, }: {
|
|
18
|
+
Icon: Icon;
|
|
19
|
+
text: string;
|
|
20
|
+
localizedTexts?: Record<string, string>;
|
|
21
|
+
}): EntityMainGridCommandItemExperience;
|
|
22
|
+
interface DeleteRecordCommandStringSet {
|
|
23
|
+
confirmation: {
|
|
24
|
+
title: string | string[];
|
|
25
|
+
text: string | string[];
|
|
26
|
+
buttonCancel: string;
|
|
27
|
+
buttonConfirm: string;
|
|
28
|
+
};
|
|
29
|
+
status: {
|
|
30
|
+
deleting: string | string[];
|
|
31
|
+
};
|
|
32
|
+
successNotification: {
|
|
33
|
+
title: string | string[];
|
|
34
|
+
text: string | string[];
|
|
35
|
+
};
|
|
36
|
+
errorNotification: {
|
|
37
|
+
title: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export const defaultDeleteRecordStringSet: DeleteRecordCommandStringSet;
|
|
41
|
+
export function createDeleteRecordCommand({ Icon, localizedText, text, stringSet, localizedStringSet, }: {
|
|
42
|
+
Icon: Icon;
|
|
43
|
+
text: string;
|
|
44
|
+
localizedText?: Record<string, string>;
|
|
45
|
+
stringSet?: DeleteRecordCommandStringSet;
|
|
46
|
+
localizedStringSet?: Localized<DeleteRecordCommandStringSet>;
|
|
47
|
+
}): EntityMainGridCommandItemExperience;
|
|
48
|
+
export function createRefreshCommand({ Icon, localizedTexts, text, }: {
|
|
49
|
+
Icon: Icon;
|
|
50
|
+
text: string;
|
|
51
|
+
localizedTexts?: Record<string, string>;
|
|
52
|
+
}): EntityMainGridCommandItemExperience;
|
|
53
|
+
export function createExportCommand({ button, csv, excel, }: {
|
|
54
|
+
button: {
|
|
55
|
+
Icon: Icon;
|
|
56
|
+
text: string;
|
|
57
|
+
localizedTexts?: Record<string, string>;
|
|
58
|
+
};
|
|
59
|
+
excel: {
|
|
60
|
+
Icon: Icon;
|
|
61
|
+
text: string;
|
|
62
|
+
localizedTexts?: Record<string, string>;
|
|
63
|
+
};
|
|
64
|
+
csv: {
|
|
65
|
+
Icon: Icon;
|
|
66
|
+
text: string;
|
|
67
|
+
localizedTexts?: Record<string, string>;
|
|
68
|
+
};
|
|
69
|
+
}): EntityMainGridCommandItemExperience;
|
|
70
|
+
export {};
|
|
71
|
+
}
|
|
72
|
+
namespace Form {
|
|
73
|
+
export function createSaveCommand({ Icon, text, localizedTexts, }: {
|
|
74
|
+
Icon: Icon;
|
|
75
|
+
text: string;
|
|
76
|
+
localizedTexts?: Record<string, string>;
|
|
77
|
+
}): EntityMainFormCommandItemExperience;
|
|
78
|
+
export function createSaveAndCloseCommand({ Icon, text, localizedTexts, }: {
|
|
79
|
+
Icon: Icon;
|
|
80
|
+
text: string;
|
|
81
|
+
localizedTexts?: Record<string, string>;
|
|
82
|
+
}): EntityMainFormCommandItemExperience;
|
|
83
|
+
interface DeleteRecordCommandStringSet {
|
|
84
|
+
confirmation: {
|
|
85
|
+
title: string;
|
|
86
|
+
text: string;
|
|
87
|
+
buttonCancel: string;
|
|
88
|
+
buttonConfirm: string;
|
|
89
|
+
};
|
|
90
|
+
status: {
|
|
91
|
+
deleting: string;
|
|
92
|
+
};
|
|
93
|
+
successNotification: {
|
|
94
|
+
title: string;
|
|
95
|
+
text: string;
|
|
96
|
+
};
|
|
97
|
+
errorNotification: {
|
|
98
|
+
title: string;
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
export const defaultDeleteRecordStringSet: DeleteRecordCommandStringSet;
|
|
102
|
+
export function createDeleteCommand({ Icon, text, localizedTexts, stringSet, }: {
|
|
103
|
+
Icon: Icon;
|
|
104
|
+
text: string;
|
|
105
|
+
localizedTexts?: Record<string, string>;
|
|
106
|
+
stringSet: DeleteRecordCommandStringSet | ((context: EntityFormCommandContext) => DeleteRecordCommandStringSet);
|
|
107
|
+
}): EntityMainFormCommandItemExperience;
|
|
108
|
+
export function createRefreshCommand({ Icon, text, localizedTexts, }: {
|
|
109
|
+
Icon: Icon;
|
|
110
|
+
text: string;
|
|
111
|
+
localizedTexts?: Record<string, string>;
|
|
112
|
+
}): EntityMainFormCommandItemExperience;
|
|
113
|
+
export {};
|
|
114
|
+
}
|
|
115
|
+
namespace Subgrid {
|
|
116
|
+
export function createNewRecordCommand({ Icon, text, localizedTexts, }: {
|
|
117
|
+
Icon: Icon;
|
|
118
|
+
text: string;
|
|
119
|
+
localizedTexts?: Record<string, string>;
|
|
120
|
+
}): SubGridCommandItemExperience;
|
|
121
|
+
export function createEditRecordCommand({ Icon, text, localizedTexts, }: {
|
|
122
|
+
Icon: Icon;
|
|
123
|
+
text: string;
|
|
124
|
+
localizedTexts?: Record<string, string>;
|
|
125
|
+
}): SubGridCommandItemExperience;
|
|
126
|
+
interface DeleteRecordCommandStringSet {
|
|
127
|
+
confirmation: {
|
|
128
|
+
title: string | string[];
|
|
129
|
+
text: string | string[];
|
|
130
|
+
buttonCancel: string;
|
|
131
|
+
buttonConfirm: string;
|
|
132
|
+
};
|
|
133
|
+
status: {
|
|
134
|
+
deleting: string | string[];
|
|
135
|
+
};
|
|
136
|
+
successNotification: {
|
|
137
|
+
title: string | string[];
|
|
138
|
+
text: string | string[];
|
|
139
|
+
};
|
|
140
|
+
errorNotification: {
|
|
141
|
+
title: string;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
export const defaultDeleteRecordStringSet: DeleteRecordCommandStringSet;
|
|
145
|
+
export function createDeleteRecordCommand({ Icon, localizedText, text, stringSet, localizedStringSet, }: {
|
|
146
|
+
Icon: Icon;
|
|
147
|
+
text: string;
|
|
148
|
+
localizedText?: Record<string, string>;
|
|
149
|
+
stringSet?: DeleteRecordCommandStringSet;
|
|
150
|
+
localizedStringSet?: Localized<DeleteRecordCommandStringSet>;
|
|
151
|
+
}): SubGridCommandItemExperience;
|
|
152
|
+
export function createRefreshCommand({ Icon, localizedTexts, text, }: {
|
|
153
|
+
Icon: Icon;
|
|
154
|
+
text: string;
|
|
155
|
+
localizedTexts?: Record<string, string>;
|
|
156
|
+
}): SubGridCommandItemExperience;
|
|
157
|
+
export function createExportCommand({ button, csv, excel, }: {
|
|
158
|
+
button: {
|
|
159
|
+
Icon: Icon;
|
|
160
|
+
text: string;
|
|
161
|
+
localizedTexts?: Record<string, string>;
|
|
162
|
+
};
|
|
163
|
+
excel: {
|
|
164
|
+
Icon: Icon;
|
|
165
|
+
text: string;
|
|
166
|
+
localizedTexts?: Record<string, string>;
|
|
167
|
+
};
|
|
168
|
+
csv: {
|
|
169
|
+
Icon: Icon;
|
|
170
|
+
text: string;
|
|
171
|
+
localizedTexts?: Record<string, string>;
|
|
172
|
+
};
|
|
173
|
+
}): SubGridCommandItemExperience;
|
|
174
|
+
export {};
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.CommandBuilder = void 0;
|
|
13
|
+
exports.localizedLabel = localizedLabel;
|
|
14
|
+
exports.createLocalizedSelector = createLocalizedSelector;
|
|
15
|
+
function localizedLabel(language, value, fallback) {
|
|
16
|
+
var _a, _b, _c, _d, _e;
|
|
17
|
+
return ((_e = (_d = (_b = (_a = value.localizedLabels) === null || _a === void 0 ? void 0 : _a[language]) !== null && _b !== void 0 ? _b : (_c = fallback === null || fallback === void 0 ? void 0 : fallback.localizedLabels) === null || _c === void 0 ? void 0 : _c[language]) !== null && _d !== void 0 ? _d : value.label) !== null && _e !== void 0 ? _e : fallback === null || fallback === void 0 ? void 0 : fallback.label);
|
|
18
|
+
}
|
|
19
|
+
function createLocalizedSelector(stringSet, localizedStringSet, language) {
|
|
20
|
+
return function selectLocalized(selector) {
|
|
21
|
+
if (localizedStringSet && localizedStringSet[language]) {
|
|
22
|
+
return selector(localizedStringSet[language]);
|
|
23
|
+
}
|
|
24
|
+
return selector(stringSet);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var CommandBuilder;
|
|
28
|
+
(function (CommandBuilder) {
|
|
29
|
+
let View;
|
|
30
|
+
(function (View) {
|
|
31
|
+
function createNewRecordCommand({ Icon, text, localizedTexts, }) {
|
|
32
|
+
return {
|
|
33
|
+
type: 'button',
|
|
34
|
+
Icon,
|
|
35
|
+
text,
|
|
36
|
+
localizedText: localizedTexts,
|
|
37
|
+
onClick: (context) => {
|
|
38
|
+
console.log('New record', context);
|
|
39
|
+
},
|
|
40
|
+
hidden: (context) => {
|
|
41
|
+
console.log(context);
|
|
42
|
+
// TODO: Implement logic to hide the button
|
|
43
|
+
return false;
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
View.createNewRecordCommand = createNewRecordCommand;
|
|
48
|
+
function createEditRecordCommand({ Icon, text, localizedTexts, }) {
|
|
49
|
+
return {
|
|
50
|
+
type: 'button',
|
|
51
|
+
Icon,
|
|
52
|
+
text,
|
|
53
|
+
localizedText: localizedTexts,
|
|
54
|
+
isContextMenu: true,
|
|
55
|
+
onClick: (context) => {
|
|
56
|
+
console.log('Edit record', context);
|
|
57
|
+
},
|
|
58
|
+
hidden: (context) => context.primaryControl.selectedIds.length !== 1, // TODO: check permissions
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
View.createEditRecordCommand = createEditRecordCommand;
|
|
62
|
+
function plurialize(count, singular, plural) {
|
|
63
|
+
if (Array.isArray(singular)) {
|
|
64
|
+
plural = singular[1];
|
|
65
|
+
singular = singular[0];
|
|
66
|
+
}
|
|
67
|
+
let msg = count === 1 ? singular : plural !== null && plural !== void 0 ? plural : singular;
|
|
68
|
+
msg = msg.replace('{count}', count.toString());
|
|
69
|
+
return msg;
|
|
70
|
+
}
|
|
71
|
+
View.defaultDeleteRecordStringSet = {
|
|
72
|
+
confirmation: {
|
|
73
|
+
text: [
|
|
74
|
+
'Are you sure you want to delete this record?',
|
|
75
|
+
'Are you sure you want to delete selected records?',
|
|
76
|
+
],
|
|
77
|
+
title: ['Delete record', 'Delete records'],
|
|
78
|
+
buttonConfirm: 'Delete',
|
|
79
|
+
buttonCancel: 'Cancel',
|
|
80
|
+
},
|
|
81
|
+
status: {
|
|
82
|
+
deleting: ['Deleting record', 'Deleting records'],
|
|
83
|
+
},
|
|
84
|
+
successNotification: {
|
|
85
|
+
title: ['Record deleted', 'Records deleted'],
|
|
86
|
+
text: ['Record deleted successfully', 'Records deleted successfully'],
|
|
87
|
+
},
|
|
88
|
+
errorNotification: {
|
|
89
|
+
title: 'Error',
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
function createDeleteRecordCommand({ Icon, localizedText, text, stringSet = View.defaultDeleteRecordStringSet, localizedStringSet, }) {
|
|
93
|
+
return {
|
|
94
|
+
type: 'button',
|
|
95
|
+
Icon,
|
|
96
|
+
text,
|
|
97
|
+
localizedText,
|
|
98
|
+
danger: true,
|
|
99
|
+
isContextMenu: true,
|
|
100
|
+
hidden: [(context) => context.primaryControl.selectedIds.length === 0], // TODO: check permissions
|
|
101
|
+
onClick: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
const recordIds = context.primaryControl.selectedIds;
|
|
103
|
+
if (!recordIds.length) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const localizeSelector = createLocalizedSelector(stringSet, localizedStringSet, context.locale.language);
|
|
107
|
+
try {
|
|
108
|
+
const confirmResult = yield context.utility.openConfirmDialog({
|
|
109
|
+
title: plurialize(recordIds.length, localizeSelector((s) => s.confirmation.title)),
|
|
110
|
+
text: plurialize(recordIds.length, localizeSelector((s) => s.confirmation.text)),
|
|
111
|
+
cancelButtonLabel: localizeSelector((s) => s.confirmation.buttonCancel),
|
|
112
|
+
confirmButtonLabel: localizeSelector((s) => s.confirmation.buttonConfirm),
|
|
113
|
+
});
|
|
114
|
+
if (!(confirmResult === null || confirmResult === void 0 ? void 0 : confirmResult.confirmed)) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
context.utility.showProgressIndicator(plurialize(recordIds.length, localizeSelector((s) => s.status.deleting)) + '...');
|
|
118
|
+
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
119
|
+
context.utility.showNotification({
|
|
120
|
+
title: plurialize(recordIds.length, localizeSelector((s) => s.successNotification.title)),
|
|
121
|
+
text: plurialize(recordIds.length, localizeSelector((s) => s.successNotification.text)),
|
|
122
|
+
type: 'success',
|
|
123
|
+
});
|
|
124
|
+
context.primaryControl.refresh();
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
context.utility.showNotification({
|
|
128
|
+
title: localizeSelector((s) => s.errorNotification.title),
|
|
129
|
+
text: error.message,
|
|
130
|
+
type: 'error',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
context.utility.hideProgressIndicator();
|
|
135
|
+
}
|
|
136
|
+
}),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
View.createDeleteRecordCommand = createDeleteRecordCommand;
|
|
140
|
+
function createRefreshCommand({ Icon, localizedTexts, text, }) {
|
|
141
|
+
return {
|
|
142
|
+
type: 'button',
|
|
143
|
+
Icon,
|
|
144
|
+
text,
|
|
145
|
+
localizedText: localizedTexts,
|
|
146
|
+
onClick: (context) => {
|
|
147
|
+
context.primaryControl.refresh();
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
View.createRefreshCommand = createRefreshCommand;
|
|
152
|
+
function createExportCommand({ button, csv, excel, }) {
|
|
153
|
+
return {
|
|
154
|
+
type: 'menu',
|
|
155
|
+
Icon: button.Icon,
|
|
156
|
+
text: button.text,
|
|
157
|
+
localizedTexts: button.localizedTexts,
|
|
158
|
+
items: [
|
|
159
|
+
[
|
|
160
|
+
{
|
|
161
|
+
Icon: excel.Icon,
|
|
162
|
+
text: excel.text,
|
|
163
|
+
localizedTexts: excel.localizedTexts,
|
|
164
|
+
onClick: (context) => {
|
|
165
|
+
console.log('Export to Excel', context);
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
{
|
|
169
|
+
Icon: csv.Icon,
|
|
170
|
+
text: csv.text,
|
|
171
|
+
localizedTexts: csv.localizedTexts,
|
|
172
|
+
onClick: (context) => {
|
|
173
|
+
console.log('Export to CSV', context);
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
],
|
|
177
|
+
],
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
View.createExportCommand = createExportCommand;
|
|
181
|
+
})(View = CommandBuilder.View || (CommandBuilder.View = {}));
|
|
182
|
+
let Form;
|
|
183
|
+
(function (Form) {
|
|
184
|
+
function createSaveCommand({ Icon, text, localizedTexts, }) {
|
|
185
|
+
return {
|
|
186
|
+
type: 'button',
|
|
187
|
+
Icon,
|
|
188
|
+
text,
|
|
189
|
+
localizedText: localizedTexts,
|
|
190
|
+
isQuickAction: true,
|
|
191
|
+
onClick: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
yield context.primaryControl.save('save');
|
|
193
|
+
}),
|
|
194
|
+
hidden: (context) => {
|
|
195
|
+
if (context.primaryControl.readonly) {
|
|
196
|
+
return true;
|
|
197
|
+
}
|
|
198
|
+
return false;
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
Form.createSaveCommand = createSaveCommand;
|
|
203
|
+
function createSaveAndCloseCommand({ Icon, text, localizedTexts, }) {
|
|
204
|
+
return {
|
|
205
|
+
type: 'button',
|
|
206
|
+
Icon,
|
|
207
|
+
text,
|
|
208
|
+
localizedText: localizedTexts,
|
|
209
|
+
onClick: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
yield context.primaryControl.save('saveandclose');
|
|
211
|
+
}),
|
|
212
|
+
hidden: (context) => {
|
|
213
|
+
if (context.primaryControl.readonly) {
|
|
214
|
+
return true;
|
|
215
|
+
}
|
|
216
|
+
return false;
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
Form.createSaveAndCloseCommand = createSaveAndCloseCommand;
|
|
221
|
+
Form.defaultDeleteRecordStringSet = {
|
|
222
|
+
confirmation: {
|
|
223
|
+
text: 'Are you sure you want to delete this record?',
|
|
224
|
+
title: 'Delete record',
|
|
225
|
+
buttonConfirm: 'Delete',
|
|
226
|
+
buttonCancel: 'Cancel',
|
|
227
|
+
},
|
|
228
|
+
status: {
|
|
229
|
+
deleting: 'Deleting record',
|
|
230
|
+
},
|
|
231
|
+
successNotification: {
|
|
232
|
+
title: 'Record deleted',
|
|
233
|
+
text: 'Record deleted successfully',
|
|
234
|
+
},
|
|
235
|
+
errorNotification: {
|
|
236
|
+
title: 'Error',
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
function createDeleteCommand({ Icon, text, localizedTexts, stringSet, }) {
|
|
240
|
+
return {
|
|
241
|
+
Icon: Icon,
|
|
242
|
+
type: 'button',
|
|
243
|
+
text,
|
|
244
|
+
localizedText: localizedTexts,
|
|
245
|
+
danger: true,
|
|
246
|
+
hidden: (context) => {
|
|
247
|
+
var _a;
|
|
248
|
+
if (!context.primaryControl.recordId) {
|
|
249
|
+
return true;
|
|
250
|
+
}
|
|
251
|
+
if ((_a = context.primaryControl.schema.restrictions) === null || _a === void 0 ? void 0 : _a.disableDelete) {
|
|
252
|
+
return true;
|
|
253
|
+
}
|
|
254
|
+
return false;
|
|
255
|
+
},
|
|
256
|
+
onClick: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
const recordId = context.primaryControl.recordId;
|
|
258
|
+
if (!recordId) {
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (typeof stringSet === 'function') {
|
|
262
|
+
stringSet = stringSet(context);
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
const confirmResult = yield context.utility.openConfirmDialog({
|
|
266
|
+
title: stringSet.confirmation.title,
|
|
267
|
+
text: stringSet.confirmation.text,
|
|
268
|
+
cancelButtonLabel: stringSet.confirmation.buttonCancel,
|
|
269
|
+
confirmButtonLabel: stringSet.confirmation.buttonConfirm,
|
|
270
|
+
});
|
|
271
|
+
if (!(confirmResult === null || confirmResult === void 0 ? void 0 : confirmResult.confirmed)) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
context.utility.showProgressIndicator(stringSet.status.deleting + '...');
|
|
275
|
+
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
276
|
+
// await context.dataService.deleteRecord(
|
|
277
|
+
// context.primaryControl.logicalName,
|
|
278
|
+
// recordId
|
|
279
|
+
// );
|
|
280
|
+
context.utility.showNotification({
|
|
281
|
+
title: stringSet.successNotification.title,
|
|
282
|
+
text: stringSet.successNotification.text,
|
|
283
|
+
type: 'success',
|
|
284
|
+
});
|
|
285
|
+
// context.primaryControl.close();
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
context.utility.showNotification({
|
|
289
|
+
title: stringSet.errorNotification.title,
|
|
290
|
+
text: error.message,
|
|
291
|
+
type: 'error',
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
finally {
|
|
295
|
+
context.utility.hideProgressIndicator();
|
|
296
|
+
}
|
|
297
|
+
}),
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
Form.createDeleteCommand = createDeleteCommand;
|
|
301
|
+
function createRefreshCommand({ Icon, text, localizedTexts, }) {
|
|
302
|
+
return {
|
|
303
|
+
Icon,
|
|
304
|
+
type: 'button',
|
|
305
|
+
text,
|
|
306
|
+
localizedText: localizedTexts,
|
|
307
|
+
onClick: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
308
|
+
yield context.primaryControl.refresh();
|
|
309
|
+
}),
|
|
310
|
+
hidden: (context) => !context.primaryControl.recordId,
|
|
311
|
+
};
|
|
312
|
+
}
|
|
313
|
+
Form.createRefreshCommand = createRefreshCommand;
|
|
314
|
+
})(Form = CommandBuilder.Form || (CommandBuilder.Form = {}));
|
|
315
|
+
let Subgrid;
|
|
316
|
+
(function (Subgrid) {
|
|
317
|
+
function createNewRecordCommand({ Icon, text, localizedTexts, }) {
|
|
318
|
+
return {
|
|
319
|
+
type: 'button',
|
|
320
|
+
Icon,
|
|
321
|
+
text,
|
|
322
|
+
localizedText: localizedTexts,
|
|
323
|
+
onClick: (context) => {
|
|
324
|
+
console.log('New record', context);
|
|
325
|
+
},
|
|
326
|
+
hidden: (context) => {
|
|
327
|
+
console.log(context);
|
|
328
|
+
// TODO: Implement logic to hide the button
|
|
329
|
+
return false;
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
Subgrid.createNewRecordCommand = createNewRecordCommand;
|
|
334
|
+
function createEditRecordCommand({ Icon, text, localizedTexts, }) {
|
|
335
|
+
return {
|
|
336
|
+
type: 'button',
|
|
337
|
+
Icon,
|
|
338
|
+
text,
|
|
339
|
+
localizedText: localizedTexts,
|
|
340
|
+
isContextMenu: true,
|
|
341
|
+
onClick: (context) => {
|
|
342
|
+
console.log('Edit record', context);
|
|
343
|
+
},
|
|
344
|
+
// hidden: (context) => context.secondaryControl.selectedIds.length !== 1, // TODO: check permissions
|
|
345
|
+
hidden: (context) => {
|
|
346
|
+
console.log('temp.', context);
|
|
347
|
+
return context.secondaryControl.selectedIds.length !== 1;
|
|
348
|
+
},
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
Subgrid.createEditRecordCommand = createEditRecordCommand;
|
|
352
|
+
function plurialize(count, singular, plural) {
|
|
353
|
+
if (Array.isArray(singular)) {
|
|
354
|
+
plural = singular[1];
|
|
355
|
+
singular = singular[0];
|
|
356
|
+
}
|
|
357
|
+
let msg = count === 1 ? singular : plural !== null && plural !== void 0 ? plural : singular;
|
|
358
|
+
msg = msg.replace('{count}', count.toString());
|
|
359
|
+
return msg;
|
|
360
|
+
}
|
|
361
|
+
Subgrid.defaultDeleteRecordStringSet = {
|
|
362
|
+
confirmation: {
|
|
363
|
+
text: [
|
|
364
|
+
'Are you sure you want to delete this record?',
|
|
365
|
+
'Are you sure you want to delete selected records?',
|
|
366
|
+
],
|
|
367
|
+
title: ['Delete record', 'Delete records'],
|
|
368
|
+
buttonConfirm: 'Delete',
|
|
369
|
+
buttonCancel: 'Cancel',
|
|
370
|
+
},
|
|
371
|
+
status: {
|
|
372
|
+
deleting: ['Deleting record', 'Deleting records'],
|
|
373
|
+
},
|
|
374
|
+
successNotification: {
|
|
375
|
+
title: ['Record deleted', 'Records deleted'],
|
|
376
|
+
text: ['Record deleted successfully', 'Records deleted successfully'],
|
|
377
|
+
},
|
|
378
|
+
errorNotification: {
|
|
379
|
+
title: 'Error',
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
function createDeleteRecordCommand({ Icon, localizedText, text, stringSet = Subgrid.defaultDeleteRecordStringSet, localizedStringSet, }) {
|
|
383
|
+
return {
|
|
384
|
+
type: 'button',
|
|
385
|
+
Icon,
|
|
386
|
+
text,
|
|
387
|
+
localizedText,
|
|
388
|
+
danger: true,
|
|
389
|
+
isContextMenu: true,
|
|
390
|
+
hidden: [
|
|
391
|
+
(context) => context.secondaryControl.selectedIds.length === 0,
|
|
392
|
+
], // TODO: check permissions
|
|
393
|
+
onClick: (context) => __awaiter(this, void 0, void 0, function* () {
|
|
394
|
+
const recordIds = context.secondaryControl.selectedIds;
|
|
395
|
+
if (!recordIds.length) {
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const localizeSelector = createLocalizedSelector(stringSet, localizedStringSet, context.locale.language);
|
|
399
|
+
try {
|
|
400
|
+
const confirmResult = yield context.utility.openConfirmDialog({
|
|
401
|
+
title: plurialize(recordIds.length, localizeSelector((s) => s.confirmation.title)),
|
|
402
|
+
text: plurialize(recordIds.length, localizeSelector((s) => s.confirmation.text)),
|
|
403
|
+
cancelButtonLabel: localizeSelector((s) => s.confirmation.buttonCancel),
|
|
404
|
+
confirmButtonLabel: localizeSelector((s) => s.confirmation.buttonConfirm),
|
|
405
|
+
});
|
|
406
|
+
if (!(confirmResult === null || confirmResult === void 0 ? void 0 : confirmResult.confirmed)) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
context.utility.showProgressIndicator(plurialize(recordIds.length, localizeSelector((s) => s.status.deleting)) + '...');
|
|
410
|
+
yield new Promise((resolve) => setTimeout(resolve, 2000));
|
|
411
|
+
context.utility.showNotification({
|
|
412
|
+
title: plurialize(recordIds.length, localizeSelector((s) => s.successNotification.title)),
|
|
413
|
+
text: plurialize(recordIds.length, localizeSelector((s) => s.successNotification.text)),
|
|
414
|
+
type: 'success',
|
|
415
|
+
});
|
|
416
|
+
yield context.primaryControl.refresh();
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
context.utility.showNotification({
|
|
420
|
+
title: localizeSelector((s) => s.errorNotification.title),
|
|
421
|
+
text: error.message,
|
|
422
|
+
type: 'error',
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
finally {
|
|
426
|
+
context.utility.hideProgressIndicator();
|
|
427
|
+
}
|
|
428
|
+
}),
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
Subgrid.createDeleteRecordCommand = createDeleteRecordCommand;
|
|
432
|
+
function createRefreshCommand({ Icon, localizedTexts, text, }) {
|
|
433
|
+
return {
|
|
434
|
+
type: 'button',
|
|
435
|
+
Icon,
|
|
436
|
+
text,
|
|
437
|
+
localizedText: localizedTexts,
|
|
438
|
+
onClick: (context) => {
|
|
439
|
+
context.secondaryControl.refresh();
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
Subgrid.createRefreshCommand = createRefreshCommand;
|
|
444
|
+
function createExportCommand({ button, csv, excel, }) {
|
|
445
|
+
return {
|
|
446
|
+
type: 'menu',
|
|
447
|
+
Icon: button.Icon,
|
|
448
|
+
text: button.text,
|
|
449
|
+
localizedTexts: button.localizedTexts,
|
|
450
|
+
items: [
|
|
451
|
+
[
|
|
452
|
+
{
|
|
453
|
+
Icon: excel.Icon,
|
|
454
|
+
text: excel.text,
|
|
455
|
+
localizedTexts: excel.localizedTexts,
|
|
456
|
+
onClick: (context) => {
|
|
457
|
+
console.log('Export to Excel', context);
|
|
458
|
+
},
|
|
459
|
+
},
|
|
460
|
+
{
|
|
461
|
+
Icon: csv.Icon,
|
|
462
|
+
text: csv.text,
|
|
463
|
+
localizedTexts: csv.localizedTexts,
|
|
464
|
+
onClick: (context) => {
|
|
465
|
+
console.log('Export to CSV', context);
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
],
|
|
469
|
+
],
|
|
470
|
+
};
|
|
471
|
+
}
|
|
472
|
+
Subgrid.createExportCommand = createExportCommand;
|
|
473
|
+
})(Subgrid = CommandBuilder.Subgrid || (CommandBuilder.Subgrid = {}));
|
|
474
|
+
})(CommandBuilder || (exports.CommandBuilder = CommandBuilder = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function useAppStore(): import("@headless-adminapp/core/store").IClientAppStore;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAppStore = useAppStore;
|
|
4
|
+
const context_1 = require("../../mutable/context");
|
|
5
|
+
const context_2 = require("../context");
|
|
6
|
+
function useAppStore() {
|
|
7
|
+
return (0, context_1.useContextSelector)(context_2.MetadataContext, (state) => state.appStore);
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/app",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.44",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"uuid": "11.0.3",
|
|
39
39
|
"yup": "^1.4.0"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "b61cc3933fdf461afd3e59859ea1a89469d4523a"
|
|
42
42
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { AppExperience } from '@headless-adminapp/core/experience/app';
|
|
2
|
+
import { IClientAppStore } from '@headless-adminapp/core/store';
|
|
3
|
+
export declare class ClientAppStore implements IClientAppStore {
|
|
4
|
+
private apps;
|
|
5
|
+
register(app: AppExperience): void;
|
|
6
|
+
getApp(id: string): Promise<AppExperience>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ClientAppStore = void 0;
|
|
13
|
+
class ClientAppStore {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.apps = {};
|
|
16
|
+
}
|
|
17
|
+
register(app) {
|
|
18
|
+
this.apps[app.id] = app;
|
|
19
|
+
}
|
|
20
|
+
getApp(id) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const app = this.apps[id];
|
|
23
|
+
if (!app) {
|
|
24
|
+
throw new Error(`App Experience for ${id} not found`);
|
|
25
|
+
}
|
|
26
|
+
return app;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.ClientAppStore = ClientAppStore;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useWidgetState = useWidgetState;
|
|
4
|
+
const mutable_1 = require("../../mutable");
|
|
5
|
+
const context_1 = require("../context");
|
|
6
|
+
function useWidgetState() {
|
|
7
|
+
return (0, mutable_1.useContextSelector)(context_1.WidgetContext, (state) => state);
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WidgetContext } from './context';
|
package/widget/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WidgetContext = void 0;
|
|
4
|
+
var context_1 = require("./context");
|
|
5
|
+
Object.defineProperty(exports, "WidgetContext", { enumerable: true, get: function () { return context_1.WidgetContext; } });
|