Skip to content

Commit

Permalink
Merge pull request #4778 from jeff-phillips-18/refactor-topology-utils
Browse files Browse the repository at this point in the history
Fix for helm application filters, refactor topology utils
  • Loading branch information
openshift-merge-robot committed Mar 27, 2020
2 parents c30741e + 1f14278 commit 26a372a
Show file tree
Hide file tree
Showing 124 changed files with 3,969 additions and 2,102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,124 @@ describe('TransformResourceData', () => {
expect(element).not.toHaveProperties([...podKeys, 'current', 'previous']);
});
});

it('should return only operator backed deployment config items as specified', () => {
spyOn(transformResourceData, 'isOperatorBackedService').and.returnValue(true);

let transformedData = transformResourceData.createDeploymentConfigItems(
sampleDeploymentConfigs.data,
);
expect(transformedData).toHaveLength(sampleDeploymentConfigs.data.length);

transformedData = transformResourceData.createDeploymentConfigItems(
sampleDeploymentConfigs.data,
true,
);
expect(transformedData).toHaveLength(sampleDeploymentConfigs.data.length);

transformedData = transformResourceData.createDeploymentConfigItems(
sampleDeploymentConfigs.data,
false,
);
expect(transformedData).toHaveLength(0);
});

it('should return only non operator backed deployment config items as specified', () => {
spyOn(transformResourceData, 'isOperatorBackedService').and.returnValue(false);

let transformedData = transformResourceData.createDeploymentConfigItems(
sampleDeploymentConfigs.data,
);
expect(transformedData).toHaveLength(sampleDeploymentConfigs.data.length);

transformedData = transformResourceData.createDeploymentConfigItems(
sampleDeploymentConfigs.data,
true,
);
expect(transformedData).toHaveLength(0);

transformedData = transformResourceData.createDeploymentConfigItems(
sampleDeploymentConfigs.data,
false,
);
expect(transformedData).toHaveLength(sampleDeploymentConfigs.data.length);
});

it('should return only operator backed deployment items as specified', () => {
spyOn(transformResourceData, 'isOperatorBackedService').and.returnValue(true);

let transformedData = transformResourceData.createDeploymentItems(sampleDeployments.data);
expect(transformedData).toHaveLength(sampleDeployments.data.length);

transformedData = transformResourceData.createDeploymentItems(sampleDeployments.data, true);
expect(transformedData).toHaveLength(sampleDeployments.data.length);

transformedData = transformResourceData.createDeploymentItems(sampleDeployments.data, false);
expect(transformedData).toHaveLength(0);
});

it('should return only non operator backed deployment items as specified', () => {
spyOn(transformResourceData, 'isOperatorBackedService').and.returnValue(false);

let transformedData = transformResourceData.createDeploymentItems(sampleDeployments.data);
expect(transformedData).toHaveLength(sampleDeployments.data.length);

transformedData = transformResourceData.createDeploymentItems(sampleDeployments.data, true);
expect(transformedData).toHaveLength(0);

transformedData = transformResourceData.createDeploymentItems(sampleDeployments.data, false);
expect(transformedData).toHaveLength(sampleDeployments.data.length);
});

it('should return only operator backed daemon set items as specified', () => {
spyOn(transformResourceData, 'isOperatorBackedService').and.returnValue(true);

let transformedData = transformResourceData.createDaemonSetItems(sampleDaemonSets.data);
expect(transformedData).toHaveLength(sampleDaemonSets.data.length);

transformedData = transformResourceData.createDaemonSetItems(sampleDaemonSets.data, true);
expect(transformedData).toHaveLength(sampleDaemonSets.data.length);

transformedData = transformResourceData.createDaemonSetItems(sampleDaemonSets.data, false);
expect(transformedData).toHaveLength(0);
});

it('should return only non operator backed daemon set items as specified', () => {
spyOn(transformResourceData, 'isOperatorBackedService').and.returnValue(false);

let transformedData = transformResourceData.createDaemonSetItems(sampleDaemonSets.data);
expect(transformedData).toHaveLength(sampleDaemonSets.data.length);

transformedData = transformResourceData.createDaemonSetItems(sampleDaemonSets.data, true);
expect(transformedData).toHaveLength(0);

transformedData = transformResourceData.createDaemonSetItems(sampleDaemonSets.data, false);
expect(transformedData).toHaveLength(sampleDaemonSets.data.length);
});

it('should return only operator backed stateful set items as specified', () => {
spyOn(transformResourceData, 'isOperatorBackedService').and.returnValue(true);

let transformedData = transformResourceData.createStatefulSetItems(sampleStatefulSets.data);
expect(transformedData).toHaveLength(sampleStatefulSets.data.length);

transformedData = transformResourceData.createStatefulSetItems(sampleStatefulSets.data, true);
expect(transformedData).toHaveLength(sampleStatefulSets.data.length);

transformedData = transformResourceData.createStatefulSetItems(sampleStatefulSets.data, false);
expect(transformedData).toHaveLength(0);
});

it('should return only non operator backed stateful set items as specified', () => {
spyOn(transformResourceData, 'isOperatorBackedService').and.returnValue(false);

let transformedData = transformResourceData.createStatefulSetItems(sampleStatefulSets.data);
expect(transformedData).toHaveLength(sampleStatefulSets.data.length);

transformedData = transformResourceData.createStatefulSetItems(sampleStatefulSets.data, true);
expect(transformedData).toHaveLength(0);

transformedData = transformResourceData.createStatefulSetItems(sampleStatefulSets.data, false);
expect(transformedData).toHaveLength(sampleStatefulSets.data.length);
});
});
40 changes: 33 additions & 7 deletions frontend/packages/console-shared/src/utils/resource-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -649,8 +649,11 @@ export class TransformResourceData {
});
};

