Skip to content

Commit

Permalink
Add cross section parameter section to edit form
Browse files Browse the repository at this point in the history
  • Loading branch information
daanboer committed Jun 5, 2024
1 parent e34864c commit 2980b0e
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
62 changes: 62 additions & 0 deletions app/src/app/author/set/[id]/edit/parameter-section.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// SPDX-FileCopyrightText: LXCat team
//
// SPDX-License-Identifier: AGPL-3.0-or-later

import { MaybePromise } from "@/app/api/util";
import { ScientificInput } from "@/shared/scientific-input";
import { type CrossSectionParameters } from "@lxcat/schema/process";
import { Fieldset, Stack } from "@mantine/core";

export type ParameterProps = {
parameters: CrossSectionParameters | undefined;
setParameters: (
parameters: CrossSectionParameters | undefined,
) => MaybePromise<void>;
};

export const ParameterSection = (
{ parameters, setParameters }: ParameterProps,
) => {
return (
<Fieldset legend="Parameters">
<Stack>
<ScientificInput
label="Mass ratio"
value={parameters && parameters.massRatio}
onChange={(massRatio) => {
if (massRatio === undefined) {
if (parameters?.statisticalWeightRatio) {
const { massRatio, ...params } = parameters;
return setParameters(params);

Check warning on line 30 in app/src/app/author/set/[id]/edit/parameter-section.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/app/author/set/[id]/edit/parameter-section.tsx#L29-L30

Added lines #L29 - L30 were not covered by tests
} else {
return setParameters(undefined);

Check warning on line 32 in app/src/app/author/set/[id]/edit/parameter-section.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/app/author/set/[id]/edit/parameter-section.tsx#L32

Added line #L32 was not covered by tests
}
} else if (parameters) {
return setParameters({ ...parameters, massRatio });

Check warning on line 35 in app/src/app/author/set/[id]/edit/parameter-section.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/app/author/set/[id]/edit/parameter-section.tsx#L35

Added line #L35 was not covered by tests
} else {
return setParameters({ massRatio });

Check warning on line 37 in app/src/app/author/set/[id]/edit/parameter-section.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/app/author/set/[id]/edit/parameter-section.tsx#L37

Added line #L37 was not covered by tests
}
}}
/>
<ScientificInput
label="Statistical weight ratio"
value={parameters && parameters.statisticalWeightRatio}
onChange={(statisticalWeightRatio) => {
if (statisticalWeightRatio === undefined) {
if (parameters?.massRatio) {
const { statisticalWeightRatio, ...params } = parameters;
return setParameters(params);

Check warning on line 48 in app/src/app/author/set/[id]/edit/parameter-section.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/app/author/set/[id]/edit/parameter-section.tsx#L47-L48

Added lines #L47 - L48 were not covered by tests
} else {
return setParameters(undefined);

Check warning on line 50 in app/src/app/author/set/[id]/edit/parameter-section.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/app/author/set/[id]/edit/parameter-section.tsx#L50

Added line #L50 was not covered by tests
}
} else if (parameters) {
return setParameters({ ...parameters, statisticalWeightRatio });

Check warning on line 53 in app/src/app/author/set/[id]/edit/parameter-section.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/app/author/set/[id]/edit/parameter-section.tsx#L53

Added line #L53 was not covered by tests
} else {
return setParameters({ statisticalWeightRatio });

Check warning on line 55 in app/src/app/author/set/[id]/edit/parameter-section.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/app/author/set/[id]/edit/parameter-section.tsx#L55

Added line #L55 was not covered by tests
}
}}
/>
</Stack>
</Fieldset>
);
};
5 changes: 5 additions & 0 deletions app/src/app/author/set/[id]/edit/process-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { useMemo, useState } from "react";
import Latex from "react-latex-next";
import { CommentSection } from "./comment-section";
import { LookupTable } from "./lookup-table";
import { ParameterSection } from "./parameter-section";
import classes from "./process-tab.module.css";
import { ReactionBuilder } from "./reaction-builder";
import { ReferenceSection } from "./reference-section";
Expand Down Expand Up @@ -149,6 +150,10 @@ const ProcessInfoItem = (
}}
/>
</Fieldset>
<ParameterSection
parameters={info.parameters}
setParameters={(parameters) => onChange({ ...info, parameters })}

Check warning on line 155 in app/src/app/author/set/[id]/edit/process-tab.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/app/author/set/[id]/edit/process-tab.tsx#L155

Added line #L155 was not covered by tests
/>
</Stack>
</Accordion.Panel>
</Accordion.Item>
Expand Down

0 comments on commit 2980b0e

Please sign in to comment.