Skip to content

Commit

Permalink
Bug 1803213: Update collapsed groups in topology to match designs
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 committed Feb 14, 2020
1 parent 94ad5e4 commit 44dc0f6
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
} from '@console/topology';
import NodeShadows, { NODE_SHADOW_FILTER_ID_HOVER, NODE_SHADOW_FILTER_ID } from '../NodeShadows';
import useSearchFilter from '../../filters/useSearchFilter';
import ResourceKindsInfo from '../nodes/ResourceKindsInfo';
import GroupNode from '../nodes/GroupNode';

export type HelmReleaseNodeProps = {
Expand Down Expand Up @@ -55,9 +54,12 @@ const HelmReleaseNode: React.FC<HelmReleaseNodeProps> = ({ element, onSelect, se
rx="5"
ry="5"
/>
<GroupNode kind="HelmRelease" title={element.getLabel()} typeIconClass="icon-helm">
<ResourceKindsInfo groupResources={element.getData().groupResources} />
</GroupNode>
<GroupNode
kind="HelmRelease"
element={element}
typeIconClass="icon-helm"
groupResources={element.getData().groupResources}
/>
</g>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import useSearchFilter from '../../filters/useSearchFilter';
import NodeShadows, { NODE_SHADOW_FILTER_ID, NODE_SHADOW_FILTER_ID_HOVER } from '../NodeShadows';
import { getTopologyResourceObject } from '../../topology-utils';
import GroupNode from './GroupNode';
import ResourceKindsInfo from './ResourceKindsInfo';
import { ApplicationModel } from '../../../../models';

type ApplicationGroupProps = {
Expand Down Expand Up @@ -83,9 +82,11 @@ const ApplicationNode: React.FC<ApplicationGroupProps> = ({
rx="5"
ry="5"
/>
<GroupNode title={element.getLabel()} kind={ApplicationModel.kind}>
<ResourceKindsInfo groupResources={element.getData().groupResources} />
</GroupNode>
<GroupNode
element={element}
kind={ApplicationModel.kind}
groupResources={element.getData().groupResources}
/>
</g>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,44 @@ import {
shouldTruncate,
TruncateOptions,
} from '@console/internal/components/utils';
import { useSize, useHover } from '@console/topology';
import { Node, useSize, useHover } from '@console/topology';
import SvgResourceIcon from './ResourceIcon';
import SvgCircledIcon from '../../../svg/SvgCircledIcon';

import './GroupNode.scss';
import { TopologyDataObject } from '../../topology-types';
import ResourceKindsInfo from './ResourceKindsInfo';

const TOP_MARGIN = 20;
const LEFT_MARGIN = 20;
const TEXT_MARGIN = 10;
const CONTENT_MARGIN = 40;

const truncateOptions: TruncateOptions = {
length: 35,
};

type GroupNodeProps = {
title: string;
element: Node;
kind?: string;
emptyValue?: React.ReactNode;
groupResources?: TopologyDataObject;
children?: React.ReactNode;
typeIconClass?: string;
};

const GroupNode: React.FC<GroupNodeProps> = ({ children, kind, title, typeIconClass }) => {
const GroupNode: React.FC<GroupNodeProps> = ({
element,
groupResources,
children,
kind,
emptyValue,
typeIconClass,
}) => {
const [textHover, textHoverRef] = useHover();
const [iconSize, iconRef] = useSize([kind]);
const iconWidth = iconSize ? iconSize.width : 0;
const iconHeight = iconSize ? iconSize.height : 0;
const title = element.getLabel();
return (
<>
{typeIconClass && (
Expand All @@ -44,7 +55,7 @@ const GroupNode: React.FC<GroupNodeProps> = ({ children, kind, title, typeIconCl
iconClass={typeIconClass}
/>
)}
<SvgResourceIcon ref={iconRef} x={TOP_MARGIN} y={LEFT_MARGIN} kind={kind} leftJustified />
<SvgResourceIcon ref={iconRef} x={LEFT_MARGIN} y={TOP_MARGIN - 2} kind={kind} leftJustified />
{title && (
<Tooltip
content={title}
Expand All @@ -64,12 +75,16 @@ const GroupNode: React.FC<GroupNodeProps> = ({ children, kind, title, typeIconCl
</text>
</Tooltip>
)}
{children && (
<g
transform={`translate(${LEFT_MARGIN + iconWidth}, ${TOP_MARGIN +
iconHeight +
CONTENT_MARGIN})`}
>
{(children || groupResources || emptyValue) && (
<g transform={`translate(${LEFT_MARGIN}, ${TOP_MARGIN + iconHeight})`}>
{(groupResources || emptyValue) && (
<ResourceKindsInfo
groupResources={groupResources}
emptyValue={emptyValue}
width={element.getBounds().width - LEFT_MARGIN}
height={element.getBounds().height - TOP_MARGIN - iconHeight}
/>
)}
{children}
</g>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { nodeDragSourceSpec } from '../../componentUtils';
import { TYPE_KNATIVE_SERVICE } from '../../const';
import NodeShadows, { NODE_SHADOW_FILTER_ID, NODE_SHADOW_FILTER_ID_HOVER } from '../NodeShadows';
import GroupNode from './GroupNode';
import ResourceKindsInfo from './ResourceKindsInfo';

type KnativeServiceNodeProps = {
element: Node;
Expand Down Expand Up @@ -97,12 +96,13 @@ const KnativeServiceNode: React.FC<KnativeServiceNodeProps> = ({
rx="5"
ry="5"
/>
<GroupNode kind={kind} title={element.getLabel()} typeIconClass="icon-knative">
<ResourceKindsInfo
groupResources={element.getData().groupResources}
emptyKind="Revisions"
/>
</GroupNode>
<GroupNode
kind={kind}
element={element}
typeIconClass="icon-knative"
groupResources={element.getData().groupResources}
emptyValue="No Revisions"
/>
</g>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { nodeDragSourceSpec } from '../../componentUtils';
import { TYPE_OPERATOR_BACKED_SERVICE } from '../../const';
import NodeShadows, { NODE_SHADOW_FILTER_ID, NODE_SHADOW_FILTER_ID_HOVER } from '../NodeShadows';
import GroupNode from './GroupNode';
import ResourceKindsInfo from './ResourceKindsInfo';

export type OperatorBackedServiceNodeProps = {
element: Node;
Expand Down Expand Up @@ -65,11 +64,10 @@ const OperatorBackedServiceNode: React.FC<OperatorBackedServiceNodeProps> = ({
/>
<GroupNode
kind={kind}
title={element.getLabel()}
element={element}
groupResources={element.getData().groupResources}
typeIconClass={element.getData().data.builderImage}
>
<ResourceKindsInfo groupResources={element.getData().groupResources} />
</GroupNode>
/>
</g>
);
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.odc-resource-kinds-info {
padding: var(--pf-global--spacer--md) var(--pf-global--spacer--md) var(--pf-global--spacer--md) 0;
width: 100%;
height: 100%;
overflow-y: auto;

&__table {
width: 100%;
td {
padding-bottom: var(--pf-global--spacer--sm);
padding-right: var(--pf-global--spacer--sm);
&:last-of-type {
padding-right: 0;
}
}
}

&__resource-icon {
width: 1%;
.co-m-resource-icon {
font-size: 80%;
margin-right: 0;
}
}
&__count {
text-align: end;
width: 1%;
}
}
Original file line number Diff line number Diff line change
@@ -1,52 +1,67 @@
import * as React from 'react';
import * as _ from 'lodash';
import { modelFor, referenceForOwnerRef } from '@console/internal/module/k8s';
import { modelFor, referenceFor, referenceForModel } from '@console/internal/module/k8s';
import { getTopologyResourceObject } from '../../topology-utils';
import { TopologyDataObject } from '../../topology-types';
import { ResourceIcon } from '@console/internal/components/utils';

import './ResourceKindsInfo.scss';

type ResourceKindsInfoProps = {
groupResources: TopologyDataObject;
emptyKind?: string;
emptyValue?: React.ReactNode;
width: number;
height: number;
};

const TEXT_MARGIN = 10;
const ROW_HEIGHT = 20 + TEXT_MARGIN;

const ResourceKindsInfo: React.FC<ResourceKindsInfoProps> = ({ groupResources, emptyKind }) => {
const ResourceKindsInfo: React.FC<ResourceKindsInfoProps> = ({
groupResources,
emptyValue,
width,
height,
}) => {
const resourcesData = {};
_.forEach(groupResources, (res: TopologyDataObject) => {
const a = getTopologyResourceObject(res);
resourcesData[a.kind] = [...(resourcesData[a.kind] ? resourcesData[a.kind] : []), a];
const kindObj = modelFor(referenceFor(a));
const key = kindObj.abbr || a.kind;
resourcesData[key] = [...(resourcesData[key] ? resourcesData[key] : []), a];
});

const resourceTypes = _.keys(resourcesData);
let resources = null;
if (resourceTypes.length) {
resources = _.map(resourceTypes, (key, index) => {
const kindObj = modelFor(referenceForOwnerRef(resourcesData[key][0]));
const rowY = ROW_HEIGHT * index;
return (
<g key={key}>
<text y={rowY} textAnchor="end">
{resourcesData[key].length}
</text>
<text x={TEXT_MARGIN} y={rowY}>
{resourcesData[key].length > 1 ? kindObj.labelPlural : kindObj.label}
</text>
</g>
);
});
} else if (emptyKind) {
const kindObj = modelFor(emptyKind);
resources = (
<g>
<text textAnchor="end">0</text>
<text x={TEXT_MARGIN}>{kindObj ? kindObj.labelPlural : emptyKind}</text>
</g>

if (!resourceTypes.length) {
return (
<foreignObject width={width} height={height}>
<div className="odc-resource-kinds-info">{emptyValue}</div>
</foreignObject>
);
}

return <g className="odc-resource-kinds-info__resources">{resources}</g>;
return (
<foreignObject width={width} height={height}>
<div className="odc-resource-kinds-info">
<table className="odc-resource-kinds-info__table">
<tbody className="odc-resource-kinds-info__body">
{resourceTypes.map((key) => {
const kindObj = modelFor(referenceFor(resourcesData[key][0]));
return (
<tr key={key} className="odc-resource-kinds-info__row">
<td className="odc-resource-kinds-info__count">{resourcesData[key].length}</td>
<td className="odc-resource-kinds-info__resource-icon">
<ResourceIcon kind={kindObj.crd ? referenceForModel(kindObj) : kindObj.kind} />
</td>
<td className="odc-resource-kinds-info__kind">
{resourcesData[key].length > 1 ? kindObj.labelPlural : kindObj.label}
</td>
</tr>
);
})}
</tbody>
</table>
</div>
</foreignObject>
);
// return <g className="odc-resource-kinds-info__resources">{resources}</g>;
};

export default ResourceKindsInfo;
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ export const topologyModelFromDataModel = (
data.groupResources = d.children && d.children.map((id) => dataModel.topology[id]);
return {
width: 300,
height: 100,
height: d.type === TYPE_KNATIVE_SERVICE ? 100 : 180,
id: d.id,
type: d.type,
label: dataModel.topology[d.id].name,
Expand Down

0 comments on commit 44dc0f6

Please sign in to comment.