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
Bug 1830181: Hide 'Start Last Run' button on topology overview page when no PLR present #5258
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you also change the button logic to be more deterministic?
Making sure we have a callback to use before enabling the button will help if there is ever an issue with the callback, we don't have a button enabled without a callback. EDIT: Updated the logic, thanks for catching the mistake |
||
<Button variant="secondary" onClick={callback} isDisabled={pipelineRuns.length === 0}> | ||
<Button | ||
variant="secondary" | ||
onClick={callback} | ||
isDisabled={pipelineRuns.length === 0 && !callback} | ||
> | ||
{label} | ||
</Button> | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While debugging the solution... I noticed a bug I accidentally made, can correct at the same time here?
In pipelineruns/triggered-by/hooks.ts:
That way it doesn't merge a label onto nothing creating an invalid k8s object.