Skip to content

Commit 4babc26

Browse files
committed
CONSOLE-3769: Address review comments
1 parent ece51f7 commit 4babc26

File tree

17 files changed

+79
-74
lines changed

17 files changed

+79
-74
lines changed

frontend/packages/console-dynamic-plugin-sdk/CHANGELOG-core.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ table in [Console dynamic plugins README](./README.md).
1212

1313
## 4.21.0-prerelease.x - TBD
1414

15-
- **Deprecated** `setPluginStore` function in `k8s-utils.ts`. The function is now a noop and the export
15+
- **Deprecated**: `setPluginStore` function in `k8s-utils.ts`. The function is now a noop and the export
1616
will be removed in a future release. ([CONSOLE-4840], [#15671])
17-
- **Type-only breaking change**: Fix `popupComponent` prop type in extension `console.dashboards/overview/health/resource` ([CONSOLE-4796], [#15526])
18-
- Increased alignment with `@openshift/dynamic-plugin-sdk` types ([CONSOLE-3769], [#15509], [#15738])
19-
- `AlwaysOnExtension` and `ModelDefinition` types are removed from `api/common-types` because they referred
20-
to a legacy system which console dynamic plugins never supported. There is no direct replacement for these
21-
types, and plugins should remove all uses of them. ([#15671])
22-
- The following types are now re-exported from `@openshift/dynamic-plugin-sdk` instead of being defined
23-
locally: `ExtensionFlags`, `ExtensionTypeGuard`, `ResolvedCodeRefProperties`, `RemoteEntryModule`, and `Update`. ([#15509], [#15738])
17+
- **Type breaking**: Fix `popupComponent` prop type in extension `console.dashboards/overview/health/resource` ([CONSOLE-4796], [#15526])
18+
- **Type breaking**: `AlwaysOnExtension` and `ModelDefinition` types are removed from `api/common-types`. ([CONSOLE-3769], [#15509])
19+
- The following types are now re-exported from `@openshift/dynamic-plugin-sdk` instead of being defined
20+
locally: `ExtensionFlags`, `ExtensionTypeGuard`, `ResolvedCodeRefProperties`, `RemoteEntryModule`, and `Update`. ([CONSOLE-4840], [#15509], [#15671])
2421
- Add optional `fetch` property to extension `console.dashboards/overview/health/url` ([CONSOLE-4796], [#15526])
2522
- Add optional `infrastructure` parameter to `PrometheusHealthHandler` type ([CONSOLE-4796], [#15526])
2623
- Allow `K8sResourceKind` in `TopologyDataObject`, `TopologyResourcesObject`, and `OverviewItem` types ([CONSOLE-4840], [#15699])
@@ -221,4 +218,3 @@ table in [Console dynamic plugins README](./README.md).
221218
[#15671]: https://github.com/openshift/console/pull/15671
222219
[#15699]: https://github.com/openshift/console/pull/15699
223220
[#15735]: https://github.com/openshift/console/pull/15735
224-
[#15738]: https://github.com/openshift/console/pull/15738

frontend/packages/console-dynamic-plugin-sdk/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ For older 1.x plugin SDK packages, refer to the following version compatibility
8989

9090
| Console Version | SDK Package | Last Package Version |
9191
| --------------- | ----------------------------------------------- | -------------------- |
92-
| 4.18.x | `@openshift-console/dynamic-plugin-sdk` | 1.8.0 |
93-
| | `@openshift-console/dynamic-plugin-sdk-webpack` | 1.3.0 |
9492
| 4.17.x | `@openshift-console/dynamic-plugin-sdk` | 1.6.0 |
9593
| | `@openshift-console/dynamic-plugin-sdk-webpack` | 1.2.0 |
9694
| 4.16.x | `@openshift-console/dynamic-plugin-sdk` | 1.4.0 |
@@ -115,15 +113,15 @@ Console.
115113

116114
| Console Version | PatternFly Versions | Notes |
117115
| --------------- | ------------------- | ------------------------------------- |
118-
| 4.19.x | 6.x + 5.x | New dynamic plugins should use PF 6.x |
116+
| 4.19.x - 4.21.x | 6.x + 5.x | New dynamic plugins should use PF 6.x |
119117
| 4.15.x - 4.18.x | 5.x + 4.x | New dynamic plugins should use PF 5.x |
120118
| 4.12.x - 4.14.x | 4.x | |
121119

122120
Refer to [PatternFly Upgrade Notes][console-pf-upgrade-notes] containing links to PatternFly documentation.
123121

124122
## Shared modules
125123

126-
Console is [configured](./src/shared-modules.ts) to share specific modules with its dynamic plugins.
124+
Console is [configured](./src/shared-modules/shared-modules-meta.ts) to share specific modules with its dynamic plugins.
127125

128126
The following shared modules are provided by Console, without plugins providing their own fallback:
129127

@@ -211,6 +209,7 @@ This section documents notable changes in Console provided shared modules and ot
211209
> [!WARNING]
212210
> Usage of non-PatternFly CSS provided by Console in plugins is not supported. This section only serves
213211
> as a courtesy for plugins which use these unsupported CSS classes.
212+
214213
- Removed support for the Bootstrap Grid system (`.row`, `.col-*`, etc.). Use
215214
[PatternFly Grid](https://www.patternfly.org/layouts/grid) instead.
216215
- Removed `co-external-link` styling. Use PatternFly Buttons with `variant="link"` instead.

frontend/packages/console-dynamic-plugin-sdk/src/api/useResolvedExtensions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import { useState, useEffect } from 'react';
22
import { useExtensions } from '@console/plugin-sdk/src/api/useExtensions';
33
import { resolveExtension } from '../coderefs/coderef-resolver';
44
import { UseResolvedExtensions } from '../extensions/console-types';
5-
import { Extension, ExtensionTypeGuard, ResolvedExtension } from '../types';
5+
import type { ExtensionDeclaration, ExtensionTypeGuard, ResolvedExtension } from '../types';
66
import { settleAllPromises } from '../utils/promise';
77

8-
export const useResolvedExtensions: UseResolvedExtensions = <E extends Extension>(
8+
export const useResolvedExtensions: UseResolvedExtensions = <E extends ExtensionDeclaration>(
99
...typeGuards: ExtensionTypeGuard<E>[]
1010
): [ResolvedExtension<E>[], boolean, any[]] => {
1111
const extensions = useExtensions<E>(...typeGuards);

frontend/packages/console-dynamic-plugin-sdk/src/coderefs/__tests__/coderef-resolver.spec.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,12 @@ describe('loadReferencedObject', () => {
206206
});
207207
});
208208

209+
type FooExtension = ExtensionDeclaration<'Foo', { test: boolean; qux: CodeRef<string> }>;
210+
type BarExtension = ExtensionDeclaration<'Bar', { test: number[]; baz: { test: CodeRef<string> } }>;
211+
209212
describe('resolveEncodedCodeRefs', () => {
210213
it('replaces encoded code references with CodeRef functions', async () => {
211-
const extensions: ExtensionDeclaration[] = [
214+
const extensions = [
212215
{
213216
type: 'Foo',
214217
properties: {
@@ -233,7 +236,7 @@ describe('resolveEncodedCodeRefs', () => {
233236
entryModule,
234237
235238
errorCallback,
236-
);
239+
) as [FooExtension, BarExtension];
237240

238241
expect(resolvedExtensions.length).toBe(extensions.length);
239242

frontend/packages/console-dynamic-plugin-sdk/src/coderefs/coderef-resolver.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* eslint-disable no-console */
22

3+
import { AnyObject } from '@openshift/dynamic-plugin-sdk';
34
import * as _ from 'lodash';
4-
import {
5-
Extension,
5+
import type {
6+
ExtensionDeclaration,
67
RemoteEntryModule,
78
EncodedCodeRef,
89
CodeRef,
@@ -94,11 +95,11 @@ export const loadReferencedObject = async <TExport = any>(
9495
* _Does not execute `CodeRef` functions to load the referenced objects._
9596
*/
9697
export const resolveEncodedCodeRefs = (
97-
extensions: Extension[],
98+
extensions: ExtensionDeclaration[],
9899
entryModule: RemoteEntryModule,
99100
pluginID: string,
100101
errorCallback: VoidFunction,
101-
): Extension[] =>
102+
): ExtensionDeclaration[] =>
102103
_.cloneDeep(extensions).map((e) => {
103104
deepForOwn<EncodedCodeRef>(e.properties, isEncodedCodeRef, (ref, key, obj) => {
104105
const loader = applyCodeRefSymbol(async () =>
@@ -114,8 +115,8 @@ export const resolveEncodedCodeRefs = (
114115
* Returns an extension with its `CodeRef` properties replaced with referenced objects.
115116
*/
116117
export const resolveExtension = async <
117-
E extends Extension<P>,
118-
P = ExtensionProperties<E>,
118+
E extends ExtensionDeclaration<string, P>,
119+
P extends AnyObject = ExtensionProperties<E>,
119120
R = UpdateExtensionProperties<E, ResolvedCodeRefProperties<P>, P>
120121
>(
121122
extension: E,

frontend/packages/console-dynamic-plugin-sdk/src/extensions/console-types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { ButtonProps } from '@patternfly/react-core';
55
import { ICell, OnSelect, SortByDirection, TableGridBreakpoint } from '@patternfly/react-table';
66
import { LocationDescriptor } from 'history';
77
import type * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
8-
import {
8+
import type {
99
ExtensionK8sGroupKindModel,
1010
K8sModel,
1111
K8sVerb,
@@ -16,7 +16,7 @@ import {
1616
ResolvedExtension,
1717
Selector,
1818
} from '../api/common-types';
19-
import { Extension, ExtensionTypeGuard } from '../types';
19+
import type { ExtensionDeclaration, ExtensionTypeGuard } from '../types';
2020
import { CustomDataSource } from './dashboard-data-source';
2121

2222
export type OwnerReference = {
@@ -250,7 +250,7 @@ export type UseK8sWatchResources = <R extends ResourcesObject>(
250250
initResources: WatchK8sResources<R>,
251251
) => WatchK8sResults<R>;
252252

253-
export type UseResolvedExtensions = <E extends Extension>(
253+
export type UseResolvedExtensions = <E extends ExtensionDeclaration>(
254254
...typeGuards: ExtensionTypeGuard<E>[]
255255
) => [ResolvedExtension<E>[], boolean, any[]];
256256

frontend/packages/console-dynamic-plugin-sdk/src/types.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
import type {
22
CodeRef as SDKCodeRef,
3+
Extension as ExtensionDeclaration,
34
ExtensionFlags,
4-
ExtensionPredicate,
55
LoadedExtension as SDKLoadedExtension,
66
ReplaceProperties as Update,
77
MapCodeRefsToValues,
8+
AnyObject,
89
} from '@openshift/dynamic-plugin-sdk';
910

1011
export type {
1112
ExtensionFlags,
1213
Extension as ExtensionDeclaration,
14+
ExtensionPredicate as ExtensionTypeGuard,
1315
MapCodeRefsToValues as ResolvedCodeRefProperties,
1416
PluginEntryModule as RemoteEntryModule,
1517
ReplaceProperties as Update,
@@ -32,15 +34,12 @@ export type Extension<P extends {} = any> = {
3234
flags?: ExtensionFlags;
3335
};
3436

35-
/**
36-
* TS type guard to narrow type of the given extension to `E`.
37-
*/
38-
export type ExtensionTypeGuard<E extends Extension> = ExtensionPredicate<E>;
39-
4037
/**
4138
* Runtime extension interface, exposing additional metadata.
4239
*/
43-
export type LoadedExtension<E extends Extension = Extension> = SDKLoadedExtension<E> & {
40+
export type LoadedExtension<
41+
E extends ExtensionDeclaration = ExtensionDeclaration
42+
> = SDKLoadedExtension<E> & {
4443
pluginID: string;
4544
};
4645

@@ -65,15 +64,15 @@ export type ExtractCodeRefType<R> = R extends CodeRef<infer T> ? T : never;
6564
/**
6665
* Infer the properties of extension `E`.
6766
*/
68-
export type ExtensionProperties<E> = E extends Extension<infer P> ? P : never;
67+
export type ExtensionProperties<E> = E extends ExtensionDeclaration<string, infer P> ? P : never;
6968

7069
/**
7170
* Update existing properties of extension `E` with ones declared in object `U`.
7271
*/
7372
export type UpdateExtensionProperties<
74-
E extends Extension<P>,
73+
E extends ExtensionDeclaration,
7574
U extends {},
76-
P = ExtensionProperties<E>
75+
P extends AnyObject = ExtensionProperties<E>
7776
> = Update<
7877
E,
7978
{
@@ -86,6 +85,7 @@ export type UpdateExtensionProperties<
8685
*
8786
* This also coerces `E` type to `LoadedExtension` interface for runtime consumption.
8887
*/
89-
export type ResolvedExtension<E extends Extension<P>, P = ExtensionProperties<E>> = LoadedExtension<
90-
UpdateExtensionProperties<E, MapCodeRefsToValues<P>, P>
91-
>;
88+
export type ResolvedExtension<
89+
E extends ExtensionDeclaration,
90+
P extends AnyObject = ExtensionProperties<E>
91+
> = LoadedExtension<UpdateExtensionProperties<E, MapCodeRefsToValues<P>, P>>;

frontend/packages/console-dynamic-plugin-sdk/src/validation/ExtensionValidator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as _ from 'lodash';
44
import * as webpack from 'webpack';
55
import { ConsolePluginBuildMetadata } from '../build-types';
66
import { isEncodedCodeRef, parseEncodedCodeRefValue } from '../coderefs/coderef-resolver';
7-
import { Extension, EncodedCodeRef } from '../types';
7+
import { ExtensionDeclaration, EncodedCodeRef } from '../types';
88
import { deepForOwn } from '../utils/object';
99
import { BaseValidator } from './BaseValidator';
1010

@@ -59,7 +59,7 @@ export const guessModuleFilePath = (
5959
return basePath;
6060
};
6161

62-
export const collectCodeRefData = (extensions: Extension[]) =>
62+
export const collectCodeRefData = (extensions: ExtensionDeclaration[]) =>
6363
extensions.reduce((acc, e, index) => {
6464
const data: ExtensionCodeRefData = { index, propToCodeRefValue: {} };
6565

@@ -106,7 +106,7 @@ export const findWebpackModules = (
106106
export class ExtensionValidator extends BaseValidator {
107107
validate(
108108
compilation: webpack.Compilation,
109-
extensions: Extension[],
109+
extensions: ExtensionDeclaration[],
110110
exposedModules: ConsolePluginBuildMetadata['exposedModules'],
111111
pluginBasePath?: string,
112112
) {

frontend/packages/console-plugin-sdk/src/api/pluginSubscriptionService.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as _ from 'lodash';
22
import { Store } from 'redux';
33
import type {
4-
Extension,
4+
ExtensionDeclaration,
55
ExtensionTypeGuard,
66
LoadedExtension,
77
} from '@console/dynamic-plugin-sdk/src/types';
@@ -46,7 +46,7 @@ export const initSubscriptionService = (pluginStore: PluginStore, reduxStore: St
4646

4747
const invokeExtensionListener = (
4848
sub: ExtensionSubscription,
49-
currentExtensions: Extension[],
49+
currentExtensions: ExtensionDeclaration[],
5050
currentFlags: FeatureFlags,
5151
) => {
5252
// Narrow extensions according to type guards
@@ -72,7 +72,7 @@ export const initSubscriptionService = (pluginStore: PluginStore, reduxStore: St
7272
listener(pluginStore.getPluginInfo());
7373
};
7474

75-
let lastExtensions: Extension[] = null;
75+
let lastExtensions: ExtensionDeclaration[] = null;
7676
let lastFlags: FeatureFlags = null;
7777

7878
const invokeAllExtensionListeners = () => {
@@ -151,7 +151,7 @@ export const getPluginStore = (): PluginStore => {
151151
*
152152
* @returns Function that unsubscribes the listener.
153153
*/
154-
export const subscribeToExtensions = <E extends Extension>(
154+
export const subscribeToExtensions = <E extends ExtensionDeclaration>(
155155
listener: ExtensionListener<LoadedExtension<E>>,
156156
...typeGuards: ExtensionTypeGuard<E>[]
157157
) => {
@@ -182,7 +182,7 @@ export const subscribeToDynamicPlugins = (listener: DynamicPluginListener) => {
182182
/**
183183
* `ExtensionListener` adapter that computes the difference between the calls.
184184
*/
185-
export const extensionDiffListener = <E extends Extension>(
185+
export const extensionDiffListener = <E extends ExtensionDeclaration>(
186186
listener: (added: E[], removed: E[]) => void,
187187
): ExtensionListener<E> => {
188188
let prevExtensions: E[] = [];
@@ -197,9 +197,9 @@ export const extensionDiffListener = <E extends Extension>(
197197
};
198198
};
199199

200-
type ExtensionListener<E extends Extension> = (extensions: E[]) => void;
200+
type ExtensionListener<E extends ExtensionDeclaration> = (extensions: E[]) => void;
201201

202-
type ExtensionSubscription<E extends Extension = Extension> = {
202+
type ExtensionSubscription<E extends ExtensionDeclaration = ExtensionDeclaration> = {
203203
listener: ExtensionListener<E>;
204204
typeGuards: ExtensionTypeGuard<E>[];
205205
listenerLastArgs?: E[];

frontend/packages/console-plugin-sdk/src/api/useExtensions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useRef, useCallback, useEffect } from 'react';
22
import * as _ from 'lodash';
33
import type {
4-
Extension,
4+
ExtensionDeclaration,
55
ExtensionTypeGuard,
66
LoadedExtension,
77
} from '@console/dynamic-plugin-sdk/src/types';
@@ -41,7 +41,7 @@ import { subscribeToExtensions } from './pluginSubscriptionService';
4141
* @returns List of extension instances which are currently in use, narrowed by the
4242
* given type guard(s).
4343
*/
44-
export const useExtensions = <E extends Extension>(
44+
export const useExtensions = <E extends ExtensionDeclaration>(
4545
...typeGuards: ExtensionTypeGuard<E>[]
4646
): LoadedExtension<E>[] => {
4747
if (typeGuards.length === 0) {

0 commit comments

Comments
 (0)