generated from openshift/console-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from lokanandaprabhu/feature/pipeline-detail-page
ODC-7525: Move the Pipeline details page component to the dynamic plugin
- Loading branch information
Showing
118 changed files
with
8,540 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* eslint-disable tsdoc/syntax */ | ||
import * as _ from 'lodash-es'; | ||
import * as React from 'react'; | ||
import * as classNames from 'classnames'; | ||
import * as PropTypes from 'prop-types'; | ||
import { Alert, AlertGroup } from '@patternfly/react-core'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { LoadingInline } from '../status/status-box'; | ||
|
||
const injectDisabled = (children, disabled) => { | ||
return React.Children.map(children, (c) => { | ||
if (!_.isObject(c) || c.type !== 'button') { | ||
return c; | ||
} | ||
|
||
return React.cloneElement(c, { disabled: c.props.disabled || disabled }); | ||
}); | ||
}; | ||
|
||
const ErrorMessage = ({ message }) => { | ||
const { t } = useTranslation('plugin__pipelines-console-plugin'); | ||
return ( | ||
<Alert | ||
isInline | ||
className="co-alert co-alert--scrollable" | ||
variant="danger" | ||
title={t('An error occurred')} | ||
data-test="alert-error" | ||
> | ||
<div className="co-pre-line">{message}</div> | ||
</Alert> | ||
); | ||
}; | ||
const InfoMessage = ({ message }) => ( | ||
<Alert | ||
isInline | ||
className="co-alert" | ||
variant="info" | ||
title={message} | ||
data-test="button-bar-info-message" | ||
/> | ||
); | ||
const SuccessMessage = ({ message }) => ( | ||
<Alert isInline className="co-alert" variant="success" title={message} /> | ||
); | ||
|
||
// NOTE: DO NOT use <a> elements within a ButtonBar. | ||
// They don't support the disabled attribute, and therefore | ||
// can't be disabled during a pending promise/request. | ||
/** @type {React.SFC<{children: any, className?: string, errorMessage?: React.ReactNode, infoMessage?: string, successMessage?: string, inProgress?: boolean}}>} */ | ||
export const ButtonBar = ({ | ||
children, | ||
className, | ||
errorMessage, | ||
infoMessage, | ||
successMessage, | ||
inProgress, | ||
}) => { | ||
return ( | ||
<div className={classNames(className, 'co-m-btn-bar')}> | ||
<AlertGroup | ||
isLiveRegion | ||
aria-live="polite" | ||
aria-atomic="false" | ||
aria-relevant="additions text" | ||
> | ||
{successMessage && <SuccessMessage message={successMessage} />} | ||
{errorMessage && <ErrorMessage message={errorMessage} />} | ||
{injectDisabled(children, inProgress)} | ||
{inProgress && <LoadingInline />} | ||
{infoMessage && <InfoMessage message={infoMessage} />} | ||
</AlertGroup> | ||
</div> | ||
); | ||
}; | ||
|
||
ButtonBar.propTypes = { | ||
children: PropTypes.node.isRequired, | ||
successMessage: PropTypes.string, | ||
errorMessage: PropTypes.node, | ||
infoMessage: PropTypes.string, | ||
inProgress: PropTypes.bool, | ||
className: PropTypes.string, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
WatchK8sResource, | ||
useK8sWatchResource, | ||
} from '@openshift-console/dynamic-plugin-sdk'; | ||
import { TektonResourceLabel } from '../../consts'; | ||
import { PipelineRunModel } from '../../models'; | ||
import { PipelineRunKind } from '../../types'; | ||
import { getReferenceForModel } from '../pipelines-overview/utils'; | ||
import { getLatestRun } from '../utils/pipeline-augment'; | ||
|
||
export const useLatestPipelineRun = ( | ||
pipelineName: string, | ||
namespace: string, | ||
): PipelineRunKind => { | ||
const pipelineRunResource: WatchK8sResource = { | ||
kind: getReferenceForModel(PipelineRunModel), | ||
namespace, | ||
selector: { | ||
matchLabels: { [TektonResourceLabel.pipeline]: pipelineName }, | ||
}, | ||
optional: true, | ||
isList: true, | ||
}; | ||
const [pipelineRun, pipelineRunLoaded, pipelineRunError] = | ||
useK8sWatchResource<PipelineRunKind[]>(pipelineRunResource); | ||
|
||
const latestRun = getLatestRun(pipelineRun, 'creationTimestamp'); | ||
return pipelineRunLoaded && !pipelineRunError ? latestRun : null; | ||
}; |
Oops, something went wrong.