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

Mass actions for datasets (Aggregations and change type) #1492

Merged
merged 56 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
189fbbc
Add buttons to batch panel
Aug 28, 2024
554ade2
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 3, 2024
e80ea8b
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 3, 2024
6ce0813
Updated type select, add dialog
Sep 4, 2024
3b54981
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 4, 2024
9b6191f
Refactor AggregationSelect component
Sep 4, 2024
ecc971a
Add i18n keysets
Sep 9, 2024
fbca82a
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 9, 2024
819fe0d
Removed logs
Sep 9, 2024
b0f5f37
Add label and icons
Sep 9, 2024
5d43316
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 10, 2024
aa4fcf3
Removed export
Sep 10, 2024
ca6d47d
Translated using Weblate (English)
Sep 9, 2024
35efbd0
Translated using Weblate (English)
Sep 9, 2024
6d8b620
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 10, 2024
1739a40
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 10, 2024
2f637e1
Added link to keyset
Sep 10, 2024
ec1041c
Removed tooltip changes
Sep 10, 2024
bfca6b9
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 11, 2024
bb1718b
Revert Type and Aggregation selects, changed Dialog
Sep 11, 2024
d2781bd
Fix types, add method for open batch dialog
Sep 11, 2024
60ad0d2
Translate key
Sep 11, 2024
6fbaaf1
Removed unused imports
Sep 11, 2024
9a41672
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 12, 2024
b453857
Merged weblate conflicts
Sep 12, 2024
5903670
Changed link
Sep 12, 2024
7b36b17
Fix types
Sep 12, 2024
4cc4efd
Changed md to Interpolate
Sep 12, 2024
4935a2a
Translated using Weblate (English)
Sep 12, 2024
25dc0e9
Add wrapper for warning message
Sep 12, 2024
0f7ddd3
Merge branch 'main' into CHARTS-9840-mass-actions-datasets
stpavlenko Sep 12, 2024
4fe2c48
Resolved weblate conflicts
Sep 12, 2024
8b50a7d
Translated using Weblate (Russian)
dtikhonova Sep 12, 2024
d30fe07
Translated using Weblate (English)
Sep 12, 2024
85de3c7
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 12, 2024
a159650
Add button
Sep 12, 2024
101b407
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 13, 2024
258b3c0
Translated using Weblate (Russian)
dtikhonova Sep 12, 2024
812ff1b
Changed alert content
Sep 16, 2024
c1ebfc3
Add icon, remove link from text
Sep 16, 2024
b992482
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 16, 2024
27cead9
Resolved weblate conflicts
Sep 16, 2024
a6b2902
Removed unused link
Sep 16, 2024
d2f1e5d
Translated using Weblate (English)
Sep 16, 2024
089be00
Translated using Weblate (English)
Sep 17, 2024
9bc5071
Translations update from Weblate Gravity for PR #1492 (#1544)
WeblateGravity Sep 17, 2024
c5f30af
Revert to link
Sep 17, 2024
e9d962e
Resolved conflicts
Sep 17, 2024
db263c5
Resolved weblate conflicts
Sep 17, 2024
e7eca48
Translations update from Weblate Gravity for PR #1492 (#1548)
WeblateGravity Sep 17, 2024
8742326
Merge branch 'main' of github.com:datalens-tech/datalens-ui into CHAR…
Sep 20, 2024
d609a15
Merge branch 'CHARTS-9840-mass-actions-datasets' of github.com:datale…
Sep 20, 2024
95e3aaf
Refactor, changed imports, types
Sep 20, 2024
befddc7
Removed React.FC
Sep 20, 2024
9ae238e
Removed validation disable, removed size from selects
Sep 20, 2024
ac4eb0e
Merge branch 'main' into CHARTS-9840-mass-actions-datasets
stpavlenko Sep 20, 2024
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
9 changes: 9 additions & 0 deletions src/i18n-keysets/dataset.dataset-editor.modify/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
"button_add-field": "Add field",
"button_apply": "Apply",
"button_ask-access-rights": "Request permissions",
"button_batch-aggregation": "Change aggregation",
"button_batch-apply": "Apply",
"button_batch-cancel": "Cancel",
"button_batch-hide": "Hide",
"button_batch-remove": "Delete",
"button_batch-show": "Show",
"button_batch-type": "Change type",
"button_copy-id": "Copy ID",
"button_create": "Create",
"button_create-widget": "Create chart",
Expand Down Expand Up @@ -35,7 +38,9 @@
"column_title": "Name",
"field_display-rows": "Number of rows:",
"field_find-field": "Field name or description",
"label_batch-aggregation": "New field aggregation",
"label_batch-selected-fields-count": "Fields selected — {{value}}",
"label_batch-type": "New field type",
"label_column-field-id": "Field ID",
"label_dataset-auto-creation-process": "Creating dataset",
"label_display-fields-id": "Show field IDs",
Expand All @@ -57,12 +62,16 @@
"label_preview-not-supported": "Preview is not available for this type of source",
"label_request-dataset-preview-error": "Error: failed to upload data for preview",
"section_preview": "Preview",
"text_batch-aggregation-alert": "<link>The aggregations available</link> depend on the selected field type",
"text_batch-aggregation-header": "Changing the field aggregation",
"text_batch-hide-header": "Hide fields",
"text_batch-hide-message": "Are you sure want to hide the selected fields?",
"text_batch-remove-header": "Delete fields",
"text_batch-remove-message": "Are you sure want to delete the selected fields?",
"text_batch-show-header": "Show fields",
"text_batch-show-message": "Are you sure want to show the selected fields?",
"text_batch-type-alert": "Some conversion types are not available",
"text_batch-type-header": "Changing the field type",
"value_array_float": "Array of fractional numbers",
"value_array_int": "Array of integers",
"value_array_str": "Array of strings",
Expand Down
9 changes: 9 additions & 0 deletions src/i18n-keysets/dataset.dataset-editor.modify/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
"button_add-field": "Добавить поле",
"button_apply": "Применить",
"button_ask-access-rights": "Запросить права",
"button_batch-aggregation": "Изменить агрегацию",
"button_batch-apply": "Изменить",
"button_batch-cancel": "Отменить",
"button_batch-hide": "Скрыть",
"button_batch-remove": "Удалить",
"button_batch-show": "Показать",
"button_batch-type": "Изменить тип",
"button_copy-id": "Скопировать ID",
"button_create": "Создать",
"button_create-widget": "Создать чарт",
Expand Down Expand Up @@ -35,7 +38,9 @@
"column_title": "Имя",
"field_display-rows": "Количество строк:",
"field_find-field": "Имя или описание поля",
"label_batch-aggregation": "Новая агрегация полей",
"label_batch-selected-fields-count": "Выбрано полей — {{value}}",
"label_batch-type": "Новый тип полей",
"label_column-field-id": "ID поля",
"label_dataset-auto-creation-process": "Создаём датасет",
"label_display-fields-id": "Отображать ID полей",
Expand All @@ -57,12 +62,16 @@
"label_preview-not-supported": "Для данного типа источника предпросмотр не доступен",
"label_request-dataset-preview-error": "Ошибка: не удалось загрузить данные для предпросмотра",
"section_preview": "Предпросмотр",
"text_batch-aggregation-alert": "<link>Доступные агрегации</link> зависят от типа выбранных полей",
"text_batch-aggregation-header": "Изменение агрегации полей",
"text_batch-hide-header": "Скрыть поля датасета",
"text_batch-hide-message": "Вы уверены, что хотите скрыть выбранные поля датасета?",
"text_batch-remove-header": "Удалить поля датасета",
"text_batch-remove-message": "Вы уверены, что хотите удалить выбранные поля датасета?",
"text_batch-show-header": "Показать поля датасета",
"text_batch-show-message": "Вы уверены, что хотите показать выбранные поля датасета?",
"text_batch-type-alert": "Некоторые преобразования типов недоступны",
"text_batch-type-header": "Изменение типа полей",
"value_array_float": "Массив дробных чисел",
"value_array_int": "Массив целых чисел",
"value_array_str": "Массив строк",
Expand Down
28 changes: 4 additions & 24 deletions src/ui/components/DialogParameter/helpers.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import React from 'react';

