From 59307392d4f107f9a167e644fa800dba7893969b Mon Sep 17 00:00:00 2001 From: Kaity A Date: Sat, 13 May 2023 23:41:36 +1000 Subject: [PATCH] add experimental feature gate --- locales/en-US.yml | 7 ++ .../1683980686995-ExperimentalFeatures.js | 16 ++++ packages/backend/src/models/entities/meta.ts | 5 ++ .../src/server/api/endpoints/admin/meta.ts | 11 +++ .../server/api/endpoints/admin/update-meta.ts | 7 ++ packages/calckey-js/src/entities.ts | 1 + .../client/src/pages/admin/experiments.vue | 83 +++++++++++++++++++ packages/client/src/pages/admin/index.vue | 6 ++ packages/client/src/router.ts | 5 ++ packages/client/src/scripts/get-note-menu.ts | 16 ++-- 10 files changed, 150 insertions(+), 7 deletions(-) create mode 100644 packages/backend/migration/1683980686995-ExperimentalFeatures.js create mode 100644 packages/client/src/pages/admin/experiments.vue diff --git a/locales/en-US.yml b/locales/en-US.yml index 9cb58e6efc..e7c25de71d 100644 --- a/locales/en-US.yml +++ b/locales/en-US.yml @@ -2008,3 +2008,10 @@ _deck: list: "List" mentions: "Mentions" direct: "Direct messages" +_experiments: + title: "Experiments" + alpha: "Alpha" + beta: "Beta" + release: "Release" + enableExperimentalPostEditing: "Enable experimental post editing" + experimentalPostEditingCaption: "Enables the option for users to edit their posts in post options" diff --git a/packages/backend/migration/1683980686995-ExperimentalFeatures.js b/packages/backend/migration/1683980686995-ExperimentalFeatures.js new file mode 100644 index 0000000000..a289a9ecdc --- /dev/null +++ b/packages/backend/migration/1683980686995-ExperimentalFeatures.js @@ -0,0 +1,16 @@ +export class ExperimentalFeatures1683980686995 { + name = "ExperimentalFeatures1683980686995"; + + async up(queryRunner) { + await queryRunner.query(` + ALTER TABLE "meta" + ADD "experimentalFeatures" jsonb NOT NULL DEFAULT '{}' + `); + } + + async down(queryRunner) { + await queryRunner.query(` + ALTER TABLE "meta" DROP COLUMN "experimentalFeatures" + `); + } +} diff --git a/packages/backend/src/models/entities/meta.ts b/packages/backend/src/models/entities/meta.ts index 84f9af4793..3a3c50d4a3 100644 --- a/packages/backend/src/models/entities/meta.ts +++ b/packages/backend/src/models/entities/meta.ts @@ -516,4 +516,9 @@ export class Meta { default: true, }) public enableActiveEmailValidation: boolean; + + @Column('jsonb', { + default: {}, + }) + public experimentalFeatures: Record; } diff --git a/packages/backend/src/server/api/endpoints/admin/meta.ts b/packages/backend/src/server/api/endpoints/admin/meta.ts index 89928af11c..b83579cd3f 100644 --- a/packages/backend/src/server/api/endpoints/admin/meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/meta.ts @@ -2,6 +2,7 @@ import config from "@/config/index.js"; import { fetchMeta } from "@/misc/fetch-meta.js"; import { MAX_NOTE_TEXT_LENGTH, MAX_CAPTION_TEXT_LENGTH } from "@/const.js"; import define from "../../define.js"; +import { Exp } from "@tensorflow/tfjs"; export const meta = { tags: ["meta"], @@ -470,10 +471,20 @@ export const meta = { optional: false, nullable: false, }, + experimentalFeatures: { + type: "object", + optional: true, + nullable: true, + ref: "MetaExperimentalFeatures", + }, }, }, } as const; +export type MetaExperimentalFeatures = { + postEditing: boolean; +}; + export const paramDef = { type: "object", properties: {}, diff --git a/packages/backend/src/server/api/endpoints/admin/update-meta.ts b/packages/backend/src/server/api/endpoints/admin/update-meta.ts index 7f92e5e29e..586378d156 100644 --- a/packages/backend/src/server/api/endpoints/admin/update-meta.ts +++ b/packages/backend/src/server/api/endpoints/admin/update-meta.ts @@ -170,6 +170,13 @@ export const paramDef = { objectStorageS3ForcePathStyle: { type: "boolean" }, enableIpLogging: { type: "boolean" }, enableActiveEmailValidation: { type: "boolean" }, + experimentalFeatures: { + type: "object", + nullable: true, + properties: { + postEditing: { type: "boolean" }, + }, + }, }, required: [], } as const; diff --git a/packages/calckey-js/src/entities.ts b/packages/calckey-js/src/entities.ts index 5a581a54cd..7ecfba649b 100644 --- a/packages/calckey-js/src/entities.ts +++ b/packages/calckey-js/src/entities.ts @@ -304,6 +304,7 @@ export type LiteInstanceMetadata = { url: string; imageUrl: string; }[]; + experimentalFeatures?: Record; }; export type DetailedInstanceMetadata = LiteInstanceMetadata & { diff --git a/packages/client/src/pages/admin/experiments.vue b/packages/client/src/pages/admin/experiments.vue new file mode 100644 index 0000000000..2f04b88ab8 --- /dev/null +++ b/packages/client/src/pages/admin/experiments.vue @@ -0,0 +1,83 @@ + + + + + diff --git a/packages/client/src/pages/admin/index.vue b/packages/client/src/pages/admin/index.vue index 34d0404fcd..ddc5fc6800 100644 --- a/packages/client/src/pages/admin/index.vue +++ b/packages/client/src/pages/admin/index.vue @@ -300,6 +300,12 @@ const menuDef = $computed(() => [ to: "/admin/database", active: currentPage?.route.name === "database", }, + { + icon: "ph-flask ph-bold ph-lg", + text: i18n.ts._experiments.title, + to: "/admin/experiments", + active: currentPage?.route.name === "experiments", + }, ], }, ] diff --git a/packages/client/src/router.ts b/packages/client/src/router.ts index 7f03279dd6..a84c2c8b3f 100644 --- a/packages/client/src/router.ts +++ b/packages/client/src/router.ts @@ -540,6 +540,11 @@ export const routes = [ name: "other-settings", component: page(() => import("./pages/admin/custom-css.vue")), }, + { + path: "/experiments", + name: "experiments", + component: page(() => import("./pages/admin/experiments.vue")), + }, { path: "/", component: page(() => import("./pages/_empty_.vue")), diff --git a/packages/client/src/scripts/get-note-menu.ts b/packages/client/src/scripts/get-note-menu.ts index d36eff609f..72147c1c63 100644 --- a/packages/client/src/scripts/get-note-menu.ts +++ b/packages/client/src/scripts/get-note-menu.ts @@ -421,7 +421,7 @@ export function getNoteMenu(props: { null, - isAppearAuthor + instance.experimentalFeatures?.postEditing && isAppearAuthor ? { icon: "ph-pencil-line ph-bold ph-lg", text: i18n.ts.edit, @@ -430,12 +430,14 @@ export function getNoteMenu(props: { } : undefined, - { - icon: "ph-copy ph-bold ph-lg", - text: i18n.ts.duplicate, - textStyle: "color: var(--accent)", - action: duplicate, - }, + instance.experimentalFeatures?.postEditing + ? { + icon: "ph-copy ph-bold ph-lg", + text: i18n.ts.duplicate, + textStyle: "color: var(--accent)", + action: duplicate, + } + : undefined, isAppearAuthor || isModerator ? {