Skip to content

Commit

Permalink
feat(JSONTree): allow case insensitive search (#1735)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raubzeug authored Dec 5, 2024
1 parent dacc546 commit d4845d3
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 33 deletions.
20 changes: 20 additions & 0 deletions src/components/JSONTree/JSONTree.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@use '../../styles/mixins.scss';

.ydb-json-tree {
position: relative;

width: 100%;
height: 100%;
&__tree {
@include mixins.json-tree-styles();
}
&__case {
position: absolute;
top: 0;
left: 308px;
}

.json-inspector__search {
height: 26px;
}
}
61 changes: 61 additions & 0 deletions src/components/JSONTree/JSONTree.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import {ActionTooltip, Button, Icon} from '@gravity-ui/uikit';
import JSONTreeBase from 'react-json-inspector';

import {cn} from '../../utils/cn';
import {CASE_SENSITIVE_JSON_SEARCH} from '../../utils/constants';
import {useSetting} from '../../utils/hooks';

import i18n from './i18n';

import FontCaseIcon from '@gravity-ui/icons/svgs/font-case.svg';

import './JSONTree.scss';
import 'react-json-inspector/json-inspector.css';

const b = cn('ydb-json-tree');

const DEBAUNCE_TIME = 300;

interface JSONTreeProps extends React.ComponentProps<typeof JSONTreeBase> {
search?: false;
treeClassName?: string;
}

export function JSONTree({treeClassName, search, ...rest}: JSONTreeProps) {
const [caseSensitiveSearch, setCaseSensitiveSearch] = useSetting(
CASE_SENSITIVE_JSON_SEARCH,
false,
);
return (
<div className={b()}>
<JSONTreeBase
className={b('tree', treeClassName)}
filterOptions={{
ignoreCase: !caseSensitiveSearch,
}}
searchOptions={{
debounceTime: DEBAUNCE_TIME,
}}
{...rest}
/>
{search !== false && (
<ActionTooltip
title={
caseSensitiveSearch
? i18n('context_case-sensitive-search')
: i18n('context_case-sensitive-search-disabled')
}
>
<Button
view="outlined"
className={b('case')}
onClick={() => setCaseSensitiveSearch(!caseSensitiveSearch)}
selected={caseSensitiveSearch}
>
<Icon data={FontCaseIcon} />
</Button>
</ActionTooltip>
)}
</div>
);
}
4 changes: 4 additions & 0 deletions src/components/JSONTree/i18n/en.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"context_case-sensitive-search": "Case sensitive search enadled",
"context_case-sensitive-search-disabled": "Case sensitive search disabled"
}
7 changes: 7 additions & 0 deletions src/components/JSONTree/i18n/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {registerKeysets} from '../../../utils/i18n';

import en from './en.json';

const COMPONENT = 'ydb-json-tree';

export default registerKeysets(COMPONENT, {en});
10 changes: 1 addition & 9 deletions src/containers/Tenant/Diagnostics/Describe/Describe.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,8 @@
padding: 0 20px 20px 0;
}

&__tree {
@include mixins.json-tree-styles();
}

&__copy {
position: absolute;
left: 308px;
}

.json-inspector__search {
height: 26px;
left: 340px;
}
}
7 changes: 1 addition & 6 deletions src/containers/Tenant/Diagnostics/Describe/Describe.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {ClipboardButton} from '@gravity-ui/uikit';
import JSONTree from 'react-json-inspector';
import {shallowEqual} from 'react-redux';