import type {SelectOption} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';
import {i18n} from 'i18n';
import type {DatasetField, WithRequired} from 'shared';
import type {DatasetField} from 'shared';
import {
AVAILABLE_FIELD_TYPES,
DATASET_FIELD_TYPES,
DatasetFieldAggregation,
DatasetFieldType,
} from 'shared';
import {DataTypeIcon} from 'ui';
import {getTypeSelectOptions} from 'ui/utils/getTypeSelectOptions';

import type {ParameterFormState} from './useParameterForm';

Expand All @@ -24,26 +20,10 @@ const NEW_PARAMETER_FIELD = {
hidden: false,
};

const b = block('dialog-parameter');

export const getTypesList = (): SelectOption[] => {
return AVAILABLE_FIELD_TYPES.map((type): WithRequired<SelectOption, 'text'> => {
const text = i18n('dataset.dataset-editor.modify', `value_${type}`);
return {
qa: `dialog-parameter-${type}`,
data: {
icon: <DataTypeIcon className={b('icon')} dataType={type as DATASET_FIELD_TYPES} />,
},
value: type,
content: text,
text,
};
}).sort((current, next) => {
const currentText = current.text;
const nextText = next.text;
const items = getTypeSelectOptions([...AVAILABLE_FIELD_TYPES]);

return currentText.localeCompare(nextText, undefined, {numeric: true});
});
return items.map((item) => ({...item, qa: `dialog-parameter-${item.value}`}));
};

