Skip to content

Commit dd91624

Browse files
committed
Remove Firehose Component and Fix and Cleanup Impacted Types
1 parent 31dcb9d commit dd91624

55 files changed

Lines changed: 317 additions & 2273 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

frontend/packages/console-dynamic-plugin-sdk/docs/console-extensions.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ Adds an activity to the Activity Card of Overview Dashboard where the triggering
389389

390390
| Name | Value Type | Optional | Description |
391391
| ---- | ---------- | -------- | ----------- |
392-
| `k8sResource` | `CodeRef<FirehoseResource & { isList: true; }>` | no | The utilization item to be replaced. |
392+
| `k8sResource` | `CodeRef<WatchK8sResource & { prop: string; } & { isList: true; }>` | no | The utilization item to be replaced. |
393393
| `component` | `CodeRef<React.ComponentType<K8sActivityProps<T>>>` | no | The action component. |
394394
| `isActivity` | `CodeRef<(resource: T) => boolean>` | yes | Function which determines if the given resource represents the action. If not defined, every resource represents activity. |
395395
| `getTimestamp` | `CodeRef<(resource: T) => Date>` | yes | Timestamp for the given action, which will be used for ordering. |
@@ -407,7 +407,7 @@ Adds a health subsystem to the status card of Overview dashboard where the sourc
407407
| Name | Value Type | Optional | Description |
408408
| ---- | ---------- | -------- | ----------- |
409409
| `title` | `string` | no | Title of operators section in the popup. |
410-
| `resources` | `CodeRef<FirehoseResource[]>` | no | Kubernetes resources which will be fetched and passed to `healthHandler`. |
410+
| `resources` | `CodeRef<WatchK8sResourceWithProp[]>` | no | Kubernetes resources which will be fetched and passed to `healthHandler`. |
411411
| `getOperatorsWithStatuses` | `CodeRef<GetOperatorsWithStatuses<T>>` | yes | Resolves status for the operators. |
412412
| `operatorRowLoader` | `CodeRef<React.ComponentType<OperatorRowProps<T>>>` | yes | Loader for popup row component. |
413413
| `viewAllLink` | `string` | yes | Links to all resources page. If not provided then a list page of the first resource from resources prop is used. |
@@ -427,7 +427,7 @@ Adds a health subsystem to the status card of Overview dashboard where the sourc
427427
| `title` | `string` | no | The display name of the subsystem. |
428428
| `queries` | `string[]` | no | The Prometheus queries |
429429
| `healthHandler` | `CodeRef<PrometheusHealthHandler>` | no | Resolve the subsystem's health. |
430-
| `additionalResource` | `CodeRef<FirehoseResource>` | yes | Additional resource which will be fetched and passed to `healthHandler`. |
430+
| `additionalResource` | `CodeRef<WatchK8sResourceWithProp>` | yes | Additional resource which will be fetched and passed to `healthHandler`. |
431431
| `popupComponent` | `CodeRef<React.ComponentType<PrometheusHealthPopupProps>>` | yes | Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. |
432432
| `popupTitle` | `string` | yes | The title of the popover. |
433433
| `popupClassname` | `string` | yes | Optional classname for the popup top-level component. |
@@ -468,8 +468,8 @@ Adds a health subsystem to the status card of Overview dashboard where the sourc
468468
| `url` | `string` | no | The URL to fetch data from. It will be prefixed with base k8s URL. |
469469
| `healthHandler` | `CodeRef<URLHealthHandler<T>>` | no | Resolve the subsystem's health. |
470470
| `fetch` | `CodeRef<Fetch>` | yes | Custom function to fetch data from the URL.<br/>If none is specified, default one (`coFetchJson`) will be used.<br/>Response is then parsed by `healthHandler`. |
471-
| `additionalResource` | `CodeRef<FirehoseResource>` | yes | Additional resource which will be fetched and passed to `healthHandler`. |
472-
| `popupComponent` | `CodeRef<React.ComponentType<{ healthResult?: T; healthResultError?: any; k8sResult?: FirehoseResult<R>; }>>` | yes | Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. |
471+
| `additionalResource` | `CodeRef<WatchK8sResourceWithProp>` | yes | Additional resource which will be fetched and passed to `healthHandler`. |
472+
| `popupComponent` | `CodeRef<React.ComponentType<{ healthResult?: T; healthResultError?: any; k8sResult?: WatchK8sResultsObject<R>; }>>` | yes | Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. |
473473
| `popupTitle` | `string` | yes | The title of the popover. |
474474

