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
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,5 @@ type PodDisruptionBudgetsListProps = {
data: PodDisruptionBudgetKind[];
loaded: boolean;
loadError?: any;
mock?: boolean;
};
41 changes: 27 additions & 14 deletions frontend/packages/console-app/src/components/pdb/PDBPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ import PodDisruptionBudgetList from './PDBList';
import type { PodDisruptionBudgetKind } from './types';

export const PodDisruptionBudgetsPage: FC<PodDisruptionBudgetsPageProps> = ({
mock,
namespace,
showTitle = true,
}) => {
const { t } = useTranslation();
const [resources, loaded, loadError] = useK8sWatchResource<PodDisruptionBudgetKind[]>({
groupVersionKind: {
group: PodDisruptionBudgetModel.apiGroup,
kind: PodDisruptionBudgetModel.kind,
version: PodDisruptionBudgetModel.apiVersion,
},
isList: true,
namespaced: true,
namespace,
});
const [resources, loaded, loadError] = useK8sWatchResource<PodDisruptionBudgetKind[]>(
mock
? null
: {
groupVersionKind: {
group: PodDisruptionBudgetModel.apiGroup,
kind: PodDisruptionBudgetModel.kind,
version: PodDisruptionBudgetModel.apiVersion,
},
isList: true,
namespaced: true,
namespace,
},
);

const resourceKind = referenceForModel(PodDisruptionBudgetModel);
const accessReview = {
Expand All @@ -33,18 +38,26 @@ export const PodDisruptionBudgetsPage: FC<PodDisruptionBudgetsPageProps> = ({
return (
<>
<ListPageHeader title={showTitle ? t(PodDisruptionBudgetModel.labelPluralKey) : undefined}>
<ListPageCreate groupVersionKind={resourceKind} createAccessReview={accessReview}>
{t('console-app~Create PodDisruptionBudget')}
</ListPageCreate>
{!mock && (
<ListPageCreate groupVersionKind={resourceKind} createAccessReview={accessReview}>
{t('console-app~Create PodDisruptionBudget')}
</ListPageCreate>
)}
</ListPageHeader>
<ListPageBody>
<PodDisruptionBudgetList data={resources} loaded={loaded} loadError={loadError} />
<PodDisruptionBudgetList
data={resources}
loaded={loaded}
loadError={loadError}
mock={mock}
/>
</ListPageBody>
</>
);
};

type PodDisruptionBudgetsPageProps = {
mock?: boolean;
namespace: string;
showTitle?: boolean;
};
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ const VolumeSnapshotTable: FC<VolumeSnapshotTableProps> = ({ data, loaded, ...pr

export const VolumeSnapshotPage: FC<VolumeSnapshotPageProps> = ({
canCreate = true,
mock,
showTitle = true,
namespace,
selector,
Expand All @@ -318,29 +319,33 @@ export const VolumeSnapshotPage: FC<VolumeSnapshotPageProps> = ({

const createPath = `/k8s/ns/${namespace || 'default'}/${VolumeSnapshotModel.plural}/~new/form`;

const [resources, loaded, loadError] = useK8sWatchResource<VolumeSnapshotKind[]>({
groupVersionKind: {
group: VolumeSnapshotModel.apiGroup,
kind: VolumeSnapshotModel.kind,
version: VolumeSnapshotModel.apiVersion,
},
isList: true,
namespaced: true,
namespace,
selector,
});
const [resources, loaded, loadError] = useK8sWatchResource<VolumeSnapshotKind[]>(
mock
? null
: {
groupVersionKind: {
group: VolumeSnapshotModel.apiGroup,
kind: VolumeSnapshotModel.kind,
version: VolumeSnapshotModel.apiVersion,
},
isList: true,
namespaced: true,
namespace,
selector,
},
);

return (
<>
<ListPageHeader title={showTitle ? t(VolumeSnapshotModel.labelPluralKey || '') : ''}>
{canCreate && (
{canCreate && !mock && (
<ListPageCreateLink to={createPath}>
{t('console-app~Create VolumeSnapshot')}
</ListPageCreateLink>
)}
</ListPageHeader>
<ListPageBody>
<VolumeSnapshotTable data={resources} loaded={loaded} loadError={loadError} />
<VolumeSnapshotTable data={resources} loaded={loaded} loadError={loadError} mock={mock} />
</ListPageBody>
</>
);
Expand Down Expand Up @@ -387,6 +392,7 @@ type VolumeSnapshotFilters = ResourceFilters & {
};

type VolumeSnapshotPageProps = {
mock?: boolean;
namespace?: string;
canCreate?: boolean;
showTitle?: boolean;
Expand All @@ -402,6 +408,7 @@ type VolumeSnapshotTableProps = {
data: VolumeSnapshotKind[];
loaded: boolean;
loadError: unknown;
mock?: boolean;
};

type VolumeSnapshotRowData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const getObjectMetadata = (release: HelmRelease) => ({
name: release.name,
});

const HelmReleaseList: FC = () => {
const HelmReleaseList: FC<{ mock?: boolean }> = ({ mock }) => {
const { t } = useTranslation();
const params = useParams();
const namespace = params.ns;
Expand All @@ -163,7 +163,7 @@ const HelmReleaseList: FC = () => {
[namespace],
);
const [secretsData, secretsLoaded, secretsLoadError] = useK8sWatchResource<K8sResourceKind[]>(
secretResource,
mock ? null : secretResource,
);
const newCount = secretsData?.length ?? 0;

Expand Down Expand Up @@ -274,7 +274,7 @@ const HelmReleaseList: FC = () => {
<DocumentTitle>{t('helm-plugin~Helm Releases')}</DocumentTitle>
<PaneBody>
<Suspense fallback={<LoadingBox />}>
{hasNoReleases ? (
{!mock && hasNoReleases ? (
emptyState()
) : (
<ConsoleDataView<HelmRelease, { obj: HelmRelease }, HelmReleaseFilters>
Expand All @@ -292,6 +292,7 @@ const HelmReleaseList: FC = () => {
hideColumnManagement
isResizable
resetAllColumnWidths={resetAllColumnWidths}
mock={mock}
/>
)}
</Suspense>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { useTranslation } from 'react-i18next';
import { PageHeading } from '@console/shared/src/components/heading/PageHeading';
import HelmReleaseList from './HelmReleaseList';

const HelmReleaseListPage: FC = () => {
const HelmReleaseListPage: FC<{ mock?: boolean }> = ({ mock }) => {
const { t } = useTranslation();
return (
<div>
<PageHeading title={t('helm-plugin~Helm Releases')} />
<HelmReleaseList />
<HelmReleaseList mock={mock} />
</div>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import HelmReleaseList from './HelmReleaseList';
import HelmReleaseListPage from './HelmReleaseListPage';
import RepositoriesPage from './RepositoriesListPage';

const HelmPage: FC<{ namespace: string | undefined }> = ({ namespace }) => {
const HelmPage: FC<{ mock?: boolean; namespace: string | undefined }> = ({ mock, namespace }) => {
const { t } = useTranslation();
const isHelmVisible = useFlag('HELM_CHARTS_CATALOG_TYPE');
const [showTitle, canCreate] = [false, false];
Expand Down Expand Up @@ -85,6 +85,9 @@ const HelmPage: FC<{ namespace: string | undefined }> = ({ namespace }) => {
// t('helm-plugin~Helm Releases')
nameKey: 'helm-plugin~Helm Releases',
component: HelmReleaseList,
pageData: {
mock,
},
},
{
href: 'repositories',
Expand Down Expand Up @@ -120,17 +123,17 @@ const HelmPage: FC<{ namespace: string | undefined }> = ({ namespace }) => {
telemetryPrefix="Helm"
/>
) : (
<HelmReleaseListPage />
<HelmReleaseListPage mock={mock} />
);
};

export const PageContents: FC = () => {
export const PageContents: FC<{ noProjectsAvailable?: boolean }> = ({ noProjectsAvailable }) => {
const { t } = useTranslation();
const { ns: namespace } = useParams();
const [activePerspective] = useActivePerspective();

return activePerspective === 'admin' || namespace ? (
<HelmPage namespace={namespace} />
<HelmPage namespace={namespace} mock={noProjectsAvailable} />
) : (
<CreateProjectListPage title={t('helm-plugin~Helm')}>
{(openProjectModal) => (
Expand Down
34 changes: 21 additions & 13 deletions frontend/public/components/RBAC/bindings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,19 +361,26 @@ export const RoleBindingsPage: FC<RoleBindingsPageProps> = ({
}`,
}) => {
const { t } = useTranslation();
const resources = useK8sWatchResources({
RoleBinding: {
kind: 'RoleBinding',
namespaced: true,
namespace,
isList: true,
},
ClusterRoleBinding: {
kind: 'ClusterRoleBinding',
namespaced: false,
isList: true,
},
});
const watchResources = useMemo(
() =>
mock
? {}
: {
RoleBinding: {
kind: 'RoleBinding',
namespaced: true,
namespace,
isList: true,
},
ClusterRoleBinding: {
kind: 'ClusterRoleBinding',
namespaced: false,
isList: true,
},
},
[mock, namespace],
);
const resources = useK8sWatchResources(watchResources);

// Only flatten when at least one resource has data to prevent undefined iteration
const data = useMemo(() => {
Expand Down Expand Up @@ -406,6 +413,7 @@ export const RoleBindingsPage: FC<RoleBindingsPageProps> = ({
data={data}
loaded={loaded}
loadError={loadError}
mock={mock}
staticFilters={staticFilters}
/>
</ListPageBody>
Expand Down
34 changes: 22 additions & 12 deletions frontend/public/components/pod-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ export const PodList: FC<PodListProps> = ({
data,
loaded,
loadError,
mock,
hideNameLabelFilters,
hideLabelFilter,
hideColumnManagement,
Expand Down Expand Up @@ -558,6 +559,7 @@ export const PodList: FC<PodListProps> = ({
data={data}
loaded={loaded}
loadError={loadError}
mock={mock}
columns={columns}
columnLayout={columnLayout}
columnManagementID={columnManagementID}
Expand All @@ -580,6 +582,7 @@ export const PodList: FC<PodListProps> = ({
export const PodsPage: FC<PodPageProps> = ({
canCreate = true,
namespace,
mock,
showNodes,
showTitle = true,
selector,
Expand All @@ -598,7 +601,7 @@ export const PodsPage: FC<PodPageProps> = ({
);

useEffect(() => {
if (showMetrics) {
if (showMetrics && !mock) {
const updateMetrics = () =>
fetchPodMetrics(namespace || '')
.then((result) => dispatch(UIActions.setPodMetrics(result)))
Expand All @@ -615,16 +618,20 @@ export const PodsPage: FC<PodPageProps> = ({
return () => clearInterval(id);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [namespace]);

const [pods, loaded, loadError] = useK8sWatchResource<PodKind[]>({
kind: PodModel.kind,
isList: true,
namespaced: true,
namespace,
selector,
fieldSelector,
});
}, [mock, namespace]);

const [pods, loaded, loadError] = useK8sWatchResource<PodKind[]>(
mock
? null
: {
kind: PodModel.kind,
isList: true,
namespaced: true,
namespace,
selector,
fieldSelector,
},
);

const resourceKind = referenceForModel(PodModel);
const accessReview = {
Expand All @@ -639,7 +646,7 @@ export const PodsPage: FC<PodPageProps> = ({
return (
<>
<ListPageHeader title={showTitle ? t('public~Pods') : ''}>
{canCreate && (
{canCreate && !mock && (
<ListPageCreate groupVersionKind={resourceKind} createAccessReview={accessReview}>
{t('public~Create Pod')}
</ListPageCreate>
Expand All @@ -650,6 +657,7 @@ export const PodsPage: FC<PodPageProps> = ({
data={pods}
loaded={loaded}
loadError={loadError}
mock={mock}
showNamespaceOverride={showNamespaceOverride}
showNodes={showNodes}
namespace={namespace}
Expand Down Expand Up @@ -691,6 +699,7 @@ type PodListProps = {
data: PodKind[];
loaded: boolean;
loadError: unknown;
mock?: boolean;
showNodes?: boolean;
showNamespaceOverride?: boolean;
hideNameLabelFilters?: boolean;
Expand All @@ -703,6 +712,7 @@ type PodListProps = {
type PodPageProps = {
canCreate?: boolean;
fieldSelector?: string;
mock?: boolean;
namespace?: string;
selector?: Selector;
showTitle?: boolean;
Expand Down