Skip to content

Commit d4845d3

Browse files
authored
feat(JSONTree): allow case insensitive search (#1735)
1 parent dacc546 commit d4845d3

File tree

12 files changed

+104
-33
lines changed

12 files changed

+104
-33
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
@use '../../styles/mixins.scss';
2+
3+
.ydb-json-tree {
4+
position: relative;
5+
6+
width: 100%;
7+
height: 100%;
8+
&__tree {
9+
@include mixins.json-tree-styles();
10+
}
11+
&__case {
12+
position: absolute;
13+
top: 0;
14+
left: 308px;
15+
}
16+
17+
.json-inspector__search {
18+
height: 26px;
19+
}
20+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import {ActionTooltip, Button, Icon} from '@gravity-ui/uikit';
2+
import JSONTreeBase from 'react-json-inspector';
3+
4+
import {cn} from '../../utils/cn';
5+
import {CASE_SENSITIVE_JSON_SEARCH} from '../../utils/constants';
6+
import {useSetting} from '../../utils/hooks';
7+
8+
import i18n from './i18n';
9+
10+
import FontCaseIcon from '@gravity-ui/icons/svgs/font-case.svg';
11+
12+
import './JSONTree.scss';
13+
import 'react-json-inspector/json-inspector.css';
14+
15+
const b = cn('ydb-json-tree');
16+
17+
const DEBAUNCE_TIME = 300;
18+
19+
interface JSONTreeProps extends React.ComponentProps<typeof JSONTreeBase> {
20+
search?: false;
21+
treeClassName?: string;
22+
}
23+
24+
export function JSONTree({treeClassName, search, ...rest}: JSONTreeProps) {
25+
const [caseSensitiveSearch, setCaseSensitiveSearch] = useSetting(
26+
CASE_SENSITIVE_JSON_SEARCH,
27+
false,
28+
);
29+
return (
30+
<div className={b()}>
31+
<JSONTreeBase
32+
className={b('tree', treeClassName)}
33+
filterOptions={{
34+
ignoreCase: !caseSensitiveSearch,
35+
}}
36+
searchOptions={{
37+
debounceTime: DEBAUNCE_TIME,
38+
}}
39+
{...rest}
40+
/>
41+
{search !== false && (
42+
<ActionTooltip
43+
title={
44+
caseSensitiveSearch
45+
? i18n('context_case-sensitive-search')
46+
: i18n('context_case-sensitive-search-disabled')
47+
}
48+
>
49+
<Button
50+
view="outlined"
51+
className={b('case')}
52+
onClick={() => setCaseSensitiveSearch(!caseSensitiveSearch)}
53+
selected={caseSensitiveSearch}
54+
>
55+
<Icon data={FontCaseIcon} />
56+
</Button>
57+
</ActionTooltip>
58+
)}
59+
</div>
60+
);
61+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"context_case-sensitive-search": "Case sensitive search enadled",
3+
"context_case-sensitive-search-disabled": "Case sensitive search disabled"
4+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import {registerKeysets} from '../../../utils/i18n';
2+
3+
import en from './en.json';
4+
5+
const COMPONENT = 'ydb-json-tree';
6+
7+
export default registerKeysets(COMPONENT, {en});

src/containers/Tenant/Diagnostics/Describe/Describe.scss

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,8 @@
1515
padding: 0 20px 20px 0;
1616
}
1717

18-
&__tree {
19-
@include mixins.json-tree-styles();
20-
}
21-
2218
&__copy {
2319
position: absolute;
24-
left: 308px;
25-
}
26-
27-
.json-inspector__search {
28-
height: 26px;
20+
left: 340px;
2921
}
3022
}

src/containers/Tenant/Diagnostics/Describe/Describe.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import {ClipboardButton} from '@gravity-ui/uikit';
2-
import JSONTree from 'react-json-inspector';
32
import {shallowEqual} from 'react-redux';
43

54
import {ResponseError} from '../../../../components/Errors/ResponseError';
5+
import {JSONTree} from '../../../../components/JSONTree/JSONTree';
66
import {Loader} from '../../../../components/Loader';
77
import {
88
selectSchemaMergedChildrenPaths,
@@ -14,7 +14,6 @@ import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks'
1414
import {isEntityWithMergedImplementation} from '../../utils/schema';
1515

1616
import './Describe.scss';
17-
import 'react-json-inspector/json-inspector.css';
1817

1918
const b = cn('ydb-describe');
2019

@@ -74,14 +73,10 @@ const Describe = ({path, database, type}: IDescribeProps) => {
7473
<div className={b('result')}>
7574
<JSONTree
7675
data={preparedDescribeData}
77-
className={b('tree')}
7876
onClick={({path}) => {
7977
const newValue = !(expandMap.get(path) || false);
8078
expandMap.set(path, newValue);
8179
}}
82-
searchOptions={{
83-
debounceTime: 300,
84-
}}
8580
isExpanded={(keypath) => {
8681
return expandMap.get(keypath) || false;
8782
}}

src/containers/Tenant/Diagnostics/TenantOverview/Healthcheck/IssuesViewer/IssueTree.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
}
2424

2525
&__inspector {
26-
@include mixins.json-tree-styles();
27-
2826
:not(.json-inspector__leaf_expanded).json-inspector__leaf_composite:before {
2927
content: '';
3028
}

src/containers/Tenant/Diagnostics/TenantOverview/Healthcheck/IssuesViewer/IssueTree.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22

33
import _omit from 'lodash/omit';
4-
import JSONTree from 'react-json-inspector';
54
import {TreeView} from 'ydb-ui-components';
65

6+
import {JSONTree} from '../../../../../../components/JSONTree/JSONTree';
77
import type {IssuesTree} from '../../../../../../store/reducers/healthcheckInfo/types';
88
import {hcStatusToColorFlag} from '../../../../../../store/reducers/healthcheckInfo/utils';
99
import {cn} from '../../../../../../utils/cn';
@@ -32,7 +32,7 @@ const IssueTree = ({issueTree}: IssuesViewerProps) => {
3232
data={info}
3333
search={false}
3434
isExpanded={() => true}
35-
className={b('inspector')}
35+
treeClassName={b('inspector')}
3636
/>
3737
</div>
3838
);
Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
@use '../../../../../../styles/mixins.scss';
2-
31
.ydb-query-json-viewer {
42
&__inspector {
53
overflow-y: auto;
64

75
width: 100%;
86
height: 100%;
97
padding: 15px 10px;
10-
@include mixins.json-tree-styles();
118
}
129
}
Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import JSONTree from 'react-json-inspector';
2-
1+
import {JSONTree} from '../../../../../../components/JSONTree/JSONTree';
32
import {cn} from '../../../../../../utils/cn';
43

54
import './QueryJSONViewer.scss';
6-
import 'react-json-inspector/json-inspector.css';
75

86
const b = cn('ydb-query-json-viewer');
97

@@ -13,13 +11,8 @@ interface QueryJSONViewerProps {
1311

1412
export function QueryJSONViewer({data}: QueryJSONViewerProps) {
1513
return (
16-
<JSONTree
17-
data={data}
18-
isExpanded={() => true}
19-
className={b('inspector')}
20-
searchOptions={{
21-
debounceTime: 300,
22-
}}
23-
/>
14+
<div className={b('inspector')}>
15+
<JSONTree data={data} isExpanded={() => true} />
16+
</div>
2417
);
2518
}

0 commit comments

Comments
 (0)