|
| 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 | +} |
0 commit comments