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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import React, { MouseEvent, memo, useCallback } from "react";
import {
getUrlRecordPath,
RecordPathDetails,
} from "../components/RecordComponent";
import Link from "../components/Link";
import { RecordInfo } from "../components/types";
import { trans } from "../i18n";
import { getPlatform } from "../utils";
import { loadData } from "../fetch";
import { showErrorDialog } from "../error-dialog";
import LinkWithHotkey from "../components/LinkWithHotkey";
const getBrowseButtonTitle = () => {
const platform = getPlatform();
if (platform === "mac") {
return trans("BROWSE_FS_MAC");
} else if (platform === "windows") {
return trans("BROWSE_FS_WINDOWS");
} else {
return trans("BROWSE_FS");
}
};
function BrowseFSLink({ record }: { record: RecordPathDetails }) {
const fsOpen = useCallback(
(ev: MouseEvent) => {
ev.preventDefault();
loadData(
"/browsefs",
{ path: record.path, alt: record.alt },
{ method: "POST" }
).then((resp) => {
if (!resp.okay) {
alert(trans("ERROR_CANNOT_BROWSE_FS"));
}
}, showErrorDialog);
},
[record]
);
return (
<a href="#" onClick={fsOpen}>
{getBrowseButtonTitle()}
</a>
);
}
const editKey = { key: "Control+e", mac: "Meta+e", preventDefault: true };
function PageActions({
record,
recordInfo,
}: {
record: RecordPathDetails;
recordInfo: RecordInfo;
}) {
const urlPath = getUrlRecordPath(record.path, record.alt);
return (
<div className="section">
<h3>
{recordInfo.is_attachment
? trans("ATTACHMENT_ACTIONS")
: trans("PAGE_ACTIONS")}
</h3>
<ul className="nav">
<li key="edit">
<LinkWithHotkey to={`${urlPath}/edit`} shortcut={editKey}>
{recordInfo.is_attachment ? trans("EDIT_METADATA") : trans("EDIT")}
</LinkWithHotkey>
</li>
{recordInfo.can_be_deleted && (
<li key="delete">
<Link to={`${urlPath}/delete`}>{trans("DELETE")}</Link>
</li>
)}
<li key="preview">
<Link to={`${urlPath}/preview`}>{trans("PREVIEW")}</Link>
</li>
{recordInfo.exists && (
<li key="fs-open">
<BrowseFSLink record={record} />
</li>
)}
{recordInfo.can_have_children && (
<li key="add-child">
<Link to={`${urlPath}/add-child`}>{trans("ADD_CHILD_PAGE")}</Link>
</li>
)}
{recordInfo.can_have_attachments && (
<li key="add-attachment">
<Link to={`${urlPath}/upload`}>{trans("ADD_ATTACHMENT")}</Link>
</li>
)}
</ul>
</div>
);
}
export default memo(PageActions);
|