Skip to content

Commit

Permalink
NCL-8947 Disable last revision for revision detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
DnsZhou committed Jan 3, 2025
1 parent eb23ce3 commit 6d68a85
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
16 changes: 15 additions & 1 deletion src/components/BuildConfigDetailPage/BuilConfigRevisionPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useEffect } from 'react';
import { useOutletContext } from 'react-router-dom';

import { useParamsRequired } from 'hooks/useParamsRequired';
import { useServiceContainer } from 'hooks/useServiceContainer';
Expand All @@ -7,8 +8,13 @@ import { BuildConfigDetail } from 'components/BuildConfigDetailPage/BuildConfigD

import * as buildConfigApi from 'services/buildConfigApi';

interface IOutletContext {
isCurrentRevision: boolean;
}

export const BuildConfigRevisionPage = () => {
const { buildConfigId, revisionId } = useParamsRequired();
const { isCurrentRevision } = useOutletContext<IOutletContext>();

const serviceContainerBuildConfigRevision = useServiceContainer(buildConfigApi.getRevision);
const serviceContainerBuildConfigRevisionRunner = serviceContainerBuildConfigRevision.run;
Expand All @@ -17,5 +23,13 @@ export const BuildConfigRevisionPage = () => {
serviceContainerBuildConfigRevisionRunner({ serviceData: { buildConfigId, buildConfigRev: Number(revisionId) } });
}, [serviceContainerBuildConfigRevisionRunner, buildConfigId, revisionId]);

return <BuildConfigDetail {...{ serviceContainerBuildConfig: serviceContainerBuildConfigRevision }} isRevisionVariant />;
return (
<BuildConfigDetail
{...{
serviceContainerBuildConfig: serviceContainerBuildConfigRevision,
isRevisionVariant: true,
isCurrentRevision,
}}
/>
);
};
4 changes: 3 additions & 1 deletion src/components/BuildConfigDetailPage/BuildConfigDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ interface IBuildConfigDetailProps {
serviceContainerBuildConfig: IServiceContainerState<BuildConfiguration | BuildConfigurationRevision>;
serviceContainerProductVersion?: IServiceContainerState<ProductVersion>;
isRevisionVariant?: boolean;
isCurrentRevision?: boolean;
}

export const BuildConfigDetail = ({
serviceContainerBuildConfig,
serviceContainerProductVersion,
isRevisionVariant = false,
isCurrentRevision = true,
}: IBuildConfigDetailProps) => {
const [isRestoreModalOpen, setIsRestoreModalOpen] = useState<boolean>(false);
const toggleRestoreModal = () => setIsRestoreModalOpen((isRestoreModalOpen) => !isRestoreModalOpen);
Expand All @@ -60,7 +62,7 @@ export const BuildConfigDetail = ({
</ToolbarItem>
{isRevisionVariant && (
<ToolbarItem alignRight>
<BuildConfigRestoreModalButton toggleModal={toggleRestoreModal} />
<BuildConfigRestoreModalButton toggleModal={toggleRestoreModal} isDisabled={isCurrentRevision} />
</ToolbarItem>
)}
</Toolbar>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import { ProtectedComponent } from 'components/ProtectedContent/ProtectedCompone

interface IBuildConfigRestoreModalButtonProps {
toggleModal: () => void;
isDisabled?: boolean;
}

export const BuildConfigRestoreModalButton = ({ toggleModal }: IBuildConfigRestoreModalButtonProps) => (
export const BuildConfigRestoreModalButton = ({ toggleModal, isDisabled = false }: IBuildConfigRestoreModalButtonProps) => (
<ProtectedComponent>
<Button variant="primary" onClick={toggleModal} size="sm">
Restore
</Button>
<div title={isDisabled ? 'Restore button is disabled for the current revision' : undefined}>
<Button variant="primary" onClick={toggleModal} size="sm" isDisabled={isDisabled}>
Restore
</Button>
</div>
</ProtectedComponent>
);
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Grid, GridItem } from '@patternfly/react-core';
import { useCallback } from 'react';
import { useCallback, useEffect, useState } from 'react';
import { Outlet, useLocation, useNavigate, useParams } from 'react-router-dom';

import { useParamsRequired } from 'hooks/useParamsRequired';
Expand All @@ -10,6 +10,8 @@ import { BuildConfigRevisionsList } from 'components/BuildConfigRevisionsList/Bu

import * as buildConfigApi from 'services/buildConfigApi';

import { getComponentQueryParamValue } from 'utils/queryParamsHelper';

interface IBuildConfigDetailPageProps {
componentId?: string;
}
Expand All @@ -23,6 +25,8 @@ export const BuildConfigRevisionPages = ({ componentId = 'r1' }: IBuildConfigDet
const serviceContainerBuildConfigRevisions = useServiceContainer(buildConfigApi.getRevisions);
const serviceContainerBuildConfigRevisionsRunner = serviceContainerBuildConfigRevisions.run;

const [isCurrentRevision, setIsCurrentRevision] = useState<boolean>(false);

if (!revisionId && serviceContainerBuildConfigRevisions.data?.content?.length) {
navigate(serviceContainerBuildConfigRevisions.data.content.at(0)?.rev + search, { replace: true });
}
Expand All @@ -36,13 +40,23 @@ export const BuildConfigRevisionPages = ({ componentId = 'r1' }: IBuildConfigDet
{ componentId, mandatoryQueryParams: listMandatoryQueryParams.pagination }
);

useEffect(() => {
const pageIndex = getComponentQueryParamValue(search, 'pageIndex', componentId);
if (serviceContainerBuildConfigRevisions.data?.content?.length && pageIndex === '1') {
const latestRev = serviceContainerBuildConfigRevisions.data.content[0]?.rev;
setIsCurrentRevision(String(latestRev) === revisionId);
} else {
setIsCurrentRevision(false);
}
}, [serviceContainerBuildConfigRevisions.data, revisionId, search, componentId]);

return (
<Grid hasGutter>
<GridItem sm={12} lg={3}>
<BuildConfigRevisionsList {...{ serviceContainerBuildConfigRevisions, componentId, selectedRevision: revisionId }} />
</GridItem>
<GridItem sm={12} lg={9}>
<Outlet />
<Outlet context={{ isCurrentRevision }} />
</GridItem>
</Grid>
);
Expand Down

0 comments on commit 6d68a85

Please sign in to comment.