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

fix(RV-447): Update fields #469

Merged
merged 1 commit into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion frontend/e2e/utils/mock_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const fakeTemplates = [
{
name: "covid",
description: "covid",
condition: "covid",
facility: "texas",
pages: [
{
fieldNames: [
Expand Down Expand Up @@ -96,6 +98,8 @@ export const fakeTemplates = [
{
name: "marge",
description: "marge",
facility: 'texas',
condtion: 'covid',
pages: [
{
fieldNames: [
Expand Down Expand Up @@ -186,7 +190,8 @@ export const fakeTemplates = [
},
{
name: "template name",
description: "description",
condition: "condition",
facility: "texas",
pages: [
{
fieldNames: [
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/components/ExtractUploadFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ interface IFilesObj {

interface Template {
name: string;
description: string;
condition: string;
facility: string;
pages: {
image: string;
fieldNames: string[];
Expand Down Expand Up @@ -64,23 +65,25 @@ export const ExtractUploadFile: React.FC<ExtractUploadFileProps> = ({
const sampleTemplates: Template[] = [
{
name: "Test Template COVID",
description: "This is the first sample template.",
pages: [
{
image: "base64encodedimage1",
fieldNames: ["patient_name", "patient_dob"],
},
],
condition: "covid",
facility: "texas"
},
{
name: "Test Template Syph",
description: "This is the second sample template.",
pages: [
{
image: "base64encodedimage2",
fieldNames: ["patient_name", "address"],
},
],
condition: "covid",
facility: "texas"
},
];
setTemplates(sampleTemplates);
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import "./Header.scss";
interface UploadHeaderProps {
title: string;
isUpload?: boolean;
isDisabled?: boolean;
onBack: () => void;
onSubmit?: () => void;
}

export const UploadHeader = ({
title,
isUpload,
isDisabled,
onBack,
onSubmit,
}: UploadHeaderProps) => {
Expand Down Expand Up @@ -43,7 +45,7 @@ export const UploadHeader = ({
</Button>
{
onSubmit && (
<Button disabled={isUpload} onClick={onSubmit} type="submit" base>
<Button disabled={isUpload || isDisabled} onClick={onSubmit} type="submit" base>
Submit
</Button>
)
Expand Down
15 changes: 10 additions & 5 deletions frontend/src/contexts/AnnotationContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ interface AnnotationContextType {
setDrawnFields: React.Dispatch<React.SetStateAction<Set<string>>>;
setShapes: React.Dispatch<React.SetStateAction<CustomShape[][]>>;
name: string;
description: string;
condition: string;
facility: string;
setName: (name: string) => void;
setDescription: (description: string) => void;
setCondition: (condition: string) => void;
setFacility: (facility: string) => void;
index: number;
setIndex: React.Dispatch<React.SetStateAction<number>>;
}
Expand Down Expand Up @@ -72,7 +74,8 @@ export const AnnotationProvider = ({ children }: AnnotationProviderProps) => {
]);
const [drawnFields, setDrawnFields] = useState<Set<string>>(new Set());
const [name, setName] = useState<string>("");
const [description, setDescription] = useState<string>("");
const [condition, setCondition] = useState<string>("");
const [facility, setFacility] = useState<string>("");
const [selectedField, setSelectedField] = useState<Field | null>(null);
const [shapes, setShapes] = useState<CustomShape[][]>([]);
const [index, setIndex] = useState<number>(0);
Expand All @@ -91,8 +94,10 @@ export const AnnotationProvider = ({ children }: AnnotationProviderProps) => {
setFields,
name,
setName,
description,
setDescription,
condition,
setCondition,
facility,
setFacility,
index,
setIndex,
drawnFields,
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/contexts/FilesContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ export interface Page {

export interface FileType {
name: string;
description: string;
condition: string;
facility: string;
pages: Page[];
}

Expand Down
13 changes: 12 additions & 1 deletion frontend/src/pages/SaveTemplate.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ describe("SaveTemplate Component", () => {
screen.getByTestId("segmentation-template-name-input"),
).toBeInTheDocument();
expect(
screen.getByTestId("segmentation-template-description-input"),
screen.getByTestId("segmentation-template-facility-input"),
).toBeInTheDocument();
expect(
screen.getByTestId("segmentation-template-condition-input"),
).toBeInTheDocument();
});

Expand Down Expand Up @@ -103,6 +106,14 @@ describe("SaveTemplate Component", () => {
</BrowserRouter>,
);

const nameInput = screen.getByTestId("segmentation-template-name-input");
const facilityInput = screen.getByTestId("segmentation-template-facility-input");
const conditionInput = screen.getByTestId("segmentation-template-condition-input");

fireEvent.change(nameInput, { target: { value: "Template 1" } });
fireEvent.change(facilityInput, { target: { value: "Facility 1" } });
fireEvent.change(conditionInput, { target: { value: "Condition 1" } });

await act(async () => {
fireEvent.click(screen.getByText(/submit/i));
});
Expand Down
48 changes: 37 additions & 11 deletions frontend/src/pages/SaveTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ export const SaveTemplate = () => {
const navigate = useNavigate();
const {
fields,
setDescription,
setName,
name,
description,
condition,
facility,
shapes,
setCondition,
setFacility,
setShapes,
setFields,
setDrawnFields,
Expand Down Expand Up @@ -57,7 +59,7 @@ export const SaveTemplate = () => {
};
});
if (pages.length !== images.length) {
images.forEach((_, idx) => {
images.forEach((_: unknown, idx: number) => {
if (!tempFields[idx]) {
pages.push({
fieldNames: [],
Expand All @@ -74,7 +76,8 @@ export const SaveTemplate = () => {
}
const tempFile: FileType = {
name,
description,
condition,
facility,
pages: pages,
};

Expand All @@ -100,6 +103,9 @@ export const SaveTemplate = () => {
setFields([new Set(), new Set()]);
setDrawnFields(new Set());
setSelectedField(null);
setName('');
setFacility('');
setCondition('');
reset();
navigate("/");
};
Expand All @@ -112,6 +118,7 @@ export const SaveTemplate = () => {
<UploadHeader
title="Save template"
onBack={() => navigate("/new-template/annotate")}
isDisabled={name.length === 0 || facility.length === 0 || condition.length === 0}
onSubmit={handleSubmit}
/>
<Divider margin="0px" />
Expand All @@ -127,7 +134,7 @@ export const SaveTemplate = () => {
<div className="display-flex flex-column flex-align-self-center">
<div className="display-flex flex-column flex-align-start width-full">
<Label htmlFor="segmentation-template-name">
Segmentation template name
Segmentation template name*
</Label>
<TextInput
id="segmentation-template-name"
Expand All @@ -141,16 +148,35 @@ export const SaveTemplate = () => {
</div>
<div className="display-flex flex-column flex-align-self-center">
<div className="display-flex flex-column flex-align-start width-full">
<Label htmlFor="segmentation-template-description">
Segmentation template description
<Label htmlFor="segmentation-template-facility">
Facility*
</Label>
<TextInput
id="segmentation-template-description"
onChange={(e) => setDescription(e.target.value)}
id="segmentation-template-facility"
onChange={(e) => setFacility(e.target.value)}
value={facility}
required
className="bg-white"
name="segmentation-template-description"
name="segmentation-template-facility"
type="text"
data-testid="segmentation-template-description-input"
data-testid="segmentation-template-facility-input"
/>
</div>
</div>
<div className="display-flex flex-column flex-align-self-center">
<div className="display-flex flex-column flex-align-start width-full">
<Label htmlFor="segmentation-template-condition">
Condition*
</Label>
<TextInput
id="segmentation-template-condition"
value={condition}
required
onChange={(e) => setCondition(e.target.value)}
className="bg-white"
name="segmentation-template-condition"
type="text"
data-testid="segmentation-template-condition-input"
/>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/types/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { Shape } from "react-image-label";
export interface Template {
id: string;
name: string;
description: string;
condition: string;
facility: string;
labName: string;
pages: Page[];
status: TemplateStatus;
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const fakeData = {
export const fakeTemplates: Array<any> = [
{
name: "covid",
description: "covid",
pages: [
{
fieldNames: [
Expand Down Expand Up @@ -98,7 +97,6 @@ export const fakeTemplates: Array<any> = [
},
{
name: "marge",
description: "marge",
pages: [
{
fieldNames: [
Expand Down Expand Up @@ -189,7 +187,6 @@ export const fakeTemplates: Array<any> = [
},
{
name: "template name",
description: "description",
pages: [
{
fieldNames: [
Expand Down
Loading