mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Improve "read only" mode
This commit is contained in:
parent
b71df1e46f
commit
8799a80bd6
@ -1,4 +1,5 @@
|
|||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
|
import { ActionIcon, Group, Paper, Stack } from '@mantine/core';
|
||||||
import { notifications } from '@mantine/notifications';
|
import { notifications } from '@mantine/notifications';
|
||||||
import {
|
import {
|
||||||
AdmonitionDirectiveDescriptor,
|
AdmonitionDirectiveDescriptor,
|
||||||
@ -29,7 +30,12 @@ import {
|
|||||||
toolbarPlugin
|
toolbarPlugin
|
||||||
} from '@mdxeditor/editor';
|
} from '@mdxeditor/editor';
|
||||||
import '@mdxeditor/editor/style.css';
|
import '@mdxeditor/editor/style.css';
|
||||||
import { IconDeviceFloppy, IconEdit, IconEye } from '@tabler/icons-react';
|
import {
|
||||||
|
IconDeviceFloppy,
|
||||||
|
IconEdit,
|
||||||
|
IconEye,
|
||||||
|
IconX
|
||||||
|
} from '@tabler/icons-react';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
|
import { ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
@ -39,6 +45,7 @@ import { ApiEndpoints } from '../../enums/ApiEndpoints';
|
|||||||
import { ModelType } from '../../enums/ModelType';
|
import { ModelType } from '../../enums/ModelType';
|
||||||
import { apiUrl } from '../../states/ApiState';
|
import { apiUrl } from '../../states/ApiState';
|
||||||
import { useLocalState } from '../../states/LocalState';
|
import { useLocalState } from '../../states/LocalState';
|
||||||
|
import { ActionButton } from '../buttons/ActionButton';
|
||||||
import { ModelInformationDict } from '../render/ModelType';
|
import { ModelInformationDict } from '../render/ModelType';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -186,52 +193,47 @@ export default function NotesEditor({
|
|||||||
linkPlugin(),
|
linkPlugin(),
|
||||||
linkDialogPlugin(),
|
linkDialogPlugin(),
|
||||||
listsPlugin(),
|
listsPlugin(),
|
||||||
markdownShortcutPlugin(),
|
|
||||||
quotePlugin(),
|
quotePlugin(),
|
||||||
tablePlugin(),
|
tablePlugin(),
|
||||||
thematicBreakPlugin()
|
thematicBreakPlugin(),
|
||||||
|
markdownShortcutPlugin()
|
||||||
];
|
];
|
||||||
|
|
||||||
let toolbar: ReactNode[] = [];
|
let toolbar: ReactNode[] = [];
|
||||||
if (editable) {
|
if (editable && editing) {
|
||||||
toolbar = [
|
toolbar = [
|
||||||
<ButtonWithTooltip
|
<ButtonWithTooltip
|
||||||
key="toggle-editing"
|
key="save-notes"
|
||||||
aria-label="toggle-notes-editing"
|
aria-label="save-notes"
|
||||||
title={editing ? t`Preview Notes` : t`Edit Notes`}
|
onClick={() => saveNotes()}
|
||||||
onClick={() => setEditing(!editing)}
|
title={t`Save Notes`}
|
||||||
|
disabled={false}
|
||||||
>
|
>
|
||||||
{editing ? <IconEye /> : <IconEdit />}
|
<IconDeviceFloppy color="green" />
|
||||||
</ButtonWithTooltip>
|
</ButtonWithTooltip>,
|
||||||
|
<ButtonWithTooltip
|
||||||
|
key="close-notes"
|
||||||
|
aria-label="close-notes"
|
||||||
|
onClick={() => setEditing(false)}
|
||||||
|
title={t`Close Editor`}
|
||||||
|
disabled={false}
|
||||||
|
>
|
||||||
|
<IconX color="red" />
|
||||||
|
</ButtonWithTooltip>,
|
||||||
|
<Separator key="separator-1" />,
|
||||||
|
<UndoRedo key="undo-redo" />,
|
||||||
|
<Separator key="separator-2" />,
|
||||||
|
<BoldItalicUnderlineToggles key="bold-italic-underline" />,
|
||||||
|
<CodeToggle key="code-toggle" />,
|
||||||
|
<ListsToggle key="lists-toggle" />,
|
||||||
|
<Separator key="separator-3" />,
|
||||||
|
<BlockTypeSelect key="block-type" />,
|
||||||
|
<Separator key="separator-4" />,
|
||||||
|
<CreateLink key="create-link" />,
|
||||||
|
<InsertTable key="insert-table" />,
|
||||||
|
<InsertAdmonition key="insert-admonition" />,
|
||||||
|
<InsertThematicBreak key="insert-thematic-break" />
|
||||||
];
|
];
|
||||||
|
|
||||||
if (editing) {
|
|
||||||
toolbar = [
|
|
||||||
...toolbar,
|
|
||||||
<ButtonWithTooltip
|
|
||||||
key="save-notes"
|
|
||||||
aria-label="save-notes"
|
|
||||||
onClick={() => saveNotes()}
|
|
||||||
title={t`Save Notes`}
|
|
||||||
disabled={false}
|
|
||||||
>
|
|
||||||
<IconDeviceFloppy />
|
|
||||||
</ButtonWithTooltip>,
|
|
||||||
<Separator key="separator-1" />,
|
|
||||||
<UndoRedo key="undo-redo" />,
|
|
||||||
<Separator key="separator-2" />,
|
|
||||||
<BoldItalicUnderlineToggles key="bold-italic-underline" />,
|
|
||||||
<CodeToggle key="code-toggle" />,
|
|
||||||
<ListsToggle key="lists-toggle" />,
|
|
||||||
<Separator key="separator-3" />,
|
|
||||||
<BlockTypeSelect key="block-type" />,
|
|
||||||
<Separator key="separator-4" />,
|
|
||||||
<CreateLink key="create-link" />,
|
|
||||||
<InsertTable key="insert-table" />,
|
|
||||||
<InsertAdmonition key="insert-admonition" />,
|
|
||||||
<InsertThematicBreak key="insert-thematic-break" />
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user is allowed to edit, then add the toolbar
|
// If the user is allowed to edit, then add the toolbar
|
||||||
@ -259,14 +261,29 @@ export default function NotesEditor({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<MDXEditor
|
<Paper p="sm" shadow="xs">
|
||||||
ref={ref}
|
<Stack gap="xs">
|
||||||
markdown={''}
|
{editable && (
|
||||||
readOnly={!editable}
|
<Group justify="left">
|
||||||
plugins={plugins}
|
{!editing && (
|
||||||
toMarkdownOptions={{
|
<ActionButton
|
||||||
rule: '-' // Use dashes for thematic breaks
|
tooltip={t`Edit`}
|
||||||
}}
|
onClick={() => setEditing(true)}
|
||||||
/>
|
icon={<IconEdit color="blue" />}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
|
<MDXEditor
|
||||||
|
ref={ref}
|
||||||
|
markdown={''}
|
||||||
|
readOnly={!editing}
|
||||||
|
plugins={plugins}
|
||||||
|
toMarkdownOptions={{
|
||||||
|
rule: '-' // Use dashes for thematic breaks
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</Paper>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user