Skip to content

Commit

Permalink
Add Installed badge and update the alert content for upgrading task
Browse files Browse the repository at this point in the history
  • Loading branch information
karthikjeeyar committed Aug 26, 2021
1 parent 0183e3b commit 0c5259e
Show file tree
Hide file tree
Showing 10 changed files with 440 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,17 @@
"Create Pipeline": "Create Pipeline",
"by name": "by name",
"Select a Project to view its details or <2>create a Project</2>.": "Select a Project to view its details or <2>create a Project</2>.",
"Install and Add": "Install and Add",
"Update and Add": "Update and Add",
"Install and add": "Install and add",
"Update and add": "Update and add",
"View all tekton tasks ({{itemCount, number}})": "View all tekton tasks ({{itemCount, number}})",
"This version is not installed": "This version is not installed",
"Adding this task may take a few moments.": "Adding this task may take a few moments.",
"Upgrading this task may take a few moments.": "Upgrading this task may take a few moments.",
"Installed": "Installed",
"Categories": "Categories",
"Tags": "Tags",
"This task is not installed": "This task is not installed",
"Adding this task may take a few moments.": "Adding this task may take a few moments.",
"Task version will be updated across all instances": "Task version will be updated across all instances",
"Only update this task's version if you'd like to replace all of its references in the namespace.": "Only update this task's version if you'd like to replace all of its references in the namespace.",
"{{version}} (latest)": "{{version}} (latest)",
"Event type": "Event type",
"Last run duration": "Last run duration",
"Repository details": "Repository details",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
isTaskSearchable,
updateTask,
} from './pipeline-quicksearch-utils';
import PipelineQuickSearchDetails from './PiplineQuickSearchDetails';
import PipelineQuickSearchDetails from './PipelineQuickSearchDetails';

interface QuickSearchProps {
namespace: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
.opp-quick-search-details {
padding-top: var(--pf-global--spacer--md);

&__form-button {
&__form-button,
&__version-dropdown {
margin: var(--pf-global--spacer--md) 0px !important;
width: max-content;
}

&__version-dropdown-item {
min-width: 7em;
display: flex;
justify-content: space-between;
align-items: center;
}

&__provider {
color: var(--pf-global--Color--200);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import * as React from 'react';
import {
Button,
ButtonVariant,
Label,
LabelGroup,
Level,
LevelItem,
Split,
SplitItem,
Stack,
StackItem,
TextContent,
Title,
} from '@patternfly/react-core';
import { CheckCircleIcon } from '@patternfly/react-icons';
import { useTranslation } from 'react-i18next';
import { handleCta } from '@console/shared';
import { QuickSearchDetailsRendererProps } from '@console/shared/src/components/quick-search/QuickSearchDetails';
import { useTelemetry } from '@console/shared/src/hooks/useTelemetry';
import {
getCtaButtonText,
getTaskCtaType,
isOneVersionInstalled,
isTaskVersionInstalled,
} from './pipeline-quicksearch-utils';
import PipelineQuickSearchTaskAlert from './PipelineQuickSearchTaskAlert';
import PipelineQuickSearchVersionDropdown from './PipelineQuickSearchVersionDropdown';

import './PipelineQuickSearchDetails.scss';

const PipelineQuickSearchDetails: React.FC<QuickSearchDetailsRendererProps> = ({
selectedItem,
closeModal,
}) => {
const { t } = useTranslation();
const fireTelemetryEvent = useTelemetry();
const [selectedVersion, setSelectedVersion] = React.useState<string>();
const versions = selectedItem?.attributes?.versions ?? [];

React.useEffect(() => {
if (isTaskVersionInstalled(selectedItem)) {
setSelectedVersion(selectedItem.attributes.installed);
} else {
setSelectedVersion(selectedItem.data?.latestVersion?.id?.toString());
}
}, [selectedItem]);

return (
<div className="opp-quick-search-details">
<Level hasGutter>
<LevelItem>
<Title data-test="task-name" headingLevel="h4">
{selectedItem.name}
</Title>
</LevelItem>
<LevelItem>
<Label data-test="task-provider">{selectedItem.provider}</Label>
</LevelItem>
</Level>
<Level hasGutter>
<LevelItem>
<Split hasGutter>
<SplitItem>
<Button
data-test="task-cta"
variant={ButtonVariant.primary}
className="opp-quick-search-details__form-button"
onClick={(e) => {
handleCta(e, selectedItem, closeModal, fireTelemetryEvent, { selectedVersion });
}}
>
{getCtaButtonText(selectedItem, selectedVersion)}
</Button>
</SplitItem>
{versions.length > 0 && (
<SplitItem data-test="task-version-dropdown">
<PipelineQuickSearchVersionDropdown
item={selectedItem}
selectedVersion={selectedVersion}
onChange={(key) => setSelectedVersion(key)}
/>
</SplitItem>
)}
</Split>
</LevelItem>
{isOneVersionInstalled(selectedItem) && (
<LevelItem>
<Label color="green" icon={<CheckCircleIcon />} data-test="task-installed-badge">
{t('pipelines-plugin~Installed')}
</Label>
</LevelItem>
)}
</Level>
{<PipelineQuickSearchTaskAlert ctaType={getTaskCtaType(selectedItem, selectedVersion)} />}
<TextContent className="opp-quick-search-details__description" data-test="task-description">
{selectedItem.description}
</TextContent>
<Stack className="opp-quick-search-details__badges-section" hasGutter>
{selectedItem?.attributes?.categories?.length > 0 && (
<StackItem>
<LabelGroup
categoryName={t('pipelines-plugin~Categories')}
data-test="task-category-list"
>
{selectedItem?.attributes?.categories.map((category) => (
<Label color="blue" key={category} data-test="task-category-list-item">
{category}
</Label>
))}
</LabelGroup>
</StackItem>
)}
{selectedItem?.tags?.length > 0 && (
<StackItem>
<LabelGroup categoryName={t('pipelines-plugin~Tags')} data-test="task-tag-list">
{selectedItem.tags.map((tag) => (
<Label color="blue" key={tag} data-test="task-tag-list-item">
{tag}
</Label>
))}
</LabelGroup>
</StackItem>
)}
</Stack>
</div>
);
};

export default PipelineQuickSearchDetails;
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;
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';
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
? i18n.t('pipelines-plugin~{{version}} (latest)', { version })
: 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;

0 comments on commit 0c5259e

Please sign in to comment.