Skip to content

Commit 682a200

Browse files
committed
fixes
1 parent fe439be commit 682a200

File tree

7 files changed

+35
-15
lines changed

7 files changed

+35
-15
lines changed

src/containers/Tenant/Diagnostics/TopicData/TopicData.scss

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
&__date-picker {
1515
min-width: 265px;
1616
}
17+
&__offset-input {
18+
width: max-content;
19+
}
1720
&__column-setup {
1821
margin-left: auto;
1922
}

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -184,27 +184,27 @@ export function TopicData({parentRef, path, database}: TopicDataProps) {
184184
);
185185

186186
//this variable is used to scroll to active offset the very first time on open page
187-
const initialActiveOffset = React.useMemo(() => activeOffset, []);
187+
const initialActiveOffset = React.useRef(activeOffset);
188188

189189
React.useEffect(() => {
190190
if (isFetching) {
191191
return;
192192
}
193193

194194
let currentOffset: number | undefined;
195-
196-
if (isNil(initialActiveOffset)) {
195+
if (isNil(initialActiveOffset.current)) {
197196
const messages = currentData?.Messages;
198197
if (messages?.length) {
199198
currentOffset = safeParseNumber(messages[0].Offset);
200199
}
201200
} else {
202-
currentOffset = safeParseNumber(initialActiveOffset);
201+
currentOffset = safeParseNumber(initialActiveOffset.current);
202+
initialActiveOffset.current = undefined;
203203
}
204204
if (!isNil(currentOffset)) {
205205
scrollToOffset(currentOffset);
206206
}
207-
}, [currentData, isFetching, scrollToOffset, initialActiveOffset]);
207+
}, [currentData, isFetching, scrollToOffset]);
208208

209209
const renderControls: RenderControls = () => {
210210
return (

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

+13
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,22 @@ function TopicDataStartControls({scrollToOffset}: TopicDataStartControlsProps) {
119119
selectedOffset,
120120
startTimestamp,
121121
topicDataFilter,
122+
activeOffset,
122123
handleSelectedOffsetChange,
123124
handleStartTimestampChange,
124125
handleTopicDataFilterChange,
125126
} = useTopicDataQueryParams();
126127

128+
const inputRef = React.useRef<HTMLInputElement>(null);
129+
130+
const isDrawerVisible = !isNil(activeOffset);
131+
132+
React.useEffect(() => {
133+
if (isDrawerVisible) {
134+
inputRef.current?.blur();
135+
}
136+
}, [isDrawerVisible]);
137+
127138
const onFilterChange = React.useCallback(
128139
(value: TopicDataFilterValue) => {
129140
if (value === 'TIMESTAMP') {
@@ -173,6 +184,8 @@ function TopicDataStartControls({scrollToOffset}: TopicDataStartControlsProps) {
173184
</RadioButton>
174185
{topicDataFilter === 'OFFSET' && (
175186
<DebouncedInput
187+
controlRef={inputRef}
188+
className={b('offset-input')}
176189
value={selectedOffset ? String(selectedOffset) : ''}
177190
onUpdate={onStartOffsetChange}
178191
label={i18n('label_from')}

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ export function TopicMessageDetails({database, path}: TopicMessageDetailsProps)
4040
limit: 1,
4141
message_size_limit: MESSAGE_SIZE_LIMIT,
4242
};
43-
params.offset = safeParseNumber(activeOffset);
43+
const parsedOffset = safeParseNumber(activeOffset);
44+
params.offset = parsedOffset;
45+
params.last_offset = parsedOffset;
4446
return params;
4547
}, [selectedPartition, activeOffset, database, path]);
4648

@@ -94,7 +96,9 @@ export function TopicMessageDetails({database, path}: TopicMessageDetailsProps)
9496
justifyContent="center"
9597
height="100%"
9698
>
97-
<Text variant="subheader-1">{i18n('context_message-not-found')}</Text>
99+
<Text variant="subheader-1">
100+
{i18n('context_message-not-found', {offset: activeOffset})}
101+
</Text>
98102
<Icon data={cryCatIcon} size={100} />
99103
</Flex>
100104
);

src/containers/Tenant/Diagnostics/TopicData/TopicMessageDetails/components/TopicMessage.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {ActionTooltip, Button, ClipboardButton, Flex, Icon, Text} from '@gravity
66
import {JsonViewer} from '../../../../../../components/JsonViewer/JsonViewer';
77
import {unipikaConvert} from '../../../../../../components/JsonViewer/unipika/unipika';
88
import ShortyString from '../../../../../../components/ShortyString/ShortyString';
9-
import {createAndDownloadStringifiedJsonFile} from '../../../../../../utils/downloadFile';
9+
import {createAndDownloadFile} from '../../../../../../utils/downloadFile';
1010
import {useTypedSelector} from '../../../../../../utils/hooks';
1111
import {bytesToMB, safeParseNumber} from '../../../../../../utils/utils';
1212
import i18n from '../../i18n';
@@ -80,13 +80,13 @@ export function TopicMessage({offset, size, message}: TopicMessageProps) {
8080
view="flat-secondary"
8181
onClick={(e) => {
8282
e.stopPropagation();
83-
createAndDownloadStringifiedJsonFile(
83+
createAndDownloadFile(
8484
decodedMessage,
8585
`topic-message-${offset ?? 'unknown-offset'}`,
8686
);
8787
}}
8888
>
89-
JSON <Icon data={ArrowDownToLine} />
89+
<Icon data={ArrowDownToLine} />
9090
</Button>
9191
</ActionTooltip>
9292
<ClipboardButton view="flat-secondary" text={decodedMessage} />

src/containers/Tenant/Diagnostics/TopicData/i18n/en.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"action_scroll-up": "Scroll to the start",
2727
"description_failed-decode": "Failed to decode message",
2828
"description_truncated": "[truncated]",
29-
"context_message-not-found": "Message not found",
29+
"context_message-not-found": "Message with offset {{offset}} not found",
3030
"context_get-data-error": "Failed to get message",
3131
"label_download": "Save message to file",
3232
"label_truncated": "Truncated {{size}}"

src/utils/downloadFile.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ export function downloadFile(url: string, filename: string) {
77
document.body.removeChild(link);
88
}
99

10-
export const createAndDownloadStringifiedJsonFile = (data: string, fileName: string) => {
10+
export const createAndDownloadFile = (data: string, fileName: string, type?: string) => {
1111
const blob = new Blob([data], {
12-
type: 'application/json',
12+
type,
1313
});
1414
const url = URL.createObjectURL(blob);
15-
downloadFile(url, `${fileName}.json`);
15+
downloadFile(url, fileName);
1616
URL.revokeObjectURL(url);
1717
};
1818

1919
export const createAndDownloadJsonFile = (data: unknown, fileName: string) => {
2020
const preparedData = JSON.stringify(data, null, 2);
21-
createAndDownloadStringifiedJsonFile(preparedData, fileName);
21+
createAndDownloadFile(preparedData, `${fileName}.json`, 'application/json');
2222
};

0 commit comments

Comments
 (0)