-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
136 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { useMemo, useState } from "react"; | ||
import { Button } from "../ui"; | ||
import { Add, Cancel, Label } from "../icons"; | ||
import ToggleChevron from "../ui/menu/ToogleChevron"; | ||
import { Colors, useCustomMutation } from "../utils"; | ||
import SelectLabels from "../datasets/SelectLabels"; | ||
import { useQueries } from "@tanstack/react-query"; | ||
import { addLabelForStudy, removeLabelForStudy } from "../services/orthanc"; | ||
|
||
type LabelProps = { | ||
selectedStudies: { [studyId: string]: boolean }; | ||
} | ||
const Labels = ({ selectedStudies }: LabelProps) => { | ||
|
||
const [isLabelDropdownOpen, setIsLabelDropdownOpen] = useState(false); | ||
const [selectedLabels, setSelectedLabels] = useState<string[]>([]); | ||
|
||
const { mutateAsync: addMutate } = useCustomMutation( | ||
({ studyId, label }) => addLabelForStudy(studyId, label) | ||
) | ||
|
||
const { mutateAsync: deleteMutate } = useCustomMutation( | ||
({ studyId, label }) => removeLabelForStudy(studyId, label) | ||
) | ||
|
||
const selectedStudiesId = useMemo(() => { | ||
return Object.entries(selectedStudies)?.filter(([id, status]) => status === true).map(([id, status]) => id) | ||
}, [selectedStudies]) | ||
|
||
const handleAddLabels = async () => { | ||
for (const studyId of selectedStudiesId) { | ||
for (const label of selectedLabels) { | ||
await addMutate({ studyId, label }) | ||
} | ||
} | ||
}; | ||
|
||
const handleRemoveLabels = async () => { | ||
for (const studyId of selectedStudiesId) { | ||
for (const label of selectedLabels) { | ||
await deleteMutate({ studyId, label }) | ||
} | ||
|
||
} | ||
}; | ||
|
||
return ( | ||
<div className="flex items-center gap-3"> | ||
<Button | ||
color={Colors.primary} | ||
className="flex items-center text-sm transition-transform duration-200 hover:scale-105" | ||
onClick={() => setIsLabelDropdownOpen(!isLabelDropdownOpen)} | ||
> | ||
<Label className="text-xl" /> | ||
<span className="ml-2">Assign Labels</span> | ||
<ToggleChevron | ||
isOpen={isLabelDropdownOpen} | ||
className="ml-2" /> | ||
</Button> | ||
{ | ||
isLabelDropdownOpen && ( | ||
<div className="flex gap-3"> | ||
|
||
<div className="flex items-center gap-3"> | ||
<SelectLabels | ||
values={selectedLabels} | ||
onChange={setSelectedLabels} | ||
/> | ||
<Add | ||
className="cursor-pointer text-primary hover:text-success-hover" | ||
onClick={handleAddLabels} | ||
/> | ||
<Cancel | ||
className="cursor-pointer" | ||
onClick={handleRemoveLabels} | ||
/> | ||
</div> | ||
<div className="flex justify-start mt-2"> | ||
<span>Apply to {selectedStudiesId.length} studies</span> | ||
</div> | ||
</div> | ||
|
||
) | ||
|
||
} | ||
</div>) | ||
|
||
} | ||
|
||
export default Labels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,18 @@ | ||
|
||
import { FaPlus } from 'react-icons/fa'; | ||
|
||
const Add = (props) => { | ||
type AddProps = { | ||
className?: string | ||
[key: string]: any | ||
} | ||
const Add = ({ className = '', ...props }: AddProps) => { | ||
|
||
return ( | ||
<FaPlus {...props} /> | ||
) | ||
<FaPlus | ||
className={`transition-transform duration-200 hover:transform hover:scale-125 ${className}`} | ||
aria-label="Add" | ||
{...props} | ||
/> | ||
); | ||
} | ||
|
||
export default Add | ||
export default Add; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
import { FaTimes } from "react-icons/fa"; | ||
|
||
const Cancel = (props) => { | ||
type CancelProps = { | ||
className? : string | ||
[key : string] : any | ||
} | ||
const Cancel = ({className, ...props } : CancelProps) => { | ||
|
||
return ( | ||
<FaTimes {...props} /> | ||
) | ||
<FaTimes | ||
className={`transition-transform duration-200 hover:text-danger-hover text-danger hover:transform hover:scale-125 ${className}`} | ||
{...props} | ||
|
||
/> | ||
); | ||
} | ||
|
||
export default Cancel | ||
export default Cancel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters