Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | 110x 110x 110x 110x 110x 110x 110x 134x 24x 110x 110x 990x 24x 110x 134x 24x 110x 110x 134x 24x 110x 440x 330x 110x 110x 134x 110x 1980x 26x 162x 440x 440x 440x 110x 134x 134x 990x 330x | import { History, Loader2 } from "lucide-react";
import {
Accordion,
AccordionContent,
AccordionItem,
AccordionTrigger,
} from "@/ahuora-design-system/ui/accordion";
import Paginator from "@/ahuora-design-system/ui/paginator";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/ahuora-design-system/ui/select";
import { FlowsheetRevisionDialogs } from "../../revisions/FlowsheetRevisionDialogs";
import { FlowsheetRevisionList } from "../../revisions/FlowsheetRevisionList";
import { FlowsheetRevisionControls } from "./FlowsheetRevisionControls";
import { useFlowsheetRevisionsMenu } from "./useFlowsheetRevisionsMenu";
type FlowsheetRevisionsMenuProps = {
flowsheetId: number;
canEdit: boolean;
};
/** Revision history and restore controls attached to the active flowsheet row. */
export function FlowsheetRevisionsMenu({
flowsheetId,
canEdit,
}: FlowsheetRevisionsMenuProps) {
const {
autoSaveEnabled,
autoSavePending,
cancelRenamingRevision,
deletePending,
deleteSelectedRevision,
deleteTarget,
editingRevisionId,
isOpen,
isPreview,
isRestoring,
isSaving,
openRevisionPreview,
renamePending,
restoreSelectedRevision,
restoreTarget,
returnToCurrent,
revisionData,
revisionError,
revisionCategory,
revisionName,
revisionStateId,
revisionsFetching,
saveLatestRevision,
saveRevisionName,
setDeleteTarget,
setIsOpen,
setRestoreTarget,
setRevisionName,
setRevisionPage,
startRenamingRevision,
updateRevisionCategory,
updateAutoRevisionSetting,
} = useFlowsheetRevisionsMenu(flowsheetId);
const emptyStateCopy = {
all: "No saved versions",
manual: "No manual versions",
solve: "No solve auto-saves",
}[revisionCategory];
return (
<>
<Accordion
type="single"
collapsible
value={isOpen ? "revisions" : ""}
onValueChange={(value) => setIsOpen(value === "revisions")}
className="w-full"
>
<AccordionItem value="revisions" className="text-sm">
<AccordionTrigger
variant="objectPanel"
className="h-8 rounded-md px-2 py-1 text-xs font-medium text-foreground hover:bg-secondary/30 data-[state=open]:bg-secondary/20"
aria-label="Versions"
onClick={(event) => event.stopPropagation()}
>
<span className="flex min-w-0 items-center gap-1.5">
<History className="h-4 w-4 shrink-0" />
Versions
</span>
</AccordionTrigger>
<AccordionContent
className="mt-0 space-y-3 px-0 pb-1 pt-1"
onClick={(event) => event.stopPropagation()}
>
{(canEdit || isPreview) && (
<FlowsheetRevisionControls
flowsheetId={flowsheetId}
disabled={isPreview}
autoSaveEnabled={autoSaveEnabled}
autoSavePending={autoSavePending}
savePending={isSaving}
onSave={saveLatestRevision}
onAutoSaveChange={updateAutoRevisionSetting}
/>
)}
<div className="flex items-center justify-between gap-2 px-1">
<label
htmlFor={`version-category-${flowsheetId}`}
className="text-xs text-muted-foreground"
>
Show
</label>
<Select
value={revisionCategory}
onValueChange={updateRevisionCategory}
>
<SelectTrigger
id={`version-category-${flowsheetId}`}
aria-label="Version category"
className="h-7 w-40 text-xs"
>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="all">All versions</SelectItem>
<SelectItem value="manual">Manual versions</SelectItem>
<SelectItem value="solve">Solve auto-saves</SelectItem>
</SelectContent>
</Select>
</div>
<section className="space-y-1.5" aria-label="Version history">
<div className="rounded-md bg-secondary/25 px-2.5 py-1.5">
<p className="font-medium text-foreground">Current</p>
<p className="mt-0.5 text-xs text-muted-foreground">
{revisionData?.current.restored_from_revision_number
? `Restored from Version ${revisionData.current.restored_from_revision_number}`
: "Working version"}
</p>
</div>
{revisionsFetching ? (
<div className="flex items-center gap-2 px-2.5 py-2 text-muted-foreground">
<Loader2 className="h-4 w-4 animate-spin" />
Loading versions...
</div>
) : revisionError ? (
<p className="px-2.5 py-2 text-destructive">
Versions could not be loaded.
</p>
) : revisionData?.revisions.length ? (
<FlowsheetRevisionList
revisions={revisionData.revisions}
previewedRevisionStateId={revisionStateId}
canEdit={canEdit}
editingRevisionId={editingRevisionId}
revisionName={revisionName}
renamePending={renamePending}
onPreview={openRevisionPreview}
onStopPreview={returnToCurrent}
onRestore={setRestoreTarget}
onDelete={setDeleteTarget}
onStartRename={startRenamingRevision}
onCancelRename={cancelRenamingRevision}
onRevisionNameChange={setRevisionName}
onSaveRevisionName={saveRevisionName}
/>
) : (
<p className="rounded-md bg-secondary/15 px-2.5 py-2 text-muted-foreground">
{emptyStateCopy}
</p>
)}
{revisionData && revisionData.pages > 1 ? (
<div className="flex items-center justify-between px-1 pt-0.5">
<span className="text-xs text-muted-foreground">
{(revisionData.page - 1) * revisionData.page_size + 1}-
{Math.min(
revisionData.page * revisionData.page_size,
revisionData.count,
)}{" "}
of {revisionData.count}
</span>
<div className="[&_button]:border-0 [&_button]:shadow-none">
<Paginator
minimal
page={revisionData.page}
setPage={setRevisionPage}
data={{
previous:
revisionData.page > 1
? `?page=${revisionData.page - 1}`
: null,
next:
revisionData.page < revisionData.pages
? `?page=${revisionData.page + 1}`
: null,
pages: revisionData.pages,
}}
/>
</div>
</div>
) : null}
</section>
</AccordionContent>
</AccordionItem>
</Accordion>
<FlowsheetRevisionDialogs
restoreTarget={restoreTarget}
deleteTarget={deleteTarget}
restorePending={isRestoring}
deletePending={deletePending}
onDismissRestore={() => setRestoreTarget(null)}
onConfirmRestore={restoreSelectedRevision}
onDismissDelete={() => setDeleteTarget(null)}
onConfirmDelete={deleteSelectedRevision}
/>
</>
);
}
|