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

fix(CellPreview): show preview button when yql v3 types disabled [#928] #936

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions packages/ui/src/ui/components/ColumnCell/ColumnCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
getStaticTableCliCommand,
loadStaticTableCellPreview,
} from './static-table';
import {isYqlTypesEnabled} from '../../../../selectors/navigation/content/table';

const getCellPath = ({
columnName,
Expand Down Expand Up @@ -56,15 +57,23 @@ const getCliCommand = ({
};
};

const loadCellPreview = ({cellPath}: {cellPath: string}): CellPreviewActionType => {
const loadCellPreview = ({
cellPath,
useYqlTypes,
}: {
cellPath: string;
useYqlTypes: boolean;
}): CellPreviewActionType => {
return (dispatch, getState) => {
const isDynamic = getIsDynamic(getState());

const output_format: any = getDefaultRequestOutputFormat({
stringLimit: PREVIEW_LIMIT,
});

output_format.$attributes.value_format = 'yql';
if (useYqlTypes) {
output_format.$attributes.value_format = 'yql';
}

const action = isDynamic ? loadDynamicTableCellPreview : loadStaticTableCellPreview;

Expand All @@ -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}));
Expand All @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/ui/store/reducers/modals/cell-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading