Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -208,7 +208,7 @@ const ConsolePluginsTable: React.FC<ConsolePluginsTableProps> = ({ obj, rows, lo
const compare = React.useCallback<Comparator<ConsolePluginTableRow>>(
(a, b) => {
const { index, direction } = sortBy;
const { id } = columns[index];
const { id } = columns[index ?? 0];
Copy link
Contributor

Choose a reason for hiding this comment

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

Would default at destructuring not be cleaner?
const { index = 0, direction } = sortBy;

const desc = direction === SortByDirection.desc;
const left = (desc ? b : a)[id];
const right = (desc ? a : b)[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 @@ -333,7 +333,7 @@ const PluginsPage: React.FC<ConsoleOperatorConfigPageProps> = (props) => {
return [];
}
return consolePlugins.map((plugin) => {
const pluginName = plugin?.metadata?.name;
const pluginName = plugin?.metadata?.name ?? 'unknown';
const enabled = enabledPlugins.includes(pluginName);
const loadedPluginInfo = pluginInfo
.filter(isLoadedDynamicPluginInfo)
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const ConsolePluginCSPStatusDetail: 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.

It would be better to be consistent with the default value for pluginName = obj?.metadata?.name. The 'unknown' is used as the default in another place.

pluginStore,
pluginName,
]);
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.NOT_AVAILABLE };
Copy link
Contributor

Choose a reason for hiding this comment

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

Returning HealthState.NOT_AVAILABLE from the function if t is undefined doesn't seem right to me, but I might be wrong.
cc: @vojtechszocs

Copy link
Contributor

@cajieh cajieh Aug 29, 2025

Choose a reason for hiding this comment

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

Returning HealthState.NOT_AVAILABLE from the function if t is undefined doesn't seem right to me, but I might be wrong. cc: @vojtechszocs

@vojtechszocs. Never mind.
@krishagarwal278 I think I figured it out using the approach I shared earlier. The issue is that the t prop is required in the child component getControlPlaneComponentHealth but optional in the parent getControlPlaneHealth. Changing thetprop in getControlPlaneComponentHealth to be optional, to match the parent, would fix the issue.
When a parent component passes props to a child, their types must align, else the child would have to handle the undefined if SNC mode is enabled. IMO, it is better to align the props if possible instead of handling undefined.

}

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