Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CNV-55107: loading on vm change #2408

Merged
merged 1 commit into from
Feb 3, 2025
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
24 changes: 17 additions & 7 deletions src/utils/components/HorizontalNavbar/HorizontalNavbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,26 @@ import { V1VirtualMachine } from '@kubevirt-ui/kubevirt-api/kubevirt';
import { isEmpty } from '@kubevirt-utils/utils/utils';
import { Nav, NavList } from '@patternfly/react-core';

import StateHandler from '../StateHandler/StateHandler';

import useDynamicPages from './utils/useDynamicPages';
import { NavPageKubevirt, trimLastHistoryPath } from './utils/utils';

import './horizontal-nav-bar.scss';

type HorizontalNavbarProps = {
expandedSpecLoading?: boolean;
instanceTypeExpandedSpec?: V1VirtualMachine;
pages: NavPageKubevirt[];
vm?: V1VirtualMachine;
};

const HorizontalNavbar: FC<HorizontalNavbarProps> = ({ instanceTypeExpandedSpec, pages, vm }) => {
const HorizontalNavbar: FC<HorizontalNavbarProps> = ({
expandedSpecLoading,
instanceTypeExpandedSpec,
pages,
vm,
}) => {
const location = useLocation();

const params = useParams();
Expand Down Expand Up @@ -73,12 +81,14 @@ const HorizontalNavbar: FC<HorizontalNavbarProps> = ({ instanceTypeExpandedSpec,
return (
<Route
Component={(props) => (
<Component
instanceTypeExpandedSpec={instanceTypeExpandedSpec}
obj={vm}
params={params}
{...props}
/>
<StateHandler loaded={!expandedSpecLoading} withBullseye>
Copy link
Member

Choose a reason for hiding this comment

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

how this works for VMs created with templates or YML?

Copy link
Member Author

Choose a reason for hiding this comment

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

works great. THe expandedSpecLoading is false from the start with template vms

<Component
instanceTypeExpandedSpec={instanceTypeExpandedSpec}
obj={vm}
params={params}
{...props}
/>
</StateHandler>
)}
key={page.href}
path={page.href}
Expand Down
13 changes: 10 additions & 3 deletions src/utils/components/StateHandler/StateHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React, { FC } from 'react';

import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { Alert, AlertVariant } from '@patternfly/react-core';
import { Alert, AlertVariant, Bullseye } from '@patternfly/react-core';

import Loading from '../Loading/Loading';

type StateHandlerProps = {
error?: any;
loaded: boolean;
withBullseye?: boolean;
};

const StateHandler: FC<StateHandlerProps> = ({ children, error, loaded }) => {
const StateHandler: FC<StateHandlerProps> = ({ children, error, loaded, withBullseye = false }) => {
const { t } = useKubevirtTranslation();

if (error) {
Expand All @@ -22,7 +23,13 @@ const StateHandler: FC<StateHandlerProps> = ({ children, error, loaded }) => {
}

if (!loaded) {
return <Loading />;
return withBullseye ? (
<Bullseye>
<Loading />
</Bullseye>
) : (
<Loading />
);
}

return <>{children}</>;
Expand Down
4 changes: 3 additions & 1 deletion src/views/virtualmachines/details/VirtualMachineNavPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const VirtualMachineNavPage: React.FC<VirtualMachineDetailsPageProps> = ({
namespace,
});

const [instanceTypeExpandedSpec] = useInstanceTypeExpandSpec(vm);
const [instanceTypeExpandedSpec, expandedSpecLoading] = useInstanceTypeExpandSpec(vm);

const pages = useVirtualMachineTabs();

Expand All @@ -43,6 +43,7 @@ const VirtualMachineNavPage: React.FC<VirtualMachineDetailsPageProps> = ({
</Bullseye>
);
}

return (
<SidebarEditorProvider>
<VirtualMachineNavPageTitle
Expand All @@ -51,6 +52,7 @@ const VirtualMachineNavPage: React.FC<VirtualMachineDetailsPageProps> = ({
/>
<div className="VirtualMachineNavPage--tabs__main">
<HorizontalNavbar
expandedSpecLoading={expandedSpecLoading}
instanceTypeExpandedSpec={instanceTypeExpandedSpec}
pages={pages}
vm={vm}
Expand Down