Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions dynamic-demo-plugin/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@openshift-console/dynamic-plugin-sdk-webpack@portal:../frontend/packages/console-dynamic-plugin-sdk/dist/webpack::locator=%40console%2Fdynamic-demo-plugin%40workspace%3A."
dependencies:
"@openshift/dynamic-plugin-sdk": "npm:^8.0.0"
"@openshift/dynamic-plugin-sdk": "git+https://github.com/openshift/dynamic-plugin-sdk.git#workspace=@openshift/dynamic-plugin-sdk&head=main"
"@openshift/dynamic-plugin-sdk-webpack": "npm:^5.1.0"
ajv: "npm:^6.12.3"
chalk: "npm:2.4.x"
Expand All @@ -173,7 +173,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@openshift-console/dynamic-plugin-sdk@portal:../frontend/packages/console-dynamic-plugin-sdk/dist/core::locator=%40console%2Fdynamic-demo-plugin%40workspace%3A."
dependencies:
"@openshift/dynamic-plugin-sdk": "npm:^8.0.0"
"@openshift/dynamic-plugin-sdk": "git+https://github.com/openshift/dynamic-plugin-sdk.git#workspace=@openshift/dynamic-plugin-sdk&head=main"
immutable: "npm:3.x"
lodash: "npm:^4.17.21"
reselect: "npm:4.x"
Expand Down Expand Up @@ -223,17 +223,17 @@ __metadata:
languageName: node
linkType: hard

"@openshift/dynamic-plugin-sdk@npm:^8.0.0":
version: 8.0.0
resolution: "@openshift/dynamic-plugin-sdk@npm:8.0.0"
"@openshift/dynamic-plugin-sdk@git+https://github.com/openshift/dynamic-plugin-sdk.git#workspace=@openshift/dynamic-plugin-sdk&head=main":
version: 8.1.0
resolution: "@openshift/dynamic-plugin-sdk@https://github.com/openshift/dynamic-plugin-sdk.git#workspace=%40openshift%2Fdynamic-plugin-sdk&commit=c35748e717d3cb259c10c5f70831bbf7705ef457"
dependencies:
lodash: "npm:^4.17.23"
semver: "npm:^7.7.3"
uuid: "npm:^8.3.2"
yup: "npm:^1.7.1"
peerDependencies:
react: ^18 || ^19
checksum: 10c0/a5c7bc5198f75fcc9fad242ffb51e264e860218e7035b87204d429cc47fa566208cc3474af739d3e05a2adc1bfe41ae9e09d3afd93a5b8c0d29f1814ee9f3127
checksum: 10c0/57d3fa90221884b613e6dedf69208219b5697be69352ef24ba71dd8404a40aeca29d39dc3896d6734ad1289b645705db45879183a1e02bcd45d4cfee7190f5bb
languageName: node
linkType: hard

Expand Down
6 changes: 6 additions & 0 deletions frontend/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
checksumBehavior: ignore

enableInlineBuilds: true

enableScripts: false
Expand All @@ -10,4 +12,8 @@ nodeLinker: node-modules

npmMinimalAgeGate: 3d

npmPreapprovedPackages:
- "@openshift/*"
- "@patternfly/*"

yarnPath: .yarn/releases/yarn-4.12.0.cjs
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
]
},
"dependencies": {
"@openshift/dynamic-plugin-sdk": "^8.0.0",
"@openshift/dynamic-plugin-sdk": "git+https://github.com/openshift/dynamic-plugin-sdk.git#workspace=@openshift/dynamic-plugin-sdk&head=main",
"@openshift/dynamic-plugin-sdk-webpack": "^5.1.0",
"@patternfly/patternfly": "~6.4.0",
"@patternfly/quickstarts": "~6.4.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ table in [Console dynamic plugins README](./README.md).

## 4.22.0-prerelease.2 - TBD

- **Breaking**: `useResolvedExtensions` hook now supports a single predicate parameter ([#16115])
- **Breaking**: Removed `pluginID` from the result in `useResolvedExtensions` hook ([CONSOLE-3769], [#15904])
- **Breaking**: Removed `AppInitSDK` and `useReduxStore` in `app` directory ([CONSOLE-5063], [#16019])
- **Deprecated**: `useUserSettings` hook has been renamed to `useUserPreference` for consistency ([OCPBUGS-44612], [#16057])
- **Type breaking**: Changed `useDeleteModal` hook's `redirectTo` parameter type from `LocationDescriptor` (from `history`) to `To` (from `react-router-dom-v5-compat`) ([CONSOLE-4990], [#15959])
- **Type breaking**: Changed `FileUploadHandler` return type from `void` to `To | void`. Handlers can now return a path (from `react-router-dom-v5-compat`) for programmatic navigation instead of calling history methods directly ([CONSOLE-4990], [#15959])
- The following types are now re-exported from `@openshift/dynamic-plugin-sdk` instead of being defined
by Console: `CodeRef`, `EncodedCodeRef`, `LoadedExtension`, and `ResolvedExtension` ([CONSOLE-3769], [#15904])
locally: `CodeRef`, `EncodedCodeRef`, `LoadedExtension`, `ResolvedExtension` and `ExtensionPredicate` ([CONSOLE-3769], [#15904], [#16115])

## 4.22.0-prerelease.1 - 2025-01-21

Expand Down Expand Up @@ -50,7 +51,7 @@ table in [Console dynamic plugins README](./README.md).
- **Type breaking**: Fix `popupComponent` prop type in extension `console.dashboards/overview/health/resource` ([CONSOLE-4796], [#15526])
- **Type breaking**: `AlwaysOnExtension` and `ModelDefinition` types are removed from `api/common-types`. ([CONSOLE-3769], [#15509])
- The following types are now re-exported from `@openshift/dynamic-plugin-sdk` instead of being defined
locally: `ExtensionFlags`, `ExtensionTypeGuard`, `ResolvedCodeRefProperties`, `RemoteEntryModule`, and `Update`. ([CONSOLE-4840], [#15509], [#15671])
locally: `ExtensionFlags`, `ExtensionTypeGuard`, `ResolvedCodeRefProperties`, `RemoteEntryModule`, and `Update` ([CONSOLE-4840], [#15509], [#15671])
- Add optional `fetch` property to extension `console.dashboards/overview/health/url` ([CONSOLE-4796], [#15526])
- Add optional `infrastructure` parameter to `PrometheusHealthHandler` type ([CONSOLE-4796], [#15526])
- Allow `K8sResourceKind` in `TopologyDataObject`, `TopologyResourcesObject`, and `OverviewItem` types ([CONSOLE-4840], [#15699])
Expand Down Expand Up @@ -264,6 +265,7 @@ table in [Console dynamic plugins README](./README.md).
[#15893]: https://github.com/openshift/console/pull/15893
[#15904]: https://github.com/openshift/console/pull/15904
[#15934]: https://github.com/openshift/console/pull/15934
[#15959]: https://github.com/openshift/console/pull/15959
[#16019]: https://github.com/openshift/console/pull/16019
[#16057]: https://github.com/openshift/console/pull/16057
[#15959]: https://github.com/openshift/console/pull/15959
[#16115]: https://github.com/openshift/console/pull/16115
12 changes: 7 additions & 5 deletions frontend/packages/console-dynamic-plugin-sdk/docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3096,14 +3096,16 @@ Quick start context values object.

### Summary

React hook for consuming Console extensions with resolved `CodeRef` properties.<br/>This hook accepts the same argument(s) as `useExtensions` hook and returns an adapted list of extension instances, resolving all code references within each extension's properties.<br/>Initially, the hook returns an empty array. Once the resolution is complete, the React component is re-rendered with the hook returning an adapted list of extensions.<br/>When the list of matching extensions changes, the resolution is restarted. The hook will continue to return the previous result until the resolution completes.<br/>The hook's result elements are guaranteed to be referentially stable across re-renders.
React hook for consuming Console extensions containing code references.<br/><br/>Initially, this hook returns a result tuple `[resolvedExtensions: [], resolved: false, errors: []]`.<br/><br/>Once the resolution is complete, this hook re-renders the component with a result tuple containing<br/>all matching extensions that had their code references resolved successfully along with any errors<br/>that occurred during the process.<br/><br/>When the list of matching extensions changes, the resolution is restarted. In such case, the hook<br/>will _not_ re-render the component with empty initial result since it's preferable to use existing<br/>state until the current resolution completes.<br/><br/>The hook's result is guaranteed to be referentially stable across re-renders, assuming referential<br/>stability of the `predicate` parameter.


### Example

```ts
const [navItemExtensions, navItemsResolved] = useResolvedExtensions<NavItem>(isNavItem);
// process adapted extensions and render your component
const Example = () => {
const [navItems, navItemsResolved] = useResolvedExtensions(isNavItem);
// process extensions and render your component
};
```


Expand All @@ -3112,13 +3114,13 @@ const [navItemExtensions, navItemsResolved] = useResolvedExtensions<NavItem>(isN

| Parameter Name | Description |
| -------------- | ----------- |
| `typeGuards` | A list of callbacks that each accept a dynamic plugin extension as an argument and return a boolean flag indicating whether or not the extension meets desired type constraints |
| `predicate` | Predicate (type guard) to filter extensions of a specific type. |



### Returns

Tuple containing a list of adapted extension instances with resolved code references, a boolean flag indicating whether the resolution is complete, and a list of errors detected during the resolution.
Tuple `[resolvedExtensions, resolved, errors]` containing a list of matching extensions,<br/>a boolean flag indicating whether the resolution is complete, and a list of errors detected during<br/>the resolution.


### Source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,33 @@ export * from './common-types';
export * from './utils';

/**
* React hook for consuming Console extensions with resolved `CodeRef` properties.
* This hook accepts the same argument(s) as `useExtensions` hook and returns an adapted list of extension instances, resolving all code references within each extension's properties.
* Initially, the hook returns an empty array. Once the resolution is complete, the React component is re-rendered with the hook returning an adapted list of extensions.
* When the list of matching extensions changes, the resolution is restarted. The hook will continue to return the previous result until the resolution completes.
* The hook's result elements are guaranteed to be referentially stable across re-renders.
* React hook for consuming Console extensions containing code references.
*
* Initially, this hook returns a result tuple `[resolvedExtensions: [], resolved: false, errors: []]`.
*
* Once the resolution is complete, this hook re-renders the component with a result tuple containing
* all matching extensions that had their code references resolved successfully along with any errors
* that occurred during the process.
*
* When the list of matching extensions changes, the resolution is restarted. In such case, the hook
* will _not_ re-render the component with empty initial result since it's preferable to use existing
* state until the current resolution completes.
*
* The hook's result is guaranteed to be referentially stable across re-renders, assuming referential
* stability of the `predicate` parameter.
*
* @example
* ```ts
* const [navItemExtensions, navItemsResolved] = useResolvedExtensions<NavItem>(isNavItem);
* // process adapted extensions and render your component
* const Example = () => {
* const [navItems, navItemsResolved] = useResolvedExtensions(isNavItem);
* // process extensions and render your component
* };
* ```
* @param typeGuards A list of callbacks that each accept a dynamic plugin extension as an argument and return a boolean flag indicating whether or not the extension meets desired type constraints
* @returns Tuple containing a list of adapted extension instances with resolved code references, a boolean flag indicating whether the resolution is complete, and a list of errors detected during the resolution.
*
* @param predicate Predicate (type guard) to filter extensions of a specific type.
* @returns Tuple `[resolvedExtensions, resolved, errors]` containing a list of matching extensions,
* a boolean flag indicating whether the resolution is complete, and a list of errors detected during
* the resolution.
*/
export const useResolvedExtensions: UseResolvedExtensions = require('@console/dynamic-plugin-sdk/src/api/useResolvedExtensions')
.useResolvedExtensions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,15 @@
import { useState, useEffect } from 'react';
import type { UseResolvedExtensionsOptions as UseResolvedExtensionsOptionsSDK } from '@openshift/dynamic-plugin-sdk';
import { useResolvedExtensions as useResolvedExtensionsSDK } from '@openshift/dynamic-plugin-sdk';
import { useExtensions } from '@console/plugin-sdk/src/api/useExtensions';
import { resolveExtension } from '../coderefs/coderef-resolver';
import type { UseResolvedExtensions } from '../extensions/console-types';
import type { Extension, ExtensionTypeGuard, ResolvedExtension } from '../types';
import { settleAllPromises } from '../utils/promise';
import type { Extension, ExtensionPredicate, ResolvedExtension } from '../types';

const hookOptions: UseResolvedExtensionsOptionsSDK = {
useExtensionsImpl: useExtensions,
};

export const useResolvedExtensions: UseResolvedExtensions = <E extends Extension>(
...typeGuards: ExtensionTypeGuard<E>[]
predicate: ExtensionPredicate<E>,
): [ResolvedExtension<E>[], boolean, any[]] => {
const extensions = useExtensions<E>(...typeGuards);

const [resolvedExtensions, setResolvedExtensions] = useState<ResolvedExtension<E>[]>([]);
const [resolved, setResolved] = useState<boolean>(false);
const [errors, setErrors] = useState<any[]>([]);

useEffect(() => {
let disposed = false;

// eslint-disable-next-line promise/catch-or-return
settleAllPromises(
extensions.map((e) => resolveExtension<typeof e, any, ResolvedExtension<E>>(e)),
).then(([fulfilledValues, rejectedReasons]) => {
if (!disposed) {
setResolvedExtensions(fulfilledValues);
setErrors(rejectedReasons);
setResolved(true);

if (rejectedReasons.length > 0) {
// eslint-disable-next-line no-console
console.error('Detected errors while resolving Console extensions', rejectedReasons);
}
}
});

return () => {
disposed = true;
};
}, [extensions]);

return [resolvedExtensions, resolved, errors];
return useResolvedExtensionsSDK(predicate, hookOptions);
};

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
ResolvedExtension,
Selector,
} from '../api/common-types';
import type { Extension, ExtensionTypeGuard } from '../types';
import type { Extension, ExtensionPredicate } from '../types';
import type { CustomDataSource } from './dashboard-data-source';

export type OwnerReference = {
Expand Down Expand Up @@ -264,7 +264,7 @@ export type UseK8sWatchResources = <R extends ResourcesObject>(
) => WatchK8sResults<R>;

export type UseResolvedExtensions = <E extends Extension>(
...typeGuards: ExtensionTypeGuard<E>[]
predicate: ExtensionPredicate<E>,
) => [ResolvedExtension<E>[], boolean, any[]];

export type GetSegmentAnalytics = () => {
Expand Down
2 changes: 1 addition & 1 deletion frontend/packages/console-dynamic-plugin-sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type {
EncodedCodeRef,
Extension,
ExtensionFlags,
ExtensionPredicate as ExtensionTypeGuard,
ExtensionPredicate,
LoadedAndResolvedExtension as ResolvedExtension,
LoadedExtension,
MapCodeRefsToValues as ResolvedCodeRefProperties,
Expand Down
Loading