Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add plugin enable/disable sub-page #764

Merged
merged 29 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
85cf99d
Feat: add plugin download API
wonderflow Apr 14, 2023
e5b13d3
Feat: add plugin download API
wonderflow Apr 14, 2023
96780b9
Feat: add uninstall plugin API
wonderflow Apr 15, 2023
00a4273
Feat: remove plugin in memory when uninstall
wonderflow Apr 15, 2023
3e4e415
Fix: use empty response
wonderflow Apr 15, 2023
255ffb2
Add plugin enable/disable sub-page
chivalryq Apr 13, 2023
97def61
Dynamic detect icon link
chivalryq Apr 13, 2023
c090578
Show config page
chivalryq Apr 14, 2023
8a7a7f9
refactor, style
chivalryq Apr 16, 2023
c81b204
reviewable
chivalryq Apr 17, 2023
de9fd39
Fix url gone after install
chivalryq Apr 19, 2023
b3ff2e6
remove log
chivalryq Apr 19, 2023
f08e39c
standalone config page
chivalryq Apr 25, 2023
eb784ed
rollback changes to addon cards
chivalryq Apr 26, 2023
a3f705d
fix enter config page loading app
chivalryq Apr 27, 2023
2fbbed1
clean up model
chivalryq Apr 27, 2023
66b7217
Move addon interface to @velaux/data
chivalryq Apr 27, 2023
6bcc68f
clean up logs
chivalryq Apr 27, 2023
cba8a22
refactor files
chivalryq Apr 28, 2023
fb8a950
migrate interface, add save&reload button to config page
chivalryq Apr 28, 2023
bfde81c
remove committed .DS_Store
chivalryq Apr 28, 2023
81264bf
Remove hack
chivalryq May 4, 2023
f33b0fd
Fix code alert
chivalryq May 9, 2023
12aec78
remove /public/plugin constraint
chivalryq May 12, 2023
606874a
optimize the page style, usage
chivalryq May 17, 2023
2c3e0be
Merge all relative imports from velaux/data
chivalryq May 18, 2023
a254cdd
remove restriction when request module.js
chivalryq May 18, 2023
00a446d
fix image build
chivalryq May 18, 2023
263ca6c
fix build
chivalryq May 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = {
},
],
'no-duplicate-imports': 'off',
'@typescript-eslint/no-duplicate-imports': 'warn',
"import/no-duplicates": "warn",
'react/no-deprecated': 'off',
'react/no-unknown-property': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
Expand Down
11 changes: 11 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ tsconfig.tsbuildinfo

e2e-plugins

npm-artifacts
npm-artifacts
bin
15 changes: 10 additions & 5 deletions e2e-test/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ limitations under the License.
package e2e_test

import (
"fmt"

"cuelang.org/go/pkg/strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand All @@ -26,6 +28,13 @@ import (
"github.com/kubevela/velaux/pkg/server/utils/bcode"
)

func enablePlugin(id string) {
res := post(fmt.Sprintf("/manage/plugins/%s/enable", id), nil)
var dto apisv1.PluginDTO
Expect(decodeResponseBody(res, &dto)).Should(Succeed())
Expect(dto.ID).Should(Equal(id))
}

var _ = Describe("Test the plugin rest api", func() {
Context("Test manage plugin API", func() {
By("Request to /manage/plugins")
Expand Down Expand Up @@ -114,11 +123,7 @@ var _ = Describe("Test the plugin rest api", func() {
Expect(strings.Contains(err.Error(), "the plugin is not enabled")).Should(BeTrue())

By("After enable the plugin, request the plugin API should return 200")

res = post("/manage/plugins/node-dashboard/enable", nil)
var dto apisv1.PluginDTO
Expect(decodeResponseBody(res, &dto)).Should(Succeed())
Expect(dto.ID).Should(Equal("node-dashboard"))
enablePlugin("node-dashboard")

res = get(baseDomain + "/proxy/plugins/node-dashboard/api/v1/nodes")
Expect(decodeResponseBody(res, &nodeList)).Should(Succeed())
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
]
},
"dependencies": {
"@alifd/next": "^1.26.15",
"history": "4.10.1",
"react": "^17.0.2",
"react-dom": "^17.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ApplicationStatus, UIParam } from './application';
import type { NameAlias } from './env';
import { KeyValue } from "../types";

export interface Addon {
name: string;
Expand All @@ -20,6 +21,7 @@ export interface Addon {
vela?: string;
kubernetes?: string;
};
uxPlugins?: KeyValue<string>
}

export interface AddonStatus {
Expand Down
15 changes: 15 additions & 0 deletions packages/velaux-data/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
export * from './addon';
export * from './application';
export * from './cluster';
export * from './component';
export * from './configs';
export * from './definitions';
export * from './env';
export * from './kubernetes';
export * from './observation';
export * from './project';
export * from './pipeline';
export * from './repository';
export * from './roles';
export * from './system';
export * from './target';
export * from './user';
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Condition, InputItem, OutputItem, WorkflowMode, WorkflowStepStatus } from './application';
import type { NameAlias } from './env';
import { KeyValue } from "../types";

export interface CreatePipelineRequest {
name: string;
Expand Down Expand Up @@ -75,11 +76,6 @@ export interface PipelineRunBase extends PipelineRunMeta {
spec: PipelineRunSpec;
}

export interface KeyValue {
key: string;
value: string;
}

export interface PipelineRunBriefing {
pipelineRunName: string;
finished: boolean;
Expand Down
4 changes: 2 additions & 2 deletions packages/velaux-data/src/plugins/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ComponentType } from 'react';
import { PluginMeta, VelaUXPlugin } from '.';
import { KeyValue } from '../types/data';
import { PluginMeta, VelaUXPlugin } from './types';
import { KeyValue } from '../types';

export interface AppPluginMeta<T extends KeyValue = KeyValue> extends PluginMeta<T> {
// TODO anything specific to apps?
Expand Down
47 changes: 40 additions & 7 deletions packages/velaux-data/src/plugins/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { ComponentType } from 'react';
import { KeyValue, MenuType, ResourceAction, Workspace } from '..';
import { Addon } from '../api'

export enum PluginType {
PageApp = 'page-app',
Definition = 'definition',
}

interface PluginMetaInfoLink {
name: string;
url: string;
Expand Down Expand Up @@ -50,7 +52,7 @@ export interface PluginInclude {
catalog?: string;
}

export interface PluginMeta<T extends KeyValue = {}> {
export interface PluginMeta<T extends KeyValue = {}> extends PluginLink, SourceAddon {
id: string;
name: string;
type: PluginType;
Expand All @@ -67,7 +69,7 @@ export interface PluginMeta<T extends KeyValue = {}> {
includes?: PluginInclude[];

// Filled in by the backend
jsonData?: T;
jsonSetting?: T;
secureJsonData?: KeyValue;
secureJsonFields?: KeyValue<boolean>;
enabled?: boolean;
Expand All @@ -78,9 +80,27 @@ export interface PluginMeta<T extends KeyValue = {}> {
live?: boolean;
}

/**
* Represents a plugin and link to get plugin tarball
*/
export interface PluginLink {
name: string
url: string
}

/**
* Represents a plugin linked to
*/
export interface SourceAddon {
addon: Addon
}


export interface PluginConfigPageProps<T extends PluginMeta> {
plugin: VelaUXPlugin<T>;
query: KeyValue; // The URL query parameters
onJSONDataChange: (key: string, value: any) => void;
onSecureJSONDataChange: (key: string, value: any) => void;
}

export interface PluginConfigPage<T extends PluginMeta> {
Expand All @@ -100,18 +120,31 @@ export class VelaUXPlugin<T extends PluginMeta = PluginMeta> {
loadError?: boolean;

// Show configuration tabs on the plugin page
configPages?: Array<PluginConfigPage<T>>;
configPages?: PluginConfigPage<T>;

// Tabs on the plugin page
addConfigPage(tab: PluginConfigPage<T>) {
if (!this.configPages) {
this.configPages = [];
}
this.configPages.push(tab);
this.configPages = tab;
return this;
}

constructor() {
this.meta = {} as T;
}
}

export type PluginEnableRequest = {
id: string
jsonData: KeyValue
secureJsonData: KeyValue
}

export type PluginInstallRequest = {
id: string
url: string
}

export type UXPlugin = {
id: string
url: string
}
8 changes: 8 additions & 0 deletions packages/velaux-data/src/types/data.ts
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
export type KeyValue<T = any> = Record<string, T>;

export function unmarshal<T>(kv: KeyValue): T {
return kv as T;
}

export function marshal<T>(obj: T): KeyValue {
return obj as KeyValue;
}
3 changes: 2 additions & 1 deletion packages/velaux-data/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"compilerOptions": {
"baseUrl": "./src",
"declarationDir": "./compiled",
"emitDeclarationOnly": true,
"isolatedModules": true,
Expand All @@ -14,4 +15,4 @@
"include": [
"src/**/*.ts*",
]
}
}
2 changes: 1 addition & 1 deletion packages/velaux-ui/src/api/addons.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EnableAddonRequest } from '../interface/addon';
import type { EnableAddonRequest } from '@velaux/data';
import { getDomain } from '../utils/common';

import { addons, addonRegistries, enabledAddon } from './productionLink';
Expand Down
2 changes: 1 addition & 1 deletion packages/velaux-ui/src/api/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type {
UpdatePolicyRequest,
UpdateTriggerRequest,
CreateTriggerRequest,
} from '../interface/application';
} from '@velaux/data';
import { getDomain } from '../utils/common';

import { application } from './productionLink';
Expand Down
2 changes: 1 addition & 1 deletion packages/velaux-ui/src/api/cluster.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CreateCluster } from '../interface/cluster';
import type { CreateCluster } from '@velaux/data';
import { getDomain } from '../utils/common';

import {
Expand Down
3 changes: 1 addition & 2 deletions packages/velaux-ui/src/api/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type {
CreateConfigRequest,
NamespacedName,
UpdateConfigRequest,
} from '../interface/configs';
import type { ProjectName } from '../interface/project';
ProjectName } from '@velaux/data';
import { getDomain } from '../utils/common';

import { configs, configTemplates, project } from './productionLink';
Expand Down
2 changes: 1 addition & 1 deletion packages/velaux-ui/src/api/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UIParam } from '../interface/application';
import type { UIParam } from '@velaux/data';
import { getDomain } from '../utils/common';

import { definition } from './productionLink';
Expand Down
2 changes: 1 addition & 1 deletion packages/velaux-ui/src/api/env.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CreateEnvRequest } from '../interface/env';
import type { CreateEnvRequest } from '@velaux/data';
import type { QueryTarget } from '../model/target';
import { getDomain } from '../utils/common';

Expand Down
2 changes: 2 additions & 0 deletions packages/velaux-ui/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './plugin';
export * from './pipeline';
2 changes: 1 addition & 1 deletion packages/velaux-ui/src/api/pipeline.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { CreatePipelineRequest } from '../interface/pipeline';
import type { CreatePipelineRequest } from '@velaux/data';
import { getDomain } from '../utils/common';

import { get, post, put, rdelete } from './request';
Expand Down
36 changes: 36 additions & 0 deletions packages/velaux-ui/src/api/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { getDomain } from '../utils/common';

import { managePlugin } from './productionLink';
import { get, post } from './request';
import { PluginEnableRequest, PluginInstallRequest } from "@velaux/data";

const baseURLOject = getDomain();
const base = baseURLOject.MOCK || baseURLOject.APIBASE;

export function getPluginList(params: any) {
return get(base + managePlugin, { params: params }).then((res) => res);
}

export function detailPlugin(params: { id: string }) {
return get(`${base + managePlugin}/${params.id}`, { params: params }).then((res) => res);
}

export function enablePlugin(params: PluginEnableRequest) {
return post(`${base + managePlugin}/${params.id}/enable`, params);
}

export function disablePlugin(params: { id: string }) {
return post(`${base + managePlugin}/${params.id}/disable`, params);
}

export function setPlugin(params: PluginEnableRequest) {
return post(`${base + managePlugin}/${params.id}/setting`, params);
}

export function installPlugin(params: PluginInstallRequest) {
return post(`${base + managePlugin}/${params.id}/install`, { url: params.url });
}

export function uninstallPlugin(params: { id: string }) {
return post(`${base + managePlugin}/${params.id}/uninstall`, {});
}
2 changes: 2 additions & 0 deletions packages/velaux-ui/src/api/productionLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ export const platformPermissions = `/api/v1/permissions`;
export const configs = `/api/v1/configs`;
export const configTemplates = `/api/v1/config_templates`;
export const cloudShell = `/api/v1/cloudshell`;
export const plugin = `/api/v1/plugins`;
export const managePlugin = `/api/v1/manage/plugins`;
2 changes: 1 addition & 1 deletion packages/velaux-ui/src/api/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
ProjectRole,
ProjectUserCreate,
ProjectUserQuery,
} from '../interface/project';
} from '@velaux/data';
import { getDomain } from '../utils/common';

import { project_mock } from './devLink';
Expand Down
2 changes: 1 addition & 1 deletion packages/velaux-ui/src/api/roles.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RolesCreateBase } from '../interface/roles';
import { RolesCreateBase } from '@velaux/data';
import { getDomain } from '../utils/common';

import { project_mock } from './devLink';
Expand Down
2 changes: 1 addition & 1 deletion packages/velaux-ui/src/api/system_config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UpdateSystemInfo } from '../interface/system';
import type { UpdateSystemInfo } from '@velaux/data';
import { getDomain } from '../utils/common';

import { get, put } from './request';
Expand Down
2 changes: 1 addition & 1 deletion packages/velaux-ui/src/api/target.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Target } from '../interface/target';
import type { Target } from '@velaux/data';
import type { QueryTarget } from '../model/target';
import { getDomain } from '../utils/common';

Expand Down
2 changes: 1 addition & 1 deletion packages/velaux-ui/src/api/users.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { User } from '../interface/user';
import type { User } from '@velaux/data';

import { users, cloudShell } from './productionLink';
import { post, get, rdelete, put } from './request';
Expand Down
2 changes: 1 addition & 1 deletion packages/velaux-ui/src/api/workflows.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { UpdateWorkflowRequest } from '../interface/application';
import type { UpdateWorkflowRequest } from '@velaux/data';
import { getDomain } from '../utils/common';

import { application, definition } from './productionLink';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Dialog, Message } from '@alifd/next';
import * as React from 'react';

import type { ApplicationCompareResponse } from '../../interface/application';
import type { ApplicationCompareResponse } from '@velaux/data';
import './index.less';
import { DiffEditor } from '../DiffEditor';
import { If } from '../If';
Expand Down
Loading