Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/components/Extensibility/contexts/DataSources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ export const DataSourcesContextProvider: FC<Props> = ({
}

const apiGroup = group ? `apis/${group}` : 'api';
let url = `/${apiGroup}/${version}${namespacePart}/${resourceType}`;
let url =
namespace === '-all-'
? `/${apiGroup}/${version}/${resourceType}`
: `/${apiGroup}/${version}${namespacePart}/${resourceType}`;
if (labelSelector) {
url += labelSelector;
} else if (name) {
Expand Down
27 changes: 24 additions & 3 deletions src/sidebar/CategoryItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { isSidebarCondensedState } from 'state/preferences/isSidebarCondensedAto

import { ExpandedCategories } from 'state/navigation/expandedCategories/expandedCategoriesAtom';
import { NavItem } from './NavItem';
import { DataSourcesContextProvider } from 'components/Extensibility/contexts/DataSources';
import {
DataSources,
DataSourcesContextProvider,
} from 'components/Extensibility/contexts/DataSources';
import { cloneDeep } from 'lodash';

type CategoryItemProps = {
category: Category;
Expand All @@ -30,6 +34,7 @@ export function CategoryItem({

if (!isSidebarCondensed) {
if (categoryName === e.target.parentElement?.getAttribute('text')) {
return;
} else if (expanded) {
handleExpandedCategories(
expandedCategories.filter(el => el !== category.key),
Expand All @@ -40,10 +45,26 @@ export function CategoryItem({
}
};

const handleEmptyNamespace = (dataSources: DataSources) => {
// Some data is available only on a certain namespace. If we don't have a given namespace, we can still get it on all namespaces.
let clonedDataSources = cloneDeep(dataSources);
Object.keys(clonedDataSources).forEach(key => {
if (clonedDataSources?.[key]?.resource) {
clonedDataSources[key].resource = {
...clonedDataSources[key]?.resource,
namespace: clonedDataSources[key]?.resource?.namespace ?? '-all-',
};
}
});
return clonedDataSources;
};

const children = category.items?.map((nn, index) => (
<React.Fragment key={index}>
<React.Fragment key={`${nn.pathSegment}-${index}`}>
{nn.dataSources ? (
<DataSourcesContextProvider dataSources={nn.dataSources}>
<DataSourcesContextProvider
dataSources={handleEmptyNamespace(nn.dataSources)}
>
<NavItem node={nn} key={nn.pathSegment} subItem={true} />
</DataSourcesContextProvider>
) : (
Expand Down
Loading