Skip to content

Commit

Permalink
feat(core/managed): support git compare link on versions (#8730)
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Munson authored Nov 12, 2020
1 parent 0429a97 commit f9b4a87
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/scripts/modules/core/src/domain/IManagedEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export interface IManagedArtifactVersion {
replacedBy?: string;
statefulConstraints?: IStatefulConstraint[];
statelessConstraints?: IStatelessConstraint[];
compareLink?: string;
}>;
build?: {
id: number; // deprecated, use number
Expand Down
10 changes: 10 additions & 0 deletions app/scripts/modules/core/src/managed/ArtifactDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { memo, useMemo } from 'react';
import ReactGA from 'react-ga';
import classNames from 'classnames';
import { useRouter } from '@uirouter/react';
import { useTransition, animated, UseTransitionProps } from 'react-spring';
Expand Down Expand Up @@ -91,6 +92,7 @@ const EnvironmentCards = memo(
vetoed,
statefulConstraints,
statelessConstraints,
compareLink,
} = environment;
const {
stateService: { go },
Expand Down Expand Up @@ -147,7 +149,15 @@ const EnvironmentCards = memo(
replacedAt={replacedAt}
replacedBy={replacedBy}
vetoed={vetoed}
compareLink={compareLink}
allVersions={allVersions}
logClick={(message) => {
ReactGA.event({
category: 'Environments - version details',
action: message,
label: `${application.name}:${environmentName}:${reference}`,
});
}}
/>
);
const constraintCards = useMemo(
Expand Down
1 change: 0 additions & 1 deletion app/scripts/modules/core/src/managed/ManagedReader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import { get, set, flatMap } from 'lodash';

import { API } from 'core/api';
Expand Down
28 changes: 25 additions & 3 deletions app/scripts/modules/core/src/managed/VersionStateCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Markdown, IconNames } from '../presentation';
import { getArtifactVersionDisplayName } from './displayNames';
import { StatusCard, IStatusCardProps } from './StatusCard';
import { Pill } from './Pill';
import { Button } from './Button';

interface CardTitleMetadata {
deployedAt?: string;
Expand Down Expand Up @@ -101,11 +102,20 @@ const cardAppearanceByState: { [state: string]: CardAppearance } = {

export type IVersionStateCardProps = Pick<
IManagedArtifactVersion['environments'][0],
'state' | 'deployedAt' | 'replacedAt' | 'replacedBy' | 'vetoed'
> & { allVersions: IManagedArtifactVersion[] };
'state' | 'deployedAt' | 'replacedAt' | 'replacedBy' | 'vetoed' | 'compareLink'
> & { allVersions: IManagedArtifactVersion[]; logClick: (message: string) => any };

export const VersionStateCard = memo(
({ state, deployedAt, replacedAt, replacedBy, vetoed, allVersions }: IVersionStateCardProps) => {
({
state,
deployedAt,
replacedAt,
replacedBy,
vetoed,
compareLink,
allVersions,
logClick,
}: IVersionStateCardProps) => {
const replacedByVersion = useMemo(() => allVersions.find(({ version }) => version === replacedBy), [
replacedBy,
allVersions,
Expand All @@ -126,6 +136,18 @@ export const VersionStateCard = memo(
timestamp={cardAppearanceByState[state].timestamp?.(cardMetadata)}
title={cardAppearanceByState[state].title(cardMetadata)}
description={cardAppearanceByState[state].description?.(cardMetadata)}
actions={
compareLink && (
<Button
onClick={() => {
window.open(compareLink, '_blank', 'noopener noreferrer');
logClick('See changes clicked');
}}
>
See changes
</Button>
)
}
/>
);
},
Expand Down

0 comments on commit f9b4a87

Please sign in to comment.