Manage request files: mark missing ones, remove them, list them all
Forms → Content requests and a new Tools → Media → Requests tab (by type folder, each linked to its request) mark a file Drive no longer has under Requests as Missing from Drive. Remove (admins and up) trashes a file and takes it off its request. Drive is asked at most every 30 seconds, and folder lookups now cache every level walked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
9ff1cd6e99
commit
e1542d8d87
6 changed files with 292 additions and 32 deletions
|
|
@ -52,10 +52,13 @@ const sizeOf = (bytes) => (bytes < 1024 * 1024 ? `${Math.ceil(bytes / 1024)} KB`
|
|||
/* A content request's files: each downloads from Drive through the
|
||||
server, and a Word document can become a draft blog post
|
||||
(the same import as Blog posts → Import from Word). */
|
||||
function RequestFiles({ row, canWrite }) {
|
||||
function RequestFiles({ row, canWrite, canRemove }) {
|
||||
const navigate = useNavigate();
|
||||
const [files, setFiles] = useState<any[]>(row.files);
|
||||
const [busy, setBusy] = useState<number | null>(null);
|
||||
const [confirming, setConfirming] = useState<number | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
useEffect(() => setFiles(row.files), [row.files]);
|
||||
|
||||
async function makePost(file) {
|
||||
setBusy(file.id);
|
||||
|
|
@ -69,29 +72,81 @@ function RequestFiles({ row, canWrite }) {
|
|||
}
|
||||
}
|
||||
|
||||
async function remove(file) {
|
||||
setBusy(file.id);
|
||||
setError(null);
|
||||
try {
|
||||
await del(`/admin/feedback/${row.id}/files/${file.id}`);
|
||||
setFiles((current) => current.filter((f) => f.id !== file.id));
|
||||
} catch (err) {
|
||||
setError(err instanceof ApiError ? err.message : "Couldn't remove it.");
|
||||
} finally {
|
||||
setBusy(null);
|
||||
setConfirming(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (files.length === 0) return null;
|
||||
const small = "rounded-full border px-3 py-0.5 text-xs font-semibold transition-colors disabled:opacity-60";
|
||||
return (
|
||||
<div className="mt-4">
|
||||
<ul className="space-y-2">
|
||||
{row.files.map((file) => (
|
||||
{files.map((file) => (
|
||||
<li key={file.id} className="flex flex-wrap items-center gap-x-3 gap-y-1 text-sm">
|
||||
<a
|
||||
href={`/api/admin/feedback/${row.id}/files/${file.id}`}
|
||||
download={file.name}
|
||||
className="font-medium text-link underline underline-offset-2"
|
||||
>
|
||||
{file.name}
|
||||
</a>
|
||||
{file.missing ? (
|
||||
// Deleted or moved out of Requests in Drive: nothing to open.
|
||||
<span className="font-medium text-muted line-through">{file.name}</span>
|
||||
) : (
|
||||
<a
|
||||
href={`/api/admin/feedback/${row.id}/files/${file.id}`}
|
||||
download={file.name}
|
||||
className="font-medium text-link underline underline-offset-2"
|
||||
>
|
||||
{file.name}
|
||||
</a>
|
||||
)}
|
||||
<span className="text-xs text-muted">{sizeOf(file.size)}</span>
|
||||
{canWrite && /\.docx$/i.test(file.name) && (
|
||||
{file.missing && (
|
||||
<span className="rounded-full bg-danger-tint px-2 py-0.5 text-xs font-medium text-danger">
|
||||
Missing from Drive
|
||||
</span>
|
||||
)}
|
||||
{canWrite && !file.missing && /\.docx$/i.test(file.name) && (
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy !== null}
|
||||
onClick={() => makePost(file)}
|
||||
className="rounded-full border border-link px-3 py-0.5 text-xs font-semibold text-link transition-colors hover:bg-tint disabled:opacity-60"
|
||||
className={`${small} border-link text-link hover:bg-tint`}
|
||||
>
|
||||
{busy === file.id ? "Making the post…" : "Make a blog post from it"}
|
||||
</button>
|
||||
)}
|
||||
{canRemove &&
|
||||
(confirming === file.id ? (
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy !== null}
|
||||
onClick={() => remove(file)}
|
||||
className={`${small} border-danger bg-danger text-white`}
|
||||
>
|
||||
{busy === file.id ? "Removing…" : "Remove it"}
|
||||
</button>
|
||||
<button type="button" onClick={() => setConfirming(null)} className="text-xs text-muted hover:underline">
|
||||
Keep it
|
||||
</button>
|
||||
</>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
disabled={busy !== null}
|
||||
onClick={() => setConfirming(file.id)}
|
||||
className="text-xs text-muted hover:text-danger"
|
||||
title={file.missing ? "Take it off this request" : "Into Drive's trash, and off this request"}
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
))}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
|
@ -276,7 +331,7 @@ function FeedbackCard({ row, onChange, onRemove, canWrite, canRemove }) {
|
|||
{row.subject && <h2 className="mt-4 text-lg font-semibold text-body">{row.subject}</h2>}
|
||||
<p className={`${row.subject ? "mt-2" : "mt-4"} whitespace-pre-wrap text-body`}>{row.message}</p>
|
||||
{row.feedback_type === "content" && <RequestDetails row={row} />}
|
||||
{row.files?.length > 0 && <RequestFiles row={row} canWrite={canWrite} />}
|
||||
{row.files?.length > 0 && <RequestFiles row={row} canWrite={canWrite} canRemove={canRemove} />}
|
||||
{row.feedback_type === "content" && canWrite && <RequestRecord row={row} />}
|
||||
|
||||
<p className="mt-4 text-sm text-muted">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue