Skip to content

Commit

Permalink
feat(md): redesign of artifacts - metadata + rollback and compare to …
Browse files Browse the repository at this point in the history
…UX (#9738)

* feat(md): redesign of rollback interactions + redesign of versions metadata

* fix(pr): use reject instead of never deploy

* fix(pr): removed the red color from the rollback button
  • Loading branch information
ranihorev committed Oct 6, 2021
1 parent 5848b4d commit ae940a0
Show file tree
Hide file tree
Showing 23 changed files with 709 additions and 479 deletions.
6 changes: 3 additions & 3 deletions packages/core/src/managed/Environments.less
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.Environments2 {
.Environments {
width: 100%;
padding: 0 var(--l-spacing);
--base-horizontal-padding: var(--xl-spacing);
Expand Down Expand Up @@ -55,11 +55,11 @@
display: grid;
gap: var(--m-spacing);
align-items: flex-start;
--row-element-icon-width: 40px;
--row-element-icon-width: 32px;

&.grid-view {
gap: var(--xl-spacing) var(--m-spacing);
--row-element-icon-width: 32px;
--row-element-icon-width: 26px;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/managed/Environments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const Environments = () => {
}, [params]);

return (
<div className="vertical Environments2">
<div className="vertical Environments">
<HorizontalTabs
tabs={tabs}
rightElement={!state.name?.endsWith('.config') ? <EnvironmentsDirectionController /> : undefined}
Expand Down
14 changes: 8 additions & 6 deletions packages/core/src/managed/RelativeTimestamp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ export const DurationRender: React.FC<{ startedAt: string; completedAt?: string
return <>{timeDiffToString(startAtDateTime, endTime)}</>;
};

const toDateTime = (timestamp: DateTime | string | number) =>
typeof timestamp === 'number'
? DateTime.fromMillis(timestamp)
: typeof timestamp === 'string'
? DateTime.fromISO(timestamp)
: timestamp;

export const formatToRelativeTimestamp = (timestamp: DateTime, withSuffix: boolean) => {
const distance = getDistanceFromNow(timestamp);
const suffix = withSuffix ? ' ago' : '';
Expand Down Expand Up @@ -68,12 +75,7 @@ export const RelativeTimestamp = memo(
removeStyles,
withSuffix = false,
}: IRelativeTimestampProps) => {
const dateTimeTimestamp =
typeof originalTimestamp === 'number'
? DateTime.fromMillis(originalTimestamp)
: typeof originalTimestamp === 'string'
? DateTime.fromISO(originalTimestamp)
: originalTimestamp;
const dateTimeTimestamp = toDateTime(originalTimestamp);
const timestamp = TIMEZONE ? dateTimeTimestamp.setZone(TIMEZONE) : dateTimeTimestamp;
const [formattedTimestamp, setFormattedTimestamp] = useState(formatToRelativeTimestamp(timestamp, withSuffix));

Expand Down
77 changes: 77 additions & 0 deletions packages/core/src/managed/artifactActions/ArtifactActions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import classnames from 'classnames';
import React from 'react';
import { Dropdown, MenuItem } from 'react-bootstrap';

import { ACTION_BUTTON_CLASS_NAME } from '../utils/defaults';
import { useLogEvent } from '../utils/logging';
import type { ICompareLinks } from '../versionMetadata/MetadataComponents';

export interface VersionAction {
onClick?: () => void;
href?: string;
content: string;
disabled?: boolean;
}

interface IArtifactActionsProps {
actions?: VersionAction[];
version: string;
buildNumber?: string;
compareLinks?: ICompareLinks;
className?: string;
}

export const ArtifactActions = ({ version, buildNumber, actions, compareLinks, className }: IArtifactActionsProps) => {
const compareActions: VersionAction[] = [
{ content: 'Current version', href: compareLinks?.current, disabled: !compareLinks?.current },
{ content: 'Previous version', href: compareLinks?.previous, disabled: !compareLinks?.previous },
];
return (
<div className={classnames('horizontal md-actions-gap', className)}>
{actions?.map((action) => (
<button
key={action.content}
className={ACTION_BUTTON_CLASS_NAME}
disabled={action.disabled}
onClick={action.onClick}
>
{action.content}
</button>
))}
<CompareToMenu id={`${version}-${buildNumber}-compare`} title="Compare to" actions={compareActions} />
</div>
);
};

export interface ICompareToMenuProps {
id: string;
actions: VersionAction[];
title: string;
className?: string;
pullRight?: boolean;
}

const CompareToMenu = ({ id, title, actions, className, pullRight }: ICompareToMenuProps) => {
const logEvent = useLogEvent('ArtifactActions');
return (
<Dropdown id={id} className={classnames('ArtifactActionsMenu', className)} pullRight={pullRight}>
<Dropdown.Toggle className="md-btn md-action-button">{title}</Dropdown.Toggle>
<Dropdown.Menu>
{actions.map((action, index) => (
<MenuItem
key={index}
disabled={action.disabled}
onClick={() => {
action.onClick?.();
logEvent({ action: `Compare to - ${action.content}` });
}}
href={action.href}
target="_blank"
>
{action.content}
</MenuItem>
))}
</Dropdown.Menu>
</Dropdown>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface IEnvironmentItemProps {
iconTooltip: string;
iconName: IIconProps['name'];
size?: 'regular' | 'small';
rightElement?: React.ReactElement;
}

export const EnvironmentItem: React.FC<IEnvironmentItemProps> = ({
Expand All @@ -20,6 +21,7 @@ export const EnvironmentItem: React.FC<IEnvironmentItemProps> = ({
iconName,
iconTooltip,
className,
rightElement,
children,
}) => {
return (
Expand All @@ -29,12 +31,15 @@ export const EnvironmentItem: React.FC<IEnvironmentItemProps> = ({
tooltip={iconTooltip}
name={iconName}
color="primary-g1"
size={size === 'regular' ? '18px' : '16px'}
size={size === 'regular' ? '16px' : '14px'}
delayShow={TOOLTIP_DELAY_SHOW}
/>
</div>
<div className="row-details">
<div className={classnames('row-title', size)}>{title}</div>
<div className={classnames('row-title', size)}>
{title}
{rightElement && <div>{rightElement}</div>}
</div>
{children}
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/managed/overview/EnvironmentOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const EnvironmentOverview = ({ environment }: IEnvironmentProps) => {
const resources = data?.application?.environments.find((env) => env.name === environment.name)?.state.resources;
const hasResourcesWithIssues = resources?.some((resource) => resource.state?.status !== 'UP_TO_DATE');
const state = environment.state;

return (
<BaseEnvironment
name={environment.name}
Expand All @@ -34,7 +35,9 @@ export const EnvironmentOverview = ({ environment }: IEnvironmentProps) => {
>
<CollapsibleSection heading="Artifacts" {...sectionProps} defaultExpanded enableCaching={false}>
{state.artifacts?.length ? (
state.artifacts.map((artifact) => <Artifact key={artifact.reference} artifact={artifact} />)
state.artifacts.map((artifact) => (
<Artifact key={artifact.reference} artifact={artifact} isPreview={environment.isPreview} />
))
) : (
<NoItemsMessage>No artifacts found</NoItemsMessage>
)}
Expand Down
50 changes: 13 additions & 37 deletions packages/core/src/managed/overview/artifact/Artifact.less
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
.Artifact {
--version-left-padding: 18px;
--version-left-padding: 0px;

@media (max-width: 768px) {
--version-left-padding: 14px;
}

.artifact-rollback-actions {
}

.artifact-current-version {
display: flex;
flex-direction: column;
Expand All @@ -21,7 +24,7 @@
}

.artifact-pending-versions {
margin-top: var(--l-spacing);
margin-top: var(~'--2xl-spacing');
position: relative;
--circle-shift: 6px;

Expand All @@ -36,48 +39,13 @@
.artifact-pending-version {
display: flex;
flex-direction: column;
padding-right: var(--l-spacing);
position: relative;
padding-left: var(--version-left-padding);

&:not(:last-of-type) {
padding-bottom: 32px;
}

// Line
&::before {
content: '';
position: absolute;
top: 0;
left: calc(4px);
height: 100%;
border-left: 2px solid var(--color-accent-g2);
}

// circle
&::after {
content: '';
position: absolute;
top: var(--circle-shift);
left: 0;
width: 10px;
height: 10px;
background: var(--color-accent-g2);
border-radius: 50%;
}

&:last-of-type {
&::before {
height: var(--circle-shift);
}
}

&:first-of-type {
&::before {
top: var(--circle-shift);
}
}

.artifact-pending-version-commit {
font-weight: 600;
display: flex;
Expand All @@ -96,4 +64,12 @@
color: var(--color-warning);
}
}

.VersionTitle {
display: grid;
grid-template-columns: minmax(auto, max-content) auto;
align-items: baseline;
column-gap: 20px;
justify-content: flex-start;
}
}
80 changes: 59 additions & 21 deletions packages/core/src/managed/overview/artifact/Artifact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import React from 'react';
import { CurrentVersion } from './CurrentVersion';
import { PendingVersions } from './PendingVersion';
import { EnvironmentItem } from '../../environmentBaseElements/EnvironmentItem';
import { HoverablePopover, Markdown } from '../../../presentation';
import { useMarkVersionAsBad } from './hooks';
import { HoverablePopover, Markdown, useApplicationContextSafe } from '../../../presentation';
import type { QueryArtifact, QueryArtifactVersion } from '../types';
import { tooltipShowHideProps } from '../../utils/defaults';
import { isVersionVetoed } from './utils';
import { ACTION_BUTTON_CLASS_NAME, tooltipShowHideProps } from '../../utils/defaults';
import { toPinnedMetadata } from '../../versionMetadata/MetadataComponents';

import './Artifact.less';
Expand Down Expand Up @@ -57,35 +59,71 @@ export const PinnedVersion = ({ version }: { version: NonNullable<QueryArtifact[
</div>
);
};
interface IRollbackActionProps {
currentVersion: QueryArtifactVersion;
environment: string;
reference: string;
isPinned: boolean;
}

const RollbackAction = ({ currentVersion, environment, reference, isPinned }: IRollbackActionProps) => {
const appName = useApplicationContextSafe().name;
const onMarkAsBad = useMarkVersionAsBad({
application: appName,
environment,
reference,
version: currentVersion.version,
isVetoed: isVersionVetoed(currentVersion),
isPinned,
isCurrent: true,
selectedVersion: {
buildNumber: currentVersion.buildNumber,
commitMessage: currentVersion.gitMetadata?.commitInfo?.message,
commitSha: currentVersion.gitMetadata?.commit,
},
});
return (
<button className={ACTION_BUTTON_CLASS_NAME} onClick={onMarkAsBad}>
Rollback...
</button>
);
};

interface IArtifactProps {
artifact: QueryArtifact;
isPreview?: boolean;
}

export const Artifact = ({ artifact }: IArtifactProps) => {
const currentVersion = artifact.versions?.find((version) => version.isCurrent === true);
const newerVersions = filterPendingVersions(artifact.versions, currentVersion);
const { pinnedVersion } = artifact;

export const Artifact = ({ artifact, isPreview }: IArtifactProps) => {
const { environment, type, reference, versions, pinnedVersion } = artifact;
const currentVersion = versions?.find((version) => version.isCurrent === true);
const newerVersions = filterPendingVersions(versions, currentVersion);
return (
<EnvironmentItem
iconName="artifact"
iconTooltip={`Artifact - ${artifact.type}`}
iconTooltip={`Artifact - ${type}`}
className="Artifact"
title={artifact.reference}
title={reference}
rightElement={
currentVersion && !isPreview ? (
<RollbackAction {...{ environment, currentVersion, reference }} isPinned={Boolean(pinnedVersion)} />
) : undefined
}
>
<div className="artifact-versions-title sp-margin-m-top">Current version</div>
{currentVersion ? (
<CurrentVersion
data={currentVersion}
environment={artifact.environment}
reference={artifact.reference}
numNewerVersions={newerVersions?.length}
pinned={pinnedVersion?.version === currentVersion.version ? toPinnedMetadata(pinnedVersion) : undefined}
/>
) : (
<div>No version is deployed</div>
)}
<div className="sp-margin-m-top">
{currentVersion ? (
<CurrentVersion
data={currentVersion}
environment={environment}
reference={reference}
numNewerVersions={newerVersions?.length}
pinned={pinnedVersion?.version === currentVersion.version ? toPinnedMetadata(pinnedVersion) : undefined}
isPreview={isPreview}
/>
) : (
<div>No version is deployed</div>
)}
</div>
{pinnedVersion && pinnedVersion.buildNumber !== currentVersion?.buildNumber && (
<PinnedVersion version={pinnedVersion} />
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.ArtifactActionModal {
.details {
display: grid;
grid-template-columns: auto 1fr;
column-gap: 10px;
align-items: baseline;

dd {
min-width: 0;
}

dt {
font-weight: 600;
text-transform: uppercase;
font-size: 13px;
color: var(--color-concrete);
}
}
}
Loading

0 comments on commit ae940a0

Please sign in to comment.