mirror of
https://github.com/apache/superset.git
synced 2026-06-01 05:39:17 +00:00
feat: Persist default folders location when repositioned in folders editor (#38105)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
8c58b998b1
commit
660357c76b
@@ -21,6 +21,10 @@ import { Metric } from '@superset-ui/core';
|
||||
import { transformDatasourceWithFolders } from './transformDatasourceFolders';
|
||||
import { DatasourceFolder, DatasourcePanelColumn } from './types';
|
||||
import { FoldersEditorItemType } from 'src/components/Datasource/types';
|
||||
import {
|
||||
DEFAULT_METRICS_FOLDER_UUID,
|
||||
DEFAULT_COLUMNS_FOLDER_UUID,
|
||||
} from 'src/components/Datasource/FoldersEditor/constants';
|
||||
|
||||
const mockMetrics: Metric[] = [
|
||||
{ metric_name: 'metric1', uuid: 'metric1-uuid', expression: 'SUM(col1)' },
|
||||
@@ -45,13 +49,13 @@ test('transforms data into default folders when no folder config is provided', (
|
||||
|
||||
expect(result).toHaveLength(2);
|
||||
|
||||
expect(result[0].id).toBe('metrics-default');
|
||||
expect(result[0].id).toBe(DEFAULT_METRICS_FOLDER_UUID);
|
||||
expect(result[0].name).toBe('Metrics');
|
||||
expect(result[0].items).toHaveLength(3);
|
||||
expect(result[0].items[0].uuid).toBe('metric1-uuid');
|
||||
expect(result[0].items[0].type).toBe(FoldersEditorItemType.Metric);
|
||||
|
||||
expect(result[1].id).toBe('columns-default');
|
||||
expect(result[1].id).toBe(DEFAULT_COLUMNS_FOLDER_UUID);
|
||||
expect(result[1].name).toBe('Columns');
|
||||
expect(result[1].items).toHaveLength(3);
|
||||
expect(result[1].items[0].uuid).toBe('column1-uuid');
|
||||
@@ -118,11 +122,11 @@ test('transforms data according to folder configuration', () => {
|
||||
expect(result[1].items).toHaveLength(1);
|
||||
expect(result[1].items[0].uuid).toBe('column1-uuid');
|
||||
|
||||
expect(result[2].id).toBe('metrics-default');
|
||||
expect(result[2].id).toBe(DEFAULT_METRICS_FOLDER_UUID);
|
||||
expect(result[2].items).toHaveLength(1);
|
||||
expect(result[2].items[0].uuid).toBe('metric3-uuid');
|
||||
|
||||
expect(result[3].id).toBe('columns-default');
|
||||
expect(result[3].id).toBe(DEFAULT_COLUMNS_FOLDER_UUID);
|
||||
expect(result[3].items).toHaveLength(2);
|
||||
});
|
||||
|
||||
|
||||
@@ -19,6 +19,10 @@
|
||||
import { t } from '@apache-superset/core';
|
||||
import { Metric } from '@superset-ui/core';
|
||||
import { FoldersEditorItemType } from 'src/components/Datasource/types';
|
||||
import {
|
||||
DEFAULT_METRICS_FOLDER_UUID,
|
||||
DEFAULT_COLUMNS_FOLDER_UUID,
|
||||
} from 'src/components/Datasource/FoldersEditor/constants';
|
||||
import {
|
||||
ColumnItem,
|
||||
DatasourceFolder,
|
||||
@@ -98,10 +102,36 @@ const transformToFolderStructure = (
|
||||
return folder;
|
||||
};
|
||||
|
||||
const addUnassignedToFolder = (
|
||||
folders: Folder[],
|
||||
items: (MetricItem | ColumnItem)[],
|
||||
folderId: string,
|
||||
folderName: string,
|
||||
allItemsCount: number,
|
||||
inFoldersCount: number,
|
||||
) => {
|
||||
if (items.length === 0) return;
|
||||
const existing = folders.find(f => f.id === folderId);
|
||||
if (existing) {
|
||||
existing.items.push(...items);
|
||||
existing.totalItems += items.length;
|
||||
existing.showingItems += items.length;
|
||||
} else {
|
||||
folders.push({
|
||||
id: folderId,
|
||||
name: folderName,
|
||||
isCollapsed: false,
|
||||
items,
|
||||
totalItems: allItemsCount - inFoldersCount,
|
||||
showingItems: items.length,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (!folderConfig) {
|
||||
return [
|
||||
{
|
||||
id: 'metrics-default',
|
||||
id: DEFAULT_METRICS_FOLDER_UUID,
|
||||
name: t('Metrics'),
|
||||
isCollapsed: false,
|
||||
items: metricsToDisplay,
|
||||
@@ -109,7 +139,7 @@ const transformToFolderStructure = (
|
||||
showingItems: metricsToDisplay.length,
|
||||
},
|
||||
{
|
||||
id: 'columns-default',
|
||||
id: DEFAULT_COLUMNS_FOLDER_UUID,
|
||||
name: t('Columns'),
|
||||
isCollapsed: false,
|
||||
items: columnsToDisplay,
|
||||
@@ -128,27 +158,22 @@ const transformToFolderStructure = (
|
||||
columnsMap.has(column.uuid),
|
||||
);
|
||||
|
||||
if (unassignedMetrics.length > 0) {
|
||||
folders.push({
|
||||
id: 'metrics-default',
|
||||
name: t('Metrics'),
|
||||
isCollapsed: false,
|
||||
items: unassignedMetrics,
|
||||
totalItems: allMetrics.length - metricsInFolders,
|
||||
showingItems: unassignedMetrics.length,
|
||||
});
|
||||
}
|
||||
|
||||
if (unassignedColumns.length > 0) {
|
||||
folders.push({
|
||||
id: 'columns-default',
|
||||
name: t('Columns'),
|
||||
isCollapsed: false,
|
||||
items: unassignedColumns,
|
||||
totalItems: allColumns.length - columnsInFolders,
|
||||
showingItems: unassignedColumns.length,
|
||||
});
|
||||
}
|
||||
addUnassignedToFolder(
|
||||
folders,
|
||||
unassignedMetrics,
|
||||
DEFAULT_METRICS_FOLDER_UUID,
|
||||
t('Metrics'),
|
||||
allMetrics.length,
|
||||
metricsInFolders,
|
||||
);
|
||||
addUnassignedToFolder(
|
||||
folders,
|
||||
unassignedColumns,
|
||||
DEFAULT_COLUMNS_FOLDER_UUID,
|
||||
t('Columns'),
|
||||
allColumns.length,
|
||||
columnsInFolders,
|
||||
);
|
||||
|
||||
return folders;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user