-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathcreateActionList.ts
More file actions
94 lines (74 loc) · 2.39 KB
/
createActionList.ts
File metadata and controls
94 lines (74 loc) · 2.39 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
import { createMemo, createEffect } from 'solid-js';
import Fuse from 'fuse.js';
import { useStore } from './StoreContext';
import { checkActionAllowed, getParentAction, getActiveParentAction } from './actionUtils/actionUtils';
import { WrappedAction } from './types';
export function createActionList() {
const [state] = useStore();
const actionsList = createMemo(() => {
return Object.values(state.actions);
});
return actionsList;
}
export function createNestedActionList() {
const actionsList = createActionList();
const [state] = useStore();
function nestedActionFilter(action: WrappedAction) {
const parent = getParentAction(action, state.actions);
const { activeId, isRoot } = getActiveParentAction(state.activeParentActionIdList);
const showAtRoot = isRoot && !parent?.isolateChildren;
const isActiveChild = action.parentActionId === activeId;
const isAllowed = showAtRoot || isActiveChild;
return isAllowed;
}
const nestedActionsList = createMemo(() => {
const nestedActionsList = actionsList().filter(nestedActionFilter);
return nestedActionsList;
});
return nestedActionsList;
}
export function createConditionalActionList() {
const [state] = useStore();
const nestedActionsList = createNestedActionList();
function conditionalActionFilter(action: WrappedAction) {
const isAllowed = checkActionAllowed(action, state.actionsContext);
return isAllowed;
}
const conditionalActionList = createMemo(() => {
const conditionalActionList = nestedActionsList().filter(conditionalActionFilter);
return conditionalActionList;
});
return conditionalActionList;
}
export function createSearchResultList() {
const [state] = useStore();
const conditionalActionList = createConditionalActionList();
const fuse = new Fuse(conditionalActionList(), {
keys: [
{
name: 'title',
weight: 1,
},
{
name: 'subtitle',
weight: 0.7,
},
{
name: 'keywords',
weight: 0.5,
},
],
});
const resultsList = createMemo(() => {
if (state.searchText.length === 0) {
return conditionalActionList();
}
const searchResults = fuse.search(state.searchText);
const resultsList = searchResults.map((result) => result.item);
return resultsList;
});
createEffect(() => {
fuse.setCollection(conditionalActionList());
});
return resultsList;
}