Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement optimistic response for Tempo field updates #129

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions frontend/src/components/SamplesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import { ErrorMessage, LoadingSpinner, Toolbar } from "../shared/tableElements";
import styles from "./records.module.scss";
import { getUserEmail } from "../utils/getUserEmail";
import { openLoginPopup } from "../utils/openLoginPopup";
import _ from "lodash";

const POLLING_INTERVAL = 2000;
const max_rows = 500;
Expand Down Expand Up @@ -140,8 +139,7 @@ export default function SamplesList({

// prevent registering a change if no actual changes are made
const noChangeInVal = rowNode.data[fieldName] === newValue;
const noChangeInEmptyCell =
_.isEmpty(rowNode.data[fieldName]) && _.isEmpty(newValue);
const noChangeInEmptyCell = !rowNode.data[fieldName] && !newValue;
ao508 marked this conversation as resolved.
Show resolved Hide resolved
if (noChangeInVal || noChangeInEmptyCell) {
const updatedChanges = changes.filter(
(c) => !(c.primaryId === primaryId && c.fieldName === fieldName)
Expand Down
21 changes: 9 additions & 12 deletions frontend/src/components/UpdateModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect, useMemo } from "react";
import { useEffect, useMemo } from "react";
import { Button } from "react-bootstrap";
import Modal from "react-bootstrap/Modal";
import { AgGridReact } from "ag-grid-react";
Expand Down Expand Up @@ -27,23 +27,18 @@ export function UpdateModal({
samples,
sampleKeyForUpdate,
}: UpdateModalProps) {
const [rowData, setRowData] = useState(changes);
const [columnDefs] = useState([
const columnDefs = [
{ field: "primaryId", rowGroup: true, hide: true },
{ field: "fieldName" },
{ field: "oldValue" },
{ field: "newValue" },
]);
];

useEffect(() => {
onOpen && onOpen();
// eslint-disable-next-line
}, []);

useEffect(() => {
setRowData(changes);
}, [changes]);

ao508 marked this conversation as resolved.
Show resolved Hide resolved
const [updateSamplesMutation] = useUpdateSamplesMutation();

async function handleSubmitUpdates() {
Expand All @@ -69,21 +64,23 @@ export function UpdateModal({
}
});

for (const [key, value] of Object.entries(changesByPrimaryId)) {
for (const [primaryId, changedFields] of Object.entries(
changesByPrimaryId
)) {
updateSamplesMutation({
variables: {
where: {
hasMetadataSampleMetadataConnection_SOME: {
node: {
primaryId: key,
primaryId: primaryId,
},
},
},
update: {
[sampleKeyForUpdate]: [
{
update: {
node: value!,
node: changedFields!,
},
},
],
Expand Down Expand Up @@ -126,7 +123,7 @@ export function UpdateModal({
<p>Are you sure you want to submit the following changes?</p>
<div className="ag-theme-alpine" style={{ height: 350 }}>
<AgGridReact
rowData={rowData}
rowData={changes}
columnDefs={columnDefs}
groupRemoveSingleChildren={true}
autoGroupColumnDef={autoGroupColumnDef}
Expand Down
134 changes: 133 additions & 1 deletion frontend/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export type BamCompleteTempoTemposHasEventNodeAggregateSelection = {
billedBy: StringAggregateSelectionNullable;
costCenter: StringAggregateSelectionNullable;
custodianInformation: StringAggregateSelectionNonNullable;
smileTempoId: StringAggregateSelectionNonNullable;
};

export type BamCompleteTemposHasEventAggregateInput = {
Expand Down Expand Up @@ -255,6 +256,26 @@ export type BamCompleteTemposHasEventNodeAggregationWhereInput = {
custodianInformation_SHORTEST_GTE?: InputMaybe<Scalars["Int"]>;
custodianInformation_SHORTEST_LT?: InputMaybe<Scalars["Int"]>;
custodianInformation_SHORTEST_LTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_AVERAGE_EQUAL?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_GT?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_GTE?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_LT?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_LTE?: InputMaybe<Scalars["Float"]>;
smileTempoId_EQUAL?: InputMaybe<Scalars["String"]>;
smileTempoId_GT?: InputMaybe<Scalars["Int"]>;
smileTempoId_GTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_EQUAL?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_GT?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_GTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_LT?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_LTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_LT?: InputMaybe<Scalars["Int"]>;
smileTempoId_LTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_EQUAL?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_GT?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_GTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_LT?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_LTE?: InputMaybe<Scalars["Int"]>;
};

export type BamCompleteTemposHasEventRelationship = {
Expand Down Expand Up @@ -1430,6 +1451,7 @@ export type MafCompleteTempoTemposHasEventNodeAggregateSelection = {
billedBy: StringAggregateSelectionNullable;
costCenter: StringAggregateSelectionNullable;
custodianInformation: StringAggregateSelectionNonNullable;
smileTempoId: StringAggregateSelectionNonNullable;
};

export type MafCompleteTemposHasEventAggregateInput = {
Expand Down Expand Up @@ -1568,6 +1590,26 @@ export type MafCompleteTemposHasEventNodeAggregationWhereInput = {
custodianInformation_SHORTEST_GTE?: InputMaybe<Scalars["Int"]>;
custodianInformation_SHORTEST_LT?: InputMaybe<Scalars["Int"]>;
custodianInformation_SHORTEST_LTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_AVERAGE_EQUAL?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_GT?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_GTE?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_LT?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_LTE?: InputMaybe<Scalars["Float"]>;
smileTempoId_EQUAL?: InputMaybe<Scalars["String"]>;
smileTempoId_GT?: InputMaybe<Scalars["Int"]>;
smileTempoId_GTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_EQUAL?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_GT?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_GTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_LT?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_LTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_LT?: InputMaybe<Scalars["Int"]>;
smileTempoId_LTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_EQUAL?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_GT?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_GTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_LT?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_LTE?: InputMaybe<Scalars["Int"]>;
};

export type MafCompleteTemposHasEventRelationship = {
Expand Down Expand Up @@ -3441,6 +3483,7 @@ export type QcCompleteTempoTemposHasEventNodeAggregateSelection = {
billedBy: StringAggregateSelectionNullable;
costCenter: StringAggregateSelectionNullable;
custodianInformation: StringAggregateSelectionNonNullable;
smileTempoId: StringAggregateSelectionNonNullable;
};

export type QcCompleteTemposHasEventAggregateInput = {
Expand Down Expand Up @@ -3579,6 +3622,26 @@ export type QcCompleteTemposHasEventNodeAggregationWhereInput = {
custodianInformation_SHORTEST_GTE?: InputMaybe<Scalars["Int"]>;
custodianInformation_SHORTEST_LT?: InputMaybe<Scalars["Int"]>;
custodianInformation_SHORTEST_LTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_AVERAGE_EQUAL?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_GT?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_GTE?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_LT?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_LTE?: InputMaybe<Scalars["Float"]>;
smileTempoId_EQUAL?: InputMaybe<Scalars["String"]>;
smileTempoId_GT?: InputMaybe<Scalars["Int"]>;
smileTempoId_GTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_EQUAL?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_GT?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_GTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_LT?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_LTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_LT?: InputMaybe<Scalars["Int"]>;
smileTempoId_LTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_EQUAL?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_GT?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_GTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_LT?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_LTE?: InputMaybe<Scalars["Int"]>;
};

export type QcCompleteTemposHasEventRelationship = {
Expand Down Expand Up @@ -7157,6 +7220,26 @@ export type SampleHasTempoTemposNodeAggregationWhereInput = {
custodianInformation_SHORTEST_GTE?: InputMaybe<Scalars["Int"]>;
custodianInformation_SHORTEST_LT?: InputMaybe<Scalars["Int"]>;
custodianInformation_SHORTEST_LTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_AVERAGE_EQUAL?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_GT?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_GTE?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_LT?: InputMaybe<Scalars["Float"]>;
smileTempoId_AVERAGE_LTE?: InputMaybe<Scalars["Float"]>;
smileTempoId_EQUAL?: InputMaybe<Scalars["String"]>;
smileTempoId_GT?: InputMaybe<Scalars["Int"]>;
smileTempoId_GTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_EQUAL?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_GT?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_GTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_LT?: InputMaybe<Scalars["Int"]>;
smileTempoId_LONGEST_LTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_LT?: InputMaybe<Scalars["Int"]>;
smileTempoId_LTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_EQUAL?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_GT?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_GTE?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_LT?: InputMaybe<Scalars["Int"]>;
smileTempoId_SHORTEST_LTE?: InputMaybe<Scalars["Int"]>;
};

export type SampleHasTempoTemposRelationship = {
Expand Down Expand Up @@ -8843,6 +8926,7 @@ export type SampleTempoHasTempoTemposNodeAggregateSelection = {
billedBy: StringAggregateSelectionNullable;
costCenter: StringAggregateSelectionNullable;
custodianInformation: StringAggregateSelectionNonNullable;
smileTempoId: StringAggregateSelectionNonNullable;
};

export type SampleUpdateInput = {
Expand Down Expand Up @@ -10020,6 +10104,7 @@ export type Tempo = {
samplesHasTempo: Array<Sample>;
samplesHasTempoAggregate?: Maybe<TempoSampleSamplesHasTempoAggregationSelection>;
samplesHasTempoConnection: TempoSamplesHasTempoConnection;
smileTempoId: Scalars["String"];
};

export type TempoHasEventBamCompletesArgs = {
Expand Down Expand Up @@ -10105,6 +10190,7 @@ export type TempoAggregateSelection = {
costCenter: StringAggregateSelectionNullable;
count: Scalars["Int"];
custodianInformation: StringAggregateSelectionNonNullable;
smileTempoId: StringAggregateSelectionNonNullable;
};

export type TempoBamCompleteHasEventBamCompletesAggregationSelection = {
Expand Down Expand Up @@ -10146,6 +10232,7 @@ export type TempoCreateInput = {
hasEventMafCompletes?: InputMaybe<TempoHasEventMafCompletesFieldInput>;
hasEventQcCompletes?: InputMaybe<TempoHasEventQcCompletesFieldInput>;
samplesHasTempo?: InputMaybe<TempoSamplesHasTempoFieldInput>;
smileTempoId: Scalars["String"];
};

export type TempoDeleteInput = {
Expand Down Expand Up @@ -10816,6 +10903,7 @@ export type TempoSort = {
billedBy?: InputMaybe<SortDirection>;
costCenter?: InputMaybe<SortDirection>;
custodianInformation?: InputMaybe<SortDirection>;
smileTempoId?: InputMaybe<SortDirection>;
};

export type TempoUpdateInput = {
Expand All @@ -10834,6 +10922,7 @@ export type TempoUpdateInput = {
Array<TempoHasEventQcCompletesUpdateFieldInput>
>;
samplesHasTempo?: InputMaybe<Array<TempoSamplesHasTempoUpdateFieldInput>>;
smileTempoId?: InputMaybe<Scalars["String"]>;
};

export type TempoWhere = {
Expand Down Expand Up @@ -10933,6 +11022,16 @@ export type TempoWhere = {
samplesHasTempo_SINGLE?: InputMaybe<SampleWhere>;
/** Return Tempos where some of the related Samples match this filter */
samplesHasTempo_SOME?: InputMaybe<SampleWhere>;
smileTempoId?: InputMaybe<Scalars["String"]>;
smileTempoId_CONTAINS?: InputMaybe<Scalars["String"]>;
smileTempoId_ENDS_WITH?: InputMaybe<Scalars["String"]>;
smileTempoId_IN?: InputMaybe<Array<Scalars["String"]>>;
smileTempoId_NOT?: InputMaybe<Scalars["String"]>;
smileTempoId_NOT_CONTAINS?: InputMaybe<Scalars["String"]>;
smileTempoId_NOT_ENDS_WITH?: InputMaybe<Scalars["String"]>;
smileTempoId_NOT_IN?: InputMaybe<Array<Scalars["String"]>>;
smileTempoId_NOT_STARTS_WITH?: InputMaybe<Scalars["String"]>;
smileTempoId_STARTS_WITH?: InputMaybe<Scalars["String"]>;
};

export type TemposConnection = {
Expand Down Expand Up @@ -11218,6 +11317,7 @@ export type FindSamplesByInputValueQuery = {
};
hasTempoTempos: Array<{
__typename?: "Tempo";
smileTempoId: string;
billed?: boolean | null;
billedBy?: string | null;
costCenter?: string | null;
Expand Down Expand Up @@ -11354,6 +11454,13 @@ export type SamplesQuery = {
tubeId?: string | null;
tumorOrNormal: string;
}>;
hasTempoTempos: Array<{
__typename?: "Tempo";
smileTempoId: string;
billed?: boolean | null;
billedBy?: string | null;
costCenter?: string | null;
}>;
}>;
};

Expand Down Expand Up @@ -11404,6 +11511,13 @@ export type UpdateSamplesMutation = {
tubeId?: string | null;
tumorOrNormal: string;
}>;
hasTempoTempos: Array<{
__typename?: "Tempo";
smileTempoId: string;
billed?: boolean | null;
billedBy?: string | null;
costCenter?: string | null;
}>;
}>;
};
};
Expand Down Expand Up @@ -11452,7 +11566,11 @@ export type CohortsListQuery = {
hasCohortSampleSamples: Array<{
__typename?: "Sample";
smileSampleId: string;
hasTempoTempos: Array<{ __typename?: "Tempo"; billed?: boolean | null }>;
hasTempoTempos: Array<{
__typename?: "Tempo";
smileTempoId: string;
billed?: boolean | null;
}>;
}>;
}>;
};
Expand Down Expand Up @@ -11717,6 +11835,7 @@ export const FindSamplesByInputValueDocument = gql`
}
}
hasTempoTempos {
smileTempoId
billed
billedBy
costCenter
Expand Down Expand Up @@ -11820,6 +11939,12 @@ export const SamplesDocument = gql`
) {
...SampleMetadataParts
}
hasTempoTempos {
smileTempoId
billed
billedBy
costCenter
}
}
}
${SampleMetadataPartsFragmentDoc}
Expand Down Expand Up @@ -11883,6 +12008,12 @@ export const UpdateSamplesDocument = gql`
hasMetadataSampleMetadata {
...SampleMetadataParts
}
hasTempoTempos {
smileTempoId
billed
billedBy
costCenter
}
}
}
}
Expand Down Expand Up @@ -12022,6 +12153,7 @@ export const CohortsListDocument = gql`
hasCohortSampleSamples {
smileSampleId
hasTempoTempos {
smileTempoId
billed
}
}
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const cache = new InMemoryCache({
SampleMetadata: {
keyFields: ["primaryId"],
},
Tempo: {
keyFields: ["smileTempoId"],
},
ao508 marked this conversation as resolved.
Show resolved Hide resolved
},
});

Expand Down
Loading