Skip to content

Commit

Permalink
Addressed PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccaalpert committed Oct 4, 2021
1 parent 174514a commit 0331eee
Show file tree
Hide file tree
Showing 7 changed files with 204 additions and 119 deletions.
51 changes: 51 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,54 @@ describe('Check cluster quota table columns by ResourceUsageRow', () => {
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import DashboardCardBody from '@console/shared/src/components/dashboard/dashboar
import DashboardCardHeader from '@console/shared/src/components/dashboard/dashboard-card/DashboardCardHeader';
import DashboardCardTitle from '@console/shared/src/components/dashboard/dashboard-card/DashboardCardTitle';
import {
AppliedClusterResourceQuotaModel,
PodModel,
DeploymentModel,
DeploymentConfigModel,
Expand Down Expand Up @@ -163,6 +164,7 @@ export const InventoryCard = () => {
<ProjectInventoryItem projectName={projectName} model={RouteModel} />
<ProjectInventoryItem projectName={projectName} model={ConfigMapModel} />
{canListSecrets && <ProjectInventoryItem projectName={projectName} model={SecretModel} />}
<ProjectInventoryItem projectName={projectName} model={AppliedClusterResourceQuotaModel} />
{itemExtensions.map((item) => (
<ProjectInventoryItem
key={item.properties.model.kind}
Expand Down
74 changes: 58 additions & 16 deletions frontend/public/components/default-resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ export const DetailsForKind = (
);
};

export const DefaultList: React.FC<TableProps & { kinds: string[] }> = (props) => {
export const DefaultList: React.FC<TableProps & { kinds: string[] } & { namespace: string }> = (
props,
) => {
const { t } = useTranslation();

const { kinds } = props;
const { kinds, namespace } = props;

const TableHeader = () => {
return [
Expand Down Expand Up @@ -104,29 +106,52 @@ 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')
)}
</TableData>
<TableData className={tableColumnClasses[2]}>
<Timestamp timestamp={obj.metadata.creationTimestamp} />
</TableData>
<TableData className={tableColumnClasses[3]}>
<ResourceKebab actions={menuActions} kind={kind} resource={obj} />
</TableData>
</>
);
};

const TableRowForACRQ: React.FC<RowFunctionArgs<K8sResourceKind>> = ({ obj, customData }) => {
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={customData.namespace}
/>
</TableData>
<TableData className={classNames(tableColumnClasses[1], 'co-break-word')}>
{customData.namespace ? (
<ResourceLink kind="Namespace" name={customData.namespace} />
) : (
t('public~None')
)}
Expand Down Expand Up @@ -157,7 +182,26 @@ export const DefaultList: React.FC<TableProps & { kinds: string[] }> = (props) =
[kinds],
);

return (
const customDataForACRQ = React.useMemo(
() => ({
kind: kinds[0],
namespace,
}),
[kinds, namespace],
);

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

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

DefaultDetailsPage.displayName = 'DefaultDetailsPage';
7 changes: 0 additions & 7 deletions frontend/public/components/factory/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ const VirtualBody: React.FC<VirtualBodyProps> = (props) => {
scrollTop,
width,
getRowProps,
namespace,
} = props;

const cellMeasurementCache = new CellMeasurerCache({
Expand All @@ -284,7 +283,6 @@ const VirtualBody: React.FC<VirtualBodyProps> = (props) => {
obj: data[index],
columns,
customData,
namespace,
};

// do not render non visible elements (this excludes overscan)
Expand Down Expand Up @@ -333,7 +331,6 @@ export type RowFunctionArgs<T = any, C = any> = {
obj: T;
columns: any[];
customData?: C;
namespace?: string;
};

export type VirtualBodyProps<D = any, C = any> = {
Expand All @@ -348,7 +345,6 @@ export type VirtualBodyProps<D = any, C = any> = {
width: number;
expand: boolean;
getRowProps?: (obj: D) => Partial<Pick<TableRowProps, 'id' | 'className' | 'title'>>;
namespace?: string;
};

type HeaderFunc = (componentProps: ComponentProps) => any[];
Expand Down Expand Up @@ -419,7 +415,6 @@ export const Table: React.FC<TableProps> = ({
expand,
label,
mock,
namespace,
selectedResourcesForKind,
'aria-label': ariaLabel,
virtualize = true,
Expand Down Expand Up @@ -575,7 +570,6 @@ export const Table: React.FC<TableProps> = ({
width={width}
expand={expand}
getRowProps={getRowProps}
namespace={namespace}
/>
</div>
)}
Expand Down Expand Up @@ -678,7 +672,6 @@ export type TableProps<D = any, C = any> = Partial<ComponentProps<D>> & {
expand?: boolean;
scrollElement?: HTMLElement | (() => HTMLElement);
getRowProps?: VirtualBodyProps<D>['getRowProps'];
namespace?: string;
};

export type ComponentProps<D = any> = {
Expand Down
Loading

0 comments on commit 0331eee

Please sign in to comment.