Skip to content

Commit

Permalink
ui: fix filter for database
Browse files Browse the repository at this point in the history
A recent change made the format of the databases change
on the UI and the filter no longer work.
This commit changes the display, to use the format:
`db1, db2, db3`, instead of `["db1", "db2", "db3"]`.
It also fixes the filter for database, now checking
for both cases (database as a single value in a string
and when is an array in a string form).

Epic: None
Release note: None
  • Loading branch information
maryliag committed Apr 11, 2023
1 parent b6982d6 commit 96efd0b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
16 changes: 12 additions & 4 deletions pkg/ui/workspaces/cluster-ui/src/sqlActivity/util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@ export function filteredStatementsData(
// Current filters: search text, database, fullScan, service latency,
// SQL Type, nodes and regions.
return statements
.filter(
statement =>
databases.length == 0 || databases.includes(statement.database),
)
.filter(statement => {
try {
// Case where the database is returned as an array in a string form.
const dbList = JSON.parse(statement.database);
return (
databases.length === 0 || databases.some(d => dbList.includes(d))
);
} catch (e) {
// Case where the database is a single value as a string.
return databases.length === 0 || databases.includes(statement.database);
}
})
.filter(statement => (filters.fullScan ? statement.fullScan : true))
.filter(
statement =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ export function shortStatement(
}
}

function formatStringArray(databases: string): string {
try {
// Case where the database is returned as an array in a string form.
return JSON.parse(databases).join(", ");
} catch (e) {
// Case where the database is a single value as a string.
return databases;
}
}

export function makeStatementsColumns(
statements: AggregateStatistics[],
selectedApps: string[],
Expand Down Expand Up @@ -173,7 +183,7 @@ export function makeStatementsColumns(
name: "database",
title: statisticsTableTitles.database(statType),
className: cx("statements-table__col-database"),
cell: (stmt: AggregateStatistics) => stmt.database,
cell: (stmt: AggregateStatistics) => formatStringArray(stmt.database),
sort: (stmt: AggregateStatistics) => stmt.database,
showByDefault: false,
},
Expand Down

0 comments on commit 96efd0b

Please sign in to comment.