-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create Resource Quotas views (#3336)
* add resource quotas views * add tests * change list to ts, fix deps * add readonly * adjust test * adjust small list and spec * cleanup * review adjustments
- Loading branch information
1 parent
ae319ec
commit 6cc72c6
Showing
16 changed files
with
443 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.resource-quota-limits { | ||
&.compact { | ||
margin: 0 0 1rem 0 !important; | ||
padding-right: 0.5rem; | ||
} | ||
text-transform: capitalize; | ||
} | ||
|
||
.resource-quota-spec-subheader { | ||
border-block-end: 0.0625rem solid var(--sapGroup_TitleBorderColor); | ||
padding-bottom: 0.5rem; | ||
} | ||
|
||
ui5-table-cell:has(> ui5-panel.resource-quota-limits.compact) { | ||
display: inline !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { ResourceDetails } from 'shared/components/ResourceDetails/ResourceDetails'; | ||
import { ResourceDescription } from '.'; | ||
import ResourceQuotaCreate from './ResourceQuotaCreate'; | ||
import ResourceQuotaLimits from './ResourceQuotaLimits'; | ||
import { UI5Panel } from 'shared/components/UI5Panel/UI5Panel'; | ||
import { LayoutPanelRow } from 'shared/components/LayoutPanelRow/LayoutPanelRow'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Tokens } from 'shared/components/Tokens'; | ||
import { Text, Title } from '@ui5/webcomponents-react'; | ||
import { spacing } from '@ui5/webcomponents-react-base'; | ||
|
||
export type ResourceQuotaProps = { | ||
kind: string; | ||
apiVersion: string; | ||
metadata: { | ||
name: string; | ||
namespace: string; | ||
}; | ||
spec: { | ||
scopes?: string[]; | ||
hard: { | ||
[key: string]: string; | ||
}; | ||
scopeSelector?: { | ||
matchExpressions: { | ||
scopeName: string; | ||
operator: string; | ||
values?: string[]; | ||
}[]; | ||
}; | ||
}; | ||
status: { | ||
hard: { | ||
[key: string]: string; | ||
}; | ||
used: { | ||
[key: string]: string; | ||
}; | ||
}; | ||
}; | ||
|
||
export default function ResourceQuotaDetails(props: any) { | ||
const { t } = useTranslation(); | ||
|
||
const customComponents = [ | ||
(resource: ResourceQuotaProps) => { | ||
return ( | ||
<> | ||
{(resource.spec.scopes || resource.spec.scopeSelector) && ( | ||
<UI5Panel title={t('common.headers.specification')}> | ||
{resource.spec?.scopes && ( | ||
<LayoutPanelRow | ||
name={t('resource-quotas.headers.scopes')} | ||
value={<Tokens tokens={resource.spec.scopes} />} | ||
/> | ||
)} | ||
{resource.spec?.scopeSelector && ( | ||
<UI5Panel title={t('resource-quotas.headers.scope-selectors')}> | ||
{resource.spec.scopeSelector?.matchExpressions?.map(scope => ( | ||
<> | ||
<Title | ||
level="H6" | ||
className="resource-quota-spec-subheader" | ||
style={spacing.sapUiSmallMargin} | ||
> | ||
{scope.scopeName} | ||
</Title> | ||
<LayoutPanelRow | ||
name={t('resource-quotas.headers.operator')} | ||
value={<Text>{scope.operator}</Text>} | ||
/> | ||
{scope.values && ( | ||
<LayoutPanelRow | ||
name={t('resource-quotas.headers.values')} | ||
value={<Tokens tokens={scope.values} />} | ||
/> | ||
)} | ||
</> | ||
))} | ||
</UI5Panel> | ||
)} | ||
</UI5Panel> | ||
)} | ||
</> | ||
); | ||
}, | ||
(resource: ResourceQuotaProps) => ( | ||
<ResourceQuotaLimits resource={resource} /> | ||
), | ||
]; | ||
|
||
return ( | ||
<ResourceDetails | ||
description={ResourceDescription} | ||
createResourceForm={ResourceQuotaCreate} | ||
customComponents={customComponents} | ||
{...props} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { useMemo } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { GenericList } from 'shared/components/GenericList/GenericList'; | ||
import { EMPTY_TEXT_PLACEHOLDER } from 'shared/constants'; | ||
import './ResourceQuotaDetails.scss'; | ||
import { ResourceQuotaProps } from './ResourceQuotaDetails'; | ||
|
||
type ResourceTableEntry = { | ||
resource: string; | ||
used: string; | ||
hard: string; | ||
}; | ||
|
||
export default function ResourceQuotaLimits({ | ||
resource, | ||
isCompact = false, | ||
}: { | ||
resource: ResourceQuotaProps; | ||
isCompact?: boolean; | ||
}) { | ||
const { t } = useTranslation(); | ||
|
||
const headerRenderer = () => [ | ||
t('resource-quotas.headers.resource'), | ||
t('resource-quotas.headers.hard'), | ||
t('resource-quotas.headers.used'), | ||
]; | ||
|
||
const parsedResourceQuota = useMemo(() => { | ||
const result: ResourceTableEntry[] = []; | ||
|
||
const hardResources = resource.spec.hard; | ||
const usedResources = resource.status.used; | ||
|
||
for (const resource in hardResources) { | ||
if (hardResources.hasOwnProperty(resource)) { | ||
result.push({ | ||
resource, | ||
hard: hardResources[resource], | ||
used: usedResources[resource] || '0', | ||
}); | ||
} | ||
} | ||
|
||
return result; | ||
}, [resource.spec.hard, resource.status.used]); | ||
|
||
const rowRenderer = ({ resource, used, hard }: ResourceTableEntry) => { | ||
return [ | ||
resource || EMPTY_TEXT_PLACEHOLDER, | ||
hard || EMPTY_TEXT_PLACEHOLDER, | ||
used || EMPTY_TEXT_PLACEHOLDER, | ||
]; | ||
}; | ||
|
||
return ( | ||
<GenericList | ||
title={!isCompact ? t('resource-quotas.headers.limits-usage') : null} | ||
entries={parsedResourceQuota || []} | ||
headerRenderer={headerRenderer} | ||
rowRenderer={rowRenderer} | ||
searchSettings={{ | ||
showSearchField: false, | ||
}} | ||
className={`resource-quota-limits ${isCompact ? 'compact' : ''}`} | ||
/> | ||
); | ||
} |
32 changes: 17 additions & 15 deletions
32
...urces/ResourceQuotas/ResourceQuotaList.js → ...rces/ResourceQuotas/ResourceQuotaList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,51 @@ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { ResourcesList } from 'shared/components/ResourcesList/ResourcesList'; | ||
import { ResourceDescription, docsURL, i18nDescriptionKey } from '.'; | ||
import { EMPTY_TEXT_PLACEHOLDER } from 'shared/constants'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { ResourceQuotaCreate } from './ResourceQuotaCreate'; | ||
import ResourceQuotaCreate from './ResourceQuotaCreate'; | ||
import { ResourceQuotaProps } from './ResourceQuotaDetails'; | ||
|
||
export function ResourceQuotaList(props) { | ||
export default function ResourceQuotaList(props: any) { | ||
const { t } = useTranslation(); | ||
|
||
const customColumns = [ | ||
{ | ||
header: t('resource-quotas.headers.limits.cpu'), | ||
value: quota => | ||
value: (quota: ResourceQuotaProps) => | ||
quota.spec?.hard?.['limits.cpu'] || EMPTY_TEXT_PLACEHOLDER, | ||
}, | ||
{ | ||
header: t('resource-quotas.headers.limits.memory'), | ||
value: quota => | ||
value: (quota: ResourceQuotaProps) => | ||
quota.spec?.hard?.['limits.memory'] || EMPTY_TEXT_PLACEHOLDER, | ||
}, | ||
{ | ||
header: t('resource-quotas.headers.requests.cpu'), | ||
value: quota => | ||
value: (quota: ResourceQuotaProps) => | ||
quota.spec?.hard?.['requests.cpu'] || | ||
quota.spec?.hard?.cpu || | ||
EMPTY_TEXT_PLACEHOLDER, | ||
}, | ||
{ | ||
header: t('resource-quotas.headers.requests.memory'), | ||
value: quota => | ||
value: (quota: ResourceQuotaProps) => | ||
quota.spec?.hard?.['requests.memory'] || | ||
quota.spec?.hard?.memory || | ||
EMPTY_TEXT_PLACEHOLDER, | ||
}, | ||
]; | ||
|
||
return ( | ||
<ResourcesList | ||
disableHiding={true} | ||
simpleEmptyListMessage={true} | ||
displayArrow={false} | ||
resourceTitle={t('resource-quotas.title')} | ||
customColumns={customColumns} | ||
resourceTitle={t('limit-ranges.title')} | ||
description={ResourceDescription} | ||
{...props} | ||
createResourceForm={ResourceQuotaCreate} | ||
emptyListProps={{ | ||
subtitleText: i18nDescriptionKey, | ||
url: docsURL, | ||
}} | ||
customColumns={customColumns} | ||
/> | ||
); | ||
} | ||
|
||
export default ResourceQuotaList; |
Oops, something went wrong.