mirror of
https://github.com/apache/superset.git
synced 2026-07-19 13:15:49 +00:00
feat(sqllab): improve table metadata UI (#32051)
This commit is contained in:
@@ -187,30 +187,40 @@ export default function sqlLabReducer(state = {}, action) {
|
||||
},
|
||||
[actions.MERGE_TABLE]() {
|
||||
const at = { ...action.table };
|
||||
let existingTable;
|
||||
state.tables.forEach(xt => {
|
||||
if (
|
||||
const existingTableIndex = state.tables.findIndex(
|
||||
xt =>
|
||||
xt.dbId === at.dbId &&
|
||||
xt.queryEditorId === at.queryEditorId &&
|
||||
xt.catalog === at.catalog &&
|
||||
xt.schema === at.schema &&
|
||||
xt.name === at.name
|
||||
) {
|
||||
existingTable = xt;
|
||||
}
|
||||
});
|
||||
if (existingTable) {
|
||||
xt.name === at.name,
|
||||
);
|
||||
if (existingTableIndex >= 0) {
|
||||
if (action.query) {
|
||||
at.dataPreviewQueryId = action.query.id;
|
||||
}
|
||||
if (existingTable.initialized) {
|
||||
at.id = existingTable.id;
|
||||
}
|
||||
return alterInArr(state, 'tables', existingTable, at);
|
||||
return {
|
||||
...state,
|
||||
tables: [
|
||||
...state.tables.slice(0, existingTableIndex),
|
||||
{
|
||||
...state.tables[existingTableIndex],
|
||||
...at,
|
||||
...(state.tables[existingTableIndex].initialized && {
|
||||
id: state.tables[existingTableIndex].id,
|
||||
}),
|
||||
},
|
||||
...state.tables.slice(existingTableIndex + 1),
|
||||
],
|
||||
...(at.expanded && {
|
||||
activeSouthPaneTab: at.id,
|
||||
}),
|
||||
};
|
||||
}
|
||||
// for new table, associate Id of query for data preview
|
||||
at.dataPreviewQueryId = null;
|
||||
let newState = addToArr(state, 'tables', at, Boolean(action.prepend));
|
||||
newState.activeSouthPaneTab = at.id;
|
||||
if (action.query) {
|
||||
newState = alterInArr(newState, 'tables', at, {
|
||||
dataPreviewQueryId: action.query.id,
|
||||
@@ -245,7 +255,6 @@ export default function sqlLabReducer(state = {}, action) {
|
||||
...state,
|
||||
queries,
|
||||
tables: newTables,
|
||||
activeSouthPaneTab: action.newQuery.id,
|
||||
};
|
||||
},
|
||||
[actions.COLLAPSE_TABLE]() {
|
||||
@@ -253,9 +262,18 @@ export default function sqlLabReducer(state = {}, action) {
|
||||
},
|
||||
[actions.REMOVE_TABLES]() {
|
||||
const tableIds = action.tables.map(table => table.id);
|
||||
const tables = state.tables.filter(table => !tableIds.includes(table.id));
|
||||
|
||||
return {
|
||||
...state,
|
||||
tables: state.tables.filter(table => !tableIds.includes(table.id)),
|
||||
tables,
|
||||
...(tableIds.includes(state.activeSouthPaneTab) && {
|
||||
activeSouthPaneTab:
|
||||
tables.find(
|
||||
({ queryEditorId }) =>
|
||||
queryEditorId === action.tables[0].queryEditorId,
|
||||
)?.id ?? 'Results',
|
||||
}),
|
||||
};
|
||||
},
|
||||
[actions.COST_ESTIMATE_STARTED]() {
|
||||
@@ -315,8 +333,6 @@ export default function sqlLabReducer(state = {}, action) {
|
||||
const queries = { ...state.queries, [q.id]: q };
|
||||
newState = { ...state, queries };
|
||||
}
|
||||
} else {
|
||||
newState.activeSouthPaneTab = action.query.id;
|
||||
}
|
||||
newState = addToObject(newState, 'queries', action.query);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user