Skip to content

Commit

Permalink
Sorted filters & handling All value filter
Browse files Browse the repository at this point in the history
Signed-off-by: Omkar Phansopkar <omkarphansopkar@gmail.com>
  • Loading branch information
OmkarPh committed Oct 25, 2023
1 parent 7a0396c commit 2590b3e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
14 changes: 6 additions & 8 deletions src/pages/TableView/CustomFilterComponent.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React, {
forwardRef,
useImperativeHandle,
useRef,
} from "react";
import React, { forwardRef, useImperativeHandle, useRef } from "react";
import { IFloatingFilterParams, TextFilterModel } from "ag-grid-community";
import { DEFAULT_EMPTY_VALUES } from "./columnGroups";

import { PLACEHOLDER_EMPTY_VALUES } from "./columnGroups";
import { parseProbableStringifiedArray } from "../../utils/text";

export interface CustomParams extends IFloatingFilterParams {
Expand Down Expand Up @@ -52,7 +49,6 @@ const CustomFilterComponent = forwardRef((props: CustomParams, ref) => {
});
}


return (
<select
ref={selectRef}
Expand All @@ -70,7 +66,9 @@ const CustomFilterComponent = forwardRef((props: CustomParams, ref) => {
value={parsedOptionValue || optionValue}
key={optionValue + idx}
>
{DEFAULT_EMPTY_VALUES.has(optionValue) ? "All" : parsedOptionValue}
{PLACEHOLDER_EMPTY_VALUES.has(optionValue)
? "All"
: parsedOptionValue}
</option>
);
})}
Expand Down
15 changes: 12 additions & 3 deletions src/pages/TableView/TableView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import CustomFilterComponent from "./CustomFilterComponent";
import { ALL_COLUMNS } from "./columnDefs";
import {
COLUMN_GROUPS,
DEFAULT_EMPTY_VALUES,
PLACEHOLDER_EMPTY_VALUES,
SET_FILTERED_COLUMNS,
} from "./columnGroups";

Expand Down Expand Up @@ -129,10 +129,19 @@ const TableView = () => {
},
}
).then((uniqueValues: { DISTINCT: string }[]) => {
const parsedUniqueValues = uniqueValues.map((val) => val.DISTINCT);
const parsedUniqueValues = uniqueValues
.map((val) => val.DISTINCT)
.sort((a, b) =>
a === "[[]]" || !a
? -1
: b === "[[]]" || !b
? 1
: a.localeCompare(b)
);

if (!parsedUniqueValues[0]) parsedUniqueValues[0] = "";

if (!DEFAULT_EMPTY_VALUES.has(parsedUniqueValues[0]))
if (!PLACEHOLDER_EMPTY_VALUES.has(parsedUniqueValues[0]))
parsedUniqueValues.unshift("");

// console.log(
Expand Down
2 changes: 1 addition & 1 deletion src/pages/TableView/columnGroups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ColDef } from "ag-grid-community";

import { ALL_COLUMNS } from "./columnDefs";

export const DEFAULT_EMPTY_VALUES = new Set<string | null>([
export const PLACEHOLDER_EMPTY_VALUES = new Set<string | null>([
"",
null,
"[]",
Expand Down

0 comments on commit 2590b3e

Please sign in to comment.