Skip to content

Commit

Permalink
Cb 4760 add to value panel more clear abstractions and separation of …
Browse files Browse the repository at this point in the history
…the logic (#2688)

* CB-4760 refactors value panel boolean presentation

* CB-4760 refactors value panel image presentation

* CB-4760 refactors value panel text presentation (part 1)

* CB-4760 refactors value panel text presentation (part 2)

* CB-4760 moves ValuePanel presentation layer to ValuePanel folder

* CB-4760 fixes type in file name

* CB-4760 modifies isBlob truncated logic

* CB-4760 booleanValuePresentation uses actions helper

* CB-4760 reverts value panel helpers location

* CB-4760 reverts getResultSetActions

* CB-4760 add preprocessBooleanValue helper instead of hook

* CB-4760 reverts truncated message isTruncated logic

* CB-4760 cleanup

* CB-4760 cleanup

* CB-4760 test commit for save file history

* CB-4760 test commit for save file history [2]

* CB-4760 test commit for save file history [3]

* CB-4760 moves back ValuePanelPresentation directory to src folder to save git history

* CB-4760 pr fixes

* CB-4760 adds placeholder for non selected elements in boolean value presentation (value panel)

* CB-4760 fixes placeholder translation for non selected elements in boolean value presentation (value panel)

* CB-4760 fix: app restart process

* CB-4760 fix: app restart process

---------

Co-authored-by: mr-anton-t <[email protected]>
Co-authored-by: Aleksei Potsetsuev <[email protected]>
  • Loading branch information
3 people authored Jun 13, 2024
1 parent 1c9b4f1 commit a65dff3
Show file tree
Hide file tree
Showing 18 changed files with 382 additions and 350 deletions.
17 changes: 10 additions & 7 deletions webapp/packages/core-di/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { IDiWrapper, inversifyWrapper } from './inversifyWrapper';
import type { PluginManifest } from './PluginManifest';

export interface IStartData {
restart: boolean;
preload: boolean;
}

Expand All @@ -29,11 +30,14 @@ export class App {

constructor(plugins: PluginManifest[] = []) {
this.plugins = plugins;
this.onStart = new Executor();
this.onStart = new Executor<IStartData>(undefined, () => true);
this.loadedServices = new Map();
this.isAppServiceBound = false;

this.onStart.addHandler(async ({ preload }) => {
this.onStart.addHandler(async ({ restart, preload }) => {
if (preload && restart) {
this.dispose();
}
await this.registerServices(preload);
await this.initializeServices(preload);
await this.loadServices(preload);
Expand All @@ -44,14 +48,13 @@ export class App {
});
}

async start(): Promise<void> {
await this.onStart.execute({ preload: true });
await this.onStart.execute({ preload: false });
async start(restart = false): Promise<void> {
await this.onStart.execute({ preload: true, restart });
await this.onStart.execute({ preload: false, restart });
}

async restart(): Promise<void> {
this.dispose();
await this.start();
await this.start(true);
}

dispose(): void {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { observer } from 'mobx-react-lite';

import { Radio, TextPlaceholder, useTranslate } from '@cloudbeaver/core-blocks';
import type { TabContainerPanelComponent } from '@cloudbeaver/core-ui';
import { isDefined } from '@cloudbeaver/core-utils';

import { ResultSetEditAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetEditAction';
import { ResultSetFormatAction } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetFormatAction';
Expand All @@ -17,41 +18,34 @@ import { ResultSetViewAction } from '../../DatabaseDataModel/Actions/ResultSet/R
import type { IDatabaseResultSet } from '../../DatabaseDataModel/IDatabaseResultSet';
import type { IDataValuePanelProps } from '../../TableViewer/ValuePanel/DataValuePanelService';
import classes from './BooleanValuePresentation.module.css';
import { isStringifiedBoolean } from './isBooleanValuePresentationAvailable';
import { preprocessBooleanValue } from './preprocessBooleanValue';

export const BooleanValuePresentation: TabContainerPanelComponent<IDataValuePanelProps<any, IDatabaseResultSet>> = observer(
function BooleanValuePresentation({ model, resultIndex }) {
const translate = useTranslate();
const selection = model.source.getAction(resultIndex, ResultSetSelectAction);
const activeElements = selection.getActiveElements();

if (activeElements.length === 0) {
return null;
}
const selectAction = model.source.getAction(resultIndex, ResultSetSelectAction);
const viewAction = model.source.getAction(resultIndex, ResultSetViewAction);
const editAction = model.source.getAction(resultIndex, ResultSetEditAction);
const formatAction = model.source.getAction(resultIndex, ResultSetFormatAction);

let value: boolean | null | undefined;
const activeElements = selectAction.getActiveElements();

const view = model.source.getAction(resultIndex, ResultSetViewAction);
const editor = model.source.getAction(resultIndex, ResultSetEditAction);
if (activeElements.length === 0) {
return <TextPlaceholder>{translate('data_viewer_presentation_value_no_active_elements')}</TextPlaceholder>;
}

const firstSelectedCell = activeElements[0];
const cellValue = view.getCellValue(firstSelectedCell);
const cellValue = viewAction.getCellValue(firstSelectedCell);
const value = preprocessBooleanValue(cellValue);

if (typeof cellValue === 'string' && isStringifiedBoolean(cellValue)) {
value = cellValue.toLowerCase() === 'true';
} else if (typeof cellValue === 'boolean' || cellValue === null) {
value = cellValue;
}

if (value === undefined) {
if (!isDefined(value)) {
return <TextPlaceholder>{translate('data_viewer_presentation_value_boolean_placeholder')}</TextPlaceholder>;
}

const format = model.source.getAction(resultIndex, ResultSetFormatAction);

const column = view.getColumn(firstSelectedCell.column);
const column = viewAction.getColumn(firstSelectedCell.column);
const nullable = column?.required === false;
const readonly = model.isReadonly(resultIndex) || model.isDisabled(resultIndex) || format.isReadOnly(firstSelectedCell);
const readonly = model.isReadonly(resultIndex) || model.isDisabled(resultIndex) || formatAction.isReadOnly(firstSelectedCell);

return (
<div className={classes.container}>
Expand All @@ -61,7 +55,7 @@ export const BooleanValuePresentation: TabContainerPanelComponent<IDataValuePane
mod={['primary']}
checked={value === true}
disabled={readonly}
onClick={() => editor.set(firstSelectedCell, true)}
onClick={() => editAction.set(firstSelectedCell, true)}
>
TRUE
</Radio>
Expand All @@ -71,7 +65,7 @@ export const BooleanValuePresentation: TabContainerPanelComponent<IDataValuePane
mod={['primary']}
checked={value === false}
disabled={readonly}
onClick={() => editor.set(firstSelectedCell, false)}
onClick={() => editAction.set(firstSelectedCell, false)}
>
FALSE
</Radio>
Expand All @@ -82,7 +76,7 @@ export const BooleanValuePresentation: TabContainerPanelComponent<IDataValuePane
mod={['primary']}
checked={value === null}
disabled={readonly}
onClick={() => editor.set(firstSelectedCell, null)}
onClick={() => editAction.set(firstSelectedCell, null)}
>
NULL
</Radio>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,11 @@ export class BooleanValuePresentationBootstrap extends Bootstrap {

if (activeElements.length > 0) {
const view = context.model.source.getAction(context.resultIndex, ResultSetViewAction);

const firstSelectedCell = activeElements[0];
const cellValue = view.getCellValue(firstSelectedCell);

if (cellValue === undefined) {
return true;
}

const column = view.getColumn(firstSelectedCell.column);

return column === undefined || !isBooleanValuePresentationAvailable(cellValue, column);
return cellValue === undefined || column === undefined || !isBooleanValuePresentationAvailable(cellValue, column);
}

return true;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* CloudBeaver - Cloud Database Manager
* Copyright (C) 2020-2024 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 type { IResultSetValue } from '../../DatabaseDataModel/Actions/ResultSet/ResultSetFormatAction';
import { isStringifiedBoolean } from './isBooleanValuePresentationAvailable';

export function preprocessBooleanValue(cellValue: IResultSetValue): boolean | null | undefined {
if (typeof cellValue === 'string' && isStringifiedBoolean(cellValue)) {
return cellValue.toLowerCase() === 'true';
}

if (typeof cellValue === 'boolean' || cellValue === null) {
return cellValue;
}

return undefined;
}
Loading

0 comments on commit a65dff3

Please sign in to comment.