feat(webui): complete files quick access
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { FileText, X } from "lucide-react";
|
||||
import { FileText, UploadCloud, X } from "lucide-react";
|
||||
import { useCallback } from "react";
|
||||
import { Link } from "react-router";
|
||||
import {
|
||||
Button,
|
||||
DismissibleAlert,
|
||||
@@ -7,6 +8,8 @@ import {
|
||||
SelectionList,
|
||||
SelectionListItem,
|
||||
SelectionListItemContent,
|
||||
hasScope,
|
||||
quickAccessLaunchState,
|
||||
useDashboardWidgetData,
|
||||
type QuickAccessToolRenderContext
|
||||
} from "@govoplan/core-webui";
|
||||
@@ -14,7 +17,7 @@ import { listFiles } from "../../api/files";
|
||||
|
||||
type Props = Pick<
|
||||
QuickAccessToolRenderContext,
|
||||
"settings" | "launchContext" | "complete" | "cancel"
|
||||
"settings" | "auth" | "launchContext" | "complete" | "cancel" | "close"
|
||||
>;
|
||||
|
||||
/**
|
||||
@@ -23,15 +26,18 @@ type Props = Pick<
|
||||
*/
|
||||
export default function FileQuickAccess({
|
||||
settings,
|
||||
auth,
|
||||
launchContext,
|
||||
complete,
|
||||
cancel
|
||||
cancel,
|
||||
close
|
||||
}: Props) {
|
||||
const load = useCallback(
|
||||
async () => (await listFiles(settings, { page_size: 7 })).files,
|
||||
async () => (await listFiles(settings, { sort: "recent", page_size: 7 })).files,
|
||||
[settings]
|
||||
);
|
||||
const { data: files, loading, error } = useDashboardWidgetData(load, 0);
|
||||
const canUpload = hasScope(auth, "files:upload");
|
||||
|
||||
return (
|
||||
<LoadingFrame loading={loading} label="Loading recent files">
|
||||
@@ -74,7 +80,17 @@ export default function FileQuickAccess({
|
||||
<p className="muted">No authorized files are available.</p>
|
||||
) : null}
|
||||
<div className="button-row compact-actions">
|
||||
<Button onClick={() => cancel("user")}><X size={15} aria-hidden="true" /> Cancel selection</Button>
|
||||
{canUpload ? (
|
||||
<Link
|
||||
className="btn btn-secondary"
|
||||
to="/files?quickAction=upload"
|
||||
state={quickAccessLaunchState(launchContext)}
|
||||
onClick={close}
|
||||
>
|
||||
<UploadCloud size={15} aria-hidden="true" /> i18n:govoplan-files.upload.8bdf057f
|
||||
</Link>
|
||||
) : null}
|
||||
<Button onClick={() => cancel("user")}><X size={15} aria-hidden="true" /> i18n:govoplan-files.cancel.77dfd213</Button>
|
||||
</div>
|
||||
</LoadingFrame>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user