Skip to content

Commit eb55175

Browse files
imgeorgiusma-efremoff
authored andcommitted
feat(ReactUnipika): add renderToolbar property
1 parent 09c712f commit eb55175

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

src/ReactUnipika/ReactUnipika.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import unipika from '@gravity-ui/unipika/lib/unipika';
55

66
import {UnipikaSettings} from '../StructuredYson/types';
77

8-
import {StructuredYson} from '../StructuredYson/StructuredYson';
8+
import {StructuredYson, ToolbarProps} from '../StructuredYson/StructuredYson';
99
import {cn} from '../utils/classname';
1010

1111
const block = cn('g-ru-react-unipika');
@@ -20,6 +20,7 @@ export interface ReactUnipikaProps {
2020
className?: string;
2121
customLayout?: (args: {toolbar: React.ReactNode; content: React.ReactNode}) => React.ReactNode;
2222
toolbarStickyTop?: number;
23+
renderToolbar?: (props: ToolbarProps) => React.ReactNode;
2324
}
2425

2526
const defaultUnipikaSettings = {
@@ -41,6 +42,7 @@ export function ReactUnipika({
4142
className,
4243
customLayout,
4344
toolbarStickyTop = 0,
45+
renderToolbar,
4446
}: ReactUnipikaProps) {
4547
const convertedValue = React.useMemo(() => {
4648
// TODO: fix me later
@@ -92,6 +94,7 @@ export function ReactUnipika({
9294
extraTools={extraTools}
9395
customLayout={customLayout}
9496
toolbarStickyTop={toolbarStickyTop}
97+
renderToolbar={renderToolbar}
9598
/>
9699
) : (
97100
<pre

src/StructuredYson/Cell.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
2-
32
import {Button, Icon} from '@gravity-ui/uikit';
3+
44
// @ts-ignore
55
import unipika from '@gravity-ui/unipika/lib/unipika';
66

@@ -130,7 +130,10 @@ interface KeyProps {
130130
function Key(props: KeyProps) {
131131
const {yson} = props;
132132
const text: React.ReactNode = renderKeyWithFilter(props);
133-
return !text ? null : (
133+
if (!text) {
134+
return null;
135+
}
136+
return (
134137
<React.Fragment>
135138
{text}
136139
<SlaveText text={yson ? ' = ' : ': '} />

src/StructuredYson/StructuredYson.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,20 @@ import './StructuredYson.scss';
2626

2727
const block = cn('g-ru-structured-yson');
2828

29+
export interface ToolbarProps {
30+
onFilterChange: (filter: string) => void;
31+
onExpandAll: () => void;
32+
onCollapseAll: () => void;
33+
isCollapsed: boolean;
34+
}
35+
2936
interface Props {
3037
value: UnipikaValue;
3138
settings: UnipikaSettings;
3239
extraTools?: React.ReactNode;
3340
customLayout?: (args: {toolbar: React.ReactNode; content: React.ReactNode}) => React.ReactNode;
3441
toolbarStickyTop?: number;
42+
renderToolbar?: (props: ToolbarProps) => React.ReactNode;
3543
}
3644

3745
interface State {
@@ -224,8 +232,21 @@ export class StructuredYson extends React.PureComponent<Props, State> {
224232
};
225233

226234
renderToolbar(className?: string) {
227-
const {matchIndex, matchedRows, filter} = this.state;
228-
const {extraTools} = this.props;
235+
const {matchIndex, matchedRows, filter, collapsedState} = this.state;
236+
const {extraTools, renderToolbar} = this.props;
237+
238+
// Calculate if there are any collapsed nodes
239+
const isCollapsed = Object.keys(collapsedState).length > 0;
240+
241+
if (renderToolbar) {
242+
return renderToolbar({
243+
onFilterChange: this.onFilterChange,
244+
onExpandAll: this.onExpandAll,
245+
onCollapseAll: this.onCollapseAll,
246+
isCollapsed,
247+
});
248+
}
249+
229250
return (
230251
<StructuredYsonToolbar
231252
className={className}

0 commit comments

Comments
 (0)