Skip to content

Commit a68dbb4

Browse files
authored
feat(TopicData): use number input for offset selection (#2890)
1 parent 2ef05b6 commit a68dbb4

File tree

7 files changed

+38
-14
lines changed

7 files changed

+38
-14
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type {NumberInputProps} from '@gravity-ui/uikit';
2+
import {NumberInput} from '@gravity-ui/uikit';
3+
4+
import {useDebouncedValue} from '../../utils/hooks/useDebouncedValue';
5+
6+
interface DebouncedInputProps extends NumberInputProps {
7+
debounce?: number;
8+
}
9+
10+
export const DebouncedNumberInput = ({
11+
onUpdate,
12+
value = null,
13+
debounce = 200,
14+
...rest
15+
}: DebouncedInputProps) => {
16+
const [currentValue, handleUpdate] = useDebouncedValue<number | null>({
17+
value,
18+
onUpdate,
19+
debounce,
20+
});
21+
22+
return <NumberInput value={currentValue} onUpdate={handleUpdate} {...rest} />;
23+
};

src/components/DebouncedInput/DebouncedTextInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface DebouncedInputProps extends TextInputProps {
77
debounce?: number;
88
}
99

10-
export const DebouncedInput = ({
10+
export const DebouncedTextInput = ({
1111
onUpdate,
1212
value = '',
1313
debounce = 200,

src/components/Search/Search.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import type {TextInputProps} from '@gravity-ui/uikit';
44

55
import {cn} from '../../utils/cn';
6-
import {DebouncedInput} from '../DebouncedInput/DebouncedTextInput';
6+
import {DebouncedTextInput} from '../DebouncedInput/DebouncedTextInput';
77

88
import './Search.scss';
99

@@ -27,7 +27,7 @@ export const Search = ({
2727
...props
2828
}: SearchProps) => {
2929
return (
30-
<DebouncedInput
30+
<DebouncedTextInput
3131
debounce={debounce}
3232
hasClear
3333
autoFocus

src/containers/Tenant/Diagnostics/TopicData/TopicData.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ export function TopicData({scrollContainerRef, path, database, databaseFullPath}
351351
getRowClassName={(row) => {
352352
return b('row', {
353353
active: Boolean(
354-
String(row.Offset) === selectedOffset ||
354+
safeParseNumber(row.Offset) === selectedOffset ||
355355
String(row.Offset) === activeOffset,
356356
),
357357
removed: row.removed,

src/containers/Tenant/Diagnostics/TopicData/TopicDataControls/TopicDataControls.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from '@gravity-ui/uikit';
1919
import {isNil} from 'lodash';
2020

21-
import {DebouncedInput} from '../../../../../components/DebouncedInput/DebouncedTextInput';
21+
import {DebouncedNumberInput} from '../../../../../components/DebouncedInput/DebouncedNumerInput';
2222
import type {PreparedPartitionData} from '../../../../../store/reducers/partitions/types';
2323
import {formatNumber} from '../../../../../utils/dataFormatters/dataFormatters';
2424
import {prepareErrorMessage} from '../../../../../utils/prepareErrorMessage';
@@ -137,7 +137,7 @@ function TopicDataStartControls({scrollToOffset}: TopicDataStartControlsProps) {
137137
[handleTopicDataFilterChange, handleSelectedOffsetChange, handleStartTimestampChange],
138138
);
139139
const onStartOffsetChange = React.useCallback(
140-
(value: string) => {
140+
(value: number | null) => {
141141
handleSelectedOffsetChange(value);
142142
},
143143
[handleSelectedOffsetChange],
@@ -176,19 +176,20 @@ function TopicDataStartControls({scrollToOffset}: TopicDataStartControlsProps) {
176176
</SegmentedRadioGroup.Option>
177177
</SegmentedRadioGroup>
178178
{topicDataFilter === 'OFFSET' && (
179-
<DebouncedInput
179+
<DebouncedNumberInput
180180
controlRef={inputRef}
181181
className={b('offset-input')}
182-
value={selectedOffset ? String(selectedOffset) : ''}
182+
max={Number.MAX_SAFE_INTEGER}
183+
min={0}
184+
value={isNil(selectedOffset) ? null : safeParseNumber(selectedOffset)}
183185
onUpdate={onStartOffsetChange}
184186
label={i18n('label_from')}
185187
placeholder={i18n('label_offset')}
186-
type="number"
187188
debounce={600}
188189
endContent={
189190
<ActionTooltip title={i18n('action_scroll-selected')}>
190191
<Button
191-
disabled={isNil(selectedOffset) || selectedOffset === ''}
192+
disabled={isNil(selectedOffset)}
192193
className={b('scroll-button')}
193194
view="flat-action"
194195
size="xs"

src/containers/Tenant/Diagnostics/TopicData/useTopicDataQueryParams.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export function useTopicDataQueryParams() {
1111
setQueryParams,
1212
] = useQueryParams({
1313
selectedPartition: StringParam,
14-
selectedOffset: StringParam,
14+
selectedOffset: NumberParam,
1515
startTimestamp: NumberParam,
1616
topicDataFilter: TopicDataFilterValueParam,
1717
activeOffset: StringParam,
@@ -25,8 +25,8 @@ export function useTopicDataQueryParams() {
2525
);
2626

2727
const handleSelectedOffsetChange = React.useCallback(
28-
(value?: string) => {
29-
setQueryParams({selectedOffset: value}, 'replaceIn');
28+
(value?: number | null) => {
29+
setQueryParams({selectedOffset: value || undefined}, 'replaceIn');
3030
},
3131
[setQueryParams],
3232
);

src/utils/hooks/useDebouncedValue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
export function useDebouncedValue<T extends string | number>({
3+
export function useDebouncedValue<T extends string | number | null>({
44
value,
55
onUpdate,
66
debounce = 200,

0 commit comments

Comments
 (0)