-
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 #1610 from merico-dev/client-panel-render
feat(dashboard): add ClientPanelRender
- Loading branch information
Showing
8 changed files
with
196 additions
and
25 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
dashboard/src/components/panel/panel-render/client-panel-render.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,26 @@ | ||
import { useDashboardContext } from '~/contexts'; | ||
import { PanelRenderBase } from './panel-render-base'; | ||
import { PanelVizFeatures } from './panel-viz-features'; | ||
|
||
export interface IClientPanelRenderProps { | ||
panelId: string; | ||
} | ||
|
||
/** | ||
* Public API to render a panel on the dashboard user side. | ||
* This component should be rendered by the ReadOnlyDashboard/DashboardEditor component, you can use it with the panel addon. | ||
* @param props | ||
* @constructor | ||
*/ | ||
export function ClientPanelRender(props: IClientPanelRenderProps) { | ||
const dashboardModel = useDashboardContext(); | ||
const panel = dashboardModel.content.panels.findByID(props.panelId); | ||
if (!panel) { | ||
return null; | ||
} | ||
return ( | ||
<PanelVizFeatures withAddon={false} withPanelTitle={false} withInteraction={false}> | ||
<PanelRenderBase panel={panel} panelStyle={{}} /> | ||
</PanelVizFeatures> | ||
); | ||
} |
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
36 changes: 36 additions & 0 deletions
36
dashboard/src/components/panel/panel-render/panel-viz-features.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,36 @@ | ||
import React from 'react'; | ||
import { defaults } from 'lodash'; | ||
|
||
export interface IPanelVizFeatures { | ||
withInteraction: boolean; | ||
/** | ||
* Render panel title | ||
* @default true | ||
*/ | ||
withPanelTitle: boolean; | ||
/** | ||
* Render panel addon from plugins | ||
* @default true | ||
*/ | ||
withAddon: boolean; | ||
} | ||
|
||
const defaultValue = { | ||
withInteraction: true, | ||
withAddon: true, | ||
withPanelTitle: true, | ||
}; | ||
const PanelVizFeaturesContext = React.createContext<IPanelVizFeatures>(defaultValue); | ||
|
||
export interface IPanelVizFeaturesProps extends Partial<IPanelVizFeatures> { | ||
children: React.ReactNode; | ||
} | ||
|
||
export function PanelVizFeatures({ children, ...rest }: IPanelVizFeaturesProps) { | ||
const value = defaults({}, rest, defaultValue); | ||
return <PanelVizFeaturesContext.Provider value={value}>{children}</PanelVizFeaturesContext.Provider>; | ||
} | ||
|
||
export function usePanelVizFeatures(): IPanelVizFeatures { | ||
return React.useContext(PanelVizFeaturesContext); | ||
} |
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
17 changes: 5 additions & 12 deletions
17
dashboard/src/interactions/hooks/use-current-interaction-manager.ts
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,18 +1,11 @@ | ||
import { useCreation } from 'ahooks'; | ||
import { InteractionManager } from '~/interactions/interaction-manager'; | ||
import { OPERATIONS } from '~/interactions/operation/operations'; | ||
import { IVizManager } from '~/components/plugins'; | ||
import { IVizManager, tokens } from '~/components/plugins'; | ||
import { IVizInteractionManager, VizInstance } from '~/types/plugin'; | ||
import { useServiceLocator } from '~/components/plugins/service/service-locator/use-service-locator'; | ||
|
||
export const useCurrentInteractionManager = ({ | ||
vizManager, | ||
instance, | ||
}: { | ||
export const useCurrentInteractionManager = ({}: { | ||
vizManager: IVizManager; | ||
instance: VizInstance; | ||
}): IVizInteractionManager => { | ||
return useCreation( | ||
() => new InteractionManager(instance, vizManager.resolveComponent(instance.type), OPERATIONS), | ||
[instance, vizManager], | ||
); | ||
const sl = useServiceLocator(); | ||
return sl.getRequired(tokens.instanceScope.interactionManager); | ||
}; |
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,101 @@ | ||
import { JsonPluginStorage } from '~/components/plugins/json-plugin-storage'; | ||
import { | ||
IDashboardOperation, | ||
IDashboardOperationSchema, | ||
ITrigger, | ||
ITriggerSchema, | ||
IVizInteraction, | ||
IVizInteractionManager, | ||
IVizOperationManager, | ||
IVizTriggerManager, | ||
PluginStorage, | ||
} from '~/types/plugin'; | ||
|
||
class NullTriggerManager implements IVizTriggerManager { | ||
getTriggerSchemaList(): ITriggerSchema[] { | ||
return []; | ||
} | ||
getTriggerList(): Promise<ITrigger[]> { | ||
return Promise.resolve([]); | ||
} | ||
removeTrigger(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
createOrGetTrigger(): Promise<ITrigger> { | ||
return Promise.resolve(nullTrigger); | ||
} | ||
retrieveTrigger(): Promise<ITrigger | undefined> { | ||
return Promise.resolve(nullTrigger); | ||
} | ||
watchTriggerSnapshotList(): () => void { | ||
return () => { | ||
return; | ||
}; | ||
} | ||
needMigration(): Promise<boolean> { | ||
return Promise.resolve(false); | ||
} | ||
runMigration(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
} | ||
|
||
class NullTrigger implements ITrigger { | ||
id = ''; | ||
schemaRef = ''; | ||
triggerData: PluginStorage = new JsonPluginStorage({}); | ||
} | ||
const nullTrigger = new NullTrigger(); | ||
|
||
class NullOperationManager implements IVizOperationManager { | ||
getOperationSchemaList(): IDashboardOperationSchema[] { | ||
return []; | ||
} | ||
getOperationList(): Promise<IDashboardOperation[]> { | ||
return Promise.resolve([]); | ||
} | ||
removeOperation(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
createOrGetOperation(): Promise<IDashboardOperation> { | ||
return Promise.resolve(nullOperation); | ||
} | ||
runOperation(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
retrieveTrigger(): Promise<IDashboardOperation | undefined> { | ||
return Promise.resolve(nullOperation); | ||
} | ||
runMigration(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
needMigration(): Promise<boolean> { | ||
return Promise.resolve(false); | ||
} | ||
} | ||
|
||
class NullDashboardOperation implements IDashboardOperation { | ||
id = ''; | ||
schemaRef = ''; | ||
operationData: PluginStorage = new JsonPluginStorage({}); | ||
} | ||
const nullOperation = new NullDashboardOperation(); | ||
|
||
export class NullInteractionManager implements IVizInteractionManager { | ||
triggerManager: IVizTriggerManager = new NullTriggerManager(); | ||
operationManager: IVizOperationManager = new NullOperationManager(); | ||
getInteractionList(): Promise<IVizInteraction[]> { | ||
return Promise.resolve([]); | ||
} | ||
addInteraction(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
removeInteraction(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
runInteraction(): Promise<void> { | ||
return Promise.resolve(); | ||
} | ||
|
||
static instance = new NullInteractionManager(); | ||
} |