import {ResponseError} from '../../../../components/Errors/ResponseError';
import {JSONTree} from '../../../../components/JSONTree/JSONTree';
import {Loader} from '../../../../components/Loader';
import {
selectSchemaMergedChildrenPaths,
Expand All @@ -14,7 +14,6 @@ import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks'
import {isEntityWithMergedImplementation} from '../../utils/schema';

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

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

Expand Down Expand Up @@ -74,14 +73,10 @@ const Describe = ({path, database, type}: IDescribeProps) => {
<div className={b('result')}>
<JSONTree
data={preparedDescribeData}
className={b('tree')}
onClick={({path}) => {
const newValue = !(expandMap.get(path) || false);
expandMap.set(path, newValue);
}}
searchOptions={{
debounceTime: 300,
}}
isExpanded={(keypath) => {
return expandMap.get(keypath) || false;
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
}

&__inspector {
@include mixins.json-tree-styles();

:not(.json-inspector__leaf_expanded).json-inspector__leaf_composite:before {
content: '';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from 'react';

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

import {JSONTree} from '../../../../../../components/JSONTree/JSONTree';
import type {IssuesTree} from '../../../../../../store/reducers/healthcheckInfo/types';
import {hcStatusToColorFlag} from '../../../../../../store/reducers/healthcheckInfo/utils';
import {cn} from '../../../../../../utils/cn';
Expand Down Expand Up @@ -32,7 +32,7 @@ const IssueTree = ({issueTree}: IssuesViewerProps) => {
data={info}
search={false}
isExpanded={() => true}
className={b('inspector')}
treeClassName={b('inspector')}
/>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
@use '../../../../../../styles/mixins.scss';

.ydb-query-json-viewer {
&__inspector {
overflow-y: auto;

width: 100%;
height: 100%;
padding: 15px 10px;
@include mixins.json-tree-styles();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import JSONTree from 'react-json-inspector';

import {JSONTree} from '../../../../../../components/JSONTree/JSONTree';
import {cn} from '../../../../../../utils/cn';

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

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

Expand All @@ -13,13 +11,8 @@ interface QueryJSONViewerProps {

export function QueryJSONViewer({data}: QueryJSONViewerProps) {
return (
<JSONTree
data={data}
isExpanded={() => true}
className={b('inspector')}
searchOptions={{
debounceTime: 300,
}}
/>
<div className={b('inspector')}>
<JSONTree data={data} isExpanded={() => true} />
</div>
);
}
2 changes: 2 additions & 0 deletions src/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
AUTOCOMPLETE_ON_ENTER,
AUTO_REFRESH_INTERVAL,
BINARY_DATA_IN_PLAIN_TEXT_DISPLAY,
CASE_SENSITIVE_JSON_SEARCH,
ENABLE_AUTOCOMPLETE,
ENABLE_NETWORK_TABLE_KEY,
INVERTED_DISKS_KEY,
Expand Down Expand Up @@ -46,6 +47,7 @@ export const DEFAULT_USER_SETTINGS = {
[AUTOCOMPLETE_ON_ENTER]: true,
[IS_HOTKEYS_HELP_HIDDEN_KEY]: false,
[AUTO_REFRESH_INTERVAL]: 0,
[CASE_SENSITIVE_JSON_SEARCH]: false,
[SHOW_DOMAIN_DATABASE_KEY]: false,
[LAST_QUERY_EXECUTION_SETTINGS_KEY]: undefined,
[QUERY_SETTINGS_BANNER_LAST_CLOSED_KEY]: undefined,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export const DATA_QA_TUNE_COLUMNS_POPUP = 'tune-columns-popup';
export const BINARY_DATA_IN_PLAIN_TEXT_DISPLAY = 'binaryDataInPlainTextDisplay';
export const AUTO_REFRESH_INTERVAL = 'auto-refresh-interval';

export const CASE_SENSITIVE_JSON_SEARCH = 'caseSensitiveJsonSearch';

export const DEFAULT_SIZE_RESULT_PANE_KEY = 'default-size-result-pane';
export const DEFAULT_SIZE_TENANT_SUMMARY_KEY = 'default-size-tenant-summary-pane';
export const DEFAULT_SIZE_TENANT_KEY = 'default-size-tenant-pane';
Expand Down

0 comments on commit d4845d3

Please sign in to comment.