Skip to content

Commit

Permalink
H-3357: Improve loading speed and state for createdBy/updatedBy e…
Browse files Browse the repository at this point in the history
…ntity table columns (#5217)
  • Loading branch information
CiaranMn authored Sep 23, 2024
1 parent 6df2a34 commit c6766dc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
18 changes: 14 additions & 4 deletions apps/hash-frontend/src/pages/shared/entities-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@ export const EntitiesTable: FunctionComponent<{
const actor =
columnId === "lastEditedBy" ? row.lastEditedBy : row.createdBy;

if (actor === "loading") {
return {
kind: GridCellKind.Text,
readonly: true,
allowOverlay: false,
displayData: "Loading...",
data: "Loading...",
};
}

const actorName = actor ? actor.displayName : undefined;

const actorIcon = actor
Expand Down Expand Up @@ -481,10 +491,10 @@ export const EntitiesTable: FunctionComponent<{
const lastEditedBySet = new Set<MinimalActor>();
const createdBySet = new Set<MinimalActor>();
for (const row of rows ?? []) {
if (row.lastEditedBy) {
if (row.lastEditedBy && row.lastEditedBy !== "loading") {
lastEditedBySet.add(row.lastEditedBy);
}
if (row.createdBy) {
if (row.createdBy && row.createdBy !== "loading") {
createdBySet.add(row.createdBy);
}
}
Expand Down Expand Up @@ -566,7 +576,7 @@ export const EntitiesTable: FunctionComponent<{
selectedFilterItemIds: selectedLastEditedByAccountIds,
setSelectedFilterItemIds: setSelectedLastEditedByAccountIds,
isRowFiltered: (row) =>
row.lastEditedBy
row.lastEditedBy && row.lastEditedBy !== "loading"
? !selectedLastEditedByAccountIds.includes(
row.lastEditedBy.accountId,
)
Expand All @@ -581,7 +591,7 @@ export const EntitiesTable: FunctionComponent<{
selectedFilterItemIds: selectedCreatedByAccountIds,
setSelectedFilterItemIds: setSelectedCreatedByAccountIds,
isRowFiltered: (row) =>
row.createdBy
row.createdBy && row.createdBy !== "loading"
? !selectedCreatedByAccountIds.includes(row.createdBy.accountId)
: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export interface TypeEntitiesRow {
entityTypeVersion: string;
archived?: boolean;
lastEdited: string;
lastEditedBy?: MinimalActor;
lastEditedBy?: MinimalActor | "loading";
created: string;
createdBy?: MinimalActor;
createdBy?: MinimalActor | "loading";
web: string;
properties?: {
[k: string]: string;
Expand Down Expand Up @@ -73,7 +73,9 @@ export const useEntitiesTable = (params: {
[entities],
);

const { actors } = useActors({ accountIds: editorActorIds });
const { actors, loading: actorsLoading } = useActors({
accountIds: editorActorIds,
});

const getOwnerForEntity = useGetOwnerForEntity();

Expand Down Expand Up @@ -203,20 +205,25 @@ export const useEntitiesTable = (params: {
"yyyy-MM-dd HH:mm",
);

const lastEditedBy = actors?.find(
({ accountId }) =>
accountId === entity.metadata.provenance.edition.createdById,
);
const lastEditedBy = actorsLoading
? "loading"
: actors?.find(
({ accountId }) =>
accountId ===
entity.metadata.provenance.edition.createdById,
);

const created = format(
new Date(entity.metadata.provenance.createdAtDecisionTime),
"yyyy-MM-dd HH:mm",
);

const createdBy = actors?.find(
({ accountId }) =>
accountId === entity.metadata.provenance.createdById,
);
const createdBy = actorsLoading
? "loading"
: actors?.find(
({ accountId }) =>
accountId === entity.metadata.provenance.createdById,
);

return {
rowId: entityId,
Expand Down Expand Up @@ -256,6 +263,8 @@ export const useEntitiesTable = (params: {

return { columns, rows };
}, [
actors,
actorsLoading,
entities,
entityTypes,
getOwnerForEntity,
Expand All @@ -266,6 +275,5 @@ export const useEntitiesTable = (params: {
hidePageArchivedColumn,
hidePropertiesColumns,
isViewingPages,
actors,
]);
};
30 changes: 16 additions & 14 deletions apps/hash-frontend/src/shared/use-actors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,22 @@ export const useActors = (params: {
includePermissions: false,
request: {
filter: {
any: (params.accountIds ?? []).map((accountId) => ({
all: [
{
equal: [
{ path: ["editionProvenance", "createdById"] },
{ parameter: accountId },
],
},
generateVersionedUrlMatchingFilter(
systemEntityTypes.machine.entityTypeId,
{ ignoreParents: true },
),
],
})),
any: (params.accountIds ? [...new Set(params.accountIds)] : []).map(
(accountId) => ({
all: [
{
equal: [
{ path: ["editionProvenance", "createdById"] },
{ parameter: accountId },
],
},
generateVersionedUrlMatchingFilter(
systemEntityTypes.machine.entityTypeId,
{ ignoreParents: true },
),
],
}),
),
},
graphResolveDepths: zeroedGraphResolveDepths,
temporalAxes: currentTimeInstantTemporalAxes,
Expand Down

0 comments on commit c6766dc

Please sign in to comment.