Skip to content

Commit

Permalink
Merge pull request #5258 from vikram-raj/odc-2403
Browse files Browse the repository at this point in the history
Bug 1830181: Hide 'Start Last Run' button on topology overview page when no PLR present
  • Loading branch information
openshift-merge-robot committed May 5, 2020
2 parents b19ffe0 + 40e1ae0 commit 325beb0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
Expand Up @@ -26,7 +26,7 @@ export const useUserLabelForManualStart = (): LabelMap => {
export const usePipelineRunWithUserLabel = (plr: PipelineRun): PipelineRun => {
const labels = useUserLabelForManualStart();

return mergeLabelsWithResource(labels, plr);
return plr && mergeLabelsWithResource(labels, plr);
};

export const useMenuActionsWithUserLabel = (menuActions: KebabAction[]): KebabAction[] => {
Expand Down
Expand Up @@ -52,7 +52,7 @@ const PipelinesOverview: React.FC<PipelinesOverviewProps> = ({
/>
</FlexItem>
<FlexItem>
<TriggerLastRunButton pipelineRuns={pipelineRuns} />
<TriggerLastRunButton pipelineRuns={pipelineRuns} namespace={namespace} />
</FlexItem>
</Flex>
</li>
Expand Down
@@ -1,30 +1,48 @@
import * as React from 'react';
import * as _ from 'lodash';
import { connect } from 'react-redux';
import { Button } from '@patternfly/react-core';
import { impersonateStateToProps } from '@console/internal/reducers/ui';
import { useAccessReview } from '@console/internal/components/utils';
import { Button } from '@patternfly/react-core';
import { AccessReviewResourceAttributes } from '@console/internal/module/k8s';
import { rerunPipelineAndStay } from '../../../utils/pipeline-actions';
import { PipelineModel } from '../../../models';
import { PipelineRunModel } from '../../../models';
import { usePipelineRunWithUserLabel } from '../../pipelineruns/triggered-by';
import { getLatestRun, PipelineRun } from '../../../utils/pipeline-augment';

type TriggerLastRunButtonProps = {
pipelineRuns: PipelineRun[];
namespace: string;
impersonate?;
};

const TriggerLastRunButton: React.FC<TriggerLastRunButtonProps> = ({
pipelineRuns,
namespace,
impersonate,
}) => {
const latestRun = usePipelineRunWithUserLabel(
getLatestRun({ data: pipelineRuns }, 'startTimestamp'),
);
const { label, callback, accessReview } = rerunPipelineAndStay(PipelineModel, latestRun);
const { label, callback, accessReview: utilityAccessReview } = rerunPipelineAndStay(
PipelineRunModel,
latestRun,
);
const defaultAccessReview: AccessReviewResourceAttributes = {
group: PipelineRunModel.apiGroup,
resource: PipelineRunModel.plural,
namespace,
verb: 'create',
};
const accessReview = _.isEmpty(utilityAccessReview) ? defaultAccessReview : utilityAccessReview;
const isAllowed = useAccessReview(accessReview, impersonate);
return (
isAllowed && (
<Button variant="secondary" onClick={callback} isDisabled={pipelineRuns.length === 0}>
<Button
variant="secondary"
onClick={callback}
isDisabled={pipelineRuns.length === 0 && !callback}
>
{label}
</Button>
)
Expand Down

0 comments on commit 325beb0

Please sign in to comment.