Skip to content

Commit

Permalink
Show config page
Browse files Browse the repository at this point in the history
Signed-off-by: Qiaozp <[email protected]>
  • Loading branch information
chivalryq committed Apr 14, 2023
1 parent 186c2b4 commit dab828d
Show file tree
Hide file tree
Showing 10 changed files with 260 additions and 37 deletions.
9 changes: 3 additions & 6 deletions packages/velaux-data/src/plugins/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,11 @@ 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;
}

Expand All @@ -117,7 +114,7 @@ export class VelaUXPlugin<T extends PluginMeta = PluginMeta> {
}

export type PluginEnableRequest = {
name: string
id: string
jsonData: KeyValue
secureJsonData: KeyValue
}
Expand Down
10 changes: 7 additions & 3 deletions packages/velaux-ui/src/api/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ export function getPluginList(params: any) {
}

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

export function disablePlugin(params: { name: string }) {
return post(`${base + managePlugin}/${params.name}/disable`, 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);
}
26 changes: 25 additions & 1 deletion packages/velaux-ui/src/layout/AppRootPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getPluginSrv, importAppPagePlugin } from '../../services/PluginService'
interface Props {
pluginId: string;
}

export function AppRootPage({ pluginId }: Props) {
const [app, setApp] = React.useState<AppPagePlugin>();
React.useEffect(() => {
Expand All @@ -27,6 +28,27 @@ export function AppRootPage({ pluginId }: Props) {
);
}

export function AppConfigPage({ pluginId }: Props) {
const [app, setApp] = React.useState<AppPagePlugin>();
React.useEffect(() => {
loadAppPlugin(pluginId, setApp);
}, [pluginId]);
if (!app || !app.configPages) {
return (
<div>
<Translation>No config app page component found</Translation>
</div>
);
}

console.log(app)
return (
<div>
<app.configPages.body plugin={app} query={{}} />
</div>
);
}

async function loadAppPlugin(
pluginId: string,
setApp: React.Dispatch<React.SetStateAction<AppPagePlugin | undefined>>
Expand All @@ -42,5 +64,7 @@ async function loadAppPlugin(
console.log(err);
});
}
} catch (err) {}
} catch (err) {
console.log(err)
}
}
9 changes: 8 additions & 1 deletion packages/velaux-ui/src/layout/LayoutRouter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import DefinitionDetails from '../DefinitionDetails';
import DefinitionsLayout from '../Definitions';
import ProjectLayout from '../Project';
import MyProjectList from '../../pages/MyProjectList';
import { AppRootPage } from '../AppRootPage';
import { AppRootPage,AppConfigPage } from '../AppRootPage';

export default function Router() {
return (
Expand Down Expand Up @@ -397,6 +397,13 @@ export default function Router() {
return <AppRootPage pluginId={props.match.params.pluginId}></AppRootPage>;
}}
/>
<Route
exact
path={"/plugin-config/:pluginId"}
render={(props: any) => {
return <AppConfigPage pluginId={props.match.params.pluginId}></AppConfigPage>;
}}
/>
<Route path="/notFound" component={NotFound} />
<Redirect to="/notFound" />
</Switch>
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React from 'react';
import './index.less';
import type { KeyValue, PluginMeta } from '@velaux/data';
import { AppConfigPage } from "@velaux/ui/src/layout/AppRootPage";

type State = {
iconValid: KeyValue<boolean>;
};

type Props = {
plugin: PluginMeta
};


class PluginConfig extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
iconValid: {},
};
}

render() {
const { plugin } = this.props;
return (
<div className="plugin-config">
<AppConfigPage pluginId={plugin.id}></AppConfigPage>;
</div>
);
}

}

export default PluginConfig;
Empty file.
157 changes: 157 additions & 0 deletions packages/velaux-ui/src/pages/Addons/components/plugin/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
import React from 'react';
import './index.less';

import { Button, Dialog, List } from "@alifd/next";
import type { KeyValue, PluginMeta } from '@velaux/data';
import PluginConfig from "../plugin-config";
import Empty from "../../../../components/Empty";

type State = {
iconValid: KeyValue<boolean>;
currentPlugin?: PluginMeta;
showConfig: boolean;
};

type Props = {
pluginList?: PluginMeta[];
enabledPlugins?: PluginMeta[];

onInstall: (id: string) => void;
onUninstall: (id: string) => void;
onEnable: (id: string) => void;
onDisable: (id: string) => void;
// onConfig: (id: string) => void;
};


class Plugin extends React.Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
iconValid: {},
showConfig: false,
};
}

componentDidMount() {
const { pluginList } = this.props;
if (pluginList) {
pluginList.forEach((plugin) => {
this.checkImage(plugin.name, plugin.info.logos.small);
});
}
}

componentDidUpdate(prevProps: Readonly<Props>) {
const { pluginList } = this.props;
if (pluginList && pluginList !== prevProps.pluginList) {
pluginList.forEach((plugin) => {
this.checkImage(plugin.name, plugin.info.logos.small);
});
}
}

