From c636c4e5df618a4632daa7f5f810fb3982876364 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Tue, 11 Jun 2024 21:14:43 -0400 Subject: [PATCH] stash --- app/actions/definitions/dataAttributes.tsx | 24 +++++++ app/hooks/useSettingsConfig.ts | 10 +++ app/models/DataAttribute.ts | 52 +++++++++++++++ app/scenes/DataAttributeNew.tsx | 0 app/scenes/Settings/DataAttributes.tsx | 63 +++++++++++++++++++ app/stores/DataAttributesStore.ts | 30 +++++++++ app/stores/RootStore.ts | 3 + server/commands/documentUpdater.ts | 30 ++++++++- .../20240611010054-create-data-attributes.js | 18 +++++- server/models/DataAttribute.ts | 44 ++++++++----- server/models/Document.ts | 8 +++ server/models/DocumentDataAttribute.ts | 51 +++++++++++++++ server/models/index.ts | 2 + server/policies/index.ts | 3 + server/presenters/dataAttribute.ts | 12 ++-- server/presenters/document.ts | 4 ++ server/presenters/documentDataAttribute.ts | 15 +++++ .../api/dataAttributes/dataAttributes.ts | 2 + server/routes/api/index.ts | 2 + shared/models/types.ts | 10 +++ shared/validations.ts | 5 ++ 21 files changed, 364 insertions(+), 24 deletions(-) create mode 100644 app/actions/definitions/dataAttributes.tsx create mode 100644 app/models/DataAttribute.ts create mode 100644 app/scenes/DataAttributeNew.tsx create mode 100644 app/scenes/Settings/DataAttributes.tsx create mode 100644 app/stores/DataAttributesStore.ts create mode 100644 server/models/DocumentDataAttribute.ts create mode 100644 server/presenters/documentDataAttribute.ts create mode 100644 shared/models/types.ts diff --git a/app/actions/definitions/dataAttributes.tsx b/app/actions/definitions/dataAttributes.tsx new file mode 100644 index 0000000000..11ac550b2f --- /dev/null +++ b/app/actions/definitions/dataAttributes.tsx @@ -0,0 +1,24 @@ +import { PlusIcon } from "outline-icons"; +import * as React from "react"; +import stores from "~/stores"; +import { createAction } from ".."; +import { SettingsSection } from "../sections"; + +export const createDataAttribute = createAction({ + name: ({ t }) => t("New attribute"), + analyticsName: "New attribute", + section: SettingsSection, + icon: , + keywords: "create", + visible: () => + stores.policies.abilities(stores.auth.team?.id || "").createDataAttribute, + perform: ({ t, event }) => { + event?.preventDefault(); + event?.stopPropagation(); + + stores.dialogs.openModal({ + title: t("New attribute"), + // content: TODO + }); + }, +}); diff --git a/app/hooks/useSettingsConfig.ts b/app/hooks/useSettingsConfig.ts index 4e3cf2ba8c..ef7cec5b82 100644 --- a/app/hooks/useSettingsConfig.ts +++ b/app/hooks/useSettingsConfig.ts @@ -14,6 +14,7 @@ import { ImportIcon, ShapesIcon, Icon, + DatabaseIcon, } from "outline-icons"; import React, { ComponentProps } from "react"; import { useTranslation } from "react-i18next"; @@ -29,6 +30,7 @@ import useCurrentUser from "./useCurrentUser"; import usePolicy from "./usePolicy"; const ApiKeys = lazy(() => import("~/scenes/Settings/ApiKeys")); +const DataAttributes = lazy(() => import("~/scenes/Settings/DataAttributes")); const Details = lazy(() => import("~/scenes/Settings/Details")); const Export = lazy(() => import("~/scenes/Settings/Export")); const Features = lazy(() => import("~/scenes/Settings/Features")); @@ -119,6 +121,14 @@ const useSettingsConfig = () => { group: t("Workspace"), icon: BeakerIcon, }, + { + name: t("Attributes"), + path: settingsPath("attributes"), + component: DataAttributes, + enabled: can.createDataAttribute, + group: t("Workspace"), + icon: DatabaseIcon, + }, { name: t("Members"), path: settingsPath("members"), diff --git a/app/models/DataAttribute.ts b/app/models/DataAttribute.ts new file mode 100644 index 0000000000..a5b43d1b89 --- /dev/null +++ b/app/models/DataAttribute.ts @@ -0,0 +1,52 @@ +import { observable } from "mobx"; +import { + DataAttributeDataType, + type DataAttributeOptions, +} from "@shared/models/types"; +import User from "./User"; +import ParanoidModel from "./base/ParanoidModel"; +import Field from "./decorators/Field"; +import Relation from "./decorators/Relation"; + +class DataAttribute extends ParanoidModel { + static modelName = "DataAttribute"; + + /** The name of this data attribute. */ + @Field + @observable + name: string; + + /** A user-facing description for the data attribute. */ + @Field + @observable + description: string | null; + + /** The data type of this data attribute. Cannot be changed after creation. */ + @Field + @observable + dataType: DataAttributeDataType; + + /** Options for `list` data type. */ + @Field + @observable + options: DataAttributeOptions | null; + + /** Whether this data attribute is pinned to the top of the document. */ + @Field + @observable + pinned: boolean; + + /** The sort index of this data attribute. */ + @Field + @observable + index: number; + + /** The user that created this data attribute. */ + @Relation(() => User, { onDelete: "cascade" }) + createdBy?: User; + + /** The user ID that created this data attribute. */ + createdById: string; +} + +export default DataAttribute; diff --git a/app/scenes/DataAttributeNew.tsx b/app/scenes/DataAttributeNew.tsx new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/scenes/Settings/DataAttributes.tsx b/app/scenes/Settings/DataAttributes.tsx new file mode 100644 index 0000000000..b803abb22b --- /dev/null +++ b/app/scenes/Settings/DataAttributes.tsx @@ -0,0 +1,63 @@ +import { observer } from "mobx-react"; +import { DatabaseIcon } from "outline-icons"; +import * as React from "react"; +import { useTranslation, Trans } from "react-i18next"; +import DataAttribute from "~/models/DataAttribute"; +import { Action } from "~/components/Actions"; +import Button from "~/components/Button"; +import Heading from "~/components/Heading"; +import PaginatedList from "~/components/PaginatedList"; +import Scene from "~/components/Scene"; +import Text from "~/components/Text"; +import { createDataAttribute } from "~/actions/definitions/dataAttributes"; +import useActionContext from "~/hooks/useActionContext"; +import useCurrentTeam from "~/hooks/useCurrentTeam"; +import usePolicy from "~/hooks/usePolicy"; +import useStores from "~/hooks/useStores"; + +function DataAttributes() { + const team = useCurrentTeam(); + const { t } = useTranslation(); + const { dataAttributes } = useStores(); + const can = usePolicy(team); + const context = useActionContext(); + + return ( + } + actions={ + <> + {can.createDataAttribute && ( + +