Skip to content

Commit

Permalink
refactor: Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
bprusinowski committed Feb 5, 2024
1 parent 96fbdfe commit 956520e
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions app/browse/datatable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,16 @@ export const PreviewTable = ({
const [sortDirection, setSortDirection] = useState<"asc" | "desc">();
const formatters = useDimensionFormatters(headers);
const sortedObservations = useMemo(() => {
if (sortBy === undefined) {
if (!sortBy) {
return observations;
}

const compare = sortDirection === "asc" ? ascending : descending;
const valuesIndex = uniqueMapBy(sortBy.values, (x) => x.label);
const valuesIndex = uniqueMapBy(sortBy.values, (d) => d.label);
const convert =
isNumericalMeasure(sortBy) || sortBy.isNumerical
? (d: string) => +d
: (d: string) => {
const value = valuesIndex.get(d);

if (value?.position) {
return value.position;
}

return d;
};
? (value: string) => +value
: (value: string) => valuesIndex.get(value)?.position ?? value;

return [...observations].sort((a, b) =>
compare(
Expand All @@ -111,11 +103,7 @@ export const PreviewTable = ({

// Tooltip contained inside the table so as not to overflow when table is scrolled
const tooltipProps = useMemo(
() => ({
PopperProps: {
container: tooltipContainerRef.current,
},
}),
() => ({ PopperProps: { container: tooltipContainerRef.current } }),
[]
);

Expand Down

0 comments on commit 956520e

Please sign in to comment.