Skip to content

Commit 6c9bbc4

Browse files
committed
enh: added edit chip
1 parent bed4c86 commit 6c9bbc4

File tree

1 file changed

+99
-24
lines changed

1 file changed

+99
-24
lines changed

frontend/src/training-materials-browser.tsx

Lines changed: 99 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default function TrainingMaterialsBrowser() {
3838
const [loading, setLoading] = useState(true)
3939
const [error, setError] = useState<string | null>(null)
4040
const [selectedRawMaterial, setSelectedRawMaterial] = useState<ReproInventoryEntry | null>(null)
41+
const [editingMaterial, setEditingMaterial] = useState<ReproInventoryEntry | null>(null)
4142

4243
useEffect(() => {
4344
const fetchData = async () => {
@@ -660,30 +661,104 @@ export default function TrainingMaterialsBrowser() {
660661
</a>
661662
)}
662663
</div>
663-
<Dialog>
664-
<DialogTrigger asChild>
665-
<Button
666-
variant="outline"
667-
className="w-fit text-xs px-2 py-1 h-auto"
668-
onClick={() => setSelectedRawMaterial(material)}
669-
>
670-
View Raw Data
671-
</Button>
672-
</DialogTrigger>
673-
<DialogContent className="sm:max-w-[800px]">
674-
<DialogHeader>
675-
<DialogTitle>Raw Data for {selectedRawMaterial?.course_name}</DialogTitle>
676-
<DialogDescription>
677-
This is the raw JSON data for the selected training material.
678-
</DialogDescription>
679-
</DialogHeader>
680-
<div className="max-h-[60vh] overflow-auto rounded-md bg-zinc-900 p-4 text-zinc-50">
681-
<pre className="text-xs">
682-
{selectedRawMaterial ? JSON.stringify(selectedRawMaterial, null, 2) : "No data selected"}
683-
</pre>
684-
</div>
685-
</DialogContent>
686-
</Dialog>
664+
<div className="flex gap-2">
665+
<Dialog>
666+
<DialogTrigger asChild>
667+
<Button
668+
variant="outline"
669+
className="w-fit text-xs px-2 py-1 h-auto"
670+
onClick={() => setSelectedRawMaterial(material)}
671+
>
672+
View Raw Data
673+
</Button>
674+
</DialogTrigger>
675+
<DialogContent className="sm:max-w-[800px]">
676+
<DialogHeader>
677+
<DialogTitle>Raw Data for {selectedRawMaterial?.course_name}</DialogTitle>
678+
<DialogDescription>
679+
This is the raw JSON data for the selected training material.
680+
</DialogDescription>
681+
</DialogHeader>
682+
<div className="max-h-[60vh] overflow-auto rounded-md bg-zinc-900 p-4 text-zinc-50">
683+
<pre className="text-xs">
684+
{selectedRawMaterial ? JSON.stringify(selectedRawMaterial, null, 2) : "No data selected"}
685+
</pre>
686+
</div>
687+
</DialogContent>
688+
</Dialog>
689+
<Dialog>
690+
<DialogTrigger asChild>
691+
<Button
692+
variant="outline"
693+
className="w-fit text-xs px-2 py-1 h-auto"
694+
onClick={() => setEditingMaterial(material)}
695+
>
696+
Edit
697+
</Button>
698+
</DialogTrigger>
699+
{editingMaterial && (
700+
<DialogContent className="sm:max-w-[800px]">
701+
<DialogHeader>
702+
<DialogTitle>Edit {editingMaterial.course_name}</DialogTitle>
703+
<DialogDescription>
704+
Update the details of this training material.
705+
</DialogDescription>
706+
</DialogHeader>
707+
<div className="grid gap-4 py-4">
708+
<div className="grid grid-cols-4 items-center gap-4">
709+
<Label htmlFor="course_name" className="text-right">
710+
Course Name
711+
</Label>
712+
<Input
713+
id="course_name"
714+
value={editingMaterial.course_name}
715+
onChange={(e) =>
716+
setEditingMaterial({ ...editingMaterial, course_name: e.target.value })
717+
}
718+
className="col-span-3"
719+
/>
720+
</div>
721+
<div className="grid grid-cols-4 items-center gap-4">
722+
<Label htmlFor="url" className="text-right">
723+
URL
724+
</Label>
725+
<Input
726+
id="url"
727+
value={editingMaterial.url}
728+
onChange={(e) =>
729+
setEditingMaterial({ ...editingMaterial, url: e.target.value })
730+
}
731+
className="col-span-3"
732+
/>
733+
</div>
734+
<div className="grid grid-cols-4 items-center gap-4">
735+
<Label htmlFor="review" className="text-right">
736+
Review
737+
</Label>
738+
<Input
739+
id="review"
740+
value={editingMaterial.review || ""}
741+
onChange={(e) =>
742+
setEditingMaterial({ ...editingMaterial, review: e.target.value })
743+
}
744+
className="col-span-3"
745+
/>
746+
</div>
747+
{/* Add more fields as needed based on ReproInventoryEntry type */}
748+
</div>
749+
<Button onClick={() => {
750+
// Update the main data array with the edited material
751+
setReproInventoryData((prevData) =>
752+
prevData.map((item) =>
753+
item.id === editingMaterial.id ? editingMaterial : item
754+
)
755+
);
756+
setEditingMaterial(null); // Close the dialog
757+
}}>Save changes</Button>
758+
</DialogContent>
759+
)}
760+
</Dialog>
761+
</div>
687762
</CardContent>
688763
</Card>
689764
))}

0 commit comments

Comments
 (0)