-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(md): split artifactDetail to smaller files (#8922)
Co-authored-by: Chris Thielen <christopherthielen@users.noreply.github.com>
- Loading branch information
1 parent
78f7d5a
commit acac332
Showing
5 changed files
with
189 additions
and
143 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
111 changes: 111 additions & 0 deletions
111
app/scripts/modules/core/src/managed/artifactDetail/EnvironmentCards.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,111 @@ | ||
import React from 'react'; | ||
import { useRouter } from '@uirouter/react'; | ||
|
||
import { IManagedArtifactVersionEnvironment } from 'core/domain'; | ||
|
||
import { Button } from '../Button'; | ||
import { StatusCard } from '../StatusCard'; | ||
import { logCategories, useLogEvent } from '../utils/logging'; | ||
import { IArtifactDetailProps } from './ArtifactDetail'; | ||
import { ConstraintCard } from './constraints/ConstraintCard'; | ||
import { isConstraintSupported } from './constraints/constraintRegistry'; | ||
import { PinnedCard } from './PinnedCard'; | ||
import { VerificationCard } from './verifications/VerificationCard'; | ||
import { VersionStateCard } from './VersionStateCard'; | ||
|
||
interface IEnvironmentCardsProps | ||
extends Pick< | ||
IArtifactDetailProps, | ||
'application' | 'reference' | 'version' | 'allVersions' | 'resourcesByEnvironment' | ||
> { | ||
environment: IManagedArtifactVersionEnvironment; | ||
pinnedVersion: string; | ||
} | ||
|
||
export const EnvironmentCards: React.FC<IEnvironmentCardsProps> = ({ | ||
application, | ||
environment, | ||
reference, | ||
version: versionDetails, | ||
allVersions, | ||
pinnedVersion, | ||
resourcesByEnvironment, | ||
}) => { | ||
const { | ||
name: environmentName, | ||
state, | ||
deployedAt, | ||
replacedAt, | ||
replacedBy, | ||
pinned, | ||
vetoed, | ||
statefulConstraints, | ||
statelessConstraints, | ||
compareLink, | ||
} = environment; | ||
const { | ||
stateService: { go }, | ||
} = useRouter(); | ||
|
||
const logEvent = useLogEvent(logCategories.artifactDetails); | ||
|
||
const differentVersionPinnedCard = pinnedVersion && | ||
pinnedVersion !== versionDetails.version && | ||
!['vetoed', 'skipped'].includes(state) && ( | ||
<StatusCard | ||
iconName="cloudWaiting" | ||
appearance="warning" | ||
background={true} | ||
title="A different version is pinned here" | ||
actions={<Button onClick={() => go('.', { version: pinnedVersion })}>See version</Button>} | ||
/> | ||
); | ||
|
||
const pinnedCard = pinned && ( | ||
<PinnedCard | ||
resourcesByEnvironment={resourcesByEnvironment} | ||
environmentName={environmentName} | ||
pinned={environment.pinned} | ||
reference={reference} | ||
version={versionDetails} | ||
/> | ||
); | ||
|
||
return ( | ||
<> | ||
{differentVersionPinnedCard} | ||
{pinnedCard} | ||
<VersionStateCard | ||
key="versionStateCard" | ||
state={state} | ||
deployedAt={deployedAt} | ||
replacedAt={replacedAt} | ||
replacedBy={replacedBy} | ||
vetoed={vetoed} | ||
compareLink={compareLink} | ||
allVersions={allVersions} | ||
logClick={(action) => logEvent({ action, label: `${environmentName}:${reference}` })} | ||
/> | ||
{environment.verifications?.map((verification) => ( | ||
<VerificationCard | ||
key={verification.id} | ||
verification={verification} | ||
wasHalted={environment.state === 'skipped'} | ||
logClick={(action) => logEvent({ action, label: `${environmentName}:${reference}` })} | ||
/> | ||
))} | ||
{[...(statelessConstraints || []), ...(statefulConstraints || [])] | ||
.filter(({ type }) => isConstraintSupported(type)) | ||
.map((constraint) => ( | ||
<ConstraintCard | ||
key={constraint.type} | ||
application={application} | ||
environment={environment} | ||
reference={reference} | ||
version={versionDetails.version} | ||
constraint={constraint} | ||
/> | ||
))} | ||
</> | ||
); | ||
}; |
57 changes: 57 additions & 0 deletions
57
app/scripts/modules/core/src/managed/artifactDetail/PinnedCard.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,57 @@ | ||
import React from 'react'; | ||
import { DateTime } from 'luxon'; | ||
|
||
import { IPinned } from 'core/domain'; | ||
|
||
import { Markdown } from '../../presentation'; | ||
import { useApplicationContext } from '../../presentation/hooks/useApplicationContext.hook'; | ||
import { Button } from '../Button'; | ||
import { StatusCard } from '../StatusCard'; | ||
import { IArtifactDetailProps } from './ArtifactDetail'; | ||
import { showUnpinArtifactModal } from './UnpinArtifactModal'; | ||
|
||
interface PinnedCardProps extends Pick<IArtifactDetailProps, 'resourcesByEnvironment' | 'reference' | 'version'> { | ||
environmentName: string; | ||
pinned?: IPinned; | ||
} | ||
|
||
export const PinnedCard: React.FC<PinnedCardProps> = ({ | ||
version, | ||
environmentName, | ||
pinned, | ||
resourcesByEnvironment, | ||
reference, | ||
}) => { | ||
const application = useApplicationContext(); | ||
return ( | ||
<StatusCard | ||
iconName="pin" | ||
appearance="warning" | ||
background={true} | ||
timestamp={pinned?.at ? DateTime.fromISO(pinned.at) : null} | ||
title={ | ||
<span className="sp-group-margin-xs-xaxis"> | ||
<span>Pinned</span> <span className="text-regular">—</span>{' '} | ||
<span className="text-regular">by {pinned.by}</span> | ||
</span> | ||
} | ||
description={pinned.comment && <Markdown message={pinned.comment} tag="span" />} | ||
actions={ | ||
<Button | ||
iconName="unpin" | ||
onClick={() => | ||
showUnpinArtifactModal({ | ||
application, | ||
reference, | ||
version, | ||
resourcesByEnvironment, | ||
environment: environmentName, | ||
}).then(({ status }) => status === 'CLOSED' && application.getDataSource('environments').refresh()) | ||
} | ||
> | ||
Unpin | ||
</Button> | ||
} | ||
/> | ||
); | ||
}; |
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