-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Plugin Overlay for static, high priority, immutable configurati…
…on (#1018) * refactor: create store only once * feat: plugin overlay * chore: remove unused stubs * refactor: use refetchOnMountOrArgChange * chore: remove unused code
- Loading branch information
1 parent
ca255a4
commit 73bbec2
Showing
28 changed files
with
172 additions
and
126 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,32 @@ | ||
import {PluginOverlayContext} from './symbols'; | ||
import {PluginProvider} from './types'; | ||
|
||
export class PluginOverlay { | ||
private [PluginOverlayContext]: Record<string, any> = {}; | ||
private providerCreator: (() => PluginProvider<any>) | null = null; | ||
|
||
public getContext() { | ||
return this[PluginOverlayContext]; | ||
} | ||
|
||
public setContext(context: Record<string, any> | ((oldContext: Record<string, any>) => Record<string, any>)) { | ||
if (typeof context === 'function') { | ||
this[PluginOverlayContext] = context(this[PluginOverlayContext]); | ||
return; | ||
} | ||
this[PluginOverlayContext] = context; | ||
} | ||
|
||
public appendContext(context: Record<string, any>) { | ||
this[PluginOverlayContext] = {...this[PluginOverlayContext], ...context}; | ||
} | ||
|
||
public useProvider() { | ||
if (!this.providerCreator) return null; | ||
return this.providerCreator(); | ||
} | ||
|
||
public provider(pc: typeof this.providerCreator) { | ||
this.providerCreator = pc; | ||
} | ||
} |
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,29 @@ | ||
import {FC, PropsWithChildren, ReactElement, createElement, useCallback} from 'react'; | ||
|
||
import {Plugin, PluginEntry} from './internal/Plugin'; | ||
import {PluginOverlay} from './internal/PluginOverlay'; | ||
|
||
export const usePluginOverlay = (plugins: PluginEntry<any>[]) => { | ||
const createProviderTree = useCallback((overlays: PluginOverlay[], children: ReactElement): ReactElement => { | ||
if (overlays.length === 0) { | ||
return children; | ||
} | ||
|
||
const lastOverlay = overlays[overlays.length - 1]; | ||
const provider = lastOverlay.useProvider(); | ||
const newChildren = provider ? createElement(provider.type, provider.props, children) : children; | ||
|
||
return createProviderTree(overlays.slice(0, -1), newChildren); | ||
}, []); | ||
|
||
const ProviderComponent = useCallback<FC<PropsWithChildren<any>>>( | ||
({children}) => | ||
createProviderTree( | ||
plugins.filter((plugin): plugin is Plugin<any> => 'overlay' in plugin).map(plugin => plugin.overlay), | ||
children | ||
), | ||
[createProviderTree] | ||
); | ||
|
||
return ProviderComponent; | ||
}; |
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
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
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
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,14 +1,9 @@ | ||
import {createPlugin, external} from '@testkube/plugins'; | ||
import {createPlugin} from '@testkube/plugins'; | ||
|
||
import type RtkPlugin from '@plugins/rtk/plugin'; | ||
import RtkPlugin from '@plugins/rtk/plugin'; | ||
|
||
import {labelsApi} from '@services/labels'; | ||
|
||
const rtkStub = external<typeof RtkPlugin>(); | ||
export default createPlugin('oss/labels').init(); | ||
|
||
export default createPlugin('oss/labels') | ||
.needs(rtkStub.slots('rtkServices')) | ||
|
||
.init(tk => { | ||
tk.slots.rtkServices.add(labelsApi); | ||
}); | ||
RtkPlugin.overlay.appendContext({labelsApi}); |
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
packages/web/src/plugins/rtk-reset-on-api-change/plugin.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.