-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…oded Cb 3555 view byte type data decoded
- Loading branch information
Showing
16 changed files
with
200 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2023 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
|
||
// be careful with this when you calculate a big size blobs | ||
// it can block the main thread and cause freezes | ||
export function base64ToHex(base64String: string): string { | ||
const raw = atob(base64String); | ||
let result = ''; | ||
for (let i = 0; i < raw.length; i++) { | ||
const hex = raw.charCodeAt(i).toString(16); | ||
result += hex.length === 2 ? hex : `0${hex}`; | ||
} | ||
return result.toUpperCase(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...s/plugin-data-viewer/src/DatabaseDataModel/Actions/ResultSet/IResultSetBinaryFileValue.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { IResultSetContentValue } from './IResultSetContentValue'; | ||
|
||
export interface IResultSetBinaryFileValue extends IResultSetContentValue { | ||
binary: string; | ||
} |
6 changes: 6 additions & 0 deletions
6
.../plugin-data-viewer/src/DatabaseDataModel/Actions/ResultSet/isResultSetBinaryFileValue.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...in-data-viewer/src/ValuePanelPresentation/ImageValue/isImageValuePresentationAvailable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2023 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { getMIME, isImageFormat, isValidUrl } from '@cloudbeaver/core-utils'; | ||
|
||
import { isResultSetBlobValue } from '../../DatabaseDataModel/Actions/ResultSet/isResultSetBlobValue'; | ||
import { isResultSetContentValue } from '../../DatabaseDataModel/Actions/ResultSet/isResultSetContentValue'; | ||
import type { IResultSetValue } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetFormatAction'; | ||
|
||
export function isImageValuePresentationAvailable(value: IResultSetValue) { | ||
if (isResultSetContentValue(value) && value?.binary) { | ||
return getMIME(value.binary || '') !== null; | ||
} | ||
if (isResultSetContentValue(value) || isResultSetBlobValue(value)) { | ||
return value?.contentType?.startsWith('image/') ?? false; | ||
} | ||
|
||
if (typeof value !== 'string') { | ||
return false; | ||
} | ||
|
||
return isValidUrl(value) && isImageFormat(value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...ugin-data-viewer/src/ValuePanelPresentation/TextValue/isTextValuePresentationAvailable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2023 DBeaver Corp and others | ||
* | ||
* Licensed under the Apache License, Version 2.0. | ||
* you may not use this file except in compliance with the License. | ||
*/ | ||
import { isResultSetBinaryFileValue } from '../../DatabaseDataModel/Actions/ResultSet/isResultSetBinaryFileValue'; | ||
import { isResultSetContentValue } from '../../DatabaseDataModel/Actions/ResultSet/isResultSetContentValue'; | ||
import { ResultSetSelectAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetSelectAction'; | ||
import { ResultSetViewAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetViewAction'; | ||
import type { IDatabaseDataResult } from '../../DatabaseDataModel/IDatabaseDataResult'; | ||
import type { IDataValuePanelProps } from '../../TableViewer/ValuePanel/DataValuePanelService'; | ||
|
||
export function isBlobPresentationAvailable(context: IDataValuePanelProps<any, IDatabaseDataResult> | undefined): boolean { | ||
if (!context?.model.source.hasResult(context.resultIndex)) { | ||
return true; | ||
} | ||
|
||
const selection = context.model.source.getAction(context.resultIndex, ResultSetSelectAction); | ||
|
||
const focusedElement = selection.getFocusedElement(); | ||
|
||
if (selection.elements.length > 0 || focusedElement) { | ||
const view = context.model.source.getAction(context.resultIndex, ResultSetViewAction); | ||
|
||
const firstSelectedCell = selection.elements[0] || focusedElement; | ||
|
||
const cellValue = view.getCellValue(firstSelectedCell); | ||
|
||
return isResultSetContentValue(cellValue) && isResultSetBinaryFileValue(cellValue); | ||
} | ||
|
||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
webapp/packages/plugin-data-viewer/src/ValuePanelPresentation/TextValue/useTextValue.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* CloudBeaver - Cloud Database Manager | ||
* Copyright (C) 2020-2023 DBeaver Corp and others | ||
* | ||
* 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 { ResultSetEditAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetEditAction'; | ||
import { ResultSetFormatAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetFormatAction'; | ||
import { ResultSetSelectAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetSelectAction'; | ||
import type { IDatabaseDataModel } from '../../DatabaseDataModel/IDatabaseDataModel'; | ||
import type { IDatabaseResultSet } from '../../DatabaseDataModel/IDatabaseResultSet'; | ||
import { useAutoFormat } from './useAutoFormat'; | ||
|
||
interface IUseTextValueArgs { | ||
resultIndex: number; | ||
model: IDatabaseDataModel<any, IDatabaseResultSet>; | ||
currentContentType: string; | ||
} | ||
|
||
export function useTextValue({ model, resultIndex, currentContentType }: IUseTextValueArgs) { | ||
const format = model.source.getAction(resultIndex, ResultSetFormatAction); | ||
const editor = model.source.getAction(resultIndex, ResultSetEditAction); | ||
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; | ||
} | ||
|
||
const blob = format.get(firstSelectedCell); | ||
|
||
if (isResultSetContentValue(blob)) { | ||
const value = formatter.formatBlob(currentContentType, blob); | ||
|
||
if (value) { | ||
return value; | ||
} | ||
} | ||
|
||
return formatter.format(currentContentType, format.getText(firstSelectedCell)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.