-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathStreamsOverview.tsx
More file actions
93 lines (81 loc) · 3.8 KB
/
StreamsOverview.tsx
File metadata and controls
93 lines (81 loc) · 3.8 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
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
import React, { useEffect, useMemo } from 'react';
import { useQueryClient } from '@tanstack/react-query';
import QueryHelper from 'components/common/QueryHelper';
import type { Stream } from 'stores/streams/StreamsStore';
import StreamsStore from 'stores/streams/StreamsStore';
import type { IndexSet } from 'stores/indices/IndexSetsStore';
import { keyFn, fetchStreams, KEY_PREFIX } from 'components/streams/hooks/useStreams';
import getStreamTableElements from 'components/streams/StreamsOverview/Constants';
import FilterValueRenderers from 'components/streams/StreamsOverview/FilterValueRenderers';
import useTableElements from 'components/streams/StreamsOverview/hooks/useTableComponents';
import PaginatedEntityTable from 'components/common/PaginatedEntityTable';
import { CurrentUserStore } from 'stores/users/CurrentUserStore';
import type { SearchParams } from 'stores/PaginationTypes';
import type { PaginatedResponse } from 'components/common/PaginatedEntityTable/useFetchEntities';
import CustomColumnRenderers from './ColumnRenderers';
import usePipelineColumn from './hooks/usePipelineColumn';
import useStreamsOverviewExtensions from './hooks/useStreamsOverviewExtensions';
const useRefetchStreamsOnStoreChange = (refetchStreams: () => void) => {
useEffect(() => {
StreamsStore.onChange(() => refetchStreams());
return () => {
StreamsStore.unregister(() => refetchStreams());
};
}, [refetchStreams]);
};
type Props = {
indexSets: Array<IndexSet>;
};
const StreamsOverview = ({ indexSets }: Props) => {
const queryClient = useQueryClient();
const { isPipelineColumnPermitted } = usePipelineColumn();
const { columnRenderers: extensionColumnRenderers, attributes: extensionAttributes, expandedSections: pluggableExpandedSections } =
useStreamsOverviewExtensions();
const { entityActions, expandedSections, bulkActions } = useTableElements({ indexSets, pluggableExpandedSections });
useRefetchStreamsOnStoreChange(() => queryClient.invalidateQueries({ queryKey: KEY_PREFIX }));
const columnRenderers = useMemo(
() => CustomColumnRenderers(indexSets, isPipelineColumnPermitted, extensionColumnRenderers),
[extensionColumnRenderers, indexSets, isPipelineColumnPermitted],
);
const { additionalAttributes, defaultLayout } = useMemo(
() => getStreamTableElements(isPipelineColumnPermitted, extensionAttributes),
[extensionAttributes, isPipelineColumnPermitted],
);
const fetchEntities = (options: SearchParams): Promise<PaginatedResponse<Stream>> => {
CurrentUserStore.update(CurrentUserStore.getInitialState().currentUser.username);
return fetchStreams(options);
};
return (
<PaginatedEntityTable<Stream>
humanName="streams"
additionalAttributes={additionalAttributes}
queryHelpComponent={<QueryHelper entityName="stream" />}
entityActions={entityActions}
tableLayout={defaultLayout}
fetchEntities={fetchEntities}
keyFn={keyFn}
expandedSectionRenderers={expandedSections}
bulkSelection={{ actions: bulkActions }}
entityAttributesAreCamelCase={false}
filterValueRenderers={FilterValueRenderers}
columnRenderers={columnRenderers}
/>
);
};
export default StreamsOverview;