475475
---

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

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -226,31 +226,12 @@ export type WatchK8sResourcesGeneric = {
226226
};
227227
};
228228

229-
export type FirehoseResource = {
230-
kind: K8sResourceKindReference;
231-
name?: string;
232-
namespace?: string;
233-
isList?: boolean;
234-
selector?: Selector;
229+
/**
230+
* Extension of WatchK8sResource that includes the prop field required by
231+
* components and extension types.
232+
*/
233+
export type WatchK8sResourceWithProp = WatchK8sResource & {
235234
prop: string;
236-
namespaced?: boolean;
237-
optional?: boolean;
238-
limit?: number;
239-
fieldSelector?: string;
240-
};
241-
242-
export type FirehoseResult<
243-
R extends K8sResourceCommon | K8sResourceCommon[] = K8sResourceCommon[]
244-
> = {
245-
loaded: boolean;
246-
loadError: string;
247-
optional?: boolean;
248-
data: R;
249-
kind?: string;
250-
};
251-
252-
export type FirehoseResourcesResult = {
253-
[key: string]: FirehoseResult<K8sResourceCommon | K8sResourceCommon[]>;
254235
};
255236

256237
export type WatchK8sResult<R extends K8sResourceCommon | K8sResourceCommon[]> = [R, boolean, any];

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ import type {
66
PrometheusResponse,
77
ResourcesObject,
88
WatchK8sResults,
9-
FirehoseResourcesResult,
10-
FirehoseResult,
9+
WatchK8sResultsObject,
1110
OverviewCardSpan,
1211
K8sResourceKind,
1312
} from './console-types';
@@ -18,7 +17,7 @@ import type {
1817
export type CardSpan = OverviewCardSpan;
1918

2019
export type GetOperatorsWithStatuses<R extends K8sResourceCommon = K8sResourceCommon> = (
21-
resources: FirehoseResourcesResult,
20+
resources: WatchK8sResults<ResourcesObject>,
2221
) => OperatorStatusWithResources<R>[];
2322

2423
export type K8sActivityProps<R extends K8sResourceCommon = K8sResourceCommon> = {
@@ -53,13 +52,13 @@ export type OperatorHealth = {
5352
export type PrometheusHealthHandler = (
5453
responses: { response: PrometheusResponse; error: any }[],
5554
t?: TFunction,
56-
additionalResource?: FirehoseResult<K8sResourceCommon | K8sResourceCommon[]>,
55+
additionalResource?: WatchK8sResultsObject<K8sResourceCommon | K8sResourceCommon[]>,
5756
infrastructure?: K8sResourceKind,
5857
) => SubsystemHealth;
5958

6059
export type PrometheusHealthPopupProps = {
6160
responses: { response: PrometheusResponse; error: any }[];
62-
k8sResult?: FirehoseResult<K8sResourceCommon | K8sResourceCommon[]>;
61+
k8sResult?: WatchK8sResultsObject<K8sResourceCommon | K8sResourceCommon[]>;
6362
hide: () => void;
6463
};
6564

@@ -80,7 +79,7 @@ export type SubsystemHealth = {
8079
export type URLHealthHandler<
8180
R,
8281
T extends K8sResourceCommon | K8sResourceCommon[] = K8sResourceCommon | K8sResourceCommon[]
83-
> = (response: R, error: any, additionalResource?: FirehoseResult<T>) => SubsystemHealth;
82+
> = (response: R, error: any, additionalResource?: WatchK8sResultsObject<T>) => SubsystemHealth;
8483

8584
export type StatusPopupItemProps = {
8685
children: ReactNode;

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import type {
88
StatusGroupMapper,
99
WatchK8sResources,
1010
WatchK8sResults,
11-
FirehoseResource,
12-
FirehoseResult,
11+
WatchK8sResourceWithProp,
12+
WatchK8sResultsObject,
1313
} from './console-types';
1414
import type {
1515
CardSpan,
@@ -62,7 +62,7 @@ export type DashboardsOverviewHealthPrometheusSubsystem = Extension<
6262
/** Resolve the subsystem's health. */
6363
healthHandler: CodeRef<PrometheusHealthHandler>;
6464
/** Additional resource which will be fetched and passed to `healthHandler`. */
65-
additionalResource?: CodeRef<FirehoseResource>;
65+
additionalResource?: CodeRef<WatchK8sResourceWithProp>;
6666
/** Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. */
6767
popupComponent?: CodeRef<React.ComponentType<PrometheusHealthPopupProps>>;
6868
/** The title of the popover. */
@@ -96,13 +96,13 @@ export type DashboardsOverviewHealthURLSubsystem<
9696
*/
9797
fetch?: CodeRef<Fetch>;
9898
/** Additional resource which will be fetched and passed to `healthHandler`. */
99-
additionalResource?: CodeRef<FirehoseResource>;
99+
additionalResource?: CodeRef<WatchK8sResourceWithProp>;
100100
/** Loader for popup content. If defined, a health item will be represented as a link which opens popup with given content. */
101101
popupComponent?: CodeRef<
102102
React.ComponentType<{
103103
healthResult?: T;
104104
healthResultError?: any;
105-
k8sResult?: FirehoseResult<R>;
105+
k8sResult?: WatchK8sResultsObject<R>;
106106
}>
107107
>;
108108
/** The title of the popover. */
@@ -138,7 +138,7 @@ export type DashboardsOverviewHealthOperator<
138138
/** Title of operators section in the popup. */
139139
title: string;
140140
/** Kubernetes resources which will be fetched and passed to `healthHandler`. */
141-
resources: CodeRef<FirehoseResource[]>;
141+
resources: CodeRef<WatchK8sResourceWithProp[]>;
142142
/** Resolves status for the operators. */
143143
getOperatorsWithStatuses?: CodeRef<GetOperatorsWithStatuses<T>>;
144144
/** Loader for popup row component. */
@@ -193,7 +193,7 @@ export type DashboardsOverviewResourceActivity<
193193
'console.dashboards/overview/activity/resource',
194194
{
195195
/** The utilization item to be replaced. */
196-
k8sResource: CodeRef<FirehoseResource & { isList: true }>;
196+
k8sResource: CodeRef<WatchK8sResourceWithProp & { isList: true }>;
197197
/** Function which determines if the given resource represents the action. If not defined, every resource represents activity. */
198198
isActivity?: CodeRef<(resource: T) => boolean>;
199199
/** Timestamp for the given action, which will be used for ordering. */

frontend/packages/console-shared/src/components/dashboard/status-card/OperatorStatusBody.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { useCallback } from 'react';
33
import * as _ from 'lodash';
44
import { useTranslation } from 'react-i18next';
55
import { Link } from 'react-router-dom-v5-compat';
6-
import type { GetOperatorsWithStatuses, OperatorRowProps } from '@console/dynamic-plugin-sdk';
6+
import type {
7+
GetOperatorsWithStatuses,
8+
OperatorRowProps,
9+
WatchK8sResults,
10+
K8sResourceCommon,
11+
} from '@console/dynamic-plugin-sdk';
712
import type { LazyLoader } from '@console/internal/components/utils/async';
8-
import type { FirehoseResourcesResult } from '@console/internal/components/utils/types';
913
import { getMostImportantStatuses } from './state-utils';
1014
import { HealthState } from './states';
1115
import StatusItem, { StatusPopupSection } from './StatusPopup';
@@ -75,7 +79,7 @@ export const OperatorsSection: FC<OperatorsSectionProps> = ({
7579
};
7680

7781
type OperatorsSectionProps = {
78-
resources: FirehoseResourcesResult;
82+
resources: WatchK8sResults<{ [key: string]: K8sResourceCommon | K8sResourceCommon[] }>;
7983
getOperatorsWithStatuses: GetOperatorsWithStatuses;
8084
title: string;
8185
linkTo: string;

frontend/packages/console-shared/src/components/dropdown/ResourceDropdown.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import * as fuzzy from 'fuzzysearch';
44
import type { TFunction } from 'i18next';
55
import * as _ from 'lodash';
66
import { withTranslation } from 'react-i18next';
7+
import type { WatchK8sResultsObject } from '@console/dynamic-plugin-sdk';
78
import type { ConsoleSelectProps } from '@console/internal/components/utils/console-select';
89
import { ConsoleSelect } from '@console/internal/components/utils/console-select';
910
import { ResourceIcon } from '@console/internal/components/utils/resource-icon';
1011
import { LoadingInline } from '@console/internal/components/utils/status-box';
11-
import type { FirehoseResult } from '@console/internal/components/utils/types';
1212
import type { K8sResourceKind, K8sKind } from '@console/internal/module/k8s';
1313
import { referenceForModel, modelFor, referenceFor } from '@console/internal/module/k8s';
1414

@@ -65,7 +65,7 @@ export interface ResourceDropdownProps {
6565
transformLabel?: Function;
6666
loaded?: boolean;
6767
loadError?: string;
68-
resources?: FirehoseResult[];
68+
resources?: WatchK8sResultsObject<K8sResourceKind | K8sResourceKind[]>[];
6969
autoSelect?: boolean;
7070
resourceFilter?: (resource: K8sResourceKind) => boolean;
7171
onChange?: (key: string, name?: string | object, selectedResource?: K8sResourceKind) => void;
@@ -195,15 +195,16 @@ class ResourceDropdownInternal extends Component<ResourceDropdownProps & { t: TF
195195
} = props;
196196

197197
const unsortedList = { ...appendItems };
198-
_.each(resources, ({ data, kind }) => {
198+
_.each(resources, ({ data }) => {
199+
const dataArray = Array.isArray(data) ? data : [data];
199200
_.reduce(
200-
data,
201+
dataArray,
201202
(acc, resource) => {
202203
const { customKey, key: name } = this.craftResourceKey(resource, props);
203204
const dataValue = customKey || name;
204205
if (dataValue) {
205206
if (showBadge) {
206-
const model = modelFor(referenceFor(resource)) || (kind && modelFor(kind));
207+
const model = modelFor(referenceFor(resource));
207208
acc[dataValue] = model ? (
208209
<DropdownItem key={resource.metadata.uid} model={model} name={name} />
209210
) : (

frontend/packages/console-shared/src/components/formik-fields/ResourceDropdownField.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { FC } from 'react';
2+
import { useMemo } from 'react';
23
import { FormGroup, FormHelperText, HelperText, HelperTextItem } from '@patternfly/react-core';
34
import type { FormikValues } from 'formik';
45
import { useField, useFormikContext } from 'formik';
5-
import type { FirehoseResult } from '@console/internal/components/utils/types';
6+
import type { WatchK8sResultsObject } from '@console/dynamic-plugin-sdk';
67
import type { K8sResourceKind } from '@console/internal/module/k8s';
78
import { useFormikValidationFix } from '../../hooks/formik-validation-fix';
89
import type { ResourceDropdownItems } from '../dropdown/ResourceDropdown';
@@ -12,7 +13,7 @@ import { getFieldId } from './field-utils';
1213

1314
export interface ResourceDropdownFieldProps extends DropdownFieldProps {
1415
dataSelector: string[] | number[] | symbol[];
15-
resources: FirehoseResult[];
16+
resources: WatchK8sResultsObject<K8sResourceKind | K8sResourceKind[]>[];
1617
showBadge?: boolean;
1718
onLoad?: (items: ResourceDropdownItems) => void;
1819
onChange?: (key: string, name?: string | object, resource?: K8sResourceKind) => void;
@@ -49,6 +50,19 @@ const ResourceDropdownField: FC<ResourceDropdownFieldProps> = ({
4950

5051
useFormikValidationFix(field.value);
5152

53+
// ResourceDropdown expects these as top-level props to manage loading state
54+
const { loaded, loadError } = useMemo(() => {
55+
if (!resources) {
56+
return { loaded: true, loadError: undefined };
57+
}
58+
const allLoaded = resources.every((r) => r.loaded);
59+
const resourceWithLoadError = resources.find((r) => r.loadError);
60+
return {
61+
loaded: allLoaded,
62+
loadError: resourceWithLoadError?.loadError,
63+
};
64+
}, [resources]);
65+
5266
return (
5367
<FormGroup fieldId={fieldId} label={label} isRequired={required} data-test={dataTest}>
5468
<ResourceDropdown
@@ -60,6 +74,8 @@ const ResourceDropdownField: FC<ResourceDropdownFieldProps> = ({
6074
onLoad={onLoad}
6175
resourceFilter={resourceFilter}
6276
resources={resources}
77+
loaded={loaded}
78+
loadError={loadError}
6379
onChange={(value: string, name: string | object, resource: K8sResourceKind) => {
6480
props.onChange && props.onChange(value, name, resource);
6581
setFieldValue(props.name, value);

frontend/packages/console-shared/src/hooks/useResourceSidebarSamples.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import YAML from 'js-yaml';
33
import * as _ from 'lodash';
44
import { useTranslation } from 'react-i18next';
55
import { PodDisruptionBudgetModel } from '@console/app/src/models';
6-
import type { AddAction, CatalogItemType, Perspective } from '@console/dynamic-plugin-sdk';
6+
import type {
7+
AddAction,
8+
CatalogItemType,
9+
Perspective,
10+
WatchK8sResultsObject,
11+
} from '@console/dynamic-plugin-sdk';
712
import { isAddAction, isCatalogItemType, isPerspective } from '@console/dynamic-plugin-sdk';
8-
import type { FirehoseResult } from '@console/internal/components/utils/types';
913
import {
1014
BuildConfigModel,
1115
ClusterRoleModel,
@@ -331,7 +335,10 @@ const useDefaultSamples = () => {
331335
);
332336
};
333337

334-
export const useResourceSidebarSamples = (kindObj: K8sKind, yamlSamplesList: FirehoseResult) => {
338+
export const useResourceSidebarSamples = (
339+
kindObj: K8sKind,
340+
yamlSamplesList: WatchK8sResultsObject<K8sResourceKind[]>,
341+
) => {
335342
const defaultSamples = useDefaultSamples();
336343

337344
if (!kindObj) {

frontend/packages/console-shared/src/types/pod.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type {
22
ExtPodKind,
3+
K8sResourceCommon,
34
PodControllerOverviewItem,
5+
WatchK8sResultsObject,
46
} from '@console/dynamic-plugin-sdk/src/extensions/console-types';
5-
import type { FirehoseResult } from '@console/internal/components/utils/types';
67
import type { DeploymentKind, PodKind } from '@console/internal/module/k8s';
78

89
export type {
@@ -15,19 +16,19 @@ export type {
1516
} from '@console/dynamic-plugin-sdk/src/extensions/console-types';
1617

1718
export interface PodDataResources {
18-
replicationControllers: FirehoseResult;
19-
replicaSets: FirehoseResult;
20-
pods: FirehoseResult<PodKind[]>;
21-
deploymentConfigs?: FirehoseResult;
22-
deployments?: FirehoseResult<DeploymentKind[]>;
19+
replicationControllers: WatchK8sResultsObject<K8sResourceCommon[]>;
20+
replicaSets: WatchK8sResultsObject<K8sResourceCommon[]>;
21+
pods: WatchK8sResultsObject<PodKind[]>;
22+
deploymentConfigs?: WatchK8sResultsObject<K8sResourceCommon[]>;
23+
deployments?: WatchK8sResultsObject<DeploymentKind[]>;
2324
}
2425

2526
export interface PodRingResources {
26-
pods: FirehoseResult<PodKind[]>;
27-
replicaSets: FirehoseResult;
28-
replicationControllers: FirehoseResult;
29-
deployments?: FirehoseResult<DeploymentKind[]>;
30-
deploymentConfigs?: FirehoseResult;
27+
pods: WatchK8sResultsObject<PodKind[]>;
28+
replicaSets: WatchK8sResultsObject<K8sResourceCommon[]>;
29+
replicationControllers: WatchK8sResultsObject<K8sResourceCommon[]>;
30+
deployments?: WatchK8sResultsObject<DeploymentKind[]>;
31+
deploymentConfigs?: WatchK8sResultsObject<K8sResourceCommon[]>;
3132
}
3233

3334
export interface PodRingData {

0 commit comments

Comments
 (0)