Skip to content

Commit

Permalink
H-3504, H-3561: Entities visualizer performance and fixes (#5633)
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranMn authored Nov 12, 2024
1 parent 9bad743 commit 69aac3b
Show file tree
Hide file tree
Showing 27 changed files with 1,788 additions and 1,075 deletions.
35 changes: 31 additions & 4 deletions apps/hash-frontend/src/components/grid/grid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ export const Grid = <T extends GridRow>({
}, []);

const [sorts, setSorts] = useState<ColumnSort<Extract<keyof T, string>>[]>(
columns.map((column) => ({
columnKey: column.id as Extract<keyof T, string>,
direction: "asc",
})),
() =>
columns.map((column) => ({
columnKey: column.id as Extract<keyof T, string>,
direction: "asc",
})),
);

const [previousSortedColumnKey, setPreviousSortedColumnKey] = useState<
Expand All @@ -138,6 +139,32 @@ export const Grid = <T extends GridRow>({
string | undefined
>(initialSortedColumnKey ?? columns[0]?.id);

useEffect(() => {
const currentSortColumns = new Set(sorts.map((sort) => sort.columnKey));
const newSortColumns = new Set(columns.map((column) => column.id));

if (
initialSortedColumnKey &&
(!currentSortedColumnKey || !newSortColumns.has(initialSortedColumnKey))
) {
setCurrentSortedColumnKey(initialSortedColumnKey);
}

if (
currentSortColumns.size === newSortColumns.size &&
currentSortColumns.isSubsetOf(newSortColumns)
) {
return;
}

setSorts(
columns.map((column) => ({
columnKey: column.id as Extract<keyof T, string>,
direction: "asc",
})),
);
}, [columns, currentSortedColumnKey, initialSortedColumnKey, sorts]);

const [openFilterColumnKey, setOpenFilterColumnKey] = useState<string>();

const handleSortClick = useCallback(
Expand Down
6 changes: 3 additions & 3 deletions apps/hash-frontend/src/pages/entities.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { Tabs } from "../shared/ui/tabs";
import { useUserPermissionsOnEntityType } from "../shared/use-user-permissions-on-entity-type";
import type { Breadcrumb } from "./shared/breadcrumbs";
import { CreateButton } from "./shared/create-button";
import { EntitiesTable } from "./shared/entities-table";
import { EntitiesVisualizer } from "./shared/entities-visualizer";
import { TopContextBar } from "./shared/top-context-bar";
import { useEnabledFeatureFlags } from "./shared/use-enabled-feature-flags";
import { useActiveWorkspace } from "./shared/workspace-context";
Expand Down Expand Up @@ -366,8 +366,8 @@ const EntitiesPage: NextPageWithLayout = () => {
</Box>
<Container sx={{ maxWidth, py: 5 }}>
<EntityTypeEntitiesContext.Provider value={entityTypeEntitiesValue}>
<EntitiesTable
hideColumns={entityTypeId ? ["entityTypeVersion"] : []}
<EntitiesVisualizer
hideColumns={entityTypeId ? ["entityTypes"] : []}
/>
</EntityTypeEntitiesContext.Provider>
</Container>
Expand Down
Loading

0 comments on commit 69aac3b

Please sign in to comment.