forked from shesha-io/shesha-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentityCrudActions.tsx
More file actions
106 lines (96 loc) · 3.34 KB
/
entityCrudActions.tsx
File metadata and controls
106 lines (96 loc) · 3.34 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { isEntityMetadata } from '@/interfaces/metadata';
import { useMetadata } from '@/providers';
import { ButtonGroupItemProps, IButtonGroupItem } from '@/providers/buttonGroupConfigurator/models';
import { DynamicItemsEvaluationHook, DynamicRenderingHoc } from '@/providers/dynamicActionsDispatcher/models';
import React, { PropsWithChildren, useMemo } from 'react';
import { FC } from 'react';
import { DynamicActionsProvider } from '../index';
export interface IEntityCrudActionsProps {
}
const EntityTestItems: ButtonGroupItemProps[] = [
{ id: '1', name: 'btn1', label: 'entity action 1', itemType: 'item', itemSubType: 'button', sortOrder: 0, buttonType: 'link' },
{ id: '2', name: 'btn2', label: 'entity action 2', itemType: 'item', itemSubType: 'button', sortOrder: 1 },
];
const useEntityCrudActions: DynamicItemsEvaluationHook = (args) => {
const { metadata } = useMetadata(false) ?? {};
const operations = useMemo<ButtonGroupItemProps[]>(() => {
if (!isEntityMetadata(metadata))
return [];
const result: IButtonGroupItem[] = [
{
id: 'create',
name: `create new`,
label: `Create new`,
itemType: 'item',
itemSubType: 'button',
sortOrder: 0
},
{
id: 'read',
name: `view details`,
label: `View details`,
itemType: 'item',
itemSubType: 'button',
sortOrder: 1
},
{
id: 'update',
name: `edit`,
label: `Edit`,
itemType: 'item',
itemSubType: 'button',
sortOrder: 2
},
{
id: 'delete',
name: `delete`,
label: `Delete`,
itemType: 'item',
itemSubType: 'button',
sortOrder: 3
},
];
return result;
/*
return metadata.properties.map<IButtonGroupItem>(sp => ({
id: sp.path,
name: sp.path,
label: sp.label,
itemSubType: 'button',
itemType: 'item',
sortOrder: 0
}));
*/
/*
return metadata.specifications.map<IButtonGroupItem>(sp => ({
id: sp.name,
name: sp.name,
label: sp.name,
itemSubType: 'button',
itemType: 'item',
sortOrder: 0
}));
*/
}, [args.item, metadata]);
return operations;
};
const entityActionsHoc: DynamicRenderingHoc = (WrappedComponent) => {
return props => {
const testItems = useMemo<ButtonGroupItemProps[]>(() => {
return EntityTestItems;
}, []);
return (<WrappedComponent {...props} items={testItems} />);
};
};
export const EntityCrudActions: FC<PropsWithChildren<IEntityCrudActionsProps>> = ({ children }) => {
return (
<DynamicActionsProvider
id='entity-crud'
name='CRUD Actions'
renderingHoc={entityActionsHoc}
useEvaluator={useEntityCrudActions}
>
{children}
</DynamicActionsProvider>
);
};