From 152d8d2f6807fd6ab593b71c15572ac6e9950414 Mon Sep 17 00:00:00 2001 From: robin Date: Fri, 13 Jan 2023 16:13:47 +0800 Subject: [PATCH] feat(ui): Add plugin configuration --- i18n/en_US.yaml | 1 + ui/src/common/interface.ts | 23 ++++ ui/src/components/AccordionNav/index.tsx | 4 +- ui/src/components/SchemaForm/index.tsx | 113 +++++++++++------- ui/src/pages/Admin/Plugins/Config/index.tsx | 110 +++++++++++++++++ .../pages/Admin/Plugins/Installed/index.tsx | 68 +++++++---- ui/src/pages/Admin/index.tsx | 25 +++- ui/src/router/routes.ts | 4 + ui/src/services/admin/index.ts | 1 + ui/src/services/admin/plugins.ts | 41 +++++++ 10 files changed, 320 insertions(+), 70 deletions(-) create mode 100644 ui/src/pages/Admin/Plugins/Config/index.tsx create mode 100644 ui/src/services/admin/plugins.ts diff --git a/i18n/en_US.yaml b/i18n/en_US.yaml index 5e48d6b3..14540a6d 100644 --- a/i18n/en_US.yaml +++ b/i18n/en_US.yaml @@ -1379,6 +1379,7 @@ ui: status: Status action: Action deactivate: Deactivate + activate: Activate settings: Settings diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts index 0e8ea12d..2e6b1883 100644 --- a/ui/src/common/interface.ts +++ b/ui/src/common/interface.ts @@ -1,3 +1,5 @@ +import { UIOptions, UIWidget } from '@/components/SchemaForm'; + export interface FormValue { value: T; isInvalid: boolean; @@ -537,3 +539,24 @@ export interface UserOauthConnectorItem extends OauthConnectorItem { binding: boolean; external_id: string; } +export interface PluginOption { + label: string; + value: string; +} + +export interface PluginItem { + name: string; + type: UIWidget; + title: string; + description: string; + uiOptions?: UIOptions; + option?: PluginOption[]; + value?: string; + required?: boolean; +} + +export interface PluginConfig { + name: string; + slug_name: string; + config_fields: PluginItem[]; +} diff --git a/ui/src/components/AccordionNav/index.tsx b/ui/src/components/AccordionNav/index.tsx index 7e9403f5..878e2141 100644 --- a/ui/src/components/AccordionNav/index.tsx +++ b/ui/src/components/AccordionNav/index.tsx @@ -32,7 +32,9 @@ function MenuNode({ 'text-nowrap d-flex flex-nowrap align-items-center w-100', { expanding, 'link-dark': activeKey !== menu.name }, )}> - {t(menu.name)} + + {menu.displayName ? menu.displayName : t(menu.name)} + {menu.badgeContent ? ( {menu.badgeContent} ) : null} diff --git a/ui/src/components/SchemaForm/index.tsx b/ui/src/components/SchemaForm/index.tsx index 47c955d1..960bef45 100644 --- a/ui/src/components/SchemaForm/index.tsx +++ b/ui/src/components/SchemaForm/index.tsx @@ -28,45 +28,48 @@ export interface JSONSchema { }; }; } + +export interface UIOptions { + rows?: number; + placeholder?: string; + type?: + | 'color' + | 'date' + | 'datetime-local' + | 'email' + | 'month' + | 'number' + | 'password' + | 'range' + | 'search' + | 'tel' + | 'text' + | 'time' + | 'url' + | 'week'; + empty?: string; + className?: string | string[]; + validator?: ( + value, + formData?, + ) => Promise | true | string; + textRender?: () => React.ReactElement; + imageType?: Type.UploadType; + acceptType?: string; +} +export type UIWidget = + | 'textarea' + | 'text' + | 'checkbox' + | 'radio' + | 'select' + | 'upload' + | 'timezone' + | 'switch'; export interface UISchema { [key: string]: { - 'ui:widget'?: - | 'textarea' - | 'text' - | 'checkbox' - | 'radio' - | 'select' - | 'upload' - | 'timezone' - | 'switch'; - 'ui:options'?: { - rows?: number; - placeholder?: string; - type?: - | 'color' - | 'date' - | 'datetime-local' - | 'email' - | 'month' - | 'number' - | 'password' - | 'range' - | 'search' - | 'tel' - | 'text' - | 'time' - | 'url' - | 'week'; - empty?: string; - className?: string | string[]; - validator?: ( - value, - formData?, - ) => Promise | true | string; - textRender?: () => React.ReactElement; - imageType?: Type.UploadType; - acceptType?: string; - }; + 'ui:widget'?: UIWidget; + 'ui:options'?: UIOptions; }; } @@ -309,7 +312,11 @@ const SchemaForm: ForwardRefRenderFunction = (