export const createParameterField = (
Expand Down
4 changes: 3 additions & 1 deletion src/ui/store/actions/openDialogTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import type {OpenDialogDeleteWorkbookArgs} from '../../components/CollectionsStr
import type {OpenDialogAddDemoWorkbookArgs} from '../../components/CollectionsStructure/AddDemoWorkbookDialog';
import type {OpenDialogCreateEntryInWorkbookArgs} from '../../components/CollectionsStructure/CreateEntryInWorkbookDialog';
import type {OpenDialogIamAccessArgs} from '../../components/IamAccessDialog';
import type {OpenDialogChangeDatasetFieldsArgs} from '../../units/datasets/components/DatasetTable/components/BatchActionPanel/components/DialogChangeDatasetFields/DialogChangeDatasetFields';

export type OpenDialogArgs<T = unknown> =
| OpenDialogMetricSettingsArgs
Expand Down Expand Up @@ -105,4 +106,5 @@ export type OpenDialogArgs<T = unknown> =
| OpenDialogDeleteWorkbookArgs
| OpenDialogAddDemoWorkbookArgs
| OpenDialogIamAccessArgs
| OpenDialogCreateEntryInWorkbookArgs;
| OpenDialogCreateEntryInWorkbookArgs
| OpenDialogChangeDatasetFieldsArgs;
118 changes: 102 additions & 16 deletions src/ui/units/datasets/components/DatasetTable/DatasetTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import React from 'react';

import {ArrowDown, ArrowUp} from '@gravity-ui/icons';
import DataTable from '@gravity-ui/react-data-table';
import {Icon} from '@gravity-ui/uikit';
import {Icon, Link} from '@gravity-ui/uikit';
import block from 'bem-cn-lite';
import {I18n} from 'i18n';
import {get} from 'lodash';
import get from 'lodash/get';
import intersection from 'lodash/intersection';
import type {
DATASET_FIELD_TYPES,
DatasetField,
Expand All @@ -16,6 +17,8 @@ import type {
DatasetSourceAvatar,
} from 'shared';
import type {Permissions} from 'shared/types/dls';
import {Interpolate} from 'ui/components/Interpolate';
import {DL} from 'ui/constants';

import type {
OpenDialogConfirmArguments,
Expand All @@ -28,8 +31,11 @@ import {DIALOG_DS_FIELD_INSPECTOR} from '../dialogs';

import {DisplaySettings} from './components';
import {BatchActionPanel} from './components/BatchActionPanel/BatchActionPanel';
import type {DialogChangeDatasetFieldsProps} from './components/BatchActionPanel/components/DialogChangeDatasetFields/DialogChangeDatasetFields';
import {DIALOG_CHANGE_DATASET_FIELDS} from './components/BatchActionPanel/components/DialogChangeDatasetFields/DialogChangeDatasetFields';
import {ObservedTableResizer} from './components/ObservedDataTable';
import {BatchFieldAction, FieldAction} from './constants';
import type {BatchUpdateFields, UpdatePayload} from './types';
import {getAggregationSwitchTo, getColumns, isHiddenSupported} from './utils';

import './DatasetTable.scss';
Expand All @@ -42,12 +48,6 @@ DataTable.setCustomIcons({
ICON_DESC: <Icon className={b('sort-icon')} data={ArrowUp} />,
});

type UpdatePayload = {
debounce?: boolean;
validateEnabled?: boolean;
updatePreview?: boolean;
};

type DatasetTableProps = {
options: DatasetOptions;
fields: DatasetField[];
Expand All @@ -59,11 +59,7 @@ type DatasetTableProps = {
field: Partial<DatasetField> & {new_id?: string};
},
) => void;
batchUpdateFields: (
data: UpdatePayload & {
fields: Partial<DatasetField>[] & {new_id?: string}[];
},
) => void;
batchUpdateFields: BatchUpdateFields;
duplicateField: (data: {field: DatasetField}) => void;
removeField: (data: {field: DatasetField}) => void;
batchRemoveFields: (data: {fields: DatasetField[]}) => void;
Expand Down Expand Up @@ -117,6 +113,8 @@ class DatasetTable extends React.Component<DatasetTableProps, DatasetTableState>
map: selectedRows,
canBeHidden,
canBeShown,
allowedTypes,
allowedAggregations,
} = this.getFilteredSelectedRows();

return (
Expand Down Expand Up @@ -160,6 +158,8 @@ class DatasetTable extends React.Component<DatasetTableProps, DatasetTableState>
disableActions={[
...(canBeHidden.count > 0 ? [] : (['hide'] as const)),
...(canBeShown.count > 0 ? [] : (['show'] as const)),
...(allowedTypes.length > 0 ? [] : (['type'] as const)),
...(allowedAggregations.length > 0 ? [] : (['aggregation'] as const)),
]}
/>
)}
Expand All @@ -169,7 +169,7 @@ class DatasetTable extends React.Component<DatasetTableProps, DatasetTableState>

private getFilteredSelectedRows() {
const {selectedRows} = this.state;
const {fields} = this.props;
const {fields, options} = this.props;

let count = 0;
const canBeHidden: {count: number; fields: DatasetField[]} = {count: 0, fields: []};
Expand Down Expand Up @@ -200,7 +200,22 @@ class DatasetTable extends React.Component<DatasetTableProps, DatasetTableState>
return memo;
}, {});

