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

Cb 4461 json and xml formatting doesnt work in value panel 🔥 #2268

Merged
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
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {
Expand Down
Loading