-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathActions.ts
More file actions
64 lines (57 loc) · 2.08 KB
/
Copy pathActions.ts
File metadata and controls
64 lines (57 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* This file belongs to Hoist, an application development toolkit
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
*
* Copyright © 2026 Extremely Heavy Industries Inc.
*/
import '@xh/hoist/desktop/register';
import {GridModel} from '@xh/hoist/cmp/grid';
import {RecordActionSpec} from '@xh/hoist/data';
import {RestGridModel} from '@xh/hoist/desktop/cmp/rest/RestGridModel';
import {Icon} from '@xh/hoist/icon/Icon';
export const addAction: RecordActionSpec = {
text: 'Add',
icon: Icon.add(),
intent: 'success',
actionFn: ({gridModel}) => getRGM(gridModel).addRecord(),
displayFn: ({gridModel}) => ({hidden: getRGM(gridModel).readonly}),
testId: 'add-action-button'
};
export const editAction: RecordActionSpec = {
text: 'Edit',
icon: Icon.edit(),
intent: 'primary',
recordsRequired: 1,
actionFn: ({record, gridModel}) => getRGM(gridModel).editRecord(record),
displayFn: ({gridModel}) => ({hidden: getRGM(gridModel).readonly}),
testId: 'edit-action-button'
};
export const viewAction: RecordActionSpec = {
text: 'View',
icon: Icon.search(),
recordsRequired: 1,
actionFn: ({record, gridModel}) => getRGM(gridModel).viewRecord(record),
testId: 'view-action-button'
};
export const cloneAction: RecordActionSpec = {
text: 'Clone',
icon: Icon.copy(),
recordsRequired: 1,
actionFn: ({record, gridModel}) => getRGM(gridModel).cloneRecord(record),
displayFn: ({gridModel}) => ({hidden: getRGM(gridModel).readonly}),
testId: 'clone-action-button'
};
export const deleteAction: RecordActionSpec = {
text: 'Delete',
icon: Icon.delete(),
intent: 'danger',
recordsRequired: true,
displayFn: ({gridModel, record}) => ({
hidden: (record && record.id === null) || getRGM(gridModel).readonly // Hide this action if we are acting on a "new" record
}),
actionFn: ({gridModel}) => getRGM(gridModel).confirmDeleteRecords(),
testId: 'delete-action-button'
};
function getRGM(gridModel: GridModel): RestGridModel {
return gridModel.appData.restGridModel as RestGridModel;
}