Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(JSONTree): allow case insensitive search #1735

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/components/JSONTreeWithSearch/JSONTreeWithSearch.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@use '../../styles/mixins.scss';

.ydb-json-tree-with-search {
position: relative;

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

.json-inspector__search {
height: 26px;
}
}
56 changes: 56 additions & 0 deletions src/components/JSONTreeWithSearch/JSONTreeWithSearch.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {ActionTooltip, Button, Icon} from '@gravity-ui/uikit';
import JSONTree 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 './JSONTreeWithSearch.scss';
import 'react-json-inspector/json-inspector.css';

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

interface JSONTreeWithSearchProps extends React.ComponentProps<typeof JSONTree> {
treeClassName?: string;
}

export function JSONTreeWithSearch({treeClassName, ...rest}: JSONTreeWithSearchProps) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could create JSONTreeWrapper and use it everywhere with search prop?
In case we want to use search anywhere else

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense!

const [caseSensitiveSearch, setCaseSensitiveSearch] = useSetting(
CASE_SENSITIVE_JSON_SEARCH,
false,
);
return (
<div className={b()}>
<JSONTree
className={b('tree', treeClassName)}
filterOptions={{
Raubzeug marked this conversation as resolved.
Show resolved Hide resolved
ignoreCase: !caseSensitiveSearch,
}}
searchOptions={{
debounceTime: 300,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const DEBOUNCE_TIME ?

}}
{...rest}
/>
<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/JSONTreeWithSearch/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/JSONTreeWithSearch/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-with-search';

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;
}
}
9 changes: 2 additions & 7 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 {JSONTreeWithSearch} from '../../../../components/JSONTreeWithSearch/JSONTreeWithSearch';
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 @@ -72,16 +71,12 @@ const Describe = ({path, database, type}: IDescribeProps) => {
{error ? <ResponseError error={error} /> : null}
{preparedDescribeData ? (
<div className={b('result')}>
<JSONTree
<JSONTreeWithSearch
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
@@ -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 {JSONTreeWithSearch} from '../../../../../../components/JSONTreeWithSearch/JSONTreeWithSearch';
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')}>
<JSONTreeWithSearch 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,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like global option but as far as I see JSONTree used in many places

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose case-sensitiveness should be scoped to JSONTreeWrapper (or JSONTreeSearch or whatever component it is used in)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a setting that should be saved to LS. Thats why it is among other settings. Or I didn't get you?..

[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
Loading