-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Qiaozp <[email protected]>
- Loading branch information
Showing
10 changed files
with
260 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
34 changes: 34 additions & 0 deletions
34
packages/velaux-ui/src/pages/Addons/components/plugin-config/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
157
packages/velaux-ui/src/pages/Addons/components/plugin/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.