Skip to content

Commit

Permalink
Addressed PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccaalpert committed Sep 30, 2021
1 parent 83e5c01 commit f59e722
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 110 deletions.
80 changes: 80 additions & 0 deletions frontend/__tests__/components/resource-quota.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,83 @@ describe('Check cluster quota table columns by ResourceUsageRow', () => {
expect(col3.text()).toBe('2');
});
});

describe('Check cluster quota table columns by ResourceUsageRow', () => {
let wrapper: ShallowWrapper;
const quota = {
apiVersion: 'quota.openshift.io/v1',
kind: 'ClusterResourceQuota',
metadata: { name: 'example' },
spec: { quota: { hard: { 'limits.cpu': 2 } } },
status: { total: { hard: { 'limits.cpu': 2 }, used: { 'limits.cpu': 1 } } },
};

beforeEach(() => {
wrapper = shallow(<ResourceUsageRow resourceType={'limits.cpu'} quota={quota} />);
});

it('renders ResourceUsageRow for each columns', () => {
const col0 = wrapper.childAt(0);
expect(col0.text()).toBe('limits.cpu');

const col1 = wrapper.childAt(1);
expect(col1.find('.co-resource-quota-icon').exists()).toBe(true);

const col2 = wrapper.childAt(2);
expect(col2.text()).toBe('1');

const col3 = wrapper.childAt(3);
expect(col3.text()).toBe('2');
});
});

describe('Check applied cluster quota table columns by ResourceUsageRow', () => {
let wrapper: ShallowWrapper;
const quota = {
apiVersion: 'quota.openshift.io/v1',
kind: 'AppliedClusterResourceQuota',
metadata: { name: 'example' },
spec: { quota: { hard: { 'limits.cpu': 2 } } },
status: {
namespaces: [
{
namespace: 'test-namespace',
status: { used: { 'limits.cpu': 0 }, total: { 'limits.cpu': 2 } },
},
{
namespace: 'test-namespace2',
status: { used: { 'limits.cpu': 1 }, total: { 'limits.cpu': 2 } },
},
],
total: { hard: { 'limits.cpu': 2 }, used: { 'limits.cpu': 1 } },
},
};

beforeEach(() => {
wrapper = shallow(
<ResourceUsageRow
resourceType={'limits.cpu'}
quota={quota}
namespace="test-namespace"
isACRQ
/>,
);
});

it('renders ResourceUsageRow for each columns', () => {
const col0 = wrapper.childAt(0);
expect(col0.text()).toBe('limits.cpu');

const col1 = wrapper.childAt(1);
expect(col1.find('.co-resource-quota-icon').exists()).toBe(true);

const col2 = wrapper.childAt(2);
expect(col2.text()).toBe('0');

const col3 = wrapper.childAt(3);
expect(col3.text()).toBe('1');

const col4 = wrapper.childAt(4);
expect(col4.text()).toBe('2');
});
});
1 change: 0 additions & 1 deletion frontend/packages/console-shared/src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export enum FLAGS {
CAN_LIST_NODE = 'CAN_LIST_NODE',
CAN_LIST_PV = 'CAN_LIST_PV',
CAN_LIST_CRD = 'CAN_LIST_CRD',
CAN_LIST_CLUSTER_QUOTA = 'CAN_LIST_CLUSTER_QUOTA',
CAN_LIST_CHARGEBACK_REPORTS = 'CAN_LIST_CHARGEBACK_REPORTS',
CAN_LIST_USERS = 'CAN_LIST_USERS',
CAN_LIST_GROUPS = 'CAN_LIST_GROUPS',
Expand Down
8 changes: 0 additions & 8 deletions frontend/public/actions/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ const ssarChecks = [
verb: 'list',
},
},
{
flag: FLAGS.CAN_LIST_CLUSTER_QUOTA,
resourceAttributes: {
group: 'quota.openshift.io',
resource: 'clusterresourcequota',
verb: 'list',
},
},
{
// TODO: Move into OLM plugin
flag: FLAGS.CAN_LIST_OPERATOR_GROUP,
Expand Down
47 changes: 34 additions & 13 deletions frontend/public/components/default-resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,29 +104,22 @@ export const DefaultList: React.FC<TableProps & { kinds: string[] }> = (props) =
];
};

