From 0f253672dd7bc6479a0c68285973e136c257a53c Mon Sep 17 00:00:00 2001 From: sergeyteleshev Date: Wed, 3 Jan 2024 17:14:18 +0100 Subject: [PATCH] =?UTF-8?q?Cb=204461=20json=20and=20xml=20formatting=20doe?= =?UTF-8?q?snt=20work=20in=20value=20panel=20=F0=9F=94=A5=20(#2268)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * CB-4461 fix: json and xml formats properly * CB-4461 fix: edited cell can show its unformatted string value * CB-4461 fix: panel value - on empty selected cell return empty string --------- Co-authored-by: s.teleshev Co-authored-by: mr-anton-t <42037741+mr-anton-t@users.noreply.github.com> --- .../ResultSet/isResultSetBinaryFileValue.ts | 5 ++--- .../TextValue/useTextValue.ts | 15 ++++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/webapp/packages/plugin-data-viewer/src/DatabaseDataModel/Actions/ResultSet/isResultSetBinaryFileValue.ts b/webapp/packages/plugin-data-viewer/src/DatabaseDataModel/Actions/ResultSet/isResultSetBinaryFileValue.ts index 87afa5cb3e..ae85c5deba 100644 --- a/webapp/packages/plugin-data-viewer/src/DatabaseDataModel/Actions/ResultSet/isResultSetBinaryFileValue.ts +++ b/webapp/packages/plugin-data-viewer/src/DatabaseDataModel/Actions/ResultSet/isResultSetBinaryFileValue.ts @@ -1,6 +1,5 @@ import type { IResultSetBinaryFileValue } from './IResultSetBinaryFileValue'; -import type { IResultSetContentValue } from './IResultSetContentValue'; -export function isResultSetBinaryFileValue(value: IResultSetContentValue): value is IResultSetBinaryFileValue { - return value.contentType === 'application/octet-stream' && Boolean(value?.binary); +export function isResultSetBinaryFileValue(value: any): value is IResultSetBinaryFileValue { + return value?.contentType === 'application/octet-stream' && Boolean(value?.binary); } diff --git a/webapp/packages/plugin-data-viewer/src/ValuePanelPresentation/TextValue/useTextValue.ts b/webapp/packages/plugin-data-viewer/src/ValuePanelPresentation/TextValue/useTextValue.ts index 62d8bf187e..a2d81fdea6 100644 --- a/webapp/packages/plugin-data-viewer/src/ValuePanelPresentation/TextValue/useTextValue.ts +++ b/webapp/packages/plugin-data-viewer/src/ValuePanelPresentation/TextValue/useTextValue.ts @@ -5,7 +5,9 @@ * Licensed under the Apache License, Version 2.0. * you may not use this file except in compliance with the License. */ -import { isResultSetContentValue } from '../../DatabaseDataModel/Actions/ResultSet/isResultSetContentValue'; +import { isNotNullDefined } from '@cloudbeaver/core-utils'; + +import { isResultSetBinaryFileValue } from '../../DatabaseDataModel/Actions/ResultSet/isResultSetBinaryFileValue'; import { ResultSetEditAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetEditAction'; import { ResultSetFormatAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetFormatAction'; import { ResultSetSelectAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetSelectAction'; @@ -25,16 +27,19 @@ export function useTextValue({ model, resultIndex, currentContentType }: IUseTex const selection = model.source.getAction(resultIndex, ResultSetSelectAction); const focusCell = selection.getFocusedElement(); const firstSelectedCell = selection.elements?.[0] ?? focusCell; - const autoFormat = !!firstSelectedCell && !editor.isElementEdited(firstSelectedCell); const formatter = useAutoFormat(); - if (!autoFormat) { - return; + if (!isNotNullDefined(firstSelectedCell)) { + return ''; + } + + if (editor.isElementEdited(firstSelectedCell)) { + return format.getText(firstSelectedCell); } const blob = format.get(firstSelectedCell); - if (isResultSetContentValue(blob)) { + if (isResultSetBinaryFileValue(blob)) { const value = formatter.formatBlob(currentContentType, blob); if (value) {