Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ const ConsolePluginsTable: React.FC<ConsolePluginsTableProps> = ({ obj, rows, lo

const compare = React.useCallback<Comparator<ConsolePluginTableRow>>(
(a, b) => {
const { index, direction } = sortBy;
const { index = 0, direction } = sortBy;
const { id } = columns[index];
const desc = direction === SortByDirection.desc;
const left = (desc ? b : a)[id];
Expand Down Expand Up @@ -256,7 +256,7 @@ const ConsolePluginsTable: React.FC<ConsolePluginsTableProps> = ({ obj, rows, lo
<Thead>
<Tr>
{columns.map(({ id, name, sortable }, columnIndex) => (
<Th key={id} sort={sortable ? { sortBy, onSort, columnIndex } : null}>
<Th key={id} sort={sortable ? { sortBy, onSort, columnIndex } : undefined}>
{name}
</Th>
))}
Expand Down Expand Up @@ -343,7 +343,7 @@ const PluginsPage: React.FC<ConsoleOperatorConfigPageProps> = (props) => {
.find((i) => i?.pluginName === pluginName);
if (loadedPluginInfo) {
return {
name: plugin?.metadata?.name,
name: pluginName,
version: loadedPluginInfo?.metadata?.version,
description: loadedPluginInfo?.metadata?.customProperties?.console?.description,
enabled,
Expand All @@ -352,9 +352,9 @@ const PluginsPage: React.FC<ConsoleOperatorConfigPageProps> = (props) => {
};
}
return {
name: plugin?.metadata?.name,
name: pluginName,
enabled,
status: notLoadedPluginInfo?.status,
status: notLoadedPluginInfo?.status || 'Pending',
errorMessage:
notLoadedPluginInfo?.status === 'Failed' ? notLoadedPluginInfo?.errorMessage : undefined,
errorCause:
Expand Down Expand Up @@ -416,7 +416,7 @@ export const ConsoleOperatorConfigDetailsPage: React.FC<React.ComponentProps<
};

export type ConsolePluginTableRow = {
name: string;
name?: string;
version?: string;
description?: string;
status: DynamicPluginInfo['status'];
Expand All @@ -442,7 +442,7 @@ type ConsolePluginStatusProps = {
};

type ConsolePluginEnabledStatusProps = {
pluginName: string;
pluginName?: string;
enabled: boolean;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ConsolePluginDescriptionDetail: React.FC<DetailsItemComponentProps> = ({ o
const pluginStore = usePluginStore();
const pluginName = React.useMemo(() => obj?.metadata?.name, [obj?.metadata?.name]);

const pluginInfo = React.useMemo(() => pluginStore.findDynamicPluginInfo(pluginName), [
const pluginInfo = React.useMemo(() => pluginStore.findDynamicPluginInfo(pluginName ?? ''), [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this still throw an SNC error after making plugin.metadata.name optional?

pluginStore,
pluginName,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const ConsolePluginEnabledStatusDetail: React.FC<DetailsItemComponentProps> = ({

const pluginName = React.useMemo(() => obj?.metadata?.name, [obj?.metadata?.name]);

const pluginInfo = React.useMemo(() => pluginStore.findDynamicPluginInfo(pluginName), [
const pluginInfo = React.useMemo(() => pluginStore.findDynamicPluginInfo(pluginName ?? ''), [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as stated previously.

pluginStore,
pluginName,
]);
Expand All @@ -25,11 +25,11 @@ const ConsolePluginEnabledStatusDetail: React.FC<DetailsItemComponentProps> = ({

return consoleOperatorConfigLoaded ? (
<ConsolePluginEnabledStatus
pluginName={pluginName}
pluginName={pluginName ?? ''}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as stated previously.

enabled={
developmentMode
? (isLoadedDynamicPluginInfo(pluginInfo) && pluginInfo.enabled) ?? false
: enabledPlugins.includes(pluginName) ?? false
: enabledPlugins.includes(pluginName ?? '') ?? false
}
/>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export const ConsolePluginManifestPage: React.FC<PageComponentProps> = ({ obj })
const pluginStore = usePluginStore();
const pluginName = React.useMemo(() => obj?.metadata?.name, [obj?.metadata?.name]);

const pluginManifest = React.useMemo(() => pluginStore.getDynamicPluginManifest(pluginName), [
pluginStore,
pluginName,
]);
const pluginManifest = React.useMemo(
() => pluginStore.getDynamicPluginManifest(pluginName ?? ''),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as stated previously.

[pluginStore, pluginName],
);

return (
<PaneBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ConsolePluginStatusDetail: React.FC<DetailsItemComponentProps> = ({ obj })
const pluginStore = usePluginStore();
const pluginName = React.useMemo(() => obj?.metadata?.name, [obj?.metadata?.name]);

const pluginInfo = React.useMemo(() => pluginStore.findDynamicPluginInfo(pluginName), [
const pluginInfo = React.useMemo(() => pluginStore.findDynamicPluginInfo(pluginName ?? ''), [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as stated previously.

pluginStore,
pluginName,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const ConsolePluginVersionDetail: React.FC<DetailsItemComponentProps> = ({ obj }
const pluginStore = usePluginStore();
const pluginName = React.useMemo(() => obj?.metadata?.name, [obj?.metadata?.name]);

const pluginInfo = React.useMemo(() => pluginStore.findDynamicPluginInfo(pluginName), [
const pluginInfo = React.useMemo(() => pluginStore.findDynamicPluginInfo(pluginName ?? ''), [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as stated previously.

pluginStore,
pluginName,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ClusterOperatorStatusRow: React.FC<OperatorRowProps<ClusterOperator>> = ({
<Status value={operatorStatus.status.title} icon={operatorStatus.status.icon}>
<ResourceLink
kind={referenceForModel(ClusterOperatorModel)}
name={operatorStatus.operators[0].metadata.name}
name={operatorStatus.operators[0]?.metadata?.name ?? ''}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be fine without a fallback value.

hideIcon
className="co-status-popup__title"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export const getControlPlaneHealth: PrometheusHealthHandler = (
resource,
infrastructure,
) => {
if (!t) {
return { state: HealthState.UNKNOWN };
}

const componentsHealth = responses.map(({ response, error }) =>
getControlPlaneComponentHealth(response, error, t),
);
Expand All @@ -105,7 +109,7 @@ export const getControlPlaneHealth: PrometheusHealthHandler = (
const worstStatus = getWorstStatus(componentsHealth, t);

const singleMasterMsg =
worstStatus.state === HealthState.OK && isSingleNode(infrastructure)
worstStatus.state === HealthState.OK && infrastructure && isSingleNode(infrastructure)
? t('console-app~Single control plane node')
: undefined;

Expand All @@ -117,7 +121,7 @@ export const getControlPlaneHealth: PrometheusHealthHandler = (
? worstStatus.count === 4
? worstStatus.message
: `${pluralize(worstStatus.count, 'component')} ${worstStatus.message.toLowerCase()}`
: null),
: undefined),
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('getValueForNamespace', () => {

it('should return false if namespace is not defined', async () => {
k8sGetMock.mockReturnValueOnce(Promise.resolve());
const exists = await checkNamespaceExists(null, true);
const exists = await checkNamespaceExists('', true);

expect(exists).toBeFalsy();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const getValueForNamespace = async (
useProjects: boolean,
activeNamespace?: string,
): Promise<string> => {
if (await checkNamespaceExists(activeNamespace, useProjects)) {
if (activeNamespace && (await checkNamespaceExists(activeNamespace, useProjects))) {
return activeNamespace;
}
if (await checkNamespaceExists(preferredNamespace, useProjects)) {
Expand Down
17 changes: 9 additions & 8 deletions frontend/packages/console-plugin-sdk/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ export const augmentExtension = <E extends Extension>(
});

export const isExtensionInUse = (e: Extension, flags: FlagsObject): boolean =>
e.flags.required.every((f) => flags[f]) && e.flags.disallowed.every((f) => !flags[f]);
(e.flags?.required?.every((f) => flags[f]) ?? true) &&
(e.flags?.disallowed?.every((f) => !flags[f]) ?? true);

export const getGatingFlagNames = (extensions: Extension[]): string[] =>
_.uniq([
..._.flatMap(extensions.map((e) => e.flags.required)),
..._.flatMap(extensions.map((e) => e.flags.disallowed)),
..._.flatMap(extensions.map((e) => e.flags?.required ?? [])),
..._.flatMap(extensions.map((e) => e.flags?.disallowed ?? [])),
]);

export const isLoadedDynamicPluginInfo = (i: DynamicPluginInfo): i is LoadedDynamicPluginInfo =>
Expand Down Expand Up @@ -203,7 +204,7 @@ export class PluginStore {

const plugin = this.loadedDynamicPlugins.get(pluginID);

if (plugin.enabled !== enabled) {
if (plugin && plugin.enabled !== enabled) {
plugin.enabled = enabled;

this.updateExtensions();
Expand All @@ -213,13 +214,13 @@ export class PluginStore {
}
}

private getLoadedDynamicPlugin(pluginName: string) {
private getLoadedDynamicPlugin(pluginName?: string) {
return Array.from(this.loadedDynamicPlugins.values()).find(
(plugin) => plugin.manifest.name === pluginName,
);
}

private isDynamicPluginLoaded(pluginName: string) {
private isDynamicPluginLoaded(pluginName?: string) {
return this.getLoadedDynamicPlugin(pluginName) !== undefined;
}

Expand Down Expand Up @@ -306,15 +307,15 @@ export class PluginStore {
return [...loadedPluginEntries, ...failedPluginEntries, ...pendingPluginEntries];
}

findDynamicPluginInfo(pluginName: string): DynamicPluginInfo {
findDynamicPluginInfo(pluginName?: string): DynamicPluginInfo | undefined {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good use case for a union type to fix the SNC error, since the find method returns undefined if the item is not found.

return this.getDynamicPluginInfo().find((entry) =>
isLoadedDynamicPluginInfo(entry)
? entry.metadata.name === pluginName
: entry.pluginName === pluginName,
);
}

getDynamicPluginManifest(pluginName: string): DynamicPluginManifest {
getDynamicPluginManifest(pluginName?: string): DynamicPluginManifest | undefined {
return this.getLoadedDynamicPlugin(pluginName)?.manifest;
}

Expand Down