Skip to content

Commit

Permalink
Make tempo fields on the Samples page view-only
Browse files Browse the repository at this point in the history
  • Loading branch information
qu8n authored and ao508 committed Jun 18, 2024
1 parent 384d9bf commit e7867d8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 31 deletions.
12 changes: 1 addition & 11 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ export default function App() {
<Route path="/" element={<RequestsPage />}>
<Route path=":igoRequestId" />
</Route>

<Route path="/requests/" element={<RequestsPage />}>
<Route path=":igoRequestId" />
</Route>

<Route
path="/patients/"
element={
Expand All @@ -40,14 +38,7 @@ export default function App() {
>
<Route path=":smilePatientId" />
</Route>

<Route
path="/samples"
element={
<SamplesPage userEmail={userEmail} setUserEmail={setUserEmail} />
}
/>

<Route path="/samples" element={<SamplesPage />} />
<Route
path="/cohorts/"
element={
Expand All @@ -56,7 +47,6 @@ export default function App() {
>
<Route path=":cohortId" />
</Route>

<Route path="/auth/login-success" element={<LoginSuccessPage />} />
</>
</Routes>
Expand Down
13 changes: 1 addition & 12 deletions frontend/src/pages/samples/SamplesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Dispatch, SetStateAction } from "react";
import { PageHeader } from "../../shared/components/PageHeader";
import SamplesList from "../../components/SamplesList";
import {
Expand All @@ -9,15 +8,7 @@ import {
} from "../../shared/helpers";
import { SampleWhere } from "../../generated/graphql";

interface ISamplesPageProps {
userEmail: string | null;
setUserEmail: Dispatch<SetStateAction<string | null>>;
}

export default function SamplesPage({
userEmail,
setUserEmail,
}: ISamplesPageProps) {
export default function SamplesPage() {
return (
<>
<PageHeader dataName={"samples"} />
Expand All @@ -34,8 +25,6 @@ export default function SamplesPage({
}),
} as SampleWhere;
}}
userEmail={userEmail}
setUserEmail={setUserEmail}
/>
</>
);
Expand Down
31 changes: 23 additions & 8 deletions frontend/src/shared/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { StatusTooltip } from "./components/StatusToolTip";
import { parseUserSearchVal } from "../utils/parseSearchQueries";
import { Dispatch, SetStateAction } from "react";
import moment from "moment";
import _ from "lodash";

export interface SampleMetadataExtended extends SampleMetadata {
revisable: boolean;
Expand Down Expand Up @@ -464,7 +465,7 @@ const toolTipIcon =

function setupEditableSampleFields(samplesColDefs: ColDef[]) {
samplesColDefs.forEach((colDef) => {
colDef.cellClassRules = {
const newClassRule = {
unsubmittedChange: (params: CellClassParams) => {
const changes: SampleChange[] = params.context.getChanges();
const changedValue = changes?.find((change) => {
Expand All @@ -475,13 +476,15 @@ function setupEditableSampleFields(samplesColDefs: ColDef[]) {
});
return changedValue !== undefined;
},
"costCenter-validation-error": (params: CellClassParams) => {
if (params.colDef.field === "costCenter") {
return !isValidCostCenter(params.value);
}
return false;
},
};
if (colDef.cellClassRules) {
colDef.cellClassRules = {
...colDef.cellClassRules,
...newClassRule,
};
} else {
colDef.cellClassRules = newClassRule;
}

if (colDef.valueGetter === undefined) {
colDef.valueGetter = (params) => {
Expand Down Expand Up @@ -751,6 +754,14 @@ export const CohortSampleDetailsColumns: ColDef[] = [
{
field: "costCenter",
headerName: "Cost Center/Fund Number",
cellClassRules: {
"costCenter-validation-error": (params: CellClassParams) => {
if (params.colDef.field === "costCenter") {
return !isValidCostCenter(params.value);
}
return false;
},
},
},
{
field: "billedBy",
Expand Down Expand Up @@ -804,13 +815,17 @@ export const CohortSampleDetailsColumns: ColDef[] = [
},
];

export const ReadOnlyCohortSampleDetailsColumns = _.cloneDeep(
CohortSampleDetailsColumns
);

setupEditableSampleFields(SampleMetadataDetailsColumns);
setupEditableSampleFields(CohortSampleDetailsColumns);

const seenColumns = new Set();
export const combinedSampleDetailsColumns = [
...SampleMetadataDetailsColumns,
...CohortSampleDetailsColumns,
...ReadOnlyCohortSampleDetailsColumns,
].filter((col) => {
if (seenColumns.has(col.field)) {
return false;
Expand Down

0 comments on commit e7867d8

Please sign in to comment.