From 0e6fd690a44a79eb4245017a7defc3950cb2e27c Mon Sep 17 00:00:00 2001 From: Vladimir Chernitsyn Date: Fri, 27 Dec 2024 12:58:59 +0100 Subject: [PATCH] fix(CellPreview): show preview button when yql v3 types disabled [#928] --- .../ui/components/ColumnCell/ColumnCell.tsx | 2 + .../CellPreviewModal/CellPreviewModal.tsx | 2 +- .../navigation/modals/cell-preview/index.ts | 72 ++++++++++++++----- .../ui/store/reducers/modals/cell-preview.ts | 2 +- 4 files changed, 58 insertions(+), 20 deletions(-) diff --git a/packages/ui/src/ui/components/ColumnCell/ColumnCell.tsx b/packages/ui/src/ui/components/ColumnCell/ColumnCell.tsx index 0f767c1d1..7bb5d5420 100644 --- a/packages/ui/src/ui/components/ColumnCell/ColumnCell.tsx +++ b/packages/ui/src/ui/components/ColumnCell/ColumnCell.tsx @@ -87,6 +87,8 @@ export function ColumnCell({ isIncompleteValue = flags.incomplete; isIncompleteTagged = flags.incomplete && $tag; tag = $tag; + } else if (value) { + isIncompleteValue = Boolean(value.$incomplete); } return {tag, isIncompleteTagged, isIncompleteValue}; diff --git a/packages/ui/src/ui/containers/CellPreviewModal/CellPreviewModal.tsx b/packages/ui/src/ui/containers/CellPreviewModal/CellPreviewModal.tsx index 19b3ad39e..65be6c5e0 100644 --- a/packages/ui/src/ui/containers/CellPreviewModal/CellPreviewModal.tsx +++ b/packages/ui/src/ui/containers/CellPreviewModal/CellPreviewModal.tsx @@ -86,7 +86,7 @@ export const CellPreviewModal: React.FC = () => { }; type PreviewContentProps = { - data: {$type: string; $value: any; $tag?: string} | undefined; + data: {$type?: string; $value?: any; $tag?: string} | undefined; unipikaSettings: YsonSettings; }; diff --git a/packages/ui/src/ui/store/actions/navigation/modals/cell-preview/index.ts b/packages/ui/src/ui/store/actions/navigation/modals/cell-preview/index.ts index 837aaf4e4..023c08aaf 100644 --- a/packages/ui/src/ui/store/actions/navigation/modals/cell-preview/index.ts +++ b/packages/ui/src/ui/store/actions/navigation/modals/cell-preview/index.ts @@ -20,6 +20,7 @@ import { getStaticTableCliCommand, loadStaticTableCellPreview, } from './static-table'; +import {isYqlTypesEnabled} from '../../../../selectors/navigation/content/table'; const getCellPath = ({ columnName, @@ -56,7 +57,13 @@ const getCliCommand = ({ }; }; -const loadCellPreview = ({cellPath}: {cellPath: string}): CellPreviewActionType => { +const loadCellPreview = ({ + cellPath, + useYqlTypes, +}: { + cellPath: string; + useYqlTypes: boolean; +}): CellPreviewActionType => { return (dispatch, getState) => { const isDynamic = getIsDynamic(getState()); @@ -64,7 +71,9 @@ const loadCellPreview = ({cellPath}: {cellPath: string}): CellPreviewActionType stringLimit: PREVIEW_LIMIT, }); - output_format.$attributes.value_format = 'yql'; + if (useYqlTypes) { + output_format.$attributes.value_format = 'yql'; + } const action = isDynamic ? loadDynamicTableCellPreview : loadStaticTableCellPreview; @@ -83,7 +92,9 @@ export const showCellPreviewModal = ( index: number, tag?: string, ): CellPreviewActionType => { - return async (dispatch) => { + return async (dispatch, getState) => { + const useYqlTypes = isYqlTypesEnabled(getState()); + const cellPath = dispatch(getCellPath({columnName, index})); const ytCliDownloadCommand: string = dispatch(getCliCommand({cellPath, columnName, tag})); @@ -93,36 +104,61 @@ export const showCellPreviewModal = ( dispatch(openCellPreview()); }); + const data: { + $type?: string; + $value?: any; + $tag?: string; + } = {}; + + let isIncomplete = false; + try { - const json = await dispatch(loadCellPreview({cellPath})); + const json = await dispatch(loadCellPreview({cellPath, useYqlTypes})); const parsed = JSON.parse(json); const column = parsed.rows[0][columnName]; - const value = column[0]; - const typeIndex = column[1]; + if (useYqlTypes) { + const value = column[0]; + const typeIndex = column[1]; - const flags: {incomplete: boolean} = {incomplete: false}; + const flags: {incomplete: boolean} = {incomplete: false}; - const {$type, $value, $tag} = unipika.converters.yql( - [value, parsed.yql_type_registry[typeIndex]], - { - maxStringSize: undefined, - maxListSize: undefined, - treatValAsData: true, - }, - flags, - ); + const {$type, $value, $tag} = unipika.converters.yql( + [value, parsed.yql_type_registry[typeIndex]], + { + maxStringSize: undefined, + maxListSize: undefined, + treatValAsData: true, + }, + flags, + ); + + isIncomplete = flags.incomplete; + + data.$type = $type; + data.$value = $tag ? $value.$value : $value; + data.$tag = $tag; + } else { + const hasType = column && column.$type; + + data.$type = column.$type; + data.$value = hasType ? column.$value : column; + + isIncomplete = column.$incomplete; + } - const isIncomplete = flags.incomplete; const noticeText = isIncomplete ? 'Unable to load content more than 16MiB. Please use the command bellow to load it locally.' : 'You could use the command bellow to load it locally.'; dispatch({ type: CELL_PREVIEW.SUCCESS, - data: {data: {$type, $value: $tag ? $value.$value : $value, $tag}, noticeText}, + data: { + data, + noticeText, + }, }); } catch (error: any) { if (!isCancelled(error)) { diff --git a/packages/ui/src/ui/store/reducers/modals/cell-preview.ts b/packages/ui/src/ui/store/reducers/modals/cell-preview.ts index 39af8ed90..2bfe5c76d 100644 --- a/packages/ui/src/ui/store/reducers/modals/cell-preview.ts +++ b/packages/ui/src/ui/store/reducers/modals/cell-preview.ts @@ -4,7 +4,7 @@ import {CELL_PREVIEW} from '../../../constants/modals/cell-preview'; export interface CellPreviewState { visible: boolean; loading: boolean; - data: {$value: any; $type: string; $tag?: string} | undefined; + data: {$value?: any; $type?: string; $tag?: string} | undefined; ytCliDownloadCommand?: string; noticeText?: string; error?: YTError;