Skip to content

Commit 4db46fd

Browse files
committed
feat(MLAB-746): add configurable collapse indicators
1 parent 6c69c4c commit 4db46fd

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

src/ReactUnipika/ReactUnipika.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface ReactUnipikaProps {
2121
customLayout?: (args: {toolbar: React.ReactNode; content: React.ReactNode}) => React.ReactNode;
2222
toolbarStickyTop?: number;
2323
renderToolbar?: (props: ToolbarProps) => React.ReactNode;
24+
useIconsForCollapse?: boolean;
2425
}
2526

2627
const defaultUnipikaSettings = {
@@ -43,6 +44,7 @@ export function ReactUnipika({
4344
customLayout,
4445
toolbarStickyTop = 0,
4546
renderToolbar,
47+
useIconsForCollapse = false, // Default to false for backward compatibility with tests
4648
}: ReactUnipikaProps) {
4749
const convertedValue = React.useMemo(() => {
4850
// TODO: fix me later
@@ -95,6 +97,7 @@ export function ReactUnipika({
9597
customLayout={customLayout}
9698
toolbarStickyTop={toolbarStickyTop}
9799
renderToolbar={renderToolbar}
100+
useIconsForCollapse={useIconsForCollapse}
98101
/>
99102
) : (
100103
<pre

src/StructuredYson/Cell.tsx

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

7-
import {ArrowUpRightFromSquare} from '@gravity-ui/icons';
7+
import {ArrowUpRightFromSquare, ChevronUp, ChevronRight} from '@gravity-ui/icons';
88

99
import {UnipikaSettings} from './types';
1010
import {BlockType, SearchInfo, UnipikaFlattenTreeItem} from '../utils/flattenUnipika';
@@ -28,6 +28,7 @@ export interface CellProps {
2828
filter?: string;
2929
index: number;
3030
showFullText: (index: number) => void;
31+
useIconsForCollapse?: boolean;
3132
}
3233

3334
export const JSON_VALUE_KEY = {
@@ -69,6 +70,7 @@ export function Cell(props: CellProps) {
6970
filter,
7071
showFullText,
7172
index,
73+
useIconsForCollapse,
7274
} = props;
7375

7476
const handleToggleCollapse = React.useCallback(() => {
@@ -90,6 +92,7 @@ export function Cell(props: CellProps) {
9092
collapsed={collapsed}
9193
path={path}
9294
onToggle={handleToggleCollapse}
95+
useIconsForCollapse={useIconsForCollapse}
9396
/>
9497
)}
9598
<Key
@@ -287,14 +290,19 @@ interface ToggleCollapseProps {
287290
collapsed?: boolean;
288291
path?: UnipikaFlattenTreeItem['path'];
289292
onToggle: () => void;
293+
useIconsForCollapse?: boolean;
290294
}
291295

292296
function ToggleCollapseButton(props: ToggleCollapseProps) {
293-
const {collapsed, onToggle, path} = props;
297+
const {collapsed, onToggle, path, useIconsForCollapse} = props;
294298
return (
295299
<span title={path} className={block('collapse')}>
296300
<Button onClick={onToggle} view="flat-secondary" size={'s'}>
297-
<span className={'unipika'}>{collapsed ? '[+]' : '[-]'}</span>
301+
{useIconsForCollapse ? (
302+
<Icon className={'unipika'} data={collapsed ? ChevronRight : ChevronUp} />
303+
) : (
304+
<span className={'unipika'}>{collapsed ? '[+]' : '[-]'}</span>
305+
)}
298306
</Button>
299307
</span>
300308
);

src/StructuredYson/StructuredYson.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface Props {
4040
customLayout?: (args: {toolbar: React.ReactNode; content: React.ReactNode}) => React.ReactNode;
4141
toolbarStickyTop?: number;
4242
renderToolbar?: (props: ToolbarProps) => React.ReactNode;
43+
useIconsForCollapse?: boolean;
4344
}
4445

4546
interface State {
@@ -156,6 +157,7 @@ export class StructuredYson extends React.PureComponent<Props, State> {
156157
settings,
157158
filter,
158159
} = this.state;
160+
const {useIconsForCollapse} = this.props;
159161

160162
return (
161163
<Table
@@ -167,6 +169,7 @@ export class StructuredYson extends React.PureComponent<Props, State> {
167169
onToggleCollapse={this.onTogglePathCollapse}
168170
onShowFullText={this.onShowFullText}
169171
scrollToRef={this.tableRef}
172+
useIconsForCollapse={useIconsForCollapse}
170173
/>
171174
);
172175
}

src/StructuredYson/Table.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface TableProps {
1919
onToggleCollapse: (path: string) => void;
2020
onShowFullText: (index: number) => void;
2121
scrollToRef: React.RefObject<null | {scrollToIndex(index: number): void}>;
22+
useIconsForCollapse?: boolean;
2223
}
2324

2425
export const Table: React.FC<TableProps> = ({
@@ -30,6 +31,7 @@ export const Table: React.FC<TableProps> = ({
3031
onToggleCollapse,
3132
onShowFullText,
3233
scrollToRef,
34+
useIconsForCollapse,
3335
}) => {
3436
const renderCell: ColumnDef<UnipikaFlattenTreeItem>['cell'] = ({row}) => {
3537
const {original, index} = row;
@@ -43,6 +45,7 @@ export const Table: React.FC<TableProps> = ({
4345
filter={filter}
4446
showFullText={onShowFullText}
4547
index={index}
48+
useIconsForCollapse={useIconsForCollapse}
4649
/>
4750
);
4851
};

0 commit comments

Comments
 (0)