-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ComponentRelation): fix visualization on details page
- Loading branch information
Showing
16 changed files
with
307 additions
and
163 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
71 changes: 71 additions & 0 deletions
71
src/components/ComponentRelation/details-page/ComponentNudges.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
.component-nudge { | ||
--spacing: 3.5rem; | ||
--diff: 1rem; | ||
--guide-color: var(--pf-global--Color--400); | ||
--stroke-width: 2px; | ||
|
||
margin-left: var(--pf-v5-global--spacer--lg); | ||
|
||
&__status-icon { | ||
height: 10px; | ||
max-width: 25px; | ||
} | ||
|
||
&__tree { | ||
& ul { | ||
margin-left: calc(var(--spacing) - var(--diff)); | ||
padding-left: 0; | ||
padding-top: 6px; | ||
} | ||
|
||
& li { | ||
display: block; | ||
position: relative; | ||
padding-left: calc(1.5 * var(--spacing) - var(--diff) - 2px); | ||
padding-top: var(--diff); | ||
} | ||
|
||
& ul li { | ||
border-left: var(--stroke-width) solid var(--guide-color); | ||
} | ||
|
||
& ul li:last-child { | ||
border-left: var(--stroke-width) solid transparent; | ||
} | ||
|
||
& ul li::before { | ||
content: ''; | ||
display: block; | ||
position: absolute; | ||
top: -1px; | ||
left: -2px; | ||
width: calc(var(--spacing)); | ||
height: calc(var(--spacing) / 3.5 + var(--diff)); | ||
border: solid var(--guide-color); | ||
border-width: 0 0 var(--stroke-width) var(--stroke-width); | ||
} | ||
} | ||
|
||
&__nudges-arrow { | ||
& ul li::after { | ||
content: "\25B6"; | ||
color: var(--guide-color); | ||
display: inline-block; | ||
position: absolute; | ||
left: calc(var(--spacing) - 6px); | ||
top: 19px; | ||
} | ||
} | ||
|
||
&__nudged-by-arrow { | ||
& ul li:first-child::after { | ||
content: "\25B6"; | ||
color: var(--guide-color); | ||
display: inline-block; | ||
position: absolute; | ||
left: -7.5px; | ||
top: -15px; | ||
transform: rotate(-90deg); | ||
} | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
src/components/ComponentRelation/details-page/ComponentNudges.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,105 @@ | ||
import * as React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import { Button, Text } from '@patternfly/react-core'; | ||
import { ExternalLinkAltIcon } from '@patternfly/react-icons/dist/esm/icons/external-link-alt-icon'; | ||
import { css } from '@patternfly/react-styles'; | ||
import { useAllComponents } from '../../../hooks/useComponents'; | ||
import { ComponentKind } from '../../../types'; | ||
import { useWorkspaceInfo } from '../../../utils/workspace-context-utils'; | ||
import { ComponentRelationStatusIcon } from './ComponentRelationStatusIcon'; | ||
|
||
import './ComponentNudges.scss'; | ||
|
||
export const enum NudgeRadios { | ||
NUDGES = 'nudges', | ||
NUDGED_BY = 'isNudgedBy', | ||
} | ||
|
||
interface ComponentNudgesSVGprops { | ||
nudgeComponents: string[]; | ||
radioChecked: string; | ||
component: ComponentKind; | ||
} | ||
|
||
const ComponentNudgesSVG: React.FC<ComponentNudgesSVGprops> = ({ | ||
nudgeComponents, | ||
radioChecked, | ||
component, | ||
}) => { | ||
const { workspace, namespace } = useWorkspaceInfo(); | ||
const [components, loaded, error] = useAllComponents(namespace); | ||
|
||
const emptyState = ( | ||
<div data-test="nudges-empty-state" className="component-nudges__empty-state"> | ||
No dependencies found | ||
</div> | ||
); | ||
|
||
const relatedComponents = React.useMemo(() => { | ||
return loaded && !error | ||
? components.filter((comp) => nudgeComponents?.includes(comp.metadata.name)) | ||
: []; | ||
}, [components, error, loaded, nudgeComponents]); | ||
|
||
const isNudges = React.useMemo(() => radioChecked === NudgeRadios.NUDGES, [radioChecked]); | ||
|
||
if (!nudgeComponents || nudgeComponents?.length === 0) { | ||
return emptyState; | ||
} | ||
|
||
return Array.isArray(nudgeComponents) && nudgeComponents.length > 0 ? ( | ||
<div | ||
className={css( | ||
'component-nudge', | ||
'component-nudge__tree', | ||
radioChecked === NudgeRadios.NUDGES && 'component-nudge__nudges-arrow', | ||
radioChecked === NudgeRadios.NUDGED_BY && 'component-nudge__nudged-by-arrow', | ||
)} | ||
> | ||
<Text style={{ marginTop: 'var(--pf-v5-global--spacer--lg)' }}> | ||
<b>{component.metadata.name}</b> | ||
</Text> | ||
<ul> | ||
{relatedComponents.map((comp, i) => ( | ||
<li key={i} data-test="nudges-connector"> | ||
<Link | ||
to={`/application-pipeline/workspaces/${workspace}/applications/${comp.spec?.application}/components/${comp.metadata.name}`} | ||
data-test={isNudges ? 'nudges-cmp-link' : 'nudged-by-cmp-link'} | ||
> | ||
{comp.metadata.name} | ||
</Link> | ||
<ComponentRelationStatusIcon | ||
component={comp} | ||
className="component-nudge__status-icon" | ||
/> | ||
{comp.spec?.application !== component.spec?.application ? ( | ||
<> | ||
( | ||
<Button | ||
isInline | ||
variant="link" | ||
icon={<ExternalLinkAltIcon />} | ||
iconPosition="end" | ||
component={(props) => ( | ||
<Link | ||
{...props} | ||
to={`/application-pipeline/workspaces/${workspace}/applications/${comp?.spec?.application}/`} | ||
target="_blank" | ||
/> | ||
)} | ||
> | ||
{comp.spec?.application} | ||
</Button> | ||
) | ||
</> | ||
) : null} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
) : ( | ||
emptyState | ||
); | ||
}; | ||
|
||
export default ComponentNudgesSVG; |
12 changes: 12 additions & 0 deletions
12
src/components/ComponentRelation/details-page/ComponentNudgesDependencies.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.component-nudges { | ||
&__radio { | ||
font-weight: 400; | ||
} | ||
&__empty-state { | ||
padding: var(--pf-v5-global--spacer--md); | ||
color: var(--pf-global--Color--400); | ||
} | ||
& .pf-v5-c-expandable-section__toggle-text { | ||
margin-left: var(--pf-v5-global--spacer--sm); | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...ails/tabs/ComponentNudgesDependencies.tsx → ...ails-page/ComponentNudgesDependencies.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
4 changes: 4 additions & 0 deletions
4
src/components/ComponentRelation/details-page/ComponentRelationStatusIcon.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.component-relation-status-icon { | ||
margin: var(--pf-v5-global--spacer--xs); | ||
vertical-align: middle; | ||
} |
27 changes: 27 additions & 0 deletions
27
src/components/ComponentRelation/details-page/ComponentRelationStatusIcon.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,27 @@ | ||
import * as React from 'react'; | ||
import { Tooltip } from '@patternfly/react-core'; | ||
import { css } from '@patternfly/react-styles'; | ||
import relationIcon from '../../../imgs/RelationsIcon.svg'; | ||
import { ComponentKind } from '../../../types'; | ||
|
||
import './ComponentRelationStatusIcon.scss'; | ||
|
||
export const ComponentRelationStatusIcon: React.FC<{ | ||
component: ComponentKind; | ||
className?: string; | ||
style?: { [key: string]: any }; | ||
}> = ({ component, className, style }) => { | ||
const isInRelationship = !!( | ||
component.spec?.['build-nudges-ref']?.length ?? component.status?.['build-nudged-by']?.length | ||
); | ||
return isInRelationship ? ( | ||
<Tooltip content="This component is in a relationship"> | ||
<img | ||
style={style} | ||
className={css('component-relation-status-icon', className)} | ||
src={relationIcon} | ||
alt="Component is in a relationship icon" | ||
/> | ||
</Tooltip> | ||
) : null; | ||
}; |
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
Oops, something went wrong.