-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathConsumers.tsx
More file actions
107 lines (91 loc) · 3.77 KB
/
Copy pathConsumers.tsx
File metadata and controls
107 lines (91 loc) · 3.77 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
import React from 'react';
import escapeRegExp from 'lodash/escapeRegExp';
import {ResponseError} from '../../../../components/Errors/ResponseError';
import {Loader} from '../../../../components/Loader';
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
import {Search} from '../../../../components/Search';
import {useClusterWithProxy} from '../../../../store/reducers/cluster/cluster';
import {
selectPreparedConsumersData,
selectPreparedTopicStats,
topicApi,
} from '../../../../store/reducers/topic/topic';
import type {EPathType} from '../../../../types/api/schema';
import {cn} from '../../../../utils/cn';
import {DEFAULT_TABLE_SETTINGS} from '../../../../utils/constants';
import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks';
import {isCdcStreamEntityType} from '../../utils/schema';
import {ConsumersTopicStats} from './TopicStats';
import {CONSUMERS_COLUMNS_WIDTH_LS_KEY, columns} from './columns';
import i18n from './i18n';
import './Consumers.scss';
const b = cn('ydb-diagnostics-consumers');
interface ConsumersProps {
path: string;
database: string;
databaseFullPath: string;
type?: EPathType;
}
export const Consumers = ({path, database, type, databaseFullPath}: ConsumersProps) => {
const isCdcStream = isCdcStreamEntityType(type);
const useMetaProxy = useClusterWithProxy();
const [searchValue, setSearchValue] = React.useState('');
const [autoRefreshInterval] = useAutoRefreshInterval();
const {currentData, isFetching, error} = topicApi.useGetTopicQuery(
{path, database, databaseFullPath, useMetaProxy},
{pollingInterval: autoRefreshInterval},
);
const loading = isFetching && currentData === undefined;
const consumers = useTypedSelector((state) =>
selectPreparedConsumersData(state, path, database, databaseFullPath, useMetaProxy),
);
const topic = useTypedSelector((state) =>
selectPreparedTopicStats(state, path, database, databaseFullPath, useMetaProxy),
);
const dataToRender = React.useMemo(() => {
if (!consumers) {
return [];
}
const searchRe = new RegExp(escapeRegExp(searchValue.trim()), 'i');
return consumers.filter((consumer) => {
return searchRe.test(String(consumer.name));
});
}, [consumers, searchValue]);
const handleSearchChange = (value: string) => {
setSearchValue(value);
};
if (loading) {
return <Loader size="m" />;
}
if (!error && (!consumers || !consumers.length)) {
return <div>{i18n(`noConsumersMessage.${isCdcStream ? 'stream' : 'topic'}`)}</div>;
}
return (
<div className={b()}>
<div className={b('controls')}>
<Search
onChange={handleSearchChange}
placeholder={i18n('controls.search')}
className={b('search')}
value={searchValue}
/>
{topic && <ConsumersTopicStats data={topic} />}
</div>
{error ? <ResponseError error={error} /> : null}
{consumers ? (
<div className={b('table-wrapper')}>
<div className={b('table-content')}>
<ResizeableDataTable
columnsWidthLSKey={CONSUMERS_COLUMNS_WIDTH_LS_KEY}
wrapperClassName={b('table')}
data={dataToRender}
columns={columns}
settings={DEFAULT_TABLE_SETTINGS}
emptyDataMessage={i18n('table.emptyDataMessage')}
/>
</div>
</div>
) : null}
</div>
);
};