Skip to content

Commit 2590b3e

Browse files
committed
Sorted filters & handling All value filter
Signed-off-by: Omkar Phansopkar <[email protected]>
1 parent 7a0396c commit 2590b3e

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

src/pages/TableView/CustomFilterComponent.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import React, {
2-
forwardRef,
3-
useImperativeHandle,
4-
useRef,
5-
} from "react";
1+
import React, { forwardRef, useImperativeHandle, useRef } from "react";
62
import { IFloatingFilterParams, TextFilterModel } from "ag-grid-community";
7-
import { DEFAULT_EMPTY_VALUES } from "./columnGroups";
3+
4+
import { PLACEHOLDER_EMPTY_VALUES } from "./columnGroups";
85
import { parseProbableStringifiedArray } from "../../utils/text";
96

107
export interface CustomParams extends IFloatingFilterParams {
@@ -52,7 +49,6 @@ const CustomFilterComponent = forwardRef((props: CustomParams, ref) => {
5249
});
5350
}
5451

55-
5652
return (
5753
<select
5854
ref={selectRef}
@@ -70,7 +66,9 @@ const CustomFilterComponent = forwardRef((props: CustomParams, ref) => {
7066
value={parsedOptionValue || optionValue}
7167
key={optionValue + idx}
7268
>
73-
{DEFAULT_EMPTY_VALUES.has(optionValue) ? "All" : parsedOptionValue}
69+
{PLACEHOLDER_EMPTY_VALUES.has(optionValue)
70+
? "All"
71+
: parsedOptionValue}
7472
</option>
7573
);
7674
})}

src/pages/TableView/TableView.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import CustomFilterComponent from "./CustomFilterComponent";
99
import { ALL_COLUMNS } from "./columnDefs";
1010
import {
1111
COLUMN_GROUPS,
12-
DEFAULT_EMPTY_VALUES,
12+
PLACEHOLDER_EMPTY_VALUES,
1313
SET_FILTERED_COLUMNS,
1414
} from "./columnGroups";
1515

@@ -129,10 +129,19 @@ const TableView = () => {
129129
},
130130
}
131131
).then((uniqueValues: { DISTINCT: string }[]) => {
132-
const parsedUniqueValues = uniqueValues.map((val) => val.DISTINCT);
132+
const parsedUniqueValues = uniqueValues
133+
.map((val) => val.DISTINCT)
134+
.sort((a, b) =>
135+
a === "[[]]" || !a
136+
? -1
137+
: b === "[[]]" || !b
138+
? 1
139+
: a.localeCompare(b)
140+
);
141+
133142
if (!parsedUniqueValues[0]) parsedUniqueValues[0] = "";
134143

135-
if (!DEFAULT_EMPTY_VALUES.has(parsedUniqueValues[0]))
144+
if (!PLACEHOLDER_EMPTY_VALUES.has(parsedUniqueValues[0]))
136145
parsedUniqueValues.unshift("");
137146

138147
// console.log(

src/pages/TableView/columnGroups.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { ColDef } from "ag-grid-community";
22

33
import { ALL_COLUMNS } from "./columnDefs";
44

5-
export const DEFAULT_EMPTY_VALUES = new Set<string | null>([
5+
export const PLACEHOLDER_EMPTY_VALUES = new Set<string | null>([
66
"",
77
null,
88
"[]",

0 commit comments

Comments
 (0)