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-5170 add number formatting #3228

Open
wants to merge 4 commits into
base: devel
Choose a base branch
from
Open
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
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,20 @@ export class ResultSetFormatAction

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

constructor(source: IDatabaseDataSource<any, IDatabaseResultSet>, view: ResultSetViewAction, edit: ResultSetEditAction) {
private readonly settings: DataViewerSettingsService;
private numberFormatter: Intl.NumberFormat | null;

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

isReadOnly(key: IResultSetPartialKey): boolean {
Expand Down Expand Up @@ -92,6 +102,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;
Comment on lines +112 to +116
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just return column?.dataKind?.toLocaleLowerCase() === 'numeric' ?

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

if (this.isNumber(key) && !this.settings.numberFormattingDisabled) {
const formatter = this.getNumberFormatter();
return formatter.format(Number(value));
}

return this.truncateText(String(value), DISPLAY_STRING_LENGTH);
}

Expand All @@ -259,4 +287,12 @@ export class ResultSetFormatAction
.map(v => (v.charCodeAt(0) < 32 ? ' ' : v))
.join('');
}

private getNumberFormatter() {
if (!this.numberFormatter) {
this.numberFormatter = new Intl.NumberFormat();
}

return this.numberFormatter;
}
}
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', '保存成功'],
];
Loading