mirror of
https://github.com/outline/outline.git
synced 2026-11-26 23:50:14 +03:00
fix initial attribute
This commit is contained in:
1 parent
5850181c29
commit
ec1cb61807
3 files changed
+28
-3
No files matched your search
@@ -1,7 +1,9 @@
|
||||
import copy from "copy-to-clipboard";
|
||||
import { observer } from "mobx-react";
|
||||
import * as React from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { useMenuState } from "reakit/Menu";
|
||||
import { toast } from "sonner";
|
||||
import DataAttribute from "~/models/DataAttribute";
|
||||
import ContextMenu from "~/components/ContextMenu";
|
||||
import MenuItem from "~/components/ContextMenu/MenuItem";
|
||||
@@ -34,6 +36,11 @@ function DataAttributeMenu({ dataAttribute }: Props) {
|
||||
});
|
||||
}, [t, dialogs, dataAttribute]);
|
||||
|
||||
const handleCopy = React.useCallback(() => {
|
||||
copy(dataAttribute.id);
|
||||
toast.success("Copied to clipboard");
|
||||
}, [dataAttribute]);
|
||||
|
||||
const handleDelete = React.useCallback(() => {
|
||||
void dataAttribute.delete();
|
||||
}, [dataAttribute]);
|
||||
@@ -45,6 +52,9 @@ function DataAttributeMenu({ dataAttribute }: Props) {
|
||||
<MenuItem {...menu} onClick={handleEdit}>
|
||||
{t("Edit")}…
|
||||
</MenuItem>
|
||||
<MenuItem {...menu} onClick={handleCopy}>
|
||||
{t("Copy ID")}
|
||||
</MenuItem>
|
||||
<Separator />
|
||||
<MenuItem {...menu} onClick={handleDelete} dangerous>
|
||||
{t("Delete")}…
|
||||
|
||||
@@ -47,6 +47,17 @@ class DataAttribute extends ParanoidModel {
|
||||
|
||||
/** The user ID that created this data attribute. */
|
||||
createdById: string;
|
||||
|
||||
/** The default value to use when creating a new property. */
|
||||
get defaultValue() {
|
||||
switch (this.dataType) {
|
||||
case DataAttributeDataType.Boolean:
|
||||
return false;
|
||||
case DataAttributeDataType.List:
|
||||
return this.options?.options?.[0]?.value;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export default DataAttribute;
|
||||
@@ -32,26 +32,30 @@ export type PropertiesRef = {
|
||||
|
||||
export const Properties = observer(
|
||||
React.forwardRef(function Properties_({ document }: Props, ref) {
|
||||
const { dataAttributes } = useStores();
|
||||
const [draftAttribute, setDraftAttribute] =
|
||||
React.useState<DocumentDataAttribute | null>(null);
|
||||
|
||||
const handleAddProperty = (dataAttributeId: string) =>
|
||||
const handleAddProperty = (dataAttributeId: string) => {
|
||||
const definition = dataAttributes.get(dataAttributeId);
|
||||
|
||||
setDraftAttribute((state) =>
|
||||
state
|
||||
? null
|
||||
: {
|
||||
value: "",
|
||||
value: definition?.defaultValue ?? "",
|
||||
dataAttributeId,
|
||||
updatedAt: new Date().toISOString(),
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
React.useImperativeHandle(ref, () => ({
|
||||
addProperty: handleAddProperty,
|
||||
}));
|
||||
|
||||
const handleSave = async () => {
|
||||
if (draftAttribute?.value) {
|
||||
if (draftAttribute) {
|
||||
document.setDataAttribute(
|
||||
draftAttribute.dataAttributeId,
|
||||
draftAttribute.value
|
||||
|
||||
Reference in new issue
Block a user