feat(sqllab): improve table metadata UI (#32051)

This commit is contained in:
JUST.in DO IT
2025-01-31 10:19:37 -08:00
committed by GitHub
parent 101d3fa78d
commit c590e90c87
22 changed files with 889 additions and 145 deletions

View File

@@ -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);