checkImage = (name: string, icon?: string) => {
if (icon && icon !== 'none' && icon !== '') {
const img = new Image();
img.src = icon;
img.onload = () => {
this.setState((preState) => {
preState.iconValid[name] = true;
return preState;
});
}
img.onerror = () => {
this.setState((preState) => {
preState.iconValid[name] = false;
return preState;
});
}
} else {
this.setState((preState) => {
preState.iconValid[name] = false;
return preState;
});
}
};

render() {
const { pluginList, enabledPlugins, onInstall, onDisable, onUninstall, } = this.props;
const { currentPlugin, showConfig } = this.state;

return (
<div>
<Dialog
title={`${currentPlugin ? currentPlugin.name : ""} Configuration`}
visible={showConfig}
footerActions={[]}
onClose={() => this.setState({ showConfig: false })}
style={{ width: '80%', height: '80%', overflow: 'auto' }}
closeMode={['close', 'esc', 'mask']}
>
{(() => {
if (currentPlugin) {
return <PluginConfig plugin={currentPlugin} />;
}
return <Empty />
})()}

</Dialog>
<List className="plugin-list">
{pluginList?.map((plugin) => {
const isEnabled = enabledPlugins?.some((p) => p.id === plugin.id);
const isInstalled = !!plugin.info;

return (
<List.Item key={plugin.id} className="plugin-row">
<div
style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', width: '100%' }}>
<div>{plugin.name}</div>
<div>
{isInstalled && isEnabled && (
<Button onClick={() => {
console.log('plugin', plugin)
this.setState({
currentPlugin: plugin,
showConfig: true,
},() => {
console.log('currentPlugin', this.state.currentPlugin)
})
}}>Config</Button>
)}
{!isInstalled && (
<Button type="primary" onClick={() => onInstall(plugin.id)}>
Install
</Button>
)}
{isInstalled && !isEnabled && (
<Button type={"primary"} onClick={() => {
console.log('plugin', plugin)
this.setState({
currentPlugin: plugin,
showConfig: true,
},() => {
console.log('currentPlugin', this.state.currentPlugin)
})
}}>Enable</Button>
)}
{isInstalled && isEnabled && (
<Button onClick={() => onDisable(plugin.id)}>Disable</Button>
)}
{isInstalled && !isEnabled && (
<Button warning onClick={() => onUninstall(plugin.id)}>
Uninstall
</Button>
)}
</div>
</div>
</List.Item>
);
})}
</List>
</div>
);
}
}

export default Plugin;
49 changes: 24 additions & 25 deletions packages/velaux-ui/src/pages/Addons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import CardContend from './components/card-conten/index';
import AddonDetailDialog from './components/detail/index';
import RegistryManageDialog from './components/registry-manage/index';
import SelectSearch from './components/search/index';
import Plugin from "./components/plugin";

type Props = {
dispatch: ({}) => {};
Expand Down Expand Up @@ -130,20 +131,31 @@ class Addons extends React.Component<Props, State> {
});
};

enablePlugin(name: string) {
installPlugin = (id: string) => {

}
uninstallPlugin = (id: string) => {

}

enablePlugin=(id: string) =>{
this.props.dispatch({
type: 'plugins/enablePlugin',
payload: { name },
payload: { id },
});
}

disablePlugin(name: string) {
disablePlugin=(id: string)=>{
this.props.dispatch({
type: 'plugins/disablePlugin',
payload: { name },
payload: { id },
});
}

configPlugin=(id: string) =>{

}


render() {
const {
Expand All @@ -160,17 +172,6 @@ class Addons extends React.Component<Props, State> {
const addonLoading = loading.models.addons;
const pluginLoading = loading.models.plugins;
const { showAddonDetail, addonName, showRegistryManage, tagList, selectTags } = this.state;
const clickPlugin: (id: string) => void = (id: string) => {
const plugin = pluginList?.find((item) => item.id === id);
if (!plugin) {
return;
}
if (enabledPlugins?.find((item) => item.id === id)) {
this.disablePlugin(plugin.id);
} else {
this.enablePlugin(plugin.id);
}
}

return (
<div>
Expand Down Expand Up @@ -239,17 +240,15 @@ class Addons extends React.Component<Props, State> {
</Tab.Item>
<Tab.Item title="VelaUX Plugins">
<Loading visible={pluginLoading} style={{ width: '100%' }}>
<If condition={addonListMessage}>
<Message style={{ marginBottom: '16px' }} type="warning">
{addonListMessage}
</Message>
</If>
<CardContend
type={'plugin'}
pluginList={pluginList}
clickPlugin={clickPlugin}
<Plugin
enabledPlugins={enabledPlugins}
/>
pluginList={pluginList}
onEnable={this.enablePlugin}
onDisable={this.disablePlugin}
onInstall={this.installPlugin}
onUninstall={this.uninstallPlugin}
// onConfig={this.configPlugin}
></Plugin>
</Loading>
</Tab.Item>
</Tab>
Expand Down
Loading

0 comments on commit dab828d

Please sign in to comment.