-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1604 from merico-dev/panel-addon
feat: add panelAddon plugin
- Loading branch information
Showing
14 changed files
with
178 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './panel-addon-manager'; | ||
export * from './panel-addon-context'; |
21 changes: 21 additions & 0 deletions
21
dashboard/src/components/plugins/panel-addon/panel-addon-context.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,21 @@ | ||
import React, { useId } from 'react'; | ||
|
||
const PanelAddonContext = React.createContext<{ addonSlotId: string | null }>({ addonSlotId: null }); | ||
|
||
export function PanelAddonProvider({ children }: { children: React.ReactNode }) { | ||
const id = `panel-addon-slot-${useId()}`; | ||
return ( | ||
<PanelAddonContext.Provider value={{ addonSlotId: id }}> | ||
<div style={{ position: 'static', top: 0, left: 0 }} id={id}></div> | ||
{children} | ||
</PanelAddonContext.Provider> | ||
); | ||
} | ||
|
||
export function usePanelAddonSlot() { | ||
const { addonSlotId } = React.useContext(PanelAddonContext); | ||
if (!addonSlotId) { | ||
return null; | ||
} | ||
return document.getElementById(addonSlotId); | ||
} |
16 changes: 16 additions & 0 deletions
16
dashboard/src/components/plugins/panel-addon/panel-addon-manager.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,16 @@ | ||
import { IPanelAddon, IPanelAddonRenderProps, IPluginManager } from '~/types/plugin'; | ||
import React from 'react'; | ||
|
||
export class PanelAddonManager { | ||
constructor(private pluginManager: IPluginManager) {} | ||
|
||
createPanelAddonNode(props: IPanelAddonRenderProps) { | ||
const addons = this.pluginManager.installedPlugins | ||
.flatMap((it) => it.manifest.panelAddon) | ||
.filter((it) => !!it) as IPanelAddon[]; | ||
const nodes = addons.map((addon) => { | ||
return React.createElement(addon.addonRender, { ...props, key: addon.name }); | ||
}); | ||
return <>{nodes}</>; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
import _ from 'lodash'; | ||
import React from 'react'; | ||
|
||
export interface ILayoutStateContext { | ||
|
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
Oops, something went wrong.