const TableRowForKind: React.FC<RowFunctionArgs<TableRowForKindProps>> = ({
obj,
customData,
namespace,
}) => {
const TableRowForKind: React.FC<RowFunctionArgs<K8sResourceKind>> = ({ obj, customData }) => {
const kind = referenceFor(obj) || customData.kind;
const menuActions = [...Kebab.getExtensionsActionsForKind(kindObj(kind)), ...common];
const appliedClusterQuotaReference = referenceForModel(AppliedClusterResourceQuotaModel);
const resourceNamespace =
kind === appliedClusterQuotaReference ? namespace : obj.metadata.namespace;

return (
<>
<TableData className={tableColumnClasses[0]}>
<ResourceLink
kind={customData.kind}
name={obj.metadata.name}
namespace={kind === appliedClusterQuotaReference ? namespace : obj.metadata.namespace}
namespace={obj.metadata.namespace}
/>
</TableData>
<TableData className={classNames(tableColumnClasses[1], 'co-break-word')}>
{resourceNamespace ? (
<ResourceLink kind="Namespace" name={resourceNamespace} />
{obj.metadata.namespace ? (
<ResourceLink kind="Namespace" name={obj.metadata.namespace} />
) : (
t('public~None')
)}
Expand All @@ -141,6 +134,32 @@ export const DefaultList: React.FC<TableProps & { kinds: string[] }> = (props) =
);
};

const TableRowForACRQ: React.FC<RowFunctionArgs<TableRowForACRQProps>> = ({
obj,
customData,
namespace,
}) => {
const kind = referenceFor(obj) || customData.kind;
const menuActions = [...Kebab.getExtensionsActionsForKind(kindObj(kind)), ...common];

return (
<>
<TableData className={tableColumnClasses[0]}>
<ResourceLink kind={customData.kind} name={obj.metadata.name} namespace={namespace} />
</TableData>
<TableData className={classNames(tableColumnClasses[1], 'co-break-word')}>
{namespace ? <ResourceLink kind="Namespace" name={namespace} /> : t('public~None')}
</TableData>
<TableData className={tableColumnClasses[2]}>
<Timestamp timestamp={obj.metadata.creationTimestamp} />
</TableData>
<TableData className={tableColumnClasses[3]}>
<ResourceKebab actions={menuActions} kind={kind} resource={obj} />
</TableData>
</>
);
};

const getAriaLabel = (item) => {
const model = modelFor(item);
// API discovery happens asynchronously. Avoid runtime errors if the model hasn't loaded.
Expand All @@ -157,13 +176,15 @@ export const DefaultList: React.FC<TableProps & { kinds: string[] }> = (props) =
[kinds],
);

const appliedClusterQuotaReference = referenceForModel(AppliedClusterResourceQuotaModel);

return (
<Table
{...props}
aria-label={getAriaLabel(kinds[0])}
customData={customData}
Header={TableHeader}
Row={TableRowForKind}
Row={kinds[0] === appliedClusterQuotaReference ? TableRowForACRQ : TableRowForKind}
virtualize
/>
);
Expand All @@ -186,6 +207,6 @@ export const DefaultDetailsPage: React.FC<React.ComponentProps<typeof DetailsPag
return <DetailsPage {...props} menuActions={menuActions} pages={pages} />;
};

export type TableRowForKindProps = K8sResourceKind & { namespace?: string };
export type TableRowForACRQProps = K8sResourceKind & { namespace?: string };

DefaultDetailsPage.displayName = 'DefaultDetailsPage';
Loading

0 comments on commit f59e722

Please sign in to comment.