From a2a3b8e6c7aa8ae65200f7e388187255769208f8 Mon Sep 17 00:00:00 2001 From: Dev Catalin <20538711+devcatalin@users.noreply.github.com> Date: Mon, 19 Feb 2024 13:24:57 +0200 Subject: [PATCH 1/5] refactor: create store only once --- packages/plugins/src/internal/Plugin.ts | 10 +++ packages/plugins/src/internal/types.ts | 2 + .../web/src/plugins/cluster-status/plugin.tsx | 9 ++- packages/web/src/plugins/executors/plugin.tsx | 9 ++- packages/web/src/plugins/labels/plugin.tsx | 9 ++- packages/web/src/plugins/rtk/plugin.tsx | 68 ++++++++++++------- .../web/src/plugins/test-sources/plugin.tsx | 12 +++- .../plugins/tests-and-test-suites/plugin.tsx | 12 +++- packages/web/src/plugins/triggers/plugin.tsx | 9 ++- packages/web/src/plugins/webhooks/plugin.tsx | 9 ++- 10 files changed, 108 insertions(+), 41 deletions(-) diff --git a/packages/plugins/src/internal/Plugin.ts b/packages/plugins/src/internal/Plugin.ts index 6f157b331..3c2b29cda 100644 --- a/packages/plugins/src/internal/Plugin.ts +++ b/packages/plugins/src/internal/Plugin.ts @@ -13,11 +13,21 @@ export class Plugin { ) { this[PluginInit] = (tk, cfg) => initFn(tk, defaults(this[PluginDetailsSymbol].config, cfg) as any); this[PluginDetailsSymbol] = config; + // this[PluginDetailsSymbol].slots } public configure(config: PluginConfigInput): PluginEntryObject { return {plugin: this, config}; } + + public getGlobals() { + return this[PluginDetailsSymbol].globals || {}; + } + + public setGlobals(replaceGlobals: (oldGlobals: Record) => Record) { + if (!this[PluginDetailsSymbol].globals) this[PluginDetailsSymbol].globals = {}; + this[PluginDetailsSymbol].globals = replaceGlobals(this[PluginDetailsSymbol].globals); + } } export type PluginEntryObject = {plugin: Plugin; config: PluginConfigInput}; diff --git a/packages/plugins/src/internal/types.ts b/packages/plugins/src/internal/types.ts index 0dd634793..fcf094271 100644 --- a/packages/plugins/src/internal/types.ts +++ b/packages/plugins/src/internal/types.ts @@ -78,6 +78,8 @@ export interface PluginState { // Routing readonly urls: Record; + + globals?: Record; } export interface EmptyPluginState extends PluginState { diff --git a/packages/web/src/plugins/cluster-status/plugin.tsx b/packages/web/src/plugins/cluster-status/plugin.tsx index 3c3d75fde..a9bee3f2c 100644 --- a/packages/web/src/plugins/cluster-status/plugin.tsx +++ b/packages/web/src/plugins/cluster-status/plugin.tsx @@ -5,7 +5,7 @@ import {createPlugin, data, external} from '@testkube/plugins'; import {SystemAccess, useSystemAccess} from '@hooks/useSystemAccess'; import type GeneralPlugin from '@plugins/general/plugin'; -import type RtkPlugin from '@plugins/rtk/plugin'; +import RtkPlugin from '@plugins/rtk/plugin'; import {configApi, useGetClusterConfigQuery} from '@services/config'; @@ -39,5 +39,10 @@ export default createPlugin('dashboard/cluster-status') }) .init(tk => { - tk.slots.rtkServices.add(configApi); + // tk.slots.rtkServices.add(configApi); }); + +RtkPlugin.setGlobals(globals => ({ + ...globals, + configApi, +})); diff --git a/packages/web/src/plugins/executors/plugin.tsx b/packages/web/src/plugins/executors/plugin.tsx index 833ac71a3..2c3ecc6fe 100644 --- a/packages/web/src/plugins/executors/plugin.tsx +++ b/packages/web/src/plugins/executors/plugin.tsx @@ -9,7 +9,7 @@ import ExecutorsList from '@pages/Executors/ExecutorsList/ExecutorsList'; import type ClusterStatusPlugin from '@plugins/cluster-status/plugin'; import type GeneralPlugin from '@plugins/general/plugin'; -import type RtkPlugin from '@plugins/rtk/plugin'; +import RtkPlugin from '@plugins/rtk/plugin'; import {executorsApi, useGetExecutorsQuery} from '@services/executors'; @@ -60,6 +60,11 @@ export default createPlugin('dashboard/executors') }) .init(tk => { - tk.slots.rtkServices.add(executorsApi); + // tk.slots.rtkServices.add(executorsApi); tk.slots.siderItems.add({path: '/executors', icon: ExecutorsIcon, title: 'Executors'}, {order: -80}); }); + +RtkPlugin.setGlobals(globals => ({ + ...globals, + executorsApi, +})); diff --git a/packages/web/src/plugins/labels/plugin.tsx b/packages/web/src/plugins/labels/plugin.tsx index 35cb00393..7a890cc09 100644 --- a/packages/web/src/plugins/labels/plugin.tsx +++ b/packages/web/src/plugins/labels/plugin.tsx @@ -1,6 +1,6 @@ import {createPlugin, external} from '@testkube/plugins'; -import type RtkPlugin from '@plugins/rtk/plugin'; +import RtkPlugin from '@plugins/rtk/plugin'; import {labelsApi} from '@services/labels'; @@ -10,5 +10,10 @@ export default createPlugin('oss/labels') .needs(rtkStub.slots('rtkServices')) .init(tk => { - tk.slots.rtkServices.add(labelsApi); + // tk.slots.rtkServices.add(labelsApi); }); + +RtkPlugin.setGlobals(globals => ({ + ...globals, + labelsApi, +})); diff --git a/packages/web/src/plugins/rtk/plugin.tsx b/packages/web/src/plugins/rtk/plugin.tsx index ee11db60c..e002db112 100644 --- a/packages/web/src/plugins/rtk/plugin.tsx +++ b/packages/web/src/plugins/rtk/plugin.tsx @@ -3,6 +3,8 @@ import {Provider as ReduxProvider} from 'react-redux'; import {Store, configureStore} from '@reduxjs/toolkit'; +import {createLogger} from 'redux-logger'; + import {createPlugin, data, slot} from '@testkube/plugins'; export interface RtkService { @@ -12,38 +14,54 @@ export interface RtkService { util: {resetApiState: () => any}; } +let store: Store | null; + // TODO: Load base URL from the plugin instead of global scope -export default createPlugin('oss/rtk') +const ossRtkPlugin = createPlugin('oss/rtk') .order(-1) .define(slot()('rtkServices')) .define(data()('rtkStore')) .define(data<() => void>()('resetRtkCache')) - .provider(({scope, useData, useSlot}) => { - const services = useSlot('rtkServices'); - scope.data.rtkStore = useMemo( - () => - configureStore({ - reducer: services.reduce((reducers, service) => ({...reducers, [service.reducerPath]: service.reducer}), {}), - middleware: getDefaultMiddleware => [ - ...getDefaultMiddleware(), - ...services.map(service => service.middleware), - ], - }), - [services] - ); - - return {type: ReduxProvider as any, props: {store: scope.data.rtkStore}}; - }) + // .provider(({scope}) => { + // scope.data.rtkStore = useMemo(() => { + // if (!store) { + // const services = Object.values(ossRtkPlugin.getGlobals()); + // store = configureStore({ + // reducer: services.reduce((reducers, service) => ({...reducers, [service.reducerPath]: service.reducer}), {}), + // middleware: getDefaultMiddleware => [ + // ...getDefaultMiddleware(), + // createLogger({ + // predicate: (_, action) => { + // return ( + // action.type.startsWith('testsApi/executeQuery') || + // action.type.startsWith('testSuitesApi/executeQuery') + // ); + // }, + // collapsed: true, + // }), + // ...services.map(service => service.middleware), + // ], + // }); + // } + // return store; + // }, []); + + // return {type: ReduxProvider as any, props: {store: scope.data.rtkStore}}; + // }) .init(tk => { - tk.data.resetRtkCache = () => { - tk.slots.rtkServices.all().forEach(service => { - const action = service.util?.resetApiState(); - if (action) { - tk.data.rtkStore?.dispatch(action); - } - }); - }; + // tk.data.resetRtkCache = () => { + // tk.slots.rtkServices.all().forEach(service => { + // const action = service.util?.resetApiState(); + // if (action) { + // tk.data.rtkStore?.dispatch(action); + // } + // }); + // }; + + ossRtkPlugin.getGlobals(); }); + +export default ossRtkPlugin; diff --git a/packages/web/src/plugins/test-sources/plugin.tsx b/packages/web/src/plugins/test-sources/plugin.tsx index 3e9d4abc8..d9081dd72 100644 --- a/packages/web/src/plugins/test-sources/plugin.tsx +++ b/packages/web/src/plugins/test-sources/plugin.tsx @@ -9,7 +9,7 @@ import SourcesList from '@pages/Sources/SourcesList/SourcesList'; import type ClusterStatusPlugin from '@plugins/cluster-status/plugin'; import type GeneralPlugin from '@plugins/general/plugin'; -import type RtkPlugin from '@plugins/rtk/plugin'; +import RtkPlugin from '@plugins/rtk/plugin'; import {repositoryApi} from '@services/repository'; import {sourcesApi, useGetSourcesQuery} from '@services/sources'; @@ -55,8 +55,14 @@ export default createPlugin('oss/test-sources') }) .init(tk => { - tk.slots.rtkServices.add(sourcesApi); - tk.slots.rtkServices.add(repositoryApi); + // tk.slots.rtkServices.add(sourcesApi); + // tk.slots.rtkServices.add(repositoryApi); tk.slots.siderItems.add({path: '/sources', icon: SourcesIcon, title: 'Sources'}, {order: -20}); }); + +RtkPlugin.setGlobals(globals => ({ + ...globals, + sourcesApi, + repositoryApi, +})); diff --git a/packages/web/src/plugins/tests-and-test-suites/plugin.tsx b/packages/web/src/plugins/tests-and-test-suites/plugin.tsx index 374c6def7..250068ac7 100644 --- a/packages/web/src/plugins/tests-and-test-suites/plugin.tsx +++ b/packages/web/src/plugins/tests-and-test-suites/plugin.tsx @@ -23,7 +23,7 @@ import TestsList from '@pages/Tests/TestsList'; import type ExecutorsPlugin from '@plugins/executors/plugin'; import type GeneralPlugin from '@plugins/general/plugin'; -import type RtkPlugin from '@plugins/rtk/plugin'; +import RtkPlugin from '@plugins/rtk/plugin'; import {testSuitesApi} from '@services/testSuites'; import {testsApi} from '@services/tests'; @@ -142,8 +142,8 @@ export default createPlugin('oss/tests-and-test-suites') .data({useLogOutput, useLogOutputPick, useLogOutputField, useLogOutputSync}) .init(tk => { - tk.slots.rtkServices.add(testSuitesApi); - tk.slots.rtkServices.add(testsApi); + // tk.slots.rtkServices.add(testSuitesApi); + // tk.slots.rtkServices.add(testsApi); // TODO: Instead of using tk.sync, use all the necessities directly in the plugin components tk.data.setExecutionTab = tk.sync(() => { @@ -233,3 +233,9 @@ export default createPlugin('oss/tests-and-test-suites') {order: -60, enabled: () => Boolean(getDecomposedVars()?.length)} ); }); + +RtkPlugin.setGlobals(globals => ({ + ...globals, + testsApi, + testSuitesApi, +})); diff --git a/packages/web/src/plugins/triggers/plugin.tsx b/packages/web/src/plugins/triggers/plugin.tsx index d3da5e201..1d81d803d 100644 --- a/packages/web/src/plugins/triggers/plugin.tsx +++ b/packages/web/src/plugins/triggers/plugin.tsx @@ -6,7 +6,7 @@ import TriggerDetails from '@pages/Triggers/TriggerDetails'; import TriggersList from '@pages/Triggers/TriggersList'; import type GeneralPlugin from '@plugins/general/plugin'; -import type RtkPlugin from '@plugins/rtk/plugin'; +import RtkPlugin from '@plugins/rtk/plugin'; import {triggersApi} from '@services/triggers'; @@ -36,6 +36,11 @@ export default createPlugin('oss/triggers') .data({useTriggers, useTriggersPick, useTriggersField, useTriggersSync}) .init(tk => { - tk.slots.rtkServices.add(triggersApi); + // tk.slots.rtkServices.add(triggersApi); tk.slots.siderItems.add({path: '/triggers', icon: TriggersIcon, title: 'Triggers'}, {order: -60}); }); + +RtkPlugin.setGlobals(globals => ({ + ...globals, + triggersApi, +})); diff --git a/packages/web/src/plugins/webhooks/plugin.tsx b/packages/web/src/plugins/webhooks/plugin.tsx index 397dd8536..4dca0d5ea 100644 --- a/packages/web/src/plugins/webhooks/plugin.tsx +++ b/packages/web/src/plugins/webhooks/plugin.tsx @@ -6,7 +6,7 @@ import WebhookDetails from '@pages/Webhooks/WebhookDetails/WebhookDetails'; import WebhooksList from '@pages/Webhooks/WebhooksList'; import type GeneralPlugin from '@plugins/general/plugin'; -import type RtkPlugin from '@plugins/rtk/plugin'; +import RtkPlugin from '@plugins/rtk/plugin'; import {webhooksApi} from '@services/webhooks'; @@ -37,7 +37,12 @@ export default createPlugin('oss/webhooks') .data({useWebhooks, useWebhooksPick, useWebhooksField, useWebhooksSync}) .init(tk => { - tk.slots.rtkServices.add(webhooksApi); + // tk.slots.rtkServices.add(webhooksApi); tk.slots.siderItems.add({path: '/webhooks', icon: WebhooksIcon, title: 'Webhooks'}, {order: -40}); }); + +RtkPlugin.setGlobals(globals => ({ + ...globals, + webhooksApi, +})); From 13a54cb7dfca7e87d0dac0d6ca5ed8e90706d704 Mon Sep 17 00:00:00 2001 From: Dev Catalin <20538711+devcatalin@users.noreply.github.com> Date: Mon, 19 Feb 2024 17:00:06 +0200 Subject: [PATCH 2/5] feat: plugin overlay --- packages/plugins/index.ts | 1 + packages/plugins/src/internal/Plugin.ts | 13 +-- .../plugins/src/internal/PluginOverlay.ts | 32 +++++++ packages/plugins/src/internal/symbols.ts | 1 + packages/plugins/src/internal/types.ts | 2 - packages/plugins/src/usePluginOverlay.ts | 29 +++++++ packages/web/src/AppRoot.tsx | 32 +++---- .../web/src/plugins/cluster-status/plugin.tsx | 11 +-- packages/web/src/plugins/executors/plugin.tsx | 8 +- packages/web/src/plugins/labels/plugin.tsx | 16 +--- .../plugins/rtk-reset-on-api-change/hooks.ts | 7 -- .../rtk-reset-on-api-change/plugin.tsx | 21 ----- packages/web/src/plugins/rtk/plugin.tsx | 86 +++++++------------ .../web/src/plugins/test-sources/plugin.tsx | 9 +- .../plugins/tests-and-test-suites/plugin.tsx | 6 +- packages/web/src/plugins/triggers/plugin.tsx | 7 +- packages/web/src/plugins/webhooks/plugin.tsx | 9 +- 17 files changed, 130 insertions(+), 160 deletions(-) create mode 100644 packages/plugins/src/internal/PluginOverlay.ts create mode 100644 packages/plugins/src/usePluginOverlay.ts delete mode 100644 packages/web/src/plugins/rtk-reset-on-api-change/hooks.ts delete mode 100644 packages/web/src/plugins/rtk-reset-on-api-change/plugin.tsx diff --git a/packages/plugins/index.ts b/packages/plugins/index.ts index 0fc0f7adb..dcab3c0f4 100644 --- a/packages/plugins/index.ts +++ b/packages/plugins/index.ts @@ -5,4 +5,5 @@ export * from './src/utils'; export * from './src/StoreProvider'; export * from './src/PluginResolver'; export * from './src/usePluginSystem'; +export * from './src/usePluginOverlay'; export type {Plugin, PluginEntry} from './src/internal/Plugin'; diff --git a/packages/plugins/src/internal/Plugin.ts b/packages/plugins/src/internal/Plugin.ts index 3c2b29cda..2465bc8c4 100644 --- a/packages/plugins/src/internal/Plugin.ts +++ b/packages/plugins/src/internal/Plugin.ts @@ -1,3 +1,4 @@ +import {PluginOverlay} from './PluginOverlay'; import type {PluginScope} from './PluginScope'; import {PluginDetails as PluginDetailsSymbol, PluginInit} from './symbols'; import type {PluginConfig, PluginConfigInput, PluginDetails, PluginScopeStateFor, PluginState} from './types'; @@ -7,27 +8,19 @@ export class Plugin { public readonly [PluginInit]: (context: PluginScope>, config: T['config']) => void; public readonly [PluginDetailsSymbol]: PluginDetails; + public readonly overlay = new PluginOverlay(); + public constructor( config: PluginDetails, initFn: (tk: PluginScope>, config: PluginConfig) => void ) { this[PluginInit] = (tk, cfg) => initFn(tk, defaults(this[PluginDetailsSymbol].config, cfg) as any); this[PluginDetailsSymbol] = config; - // this[PluginDetailsSymbol].slots } public configure(config: PluginConfigInput): PluginEntryObject { return {plugin: this, config}; } - - public getGlobals() { - return this[PluginDetailsSymbol].globals || {}; - } - - public setGlobals(replaceGlobals: (oldGlobals: Record) => Record) { - if (!this[PluginDetailsSymbol].globals) this[PluginDetailsSymbol].globals = {}; - this[PluginDetailsSymbol].globals = replaceGlobals(this[PluginDetailsSymbol].globals); - } } export type PluginEntryObject = {plugin: Plugin; config: PluginConfigInput}; diff --git a/packages/plugins/src/internal/PluginOverlay.ts b/packages/plugins/src/internal/PluginOverlay.ts new file mode 100644 index 000000000..88c08392d --- /dev/null +++ b/packages/plugins/src/internal/PluginOverlay.ts @@ -0,0 +1,32 @@ +import {PluginOverlayContext} from './symbols'; +import {PluginProvider} from './types'; + +export class PluginOverlay { + private [PluginOverlayContext]: Record = {}; + private providerCreator: (() => PluginProvider) | null = null; + + public getContext() { + return this[PluginOverlayContext]; + } + + public setContext(context: Record | ((oldContext: Record) => Record)) { + if (typeof context === 'function') { + this[PluginOverlayContext] = context(this[PluginOverlayContext]); + return; + } + this[PluginOverlayContext] = context; + } + + public appendContext(context: Record) { + this[PluginOverlayContext] = {...this[PluginOverlayContext], ...context}; + } + + public useProvider() { + if (!this.providerCreator) return null; + return this.providerCreator(); + } + + public provider(pc: typeof this.providerCreator) { + this.providerCreator = pc; + } +} diff --git a/packages/plugins/src/internal/symbols.ts b/packages/plugins/src/internal/symbols.ts index 5f9e6d8f0..dd5c5e568 100644 --- a/packages/plugins/src/internal/symbols.ts +++ b/packages/plugins/src/internal/symbols.ts @@ -20,3 +20,4 @@ export const PluginScopeScheduleUpdate = Symbol.for('schedule informing about ch export const PluginScopeEmitChange = Symbol.for('inform about data change'); export const PluginScopeSubscribeChange = Symbol.for('subscribe to data change'); export const PluginScopeListeners = Symbol.for('subscription listeners list'); +export const PluginOverlayContext = Symbol.for('context used only for overlay'); diff --git a/packages/plugins/src/internal/types.ts b/packages/plugins/src/internal/types.ts index fcf094271..0dd634793 100644 --- a/packages/plugins/src/internal/types.ts +++ b/packages/plugins/src/internal/types.ts @@ -78,8 +78,6 @@ export interface PluginState { // Routing readonly urls: Record; - - globals?: Record; } export interface EmptyPluginState extends PluginState { diff --git a/packages/plugins/src/usePluginOverlay.ts b/packages/plugins/src/usePluginOverlay.ts new file mode 100644 index 000000000..ceaa12545 --- /dev/null +++ b/packages/plugins/src/usePluginOverlay.ts @@ -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[]) => { + 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>>( + ({children}) => + createProviderTree( + plugins.filter((plugin): plugin is Plugin => 'overlay' in plugin).map(plugin => plugin.overlay), + children + ), + [createProviderTree] + ); + + return ProviderComponent; +}; diff --git a/packages/web/src/AppRoot.tsx b/packages/web/src/AppRoot.tsx index 64fd06716..7e96839ee 100644 --- a/packages/web/src/AppRoot.tsx +++ b/packages/web/src/AppRoot.tsx @@ -3,7 +3,7 @@ import {useMemo} from 'react'; import {Layout} from 'antd'; import {Content} from 'antd/lib/layout/layout'; -import {usePluginSystem} from '@testkube/plugins'; +import {usePluginOverlay, usePluginSystem} from '@testkube/plugins'; import {ReactComponent as Logo} from '@assets/testkube-symbol-color.svg'; @@ -26,7 +26,6 @@ import ModalPlugin from '@plugins/modal/plugin'; import PermissionsPlugin from '@plugins/permissions/plugin'; import PromoBannersPlugin from '@plugins/promo-banners/plugin'; import RouterPlugin from '@plugins/router/plugin'; -import RtkResetOnApiChangePlugin from '@plugins/rtk-reset-on-api-change/plugin'; import RtkPlugin from '@plugins/rtk/plugin'; import SettingsPlugin from '@plugins/settings/plugin'; import SiderCloudMigratePlugin from '@plugins/sider-cloud-migrate/plugin'; @@ -51,7 +50,6 @@ const AppRoot: React.FC = () => { ConfigPlugin.configure({slackUrl: externalLinks.slack}), RouterPlugin.configure({baseUrl: env.basename || ''}), PermissionsPlugin.configure({resolver: new BasePermissionsResolver()}), - RtkResetOnApiChangePlugin, RtkPlugin, ModalPlugin, SiderLogoPlugin.configure({logo: }), @@ -67,6 +65,8 @@ const AppRoot: React.FC = () => { ); const [PluginProvider, {routes}] = usePluginSystem(plugins); + const PluginOverlayProvider = usePluginOverlay(plugins); + return ( { debug={env.debugTelemetry} paused > - - - - - - - - - - - - + + + + + + + + + + + + + + ); diff --git a/packages/web/src/plugins/cluster-status/plugin.tsx b/packages/web/src/plugins/cluster-status/plugin.tsx index a9bee3f2c..3a5ecb200 100644 --- a/packages/web/src/plugins/cluster-status/plugin.tsx +++ b/packages/web/src/plugins/cluster-status/plugin.tsx @@ -12,11 +12,9 @@ import {configApi, useGetClusterConfigQuery} from '@services/config'; import {safeRefetch} from '@utils/fetchUtils'; const generalStub = external(); -const rtkStub = external(); export default createPlugin('dashboard/cluster-status') .needs(generalStub.data('useApiEndpoint')) - .needs(rtkStub.slots('rtkServices')) .define(data()('isClusterAvailable', 'isSystemAvailable', 'isTelemetryEnabled')) @@ -38,11 +36,6 @@ export default createPlugin('dashboard/cluster-status') }, [apiEndpoint]); }) - .init(tk => { - // tk.slots.rtkServices.add(configApi); - }); + .init(); -RtkPlugin.setGlobals(globals => ({ - ...globals, - configApi, -})); +RtkPlugin.overlay.appendContext({configApi}); diff --git a/packages/web/src/plugins/executors/plugin.tsx b/packages/web/src/plugins/executors/plugin.tsx index 2c3ecc6fe..568af3d42 100644 --- a/packages/web/src/plugins/executors/plugin.tsx +++ b/packages/web/src/plugins/executors/plugin.tsx @@ -26,13 +26,11 @@ import {PollingIntervals} from '@utils/numbers'; const generalStub = external(); const clusterStatusStub = external(); -const rtkStub = external(); export default createPlugin('dashboard/executors') .needs(clusterStatusStub.data('useSystemAccess', 'SystemAccess')) .needs(generalStub.slots('siderItems')) .needs(generalStub.data('useApiEndpoint')) - .needs(rtkStub.slots('rtkServices')) .route('/executors', ) .route('/executors/:id', ) @@ -60,11 +58,7 @@ export default createPlugin('dashboard/executors') }) .init(tk => { - // tk.slots.rtkServices.add(executorsApi); tk.slots.siderItems.add({path: '/executors', icon: ExecutorsIcon, title: 'Executors'}, {order: -80}); }); -RtkPlugin.setGlobals(globals => ({ - ...globals, - executorsApi, -})); +RtkPlugin.overlay.appendContext({executorsApi}); diff --git a/packages/web/src/plugins/labels/plugin.tsx b/packages/web/src/plugins/labels/plugin.tsx index 7a890cc09..5d9200449 100644 --- a/packages/web/src/plugins/labels/plugin.tsx +++ b/packages/web/src/plugins/labels/plugin.tsx @@ -1,19 +1,9 @@ -import {createPlugin, external} from '@testkube/plugins'; +import {createPlugin} from '@testkube/plugins'; import RtkPlugin from '@plugins/rtk/plugin'; import {labelsApi} from '@services/labels'; -const rtkStub = external(); +export default createPlugin('oss/labels').init(); -export default createPlugin('oss/labels') - .needs(rtkStub.slots('rtkServices')) - - .init(tk => { - // tk.slots.rtkServices.add(labelsApi); - }); - -RtkPlugin.setGlobals(globals => ({ - ...globals, - labelsApi, -})); +RtkPlugin.overlay.appendContext({labelsApi}); diff --git a/packages/web/src/plugins/rtk-reset-on-api-change/hooks.ts b/packages/web/src/plugins/rtk-reset-on-api-change/hooks.ts deleted file mode 100644 index cd350e2bc..000000000 --- a/packages/web/src/plugins/rtk-reset-on-api-change/hooks.ts +++ /dev/null @@ -1,7 +0,0 @@ -import {createUseData, createUseSlot, createUseSlotFirst} from '@testkube/plugins'; - -import type plugin from './plugin'; - -export const useRtkResetOnApiChangePlugin = createUseData(); -export const useRtkResetOnApiChangeSlot = createUseSlot(); -export const useRtkResetOnApiChangeSlotFirst = createUseSlotFirst(); diff --git a/packages/web/src/plugins/rtk-reset-on-api-change/plugin.tsx b/packages/web/src/plugins/rtk-reset-on-api-change/plugin.tsx deleted file mode 100644 index 6d5b8fdf6..000000000 --- a/packages/web/src/plugins/rtk-reset-on-api-change/plugin.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import {useMemo} from 'react'; - -import {createPlugin, external} from '@testkube/plugins'; - -import type GeneralPlugin from '@plugins/general/plugin'; -import type RtkPlugin from '@plugins/rtk/plugin'; - -const generalStub = external(); -const rtkStub = external(); - -export default createPlugin('oss/rtk-reset-on-api-change') - .needs(generalStub.data('useApiEndpoint')) - .needs(rtkStub.data('resetRtkCache')) - - .provider(({useData}) => { - // Reset the in-memory API cache on API endpoint change - const {resetRtkCache, useApiEndpoint} = useData.pick('resetRtkCache', 'useApiEndpoint'); - useMemo(resetRtkCache, [useApiEndpoint()]); - }) - - .init(); diff --git a/packages/web/src/plugins/rtk/plugin.tsx b/packages/web/src/plugins/rtk/plugin.tsx index e002db112..9d74d9db4 100644 --- a/packages/web/src/plugins/rtk/plugin.tsx +++ b/packages/web/src/plugins/rtk/plugin.tsx @@ -1,11 +1,11 @@ -import {useMemo} from 'react'; +import {useRef} from 'react'; import {Provider as ReduxProvider} from 'react-redux'; -import {Store, configureStore} from '@reduxjs/toolkit'; +import {configureStore} from '@reduxjs/toolkit'; import {createLogger} from 'redux-logger'; -import {createPlugin, data, slot} from '@testkube/plugins'; +import {createPlugin} from '@testkube/plugins'; export interface RtkService { reducerPath: string; @@ -14,54 +14,34 @@ export interface RtkService { util: {resetApiState: () => any}; } -let store: Store | null; - // TODO: Load base URL from the plugin instead of global scope -const ossRtkPlugin = createPlugin('oss/rtk') - .order(-1) - - .define(slot()('rtkServices')) - .define(data()('rtkStore')) - .define(data<() => void>()('resetRtkCache')) - - // .provider(({scope}) => { - // scope.data.rtkStore = useMemo(() => { - // if (!store) { - // const services = Object.values(ossRtkPlugin.getGlobals()); - // store = configureStore({ - // reducer: services.reduce((reducers, service) => ({...reducers, [service.reducerPath]: service.reducer}), {}), - // middleware: getDefaultMiddleware => [ - // ...getDefaultMiddleware(), - // createLogger({ - // predicate: (_, action) => { - // return ( - // action.type.startsWith('testsApi/executeQuery') || - // action.type.startsWith('testSuitesApi/executeQuery') - // ); - // }, - // collapsed: true, - // }), - // ...services.map(service => service.middleware), - // ], - // }); - // } - // return store; - // }, []); - - // return {type: ReduxProvider as any, props: {store: scope.data.rtkStore}}; - // }) - - .init(tk => { - // tk.data.resetRtkCache = () => { - // tk.slots.rtkServices.all().forEach(service => { - // const action = service.util?.resetApiState(); - // if (action) { - // tk.data.rtkStore?.dispatch(action); - // } - // }); - // }; - - ossRtkPlugin.getGlobals(); - }); - -export default ossRtkPlugin; +const rtkPlugin = createPlugin('oss/rtk').order(-1).init(); + +rtkPlugin.overlay.provider(() => { + const services = Object.values(rtkPlugin.overlay.getContext()) as RtkService[]; + + const store = useRef( + configureStore({ + reducer: services.reduce((reducers, service) => ({...reducers, [service.reducerPath]: service.reducer}), {}), + middleware: getDefaultMiddleware => [ + ...getDefaultMiddleware(), + createLogger({ + predicate: (_, action) => { + return ( + action.type.startsWith('testsApi/executeQuery') || action.type.startsWith('testSuitesApi/executeQuery') + ); + }, + collapsed: true, + }), + ...services.map(service => service.middleware), + ], + }) + ); + + return { + type: ReduxProvider, + props: {store: store.current}, + }; +}); + +export default rtkPlugin; diff --git a/packages/web/src/plugins/test-sources/plugin.tsx b/packages/web/src/plugins/test-sources/plugin.tsx index d9081dd72..825443e52 100644 --- a/packages/web/src/plugins/test-sources/plugin.tsx +++ b/packages/web/src/plugins/test-sources/plugin.tsx @@ -27,7 +27,6 @@ export default createPlugin('oss/test-sources') .needs(clusterStatusStub.data('useSystemAccess', 'SystemAccess')) .needs(generalStub.slots('siderItems')) .needs(generalStub.data('useApiEndpoint')) - .needs(rtkStub.slots('rtkServices')) .route('/sources', ) .route('/sources/:id', ) @@ -55,14 +54,10 @@ export default createPlugin('oss/test-sources') }) .init(tk => { - // tk.slots.rtkServices.add(sourcesApi); - // tk.slots.rtkServices.add(repositoryApi); - tk.slots.siderItems.add({path: '/sources', icon: SourcesIcon, title: 'Sources'}, {order: -20}); }); -RtkPlugin.setGlobals(globals => ({ - ...globals, +RtkPlugin.overlay.appendContext({ sourcesApi, repositoryApi, -})); +}); diff --git a/packages/web/src/plugins/tests-and-test-suites/plugin.tsx b/packages/web/src/plugins/tests-and-test-suites/plugin.tsx index 250068ac7..156ed919f 100644 --- a/packages/web/src/plugins/tests-and-test-suites/plugin.tsx +++ b/packages/web/src/plugins/tests-and-test-suites/plugin.tsx @@ -71,7 +71,6 @@ export default createPlugin('oss/tests-and-test-suites') .needs(generalStub.slots('siderItems')) .needs(generalStub.data('useApiEndpoint')) .needs(executorsStub.data('useExecutors')) - .needs(rtkStub.slots('rtkServices')) // Backwards compatibility .route('/tests/executions/:id', ) @@ -234,8 +233,7 @@ export default createPlugin('oss/tests-and-test-suites') ); }); -RtkPlugin.setGlobals(globals => ({ - ...globals, +RtkPlugin.overlay.appendContext({ testsApi, testSuitesApi, -})); +}); diff --git a/packages/web/src/plugins/triggers/plugin.tsx b/packages/web/src/plugins/triggers/plugin.tsx index 1d81d803d..4b29bf5ab 100644 --- a/packages/web/src/plugins/triggers/plugin.tsx +++ b/packages/web/src/plugins/triggers/plugin.tsx @@ -24,7 +24,6 @@ const rtkStub = external(); export default createPlugin('oss/triggers') .needs(generalStub.slots('siderItems')) .needs(generalStub.data('useApiEndpoint')) - .needs(rtkStub.slots('rtkServices')) .route('/triggers', ) .route('/triggers/:id', ) @@ -36,11 +35,9 @@ export default createPlugin('oss/triggers') .data({useTriggers, useTriggersPick, useTriggersField, useTriggersSync}) .init(tk => { - // tk.slots.rtkServices.add(triggersApi); tk.slots.siderItems.add({path: '/triggers', icon: TriggersIcon, title: 'Triggers'}, {order: -60}); }); -RtkPlugin.setGlobals(globals => ({ - ...globals, +RtkPlugin.overlay.appendContext({ triggersApi, -})); +}); diff --git a/packages/web/src/plugins/webhooks/plugin.tsx b/packages/web/src/plugins/webhooks/plugin.tsx index 4dca0d5ea..ee5ffea86 100644 --- a/packages/web/src/plugins/webhooks/plugin.tsx +++ b/packages/web/src/plugins/webhooks/plugin.tsx @@ -19,12 +19,10 @@ import { } from '@store/webhooks'; const generalStub = external(); -const rtkStub = external(); export default createPlugin('oss/webhooks') .needs(generalStub.slots('siderItems')) .needs(generalStub.data('useApiEndpoint')) - .needs(rtkStub.slots('rtkServices')) .route('/webhooks', ) .route('/webhooks/:id', ) @@ -37,12 +35,9 @@ export default createPlugin('oss/webhooks') .data({useWebhooks, useWebhooksPick, useWebhooksField, useWebhooksSync}) .init(tk => { - // tk.slots.rtkServices.add(webhooksApi); - tk.slots.siderItems.add({path: '/webhooks', icon: WebhooksIcon, title: 'Webhooks'}, {order: -40}); }); -RtkPlugin.setGlobals(globals => ({ - ...globals, +RtkPlugin.overlay.appendContext({ webhooksApi, -})); +}); From 8a6861f5d2ad9d3193dbc773f3fb204652172a44 Mon Sep 17 00:00:00 2001 From: Dev Catalin <20538711+devcatalin@users.noreply.github.com> Date: Mon, 19 Feb 2024 17:02:52 +0200 Subject: [PATCH 3/5] chore: remove unused stubs --- packages/web/src/plugins/test-sources/plugin.tsx | 1 - packages/web/src/plugins/tests-and-test-suites/plugin.tsx | 1 - packages/web/src/plugins/triggers/plugin.tsx | 1 - 3 files changed, 3 deletions(-) diff --git a/packages/web/src/plugins/test-sources/plugin.tsx b/packages/web/src/plugins/test-sources/plugin.tsx index 825443e52..15d7b88a6 100644 --- a/packages/web/src/plugins/test-sources/plugin.tsx +++ b/packages/web/src/plugins/test-sources/plugin.tsx @@ -21,7 +21,6 @@ import {PollingIntervals} from '@utils/numbers'; const generalStub = external(); const clusterStatusStub = external(); -const rtkStub = external(); export default createPlugin('oss/test-sources') .needs(clusterStatusStub.data('useSystemAccess', 'SystemAccess')) diff --git a/packages/web/src/plugins/tests-and-test-suites/plugin.tsx b/packages/web/src/plugins/tests-and-test-suites/plugin.tsx index 156ed919f..13ee399c4 100644 --- a/packages/web/src/plugins/tests-and-test-suites/plugin.tsx +++ b/packages/web/src/plugins/tests-and-test-suites/plugin.tsx @@ -64,7 +64,6 @@ import {decomposeVariables} from '@utils/variables'; const generalStub = external(); const executorsStub = external(); -const rtkStub = external(); // TODO: Split export default createPlugin('oss/tests-and-test-suites') diff --git a/packages/web/src/plugins/triggers/plugin.tsx b/packages/web/src/plugins/triggers/plugin.tsx index 4b29bf5ab..ce2525a4b 100644 --- a/packages/web/src/plugins/triggers/plugin.tsx +++ b/packages/web/src/plugins/triggers/plugin.tsx @@ -19,7 +19,6 @@ import { } from '@store/triggers'; const generalStub = external(); -const rtkStub = external(); export default createPlugin('oss/triggers') .needs(generalStub.slots('siderItems')) From 840941327ca7f1ce3bbe7995b261f4a0d8450f3b Mon Sep 17 00:00:00 2001 From: Dev Catalin <20538711+devcatalin@users.noreply.github.com> Date: Mon, 19 Feb 2024 17:08:05 +0200 Subject: [PATCH 4/5] refactor: use refetchOnMountOrArgChange --- .../src/components/molecules/LabelsSelect/LabelsSelect.tsx | 1 + .../molecules/TestActionsDropdown/TestActionsDropdown.tsx | 6 +++++- .../TestSuiteActionsDropdown/TestSuiteActionsDropdown.tsx | 6 +++++- .../organisms/EntityDetails/EntityDetailsLayer.tsx | 4 +++- .../organisms/EntityDetails/ExecutionDetailsLayer.tsx | 1 + .../EntityViewFilters/LabelsFilter/LabelsFilters.tsx | 1 + .../pages/TestSuites/TestSuitesList/TestSuiteCard.tsx | 6 +++++- .../pages/TestSuites/TestSuitesList/TestSuitesList.tsx | 1 + .../TestDetails/TestExecution/TestExecutionArtifacts.tsx | 1 + .../web/src/components/pages/Tests/TestsList/TestCard.tsx | 6 +++++- .../web/src/components/pages/Tests/TestsList/TestsList.tsx | 1 + .../components/pages/Webhooks/WebhooksList/WebhooksList.tsx | 6 +++++- 12 files changed, 34 insertions(+), 6 deletions(-) diff --git a/packages/web/src/components/molecules/LabelsSelect/LabelsSelect.tsx b/packages/web/src/components/molecules/LabelsSelect/LabelsSelect.tsx index 68b14832c..f683dbfb7 100644 --- a/packages/web/src/components/molecules/LabelsSelect/LabelsSelect.tsx +++ b/packages/web/src/components/molecules/LabelsSelect/LabelsSelect.tsx @@ -51,6 +51,7 @@ const LabelsSelect: React.FC = props => { const {data, isFetching} = useGetLabelsQuery(null, { pollingInterval: PollingIntervals.default, skip: Boolean(options) || !isClusterAvailable, + refetchOnMountOrArgChange: true, }); const formattedValue = useMemo(() => (value || []).map(label => ({label, value: label})), [value]); diff --git a/packages/web/src/components/molecules/TestActionsDropdown/TestActionsDropdown.tsx b/packages/web/src/components/molecules/TestActionsDropdown/TestActionsDropdown.tsx index 199376396..9a0a3e064 100644 --- a/packages/web/src/components/molecules/TestActionsDropdown/TestActionsDropdown.tsx +++ b/packages/web/src/components/molecules/TestActionsDropdown/TestActionsDropdown.tsx @@ -39,7 +39,11 @@ const TestActionsDropdown: React.FC = props => { const {data: metrics, refetch} = useGetTestExecutionMetricsQuery( {id: name, last: 7, limit: 13}, - {skip: !isInViewport || !isSystemAvailable, pollingInterval: PollingIntervals.halfMin} + { + skip: !isInViewport || !isSystemAvailable, + pollingInterval: PollingIntervals.halfMin, + refetchOnMountOrArgChange: true, + } ); const executions: ExecutionMetrics[] = useMemo(() => metrics?.executions ?? [], [metrics]); diff --git a/packages/web/src/components/molecules/TestSuiteActionsDropdown/TestSuiteActionsDropdown.tsx b/packages/web/src/components/molecules/TestSuiteActionsDropdown/TestSuiteActionsDropdown.tsx index 7ef497335..88ec4b04e 100644 --- a/packages/web/src/components/molecules/TestSuiteActionsDropdown/TestSuiteActionsDropdown.tsx +++ b/packages/web/src/components/molecules/TestSuiteActionsDropdown/TestSuiteActionsDropdown.tsx @@ -39,7 +39,11 @@ const TestSuiteActionsDropdown: React.FC = props => { const {data: metrics, refetch} = useGetTestSuiteExecutionMetricsQuery( {id: name, last: 7, limit: 13}, - {skip: !isInViewport || !isSystemAvailable, pollingInterval: PollingIntervals.halfMin} + { + skip: !isInViewport || !isSystemAvailable, + pollingInterval: PollingIntervals.halfMin, + refetchOnMountOrArgChange: true, + } ); const executions: ExecutionMetrics[] = useMemo(() => metrics?.executions ?? [], [metrics]); diff --git a/packages/web/src/components/organisms/EntityDetails/EntityDetailsLayer.tsx b/packages/web/src/components/organisms/EntityDetails/EntityDetailsLayer.tsx index 5d72814cc..e5842e3f3 100644 --- a/packages/web/src/components/organisms/EntityDetails/EntityDetailsLayer.tsx +++ b/packages/web/src/components/organisms/EntityDetails/EntityDetailsLayer.tsx @@ -73,16 +73,18 @@ const EntityDetailsLayer: FC> = ({ { pollingInterval: PollingIntervals.long, skip: !isSystemAvailable || daysFilterValue === undefined, + refetchOnMountOrArgChange: true, } ); const {data: rawMetrics, refetch: refetchMetrics} = useGetMetrics( {id, last: daysFilterValue}, - {skip: !isSystemAvailable} + {skip: !isSystemAvailable, refetchOnMountOrArgChange: true} ); const {data: rawDetails, error} = useGetEntityDetails(id, { pollingInterval: PollingIntervals.long, skip: !isSystemAvailable, + refetchOnMountOrArgChange: true, }); const isV2 = isTestSuiteV2(rawDetails); diff --git a/packages/web/src/components/organisms/EntityDetails/ExecutionDetailsLayer.tsx b/packages/web/src/components/organisms/EntityDetails/ExecutionDetailsLayer.tsx index f421dfc2f..94c1f275a 100644 --- a/packages/web/src/components/organisms/EntityDetails/ExecutionDetailsLayer.tsx +++ b/packages/web/src/components/organisms/EntityDetails/ExecutionDetailsLayer.tsx @@ -55,6 +55,7 @@ const ExecutionDetailsLayer: FC> = const {data: rawFetchedData, error} = useGetExecutionDetails(execId!, { pollingInterval: PollingIntervals.everySecond, skip: !isClusterAvailable || !execId || (data?.id === execId && isExecutionFinished(data)), + refetchOnMountOrArgChange: true, }); const fetchedData = rawFetchedData?.id === execId ? rawFetchedData : null; const isV2 = isTestSuiteV2Execution(fetchedData); diff --git a/packages/web/src/components/organisms/EntityView/EntityViewFilters/LabelsFilter/LabelsFilters.tsx b/packages/web/src/components/organisms/EntityView/EntityViewFilters/LabelsFilter/LabelsFilters.tsx index bd78bd0a1..08d015dff 100644 --- a/packages/web/src/components/organisms/EntityView/EntityViewFilters/LabelsFilter/LabelsFilters.tsx +++ b/packages/web/src/components/organisms/EntityView/EntityViewFilters/LabelsFilter/LabelsFilters.tsx @@ -36,6 +36,7 @@ const LabelsFilter: React.FC = props => { const {data} = useGetLabelsQuery(null, { pollingInterval: PollingIntervals.default, skip: !isClusterAvailable, + refetchOnMountOrArgChange: true, }); const [isVisible, setIsVisible] = useState(false); diff --git a/packages/web/src/components/pages/TestSuites/TestSuitesList/TestSuiteCard.tsx b/packages/web/src/components/pages/TestSuites/TestSuitesList/TestSuiteCard.tsx index b04e9bd26..044eccbfe 100644 --- a/packages/web/src/components/pages/TestSuites/TestSuitesList/TestSuiteCard.tsx +++ b/packages/web/src/components/pages/TestSuites/TestSuitesList/TestSuiteCard.tsx @@ -26,7 +26,11 @@ const TestSuiteCard: FC = ({item: {testSuite, latestExecutio const {data: metrics} = useGetTestSuiteExecutionMetricsQuery( {id: testSuite.name, last: 7, limit: 13}, - {skip: !isInViewport || !isSystemAvailable, pollingInterval: PollingIntervals.halfMin} + { + skip: !isInViewport || !isSystemAvailable, + pollingInterval: PollingIntervals.halfMin, + refetchOnMountOrArgChange: true, + } ); return ( diff --git a/packages/web/src/components/pages/TestSuites/TestSuitesList/TestSuitesList.tsx b/packages/web/src/components/pages/TestSuites/TestSuitesList/TestSuitesList.tsx index 89f8f7ee8..c279c5945 100644 --- a/packages/web/src/components/pages/TestSuites/TestSuitesList/TestSuitesList.tsx +++ b/packages/web/src/components/pages/TestSuites/TestSuitesList/TestSuitesList.tsx @@ -44,6 +44,7 @@ const TestSuitesList: React.FC = () => { } = useGetTestSuitesQuery(filters || null, { pollingInterval: PollingIntervals.everySecond, skip: !isSystemAvailable, + refetchOnMountOrArgChange: true, }); useTestSuitesSync({testSuites}); diff --git a/packages/web/src/components/pages/Tests/TestDetails/TestExecution/TestExecutionArtifacts.tsx b/packages/web/src/components/pages/Tests/TestDetails/TestExecution/TestExecutionArtifacts.tsx index 697f2397a..7115edcb6 100644 --- a/packages/web/src/components/pages/Tests/TestDetails/TestExecution/TestExecutionArtifacts.tsx +++ b/packages/web/src/components/pages/Tests/TestDetails/TestExecution/TestExecutionArtifacts.tsx @@ -30,6 +30,7 @@ const TestExecutionArtifacts: React.FC = props => { const {data, isLoading, error} = useGetTestExecutionArtifactsQuery(id, { skip: !isSystemAvailable, pollingInterval: PollingIntervals.everyTwoSeconds, + refetchOnMountOrArgChange: true, }); useEffect(() => { diff --git a/packages/web/src/components/pages/Tests/TestsList/TestCard.tsx b/packages/web/src/components/pages/Tests/TestsList/TestCard.tsx index 703a34f66..dc48f0b0d 100644 --- a/packages/web/src/components/pages/Tests/TestsList/TestCard.tsx +++ b/packages/web/src/components/pages/Tests/TestsList/TestCard.tsx @@ -26,7 +26,11 @@ const TestCard: FC = ({item: {test, latestExecution}, onClick}) = const {data: metrics} = useGetTestExecutionMetricsQuery( {id: test.name, last: 7, limit: 13}, - {skip: !isInViewport || !isSystemAvailable, pollingInterval: PollingIntervals.halfMin} + { + skip: !isInViewport || !isSystemAvailable, + pollingInterval: PollingIntervals.halfMin, + refetchOnMountOrArgChange: true, + } ); return ( diff --git a/packages/web/src/components/pages/Tests/TestsList/TestsList.tsx b/packages/web/src/components/pages/Tests/TestsList/TestsList.tsx index c1333db2c..f76c1ddc9 100644 --- a/packages/web/src/components/pages/Tests/TestsList/TestsList.tsx +++ b/packages/web/src/components/pages/Tests/TestsList/TestsList.tsx @@ -51,6 +51,7 @@ const TestsList: React.FC = () => { } = useGetTestsQuery(filters, { pollingInterval: PollingIntervals.everySecond, skip: !isSystemAvailable, + refetchOnMountOrArgChange: true, }); useTestsSync({tests}); diff --git a/packages/web/src/components/pages/Webhooks/WebhooksList/WebhooksList.tsx b/packages/web/src/components/pages/Webhooks/WebhooksList/WebhooksList.tsx index 810601afa..642ea3546 100644 --- a/packages/web/src/components/pages/Webhooks/WebhooksList/WebhooksList.tsx +++ b/packages/web/src/components/pages/Webhooks/WebhooksList/WebhooksList.tsx @@ -36,7 +36,11 @@ const WebhooksList: FC = () => { data: webhooks, error, isLoading, - } = useGetWebhooksQuery(null, {pollingInterval: PollingIntervals.everyTwoSeconds, skip: !isClusterAvailable}); + } = useGetWebhooksQuery(null, { + pollingInterval: PollingIntervals.everyTwoSeconds, + skip: !isClusterAvailable, + refetchOnMountOrArgChange: true, + }); const mayCreate = usePermission(Permissions.createEntity); From bee0b774c117e54b061bb1213ebc5a7a63b94f92 Mon Sep 17 00:00:00 2001 From: Dev Catalin <20538711+devcatalin@users.noreply.github.com> Date: Wed, 21 Feb 2024 10:08:36 +0200 Subject: [PATCH 5/5] chore: remove unused code --- packages/web/src/plugins/rtk/plugin.tsx | 15 +-------------- .../src/plugins/tests-and-test-suites/plugin.tsx | 3 --- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/packages/web/src/plugins/rtk/plugin.tsx b/packages/web/src/plugins/rtk/plugin.tsx index 9d74d9db4..499f4fcf2 100644 --- a/packages/web/src/plugins/rtk/plugin.tsx +++ b/packages/web/src/plugins/rtk/plugin.tsx @@ -3,8 +3,6 @@ import {Provider as ReduxProvider} from 'react-redux'; import {configureStore} from '@reduxjs/toolkit'; -import {createLogger} from 'redux-logger'; - import {createPlugin} from '@testkube/plugins'; export interface RtkService { @@ -23,18 +21,7 @@ rtkPlugin.overlay.provider(() => { const store = useRef( configureStore({ reducer: services.reduce((reducers, service) => ({...reducers, [service.reducerPath]: service.reducer}), {}), - middleware: getDefaultMiddleware => [ - ...getDefaultMiddleware(), - createLogger({ - predicate: (_, action) => { - return ( - action.type.startsWith('testsApi/executeQuery') || action.type.startsWith('testSuitesApi/executeQuery') - ); - }, - collapsed: true, - }), - ...services.map(service => service.middleware), - ], + middleware: getDefaultMiddleware => [...getDefaultMiddleware(), ...services.map(service => service.middleware)], }) ); diff --git a/packages/web/src/plugins/tests-and-test-suites/plugin.tsx b/packages/web/src/plugins/tests-and-test-suites/plugin.tsx index 13ee399c4..1537ba799 100644 --- a/packages/web/src/plugins/tests-and-test-suites/plugin.tsx +++ b/packages/web/src/plugins/tests-and-test-suites/plugin.tsx @@ -140,9 +140,6 @@ export default createPlugin('oss/tests-and-test-suites') .data({useLogOutput, useLogOutputPick, useLogOutputField, useLogOutputSync}) .init(tk => { - // tk.slots.rtkServices.add(testSuitesApi); - // tk.slots.rtkServices.add(testsApi); - // TODO: Instead of using tk.sync, use all the necessities directly in the plugin components tk.data.setExecutionTab = tk.sync(() => { const entityId = tk.data.useEntityDetails(x => x.id);