From 61ee843e57de8793c70ff5d3fd97884ff89146f2 Mon Sep 17 00:00:00 2001 From: Yannan <73408381+YannanGao-gs@users.noreply.github.com> Date: Wed, 9 Aug 2023 16:43:52 -0400 Subject: [PATCH] Fix a bug where failing to start filtering by current value after the column results are re-ordered (#2483) --- .changeset/five-pants-burn.md | 3 +++ .changeset/shy-oranges-cheer.md | 5 +++++ .../action/execution/ExecutionResult.ts | 18 +++++++++++++++++- packages/legend-graph/src/index.ts | 1 + .../src/components/QueryBuilderResultPanel.tsx | 16 +++++++++++++--- 5 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 .changeset/five-pants-burn.md create mode 100644 .changeset/shy-oranges-cheer.md diff --git a/.changeset/five-pants-burn.md b/.changeset/five-pants-burn.md new file mode 100644 index 0000000000..d78bbd6f64 --- /dev/null +++ b/.changeset/five-pants-burn.md @@ -0,0 +1,3 @@ +--- +'@finos/legend-graph': patch +--- diff --git a/.changeset/shy-oranges-cheer.md b/.changeset/shy-oranges-cheer.md new file mode 100644 index 0000000000..f0da387f04 --- /dev/null +++ b/.changeset/shy-oranges-cheer.md @@ -0,0 +1,5 @@ +--- +'@finos/legend-query-builder': patch +--- + +Fix a bug where failing to start filtering by current value after the column results are re-ordered diff --git a/packages/legend-graph/src/graph-manager/action/execution/ExecutionResult.ts b/packages/legend-graph/src/graph-manager/action/execution/ExecutionResult.ts index 48cc7b1382..2bb1ea3b20 100644 --- a/packages/legend-graph/src/graph-manager/action/execution/ExecutionResult.ts +++ b/packages/legend-graph/src/graph-manager/action/execution/ExecutionResult.ts @@ -14,7 +14,7 @@ * limitations under the License. */ -import { uuid } from '@finos/legend-shared'; +import { guaranteeNonNullable, uuid } from '@finos/legend-shared'; // Core export enum BuilderType { @@ -138,3 +138,19 @@ export class ClassExecutionResult extends ExecutionResult { override builder = new ClassBuilder(BuilderType.CLASS_BUILDER); objects!: object; } + +export const getTDSRowRankByColumnInAsc = ( + a: TDSRow, + b: TDSRow, + colIndex: number, +): number => { + const a1 = + a.values[colIndex] === null || a.values[colIndex] === undefined + ? -Infinity + : a.values[colIndex]; + const b1 = + b.values[colIndex] === null || b.values[colIndex] === undefined + ? -Infinity + : b.values[colIndex]; + return Number(guaranteeNonNullable(a1)) - Number(guaranteeNonNullable(b1)); +}; diff --git a/packages/legend-graph/src/index.ts b/packages/legend-graph/src/index.ts index f9afabd985..110c5c0fc2 100644 --- a/packages/legend-graph/src/index.ts +++ b/packages/legend-graph/src/index.ts @@ -220,6 +220,7 @@ export { TDSExecutionResult as TDSExecutionResult, RawExecutionResult, EXECUTION_SERIALIZATION_FORMAT, + getTDSRowRankByColumnInAsc, } from './graph-manager/action/execution/ExecutionResult.js'; export { ExternalFormatDescription } from './graph-manager/action/externalFormat/ExternalFormatDescription.js'; export * from './graph-manager/action/generation/ArtifactGenerationExtensionResult.js'; diff --git a/packages/legend-query-builder/src/components/QueryBuilderResultPanel.tsx b/packages/legend-query-builder/src/components/QueryBuilderResultPanel.tsx index 4f6df7d555..55f9f28c28 100644 --- a/packages/legend-query-builder/src/components/QueryBuilderResultPanel.tsx +++ b/packages/legend-query-builder/src/components/QueryBuilderResultPanel.tsx @@ -53,6 +53,7 @@ import { EnumValueInstanceValue, EnumValueExplicitReference, RelationalExecutionActivities, + getTDSRowRankByColumnInAsc, } from '@finos/legend-graph'; import { ActionAlertActionType, @@ -523,10 +524,19 @@ const QueryResultCellRenderer = observer( ) { return undefined; } - - return resultState.executionResult.result.rows[rowIndex]?.values[ - colIndex + const sortedExecutionResult = [ + ...resultState.executionResult.result.rows, ]; + if (params.columnApi.getColumnState()[colIndex]?.sort === 'asc') { + sortedExecutionResult.sort((a, b) => + getTDSRowRankByColumnInAsc(a, b, colIndex), + ); + } else if (params.columnApi.getColumnState()[colIndex]?.sort === 'desc') { + sortedExecutionResult.sort((a, b) => + getTDSRowRankByColumnInAsc(b, a, colIndex), + ); + } + return sortedExecutionResult[rowIndex]?.values[colIndex]; }; const isCoordinatesSelected = (