return {count, map, fields: filteredFields, canBeHidden, canBeShown};
const selectedItems = options.fields.items.filter(
(item) => this.state.selectedRows[item.guid],
);

const allowedTypes = intersection(...selectedItems.map((item) => item.casts));
const allowedAggregations = intersection(...selectedItems.map((item) => item.aggregations));

return {
count,
map,
fields: filteredFields,
canBeHidden,
canBeShown,
allowedTypes,
allowedAggregations,
};
}

private getColumns(selectedRows: DatasetSelectionMap = {}) {
Expand Down Expand Up @@ -248,6 +263,26 @@ class DatasetTable extends React.Component<DatasetTableProps, DatasetTableState>

private setActiveRow = (activeRow?: number) => this.setState({activeRow});

private batchChangeDialog = (
fields: DatasetField[],
props: Omit<
DialogChangeDatasetFieldsProps,
'open' | 'onClose' | 'fieldsGuids' | 'batchUpdateFields' | 'onApply'
>,
) => {
this.props.openDialog({
id: DIALOG_CHANGE_DATASET_FIELDS,
props: {
open: true,
onClose: this.props.closeDialog,
fieldsGuids: fields.map(({guid}) => guid),
batchUpdateFields: this.props.batchUpdateFields,
onApply: this.resetSelection,
...props,
},
});
};

private batchConfirmDialog = (
options: Partial<OpenDialogConfirmArguments> &
Pick<
Expand Down Expand Up @@ -301,8 +336,49 @@ class DatasetTable extends React.Component<DatasetTableProps, DatasetTableState>
});
};

