Skip to content

Commit

Permalink
CONSOLE-922: Support AppliedClusterResourceQuota for normal users
Browse files Browse the repository at this point in the history
Have only added list page support so far; will work on details page next.

Fixes https://issues.redhat.com/browse/CONSOLE-922
  • Loading branch information
rebeccaalpert committed Sep 28, 2021
1 parent 4523586 commit 740be0e
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 89 deletions.
1 change: 1 addition & 0 deletions frontend/packages/console-shared/src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ 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: 8 additions & 0 deletions frontend/public/actions/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ 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
20 changes: 16 additions & 4 deletions frontend/public/components/default-resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Conditions } from './conditions';
import { DetailsPage, ListPage, Table, TableData, TableProps, RowFunctionArgs } from './factory';
import {
referenceFor,
referenceForModel,
kindForReference,
K8sResourceKind,
modelFor,
Expand All @@ -23,6 +24,7 @@ import {
SectionHeading,
Timestamp,
} from './utils';
import { AppliedClusterResourceQuotaModel } from '../models';

const { common } = Kebab.factory;

Expand Down Expand Up @@ -102,22 +104,29 @@ export const DefaultList: React.FC<TableProps & { kinds: string[] }> = (props) =
];
};

const TableRowForKind: React.FC<RowFunctionArgs<K8sResourceKind>> = ({ obj, customData }) => {
const TableRowForKind: React.FC<RowFunctionArgs<TableRowForKindProps>> = ({
obj,
customData,
namespace,
}) => {
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={obj.metadata.namespace}
namespace={kind === appliedClusterQuotaReference ? namespace : obj.metadata.namespace}
/>
</TableData>
<TableData className={classNames(tableColumnClasses[1], 'co-break-word')}>
{obj.metadata.namespace ? (
<ResourceLink kind="Namespace" name={obj.metadata.namespace} />
{resourceNamespace ? (
<ResourceLink kind="Namespace" name={resourceNamespace} />
) : (
t('public~None')
)}
Expand Down Expand Up @@ -176,4 +185,7 @@ 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';
2 changes: 2 additions & 0 deletions frontend/public/components/factory/list-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ type ListPageWrapperProps<L = any, C = any> = {
reduxIDs?: string[];
textFilter?: string;
nameFilterPlaceholder?: string;
namespace?: string;
labelFilterPlaceholder?: string;
label?: string;
staticFilters?: { key: string; value: string }[];
Expand Down Expand Up @@ -573,6 +574,7 @@ export const MultiListPage: React.FC<MultiListPageProps> = (props) => {
columnLayout={columnLayout}
nameFilterPlaceholder={nameFilterPlaceholder}
labelFilterPlaceholder={labelFilterPlaceholder}
namespace={namespace}
/>
</Firehose>
</FireMan>
Expand Down
7 changes: 7 additions & 0 deletions frontend/public/components/factory/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ const VirtualBody: React.FC<VirtualBodyProps> = (props) => {
scrollTop,
width,
getRowProps,
namespace,
} = props;

const cellMeasurementCache = new CellMeasurerCache({
Expand All @@ -283,6 +284,7 @@ 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 @@ -331,6 +333,7 @@ export type RowFunctionArgs<T = any, C = any> = {
obj: T;
columns: any[];
customData?: C;
namespace?: string;
};

export type VirtualBodyProps<D = any, C = any> = {
Expand All @@ -345,6 +348,7 @@ 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 @@ -415,6 +419,7 @@ export const Table: React.FC<TableProps> = ({
expand,
label,
mock,
namespace,
selectedResourcesForKind,
'aria-label': ariaLabel,
virtualize = true,
Expand Down Expand Up @@ -570,6 +575,7 @@ export const Table: React.FC<TableProps> = ({
width={width}
expand={expand}
getRowProps={getRowProps}
namespace={namespace}
/>
</div>
)}
Expand Down Expand Up @@ -672,6 +678,7 @@ 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
6 changes: 6 additions & 0 deletions frontend/public/components/resource-pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ReportReference, ReportGenerationQueryReference } from './chargeback';
import { referenceForModel, GroupVersionKind, referenceForExtensionModel } from '../module/k8s';
import {
AlertmanagerModel,
AppliedClusterResourceQuotaModel,
BuildConfigModel,
BuildModel,
ClusterOperatorModel,
Expand Down Expand Up @@ -275,6 +276,11 @@ export const baseDetailsPages = ImmutableMap<ResourceMapKey, ResourceMapValue>()
(m) => m.ResourceQuotasDetailsPage,
),
)
.set(referenceForModel(AppliedClusterResourceQuotaModel), () =>
import('./resource-quota' /* webpackChunkName: "resource-quota" */).then(
(m) => m.ResourceQuotasDetailsPage,
),
)
.set(referenceForModel(LimitRangeModel), () =>
import('./limit-range' /* webpackChunkName: "limit-range" */).then(
(m) => m.LimitRangeDetailsPage,
Expand Down
Loading

0 comments on commit 740be0e

Please sign in to comment.