public createDeploymentConfigItems = (deploymentConfigs: K8sResourceKind[]): OverviewItem[] => {
return _.map(deploymentConfigs, (dc) => {
public createDeploymentConfigItems = (
deploymentConfigs: K8sResourceKind[],
operatorsFilter?: boolean,
): OverviewItem[] => {
const items = _.map(deploymentConfigs, (dc) => {
const obj: K8sResourceKind = {
...dc,
apiVersion: apiVersionForModel(DeploymentConfigModel),
Expand Down Expand Up @@ -696,12 +699,17 @@ export class TransformResourceData {
}
return overviewItems;
});
if (operatorsFilter !== undefined) {
return items.filter((item) => item.isOperatorBackedService === operatorsFilter);
}
return items;
};

public createDeploymentItems = (
deployments: DeploymentKind[],
operatorsFilter?: boolean,
): OverviewItem<DeploymentKind>[] => {
return _.map(deployments, (d) => {
const items = _.map(deployments, (d) => {
const obj: DeploymentKind = {
...d,
apiVersion: apiVersionForModel(DeploymentModel),
Expand Down Expand Up @@ -742,10 +750,17 @@ export class TransformResourceData {
}
return overviewItems;
});
if (operatorsFilter !== undefined) {
return items.filter((item) => item.isOperatorBackedService === operatorsFilter);
}
return items;
};

public createDaemonSetItems = (daemonSets: K8sResourceKind[]): OverviewItem[] => {
return _.map(daemonSets, (ds) => {
public createDaemonSetItems = (
daemonSets: K8sResourceKind[],
operatorsFilter?: boolean,
): OverviewItem[] => {
const items = _.map(daemonSets, (ds) => {
const obj: K8sResourceKind = {
...ds,
apiVersion: apiVersionForModel(DaemonSetModel),
Expand Down Expand Up @@ -773,10 +788,17 @@ export class TransformResourceData {
isOperatorBackedService,
};
});
if (operatorsFilter !== undefined) {
return items.filter((item) => item.isOperatorBackedService === operatorsFilter);
}
return items;
};

public createStatefulSetItems = (statefulSets: K8sResourceKind[]): OverviewItem[] => {
return _.map(statefulSets, (ss) => {
public createStatefulSetItems = (
statefulSets: K8sResourceKind[],
operatorsFilter?: boolean,
): OverviewItem[] => {
const items = _.map(statefulSets, (ss) => {
const obj: K8sResourceKind = {
...ss,
apiVersion: apiVersionForModel(StatefulSetModel),
Expand Down Expand Up @@ -804,6 +826,10 @@ export class TransformResourceData {
isOperatorBackedService,
};
});
if (operatorsFilter !== undefined) {
return items.filter((item) => item.isOperatorBackedService === operatorsFilter);
}
return items;
};

public createPodItems = (): OverviewItem[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from '@console/topology';
import { truncateMiddle } from '@console/internal/components/utils';
import { RESOURCE_NAME_TRUNCATE_LENGTH } from '../../const';
import SvgResourceIcon from '../topology/components/nodes/ResourceIcon';
import { SvgResourceIcon } from './SvgResourceIcon';
import SvgCircledIcon from './SvgCircledIcon';
import SvgDropShadowFilter from './SvgDropShadowFilter';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import '../../../../../../../public/style/vars';
@import '../../../../../public/style/vars';

.odc-resource-icon {
font-size: 80%;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ import cx from 'classnames';
import { get } from 'lodash';
import { useSize } from '@console/topology';
import { modelFor, kindToAbbr } from '@console/internal/module/k8s';
import './ResourceIcon.scss';
import './SvgResourceIcon.scss';

export interface ResourceIconProps {
interface ResourceIconProps {
x: number;
y: number;
kind: string;
leftJustified?: boolean;
}

export function getKindStringAndAbbrivation(kind: string) {
function getKindStringAndAbbreviation(kind: string) {
const kindObj = modelFor(kind);
const kindStr = get(kindObj, 'kind', kind);
const kindColor = get(kindObj, 'color', undefined);
const kindAbbr = (kindObj && kindObj.abbr) || kindToAbbr(kindStr);
return { kindStr, kindAbbr, kindColor };
}

export const ResourceIcon: React.FC<ResourceIconProps> = (
const ForwardSvgResourceIcon: React.FC<ResourceIconProps> = (
{ kind, x, y, leftJustified },
iconRef,
) => {
const { kindAbbr, kindStr, kindColor } = getKindStringAndAbbrivation(kind);
const { kindAbbr, kindStr, kindColor } = getKindStringAndAbbreviation(kind);
const [textSize, textRef] = useSize([]);

let rect = null;
Expand Down Expand Up @@ -73,4 +73,5 @@ export const ResourceIcon: React.FC<ResourceIconProps> = (
);
};

export default React.forwardRef(ResourceIcon);
const SvgResourceIcon = React.forwardRef(ForwardSvgResourceIcon);
export { SvgResourceIcon, getKindStringAndAbbreviation };
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import * as React from 'react';
import { shallow } from 'enzyme';
import { getKindStringAndAbbrivation, ResourceIcon } from '../ResourceIcon';
import { getKindStringAndAbbreviation, SvgResourceIcon } from '../SvgResourceIcon';

describe(getKindStringAndAbbrivation.name, () => {
describe(getKindStringAndAbbreviation.name, () => {
it('should return correct name and its abbrivation for the given string', () => {
expect(getKindStringAndAbbrivation('DeploymentConfig')).toEqual({
expect(getKindStringAndAbbreviation('DeploymentConfig')).toEqual({
kindAbbr: 'DC',
kindStr: 'DeploymentConfig',
});
expect(getKindStringAndAbbrivation('Deployment')).toEqual({
expect(getKindStringAndAbbreviation('Deployment')).toEqual({
kindAbbr: 'D',
kindStr: 'Deployment',
});
expect(getKindStringAndAbbrivation('DaemonSet')).toEqual({
expect(getKindStringAndAbbreviation('DaemonSet')).toEqual({
kindAbbr: 'DS',
kindStr: 'DaemonSet',
});
});
});

describe(ResourceIcon.name, () => {
describe(SvgResourceIcon.name, () => {
it('should exists', () => {
const wrapper = shallow(<ResourceIcon kind="Deplyoment" x={0} y={0} />);
const wrapper = shallow(<SvgResourceIcon kind="Deplyoment" x={0} y={0} />);
expect(wrapper.exists()).toBeTruthy();
});

it('should render correct kind abbrivation', () => {
const wrapper = shallow(<ResourceIcon kind="Deplyoment" x={0} y={0} />);
const wrapper = shallow(<SvgResourceIcon kind="Deplyoment" x={0} y={0} />);
expect(wrapper.find('text').text()).toEqual('D');
});
});

0 comments on commit 26a372a

Please sign in to comment.