-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathNotes.tsx
More file actions
229 lines (217 loc) · 6.26 KB
/
Notes.tsx
File metadata and controls
229 lines (217 loc) · 6.26 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
import React, { FunctionComponent } from 'react';
import { graphql } from 'react-relay';
import { NotesLines_data$data } from '@components/analyses/__generated__/NotesLines_data.graphql';
import { NotesLinesPaginationQuery, NotesLinesPaginationQuery$variables } from '@components/analyses/__generated__/NotesLinesPaginationQuery.graphql';
import Security from '../../../utils/Security';
import { KNOWLEDGE_KNPARTICIPATE, KNOWLEDGE_KNUPDATE } from '../../../utils/hooks/useGranted';
import useAuth from '../../../utils/hooks/useAuth';
import { usePaginationLocalStorage } from '../../../utils/hooks/useLocalStorage';
import useQueryLoading from '../../../utils/hooks/useQueryLoading';
import NoteCreation from './notes/NoteCreation';
import { emptyFilterGroup, useBuildEntityTypeBasedFilterContext, useGetDefaultFilterObject } from '../../../utils/filters/filtersUtils';
import { useFormatter } from '../../../components/i18n';
import Breadcrumbs from '../../../components/Breadcrumbs';
import DataTable from '../../../components/dataGrid/DataTable';
import { DataTableProps } from '../../../components/dataGrid/dataTableTypes';
import { UsePreloadedPaginationFragment } from '../../../utils/hooks/usePreloadedPaginationFragment';
import useConnectedDocumentModifier from '../../../utils/hooks/useConnectedDocumentModifier';
import { useEntityLabelResolver } from '../../../utils/hooks/useEntityLabel';
const LOCAL_STORAGE_KEY = 'notes';
const notesLineFragment = graphql`
fragment NotesLine_node on Note {
id
entity_type
attribute_abstract
content
created
note_types
likelihood
confidence
draftVersion {
draft_id
draft_operation
}
createdBy {
... on Identity {
id
name
entity_type
}
}
objectMarking {
id
definition_type
definition
x_opencti_order
x_opencti_color
}
objectLabel {
id
value
color
}
creators {
id
name
}
status {
id
order
template {
name
color
}
}
workflowEnabled
}
`;
const notesLinesQuery = graphql`
query NotesLinesPaginationQuery(
$search: String
$count: Int!
$cursor: ID
$orderBy: NotesOrdering
$orderMode: OrderingMode
$filters: FilterGroup
) {
...NotesLines_data
@arguments(
search: $search
count: $count
cursor: $cursor
orderBy: $orderBy
orderMode: $orderMode
filters: $filters
)
}
`;
const notesLinesFragment = graphql`
fragment NotesLines_data on Query
@argumentDefinitions(
search: { type: "String" }
count: { type: "Int", defaultValue: 25 }
cursor: { type: "ID" }
orderBy: { type: "NotesOrdering", defaultValue: created }
orderMode: { type: "OrderingMode", defaultValue: desc }
filters: { type: "FilterGroup" }
)
@refetchable(queryName: "NotesLinesRefetchQuery") {
notes(
search: $search
first: $count
after: $cursor
orderBy: $orderBy
orderMode: $orderMode
filters: $filters
) @connection(key: "Pagination_notes") {
edges {
node {
id
attribute_abstract
content
created
createdBy {
... on Identity {
id
name
entity_type
}
}
objectMarking {
id
definition_type
definition
x_opencti_order
x_opencti_color
}
...NotesLine_node
}
}
pageInfo {
endCursor
hasNextPage
globalCount
}
}
}
`;
const Notes: FunctionComponent = () => {
const { t_i18n } = useFormatter();
const entityLabel = useEntityLabelResolver();
const { setTitle } = useConnectedDocumentModifier();
setTitle(t_i18n('Notes | Analyses'));
const {
platformModuleHelpers: { isRuntimeFieldEnable },
} = useAuth();
const initialValues = {
searchTerm: '',
sortBy: 'created',
orderAsc: false,
openExports: false,
filters: {
...emptyFilterGroup,
filters: useGetDefaultFilterObject(['note_types'], ['Note']),
},
};
const {
viewStorage,
helpers: storageHelpers,
paginationOptions,
} = usePaginationLocalStorage<NotesLinesPaginationQuery$variables>(
LOCAL_STORAGE_KEY,
initialValues,
);
const {
filters,
} = viewStorage;
const contextFilters = useBuildEntityTypeBasedFilterContext('Note', filters);
const queryPaginationOptions = {
...paginationOptions,
filters: contextFilters,
} as unknown as NotesLinesPaginationQuery$variables;
const queryRef = useQueryLoading<NotesLinesPaginationQuery>(
notesLinesQuery,
queryPaginationOptions,
);
const isRuntimeSort = isRuntimeFieldEnable() ?? false;
const dataColumns: DataTableProps['dataColumns'] = {
attribute_abstract: {},
note_types: {},
createdBy: { isSortable: isRuntimeSort },
creator: { isSortable: isRuntimeSort },
objectLabel: {},
created: { percentWidth: 10 },
x_opencti_workflow_id: {},
objectMarking: { isSortable: isRuntimeSort },
};
const preloadedPaginationProps = {
linesQuery: notesLinesQuery,
linesFragment: notesLinesFragment,
queryRef,
nodePath: ['notes', 'pageInfo', 'globalCount'],
setNumberOfElements: storageHelpers.handleSetNumberOfElements,
} as UsePreloadedPaginationFragment<NotesLinesPaginationQuery>;
return (
<span data-testid="notes-page">
<Breadcrumbs elements={[{ label: t_i18n('Analyses') }, { label: entityLabel('Note', t_i18n('Notes')), current: true }]} />
{queryRef && (
<DataTable
dataColumns={dataColumns}
resolvePath={(data: NotesLines_data$data) => data.notes?.edges?.map((n) => n?.node)}
storageKey={LOCAL_STORAGE_KEY}
initialValues={initialValues}
contextFilters={contextFilters}
preloadedPaginationProps={preloadedPaginationProps}
lineFragment={notesLineFragment}
exportContext={{ entity_type: 'Note' }}
createButton={(
<Security needs={[KNOWLEDGE_KNUPDATE, KNOWLEDGE_KNPARTICIPATE]}>
<NoteCreation paginationOptions={queryPaginationOptions} />
</Security>
)}
/>
)}
</span>
);
};
export default Notes;