-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Installed badge and update the alert content for upgrading task
- Loading branch information
1 parent
0183e3b
commit 412c2b6
Showing
9 changed files
with
348 additions
and
77 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
10 changes: 9 additions & 1 deletion
10
...tend/packages/pipelines-plugin/src/components/quicksearch/PipelineQuickSearchDetails.scss
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
44 changes: 44 additions & 0 deletions
44
...end/packages/pipelines-plugin/src/components/quicksearch/PipelineQuickSearchTaskAlert.tsx
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,44 @@ | ||
import * as React from 'react'; | ||
import { Alert } from '@patternfly/react-core'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { CTALabel } from './const'; | ||
|
||
interface PipelineQuickSearchTaskAlertProps { | ||
ctaType: string; | ||
} | ||
|
||
const PipelineQuickSearchTaskAlert: React.FC<PipelineQuickSearchTaskAlertProps> = ({ ctaType }) => { | ||
const { t } = useTranslation(); | ||
switch (ctaType) { | ||
case CTALabel.Install: | ||
return ( | ||
<Alert | ||
className="co-alert" | ||
variant="info" | ||
title={t('pipelines-plugin~This task is not installed')} | ||
isInline | ||
> | ||
<p>{t('pipelines-plugin~Adding this task may take a few moments.')}</p> | ||
</Alert> | ||
); | ||
case CTALabel.Update: | ||
return ( | ||
<Alert | ||
className="co-alert" | ||
title={t('pipelines-plugin~Task version will be updated across all instances')} | ||
variant="warning" | ||
isInline | ||
> | ||
<p> | ||
{t( | ||
`pipelines-plugin~Only update this task's version if you'd like to replace all of its references in the namespace.`, | ||
)} | ||
</p> | ||
</Alert> | ||
); | ||
default: | ||
return null; | ||
} | ||
}; | ||
|
||
export default PipelineQuickSearchTaskAlert; |
66 changes: 66 additions & 0 deletions
66
...ckages/pipelines-plugin/src/components/quicksearch/PipelineQuickSearchVersionDropdown.tsx
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,66 @@ | ||
import * as React from 'react'; | ||
import { Dropdown, DropdownItem, DropdownToggle } from '@patternfly/react-core'; | ||
import { CheckCircleIcon } from '@patternfly/react-icons'; | ||
import { global_palette_green_500 as greenColor } from '@patternfly/react-tokens/dist/js/global_palette_green_500'; | ||
import i18n from 'i18next'; | ||
import { CatalogItem } from 'packages/console-dynamic-plugin-sdk/src'; | ||
import { isSelectedVersionInstalled } from './pipeline-quicksearch-utils'; | ||
|
||
interface PipelineQuickSearchVersionDropdownProps { | ||
selectedVersion: string; | ||
item: CatalogItem; | ||
onChange: (key: string) => void; | ||
} | ||
|
||
const PipelineQuickSearchVersionDropdown: React.FC<PipelineQuickSearchVersionDropdownProps> = ({ | ||
item, | ||
onChange, | ||
selectedVersion, | ||
}) => { | ||
const [isOpen, setOpen] = React.useState(false); | ||
const toggleIsOpen = React.useCallback(() => setOpen((v) => !v), []); | ||
const versions = item?.attributes?.versions ?? []; | ||
const versionItems = versions.reduce((acc, { version, id }) => { | ||
acc[id.toString()] = | ||
id === item.data?.latestVersion?.id | ||
? `${version} ${i18n.t('pipelines-plugin~(latest)')}` | ||
: version; | ||
return acc; | ||
}, {}); | ||
|
||
return versions.length === 0 ? null : ( | ||
<Dropdown | ||
data-test={'task-version'} | ||
className="opp-quick-search-details__version-dropdown" | ||
dropdownItems={Object.keys(versionItems).map((key) => ( | ||
<DropdownItem | ||
component="button" | ||
key={key} | ||
label={versionItems[key]} | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
onChange(key); | ||
setOpen(false); | ||
}} | ||
> | ||
<div className="opp-quick-search-details__version-dropdown-item"> | ||
{versionItems[key]} | ||
{isSelectedVersionInstalled(item, key) && <CheckCircleIcon color={greenColor.value} />} | ||
</div> | ||
</DropdownItem> | ||
))} | ||
isOpen={isOpen} | ||
toggle={ | ||
<DropdownToggle | ||
isDisabled={versions.length === 1} | ||
data-test={'task-version-toggle'} | ||
onToggle={toggleIsOpen} | ||
> | ||
{versionItems[selectedVersion]} | ||
</DropdownToggle> | ||
} | ||
/> | ||
); | ||
}; | ||
|
||
export default PipelineQuickSearchVersionDropdown; |
38 changes: 38 additions & 0 deletions
38
...s-plugin/src/components/quicksearch/__tests__/PipelineQuickSearchVersionDropdown.spec.tsx
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,38 @@ | ||
import * as React from 'react'; | ||
import { render, cleanup, waitFor, configure } from '@testing-library/react'; | ||
import { omit } from 'lodash'; | ||
import PipelineQuickSearchVersionDropdown from '../PipelineQuickSearchVersionDropdown'; | ||
import { sampleClusterTaskCatalogItem } from './pipeline-quicksearch-data'; | ||
|
||
configure({ testIdAttribute: 'data-test' }); | ||
|
||
describe('pipelineQuickSearchVersionDropdown', () => { | ||
const versionDropdownProps = { | ||
item: sampleClusterTaskCatalogItem, | ||
selectedVersion: '0.1', | ||
onChange: jest.fn(), | ||
}; | ||
|
||
afterEach(() => cleanup()); | ||
|
||
it('should not show version dropdown if there are no versions available', async () => { | ||
const { queryByTestId } = render( | ||
<PipelineQuickSearchVersionDropdown | ||
{...versionDropdownProps} | ||
item={omit(sampleClusterTaskCatalogItem, 'attributes.versions')} | ||
/>, | ||
); | ||
await waitFor(() => { | ||
expect(queryByTestId('task-version')).toBeNull(); | ||
}); | ||
}); | ||
|
||
it('should show the version dropdown if there are versions available', async () => { | ||
const { queryByTestId } = render( | ||
<PipelineQuickSearchVersionDropdown {...versionDropdownProps} />, | ||
); | ||
await waitFor(() => { | ||
expect(queryByTestId('task-version')).not.toBeNull(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.