private openBatchUpdateTypesDialog = (
fields: DatasetField[],
allowedTypes: DATASET_FIELD_TYPES[],
) => {
this.batchChangeDialog(fields, {
warningMessage: i18n('text_batch-type-alert'),
title: i18n('text_batch-type-header'),
label: i18n('label_batch-type'),
types: allowedTypes,
});
};

private openBatchUpdateAggregationsDialog = (
fields: DatasetField[],
allowedAggregations: DatasetFieldAggregation[],
) => {
this.batchChangeDialog(fields, {
warningMessage: (
<Interpolate
text={i18n('text_batch-aggregation-alert')}
matches={{
link(match) {
return (
<Link
target="_blank"
href={`${DL.ENDPOINTS.datalensDocs}/dataset/data-model#aggregation`}
>
{match}
</Link>
);
},
}}
></Interpolate>
),
title: i18n('text_batch-aggregation-header'),
label: i18n('label_batch-aggregation'),
aggregations: allowedAggregations,
});
};

private handleBatchUpdate = (action: BatchFieldAction) => {
const {fields, canBeShown, canBeHidden} = this.getFilteredSelectedRows();
const {fields, canBeShown, canBeHidden, allowedTypes, allowedAggregations} =
this.getFilteredSelectedRows();

switch (action) {
case BatchFieldAction.Remove: {
Expand All @@ -320,6 +396,16 @@ class DatasetTable extends React.Component<DatasetTableProps, DatasetTableState>
return;
}

case BatchFieldAction.Type: {
this.openBatchUpdateTypesDialog(fields, allowedTypes);
return;
}

case BatchFieldAction.Aggregation: {
this.openBatchUpdateAggregationsDialog(fields, allowedAggregations);
return;
}

default: {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import {connect} from 'react-redux';
import type {DatasetField, DatasetFieldAggregation} from 'shared';
import type {DatalensGlobalState} from 'ui';

import {getSelectedValueForSelect} from '../../../../../../utils/helpers';
import {getDatasetLabelValue, getSelectedValueForSelect} from '../../../../../../utils/helpers';
import {AGGREGATION_AUTO, AGGREGATION_NONE} from '../../../../constants';
import {datasetValidationSelector} from '../../../../store/selectors/dataset';
import {getLabelValue} from '../../utils';

import './AggregationSelect.scss';

Expand Down Expand Up @@ -65,7 +64,7 @@ class AggregationSelectComponent extends React.Component<Props> {

return {
value: aggregation,
content: getLabelValue(aggregationTitle),
content: getDatasetLabelValue(aggregationTitle),
disabled: validation.isLoading,
};
})
Expand Down Expand Up @@ -139,7 +138,9 @@ class AggregationSelectComponent extends React.Component<Props> {
view="flat"
className={b('select-control', {[this.type]: true})}
>
<span className={b('selected-value')}>{getLabelValue(aggregationTitle)}</span>
<span className={b('selected-value')}>
{getDatasetLabelValue(aggregationTitle)}
</span>
</Button>
);
};
Expand Down
Loading
Loading