Skip to content

Commit 23ea45f

Browse files
committed
fix: review
1 parent 85e2b80 commit 23ea45f

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

src/components/JsonViewer/JsonViewer.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,12 @@ export function JsonViewer({
198198
data={data}
199199
theme={'yson'}
200200
settings={normalizedTableSettings}
201-
rowClassName={rowClassName}
201+
rowClassName={() => block('row')}
202202
/>
203203
</div>
204204
);
205205
};
206206

207-
const rowClassName = ({key}: UnipikaFlattenTreeItem) => {
208-
const k = key?.$decoded_value ?? '';
209-
return block('row', {key: asModifier(k)});
210-
};
211-
212207
const onExpandAll = () => {
213208
updateState({collapsedState: {}}, () => {
214209
onNextMatch(null, 0);
@@ -331,7 +326,3 @@ export function JsonViewer({
331326
</div>
332327
);
333328
}
334-
335-
function asModifier(path = '') {
336-
return path.replace(/[^-\w\d]/g, '_');
337-
}

src/components/JsonViewer/components/Cell.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export function Cell(props: CellProps) {
7373
)}
7474
{collapsed && depth === undefined && <span className={'unipika'}>...</span>}
7575
{close && <OpenClose type={close} settings={settings} close />}
76-
{hasDelimiter && <SlaveText text={','} />}
76+
{hasDelimiter && <AdditionalText text={','} />}
7777
</div>
7878
);
7979
}
@@ -90,7 +90,7 @@ function Key(props: KeyProps) {
9090
return text ? (
9191
<React.Fragment>
9292
{text}
93-
<SlaveText text={': '} />
93+
<AdditionalText text={': '} />
9494
</React.Fragment>
9595
) : null;
9696
}
@@ -117,7 +117,8 @@ function renderValueWithFilter(props: ValueProps, className: string) {
117117
function renderStringWithFilter(props: ValueProps, className: string, maxWidth = Infinity) {
118118
const {text, settings = defaultUnipikaSettings, matched = [], filter, showFullText} = props;
119119
const tmp = unipika.format(text, {...settings, asHTML: false});
120-
const visible = tmp.substr(1, Math.min(tmp.length - 2, maxWidth));
120+
const length = tmp.length;
121+
const visible = tmp.substring(1, Math.min(length - 1, maxWidth + 1));
121122
const truncated = visible.length < tmp.length - 2;
122123
let hasHiddenMatch = false;
123124
if (truncated) {
@@ -178,17 +179,17 @@ function renderWithFilter(props: KeyProps, className: string) {
178179
return res ? res : null;
179180
}
180181

181-
function SlaveText({text}: {text: string}) {
182-
return <span className={''}>{text}</span>;
182+
function AdditionalText({text}: {text: string}) {
183+
return <span>{text}</span>;
183184
}
184185

185186
function OpenClose(props: {type: BlockType; close?: boolean; settings?: UnipikaSettings}) {
186187
const {type, close} = props;
187188
switch (type) {
188189
case 'array':
189-
return <SlaveText text={close ? ']' : '['} />;
190+
return <AdditionalText text={close ? ']' : '['} />;
190191
case 'object':
191-
return <SlaveText text={close ? '}' : '{'} />;
192+
return <AdditionalText text={close ? '}' : '{'} />;
192193
}
193194
}
194195

src/components/JsonViewer/components/Filter.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const Filter = React.forwardRef<HTMLInputElement, FilterProps>(function F
6666
<Button
6767
className={block('match-btn')}
6868
view="flat-secondary"
69-
title="Next"
69+
title={i18n('action_next')}
7070
onClick={onNextMatch}
7171
disabled={!count}
7272
>
@@ -75,14 +75,14 @@ export const Filter = React.forwardRef<HTMLInputElement, FilterProps>(function F
7575
<Button
7676
className={block('match-btn')}
7777
view="flat-secondary"
78-
title="Back"
78+
title={i18n('action_back')}
7979
onClick={onPrevMatch}
8080
disabled={!count}
8181
>
8282
<Icon data={ChevronUpIcon} />
8383
</Button>
8484
</Flex>
85-
<span className={block('match-counter')} title={'Matched rows'}>
85+
<span className={block('match-counter')} title={i18n('description_matched-rows')}>
8686
{matchPosition} / {count || 0}
8787
</span>
8888
</React.Fragment>

src/components/JsonViewer/components/FullValueDialog.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {Dialog, Flex} from '@gravity-ui/uikit';
22

33
import {block} from '../constants';
4+
import i18n from '../i18n';
45
import {getHightLightedClassName} from '../utils';
56

67
import {MultiHighlightedText} from './HighlightedText';
@@ -15,7 +16,7 @@ interface FullValueDialogProps {
1516
export function FullValueDialog({onClose, text, starts, length}: FullValueDialogProps) {
1617
return (
1718
<Dialog open={true} onClose={onClose}>
18-
<Dialog.Header caption={'Full value'} />
19+
<Dialog.Header caption={i18n('description_full-value')} />
1920
<Dialog.Divider />
2021
<Dialog.Body>
2122
<Flex direction="column" gap={2} width="70vw" maxHeight="80vh">

src/components/JsonViewer/components/HighlightedText.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ interface Props {
1414
export default function HighlightedText({className, text, start, length, hasComa}: Props) {
1515
const comma = hasComa ? <React.Fragment>,&nbsp;</React.Fragment> : null;
1616

17-
if (length! > 0 && start! >= 0 && start! < text.length) {
18-
const begin = text.substr(0, start);
19-
const highlighted = text.substr(start!, length);
20-
const end = text.substr(start! + length!);
17+
if (length && typeof start === 'number' && start >= 0 && start < text.length) {
18+
const begin = text.substring(0, start);
19+
const highlighted = text.substring(start, start + length);
20+
const end = text.substring(start + length);
2121

2222
return (
2323
<React.Fragment>

src/components/JsonViewer/i18n/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
{
22
"action_collapse-all": "Collapse all",
33
"action_expand-all": "Expand all",
4+
"action_next": "Next",
5+
"action_back": "Back",
46
"description_search": "Search...",
7+
"description_matched-rows": "Matched rows",
8+
"description_full-value": "Full value",
59
"context_case-sensitive-search": "Case sensitive search enadled",
610
"context_case-sensitive-search-disabled": "Case sensitive search disabled",
711
"context_items-count": [

src/components/JsonViewer/unipika/flattenUnipika.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ function pushPath(path: string, ctx: FlatContext) {
181181
function popPath(ctx: FlatContext) {
182182
const last = ctx.path.pop();
183183
if (last !== undefined) {
184-
ctx.collapsedPath = ctx.collapsedPath.substr(0, ctx.collapsedPath.length - last.length - 1);
184+
ctx.collapsedPath = ctx.collapsedPath.substring(
185+
0,
186+
ctx.collapsedPath.length - last.length - 1,
187+
);
185188
}
186189
}
187190

0 commit comments

Comments
 (0)