Skip to content

Commit

Permalink
CB-5170 add number formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
devnaumov committed Jan 30, 2025
1 parent dc71e65 commit 0da8006
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const defaultSettings = schema.object({
'plugin.data-viewer.fetchMax': schema.coerce.number().min(FETCH_MIN).default(FETCH_MAX),
'resultset.maxrows': schema.coerce.number().min(FETCH_MIN).max(FETCH_MAX).default(DEFAULT_FETCH_SIZE),
'plugin.data-viewer.export.disabled': schemaExtra.stringedBoolean().default(false),
'plugin.data-viewer.format.number.disabled': schemaExtra.stringedBoolean().default(true),
});

export type DataViewerSettings = schema.infer<typeof defaultSettings>;
Expand Down Expand Up @@ -61,6 +62,10 @@ export class DataViewerSettingsService extends Dependency {
return this.settings.getValue('resultset.maxrows');
}

get numberFormattingDisabled(): boolean {
return this.settings.getValue('plugin.data-viewer.format.number.disabled');
}

readonly settings: SettingsProvider<typeof defaultSettings>;

constructor(
Expand Down Expand Up @@ -155,6 +160,15 @@ export class DataViewerSettingsService extends Dependency {
scope: ['server'],
},
},
{
group: DATA_EDITOR_SETTINGS_GROUP,
key: 'plugin.data-viewer.format.number.disabled',
type: ESettingsValueType.Checkbox,
name: 'settings_data_editor_disable_number_formatting',
access: {
scope: ['client'],
},
},
];

if (!this.serverSettingsManagerService.providedSettings.has('resultset.maxrows')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
import { ResultDataFormat } from '@cloudbeaver/core-sdk';

import { DataViewerSettingsService } from '../../../DataViewerSettingsService.js';
import { DatabaseDataAction } from '../../DatabaseDataAction.js';
import type { IDatabaseDataSource } from '../../IDatabaseDataSource.js';
import type { IDatabaseResultSet } from '../../IDatabaseResultSet.js';
Expand Down Expand Up @@ -41,11 +42,18 @@ export class ResultSetFormatAction

private readonly view: ResultSetViewAction;
private readonly edit: ResultSetEditAction;

constructor(source: IDatabaseDataSource<any, IDatabaseResultSet>, view: ResultSetViewAction, edit: ResultSetEditAction) {
private readonly settings: DataViewerSettingsService;

constructor(
source: IDatabaseDataSource<any, IDatabaseResultSet>,
view: ResultSetViewAction,
edit: ResultSetEditAction,
settings: DataViewerSettingsService,
) {
super(source);
this.view = view;
this.edit = edit;
this.settings = settings;
}

isReadOnly(key: IResultSetPartialKey): boolean {
Expand Down Expand Up @@ -92,6 +100,19 @@ export class ResultSetFormatAction
return false;
}

isNumber(key: IResultSetPartialKey): boolean {
if (!key.column) {
return false;
}

const column = this.view.getColumn(key.column);

if (column?.dataKind?.toLocaleLowerCase() === 'numeric') {
return true;
}

return false;
}
isGeometry(key: IResultSetPartialKey) {
if (key.column) {
const column = this.view.getColumn(key.column);
Expand Down Expand Up @@ -249,6 +270,9 @@ export class ResultSetFormatAction
return '[null]';
}

if (this.isNumber(key) && !this.settings.numberFormattingDisabled) {
return Number(value).toLocaleString();
}
return this.truncateText(String(value), DISPLAY_STRING_LENGTH);
}

Expand Down
1 change: 1 addition & 0 deletions webapp/packages/plugin-data-viewer/src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ export default [
['settings_data_editor_fetch_max_description', 'Maximale Anzahl von Zeilen zum Abrufen'],
['settings_data_editor_fetch_default_name', 'Standard fetch size'],
['settings_data_editor_fetch_default_description', 'Standardnummer der Zeilen zum Abrufen'],
['settings_data_editor_disable_number_formatting', 'Disable number formatting'],
['plugin_data_viewer_no_available_presentation', 'Keine verfügbare Präsentation'],
];
1 change: 1 addition & 0 deletions webapp/packages/plugin-data-viewer/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default [
['settings_data_editor_fetch_max_description', 'Maximum number of rows to fetch'],
['settings_data_editor_fetch_default_name', 'Default fetch size'],
['settings_data_editor_fetch_default_description', 'Default number of rows to fetch'],
['settings_data_editor_disable_number_formatting', 'Disable number formatting'],
['plugin_data_viewer_no_available_presentation', 'No available presentation'],
['plugin_data_viewer_result_set_save_success', 'Saved successfully'],
];
1 change: 1 addition & 0 deletions webapp/packages/plugin-data-viewer/src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ export default [
['settings_data_editor_fetch_max_description', 'Nombre maximal de lignes à récupérer'],
['settings_data_editor_fetch_default_name', 'Taille de récupération par défaut'],
['settings_data_editor_fetch_default_description', 'Nombre par défaut de lignes à récupérer'],
['settings_data_editor_disable_number_formatting', 'Disable number formatting'],
['plugin_data_viewer_no_available_presentation', 'Aucune présentation disponible'],
];
1 change: 1 addition & 0 deletions webapp/packages/plugin-data-viewer/src/locales/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export default [
['settings_data_editor_fetch_max_description', 'Maximum number of rows to fetch'],
['settings_data_editor_fetch_default_name', 'Default fetch size'],
['settings_data_editor_fetch_default_description', 'Default number of rows to fetch'],
['settings_data_editor_disable_number_formatting', 'Disable number formatting'],
['plugin_data_viewer_no_available_presentation', 'No available presentation'],
['plugin_data_viewer_result_set_save_success', 'Saved successfully'],
];
1 change: 1 addition & 0 deletions webapp/packages/plugin-data-viewer/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default [
['settings_data_editor_fetch_max_description', 'Максимальное количество строк для выборки'],
['settings_data_editor_fetch_default_name', 'Размер выборки по умолчанию'],
['settings_data_editor_fetch_default_description', 'Количество строк для выборки по умолчанию'],
['settings_data_editor_disable_number_formatting', 'Отключить форматирование чисел'],
['plugin_data_viewer_no_available_presentation', 'Нет доступных представлений'],
['plugin_data_viewer_result_set_save_success', 'Успешно сохранено'],
];
1 change: 1 addition & 0 deletions webapp/packages/plugin-data-viewer/src/locales/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default [
['settings_data_editor_fetch_max_description', '最大查询数据行数'],
['settings_data_editor_fetch_default_name', '默认查询数量'],
['settings_data_editor_fetch_default_description', '默认查询数据行数'],
['settings_data_editor_disable_number_formatting', 'Disable number formatting'],
['plugin_data_viewer_no_available_presentation', '无可用展示项'],
['plugin_data_viewer_result_set_save_success', '保存成功'],
];

0 comments on commit 0da8006

Please sign in to comment.