-
Notifications
You must be signed in to change notification settings - Fork 19
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 #1022 from kubeshop/release/v1.16.7
Release/v1.16.7
- Loading branch information
Showing
33 changed files
with
201 additions
and
136 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
Oops, something went wrong.