Skip to content

Commit

Permalink
fix: add max value for User/Project setting modal
Browse files Browse the repository at this point in the history
  • Loading branch information
nowgnuesLee committed Jan 20, 2025
1 parent 5e36c40 commit 5d00863
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 62 deletions.
119 changes: 64 additions & 55 deletions react/src/components/KeypairResourcePolicySettingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -329,65 +329,74 @@ const KeypairResourcePolicySettingModal: React.FC<
},
}}
>
{_.map(
_.chunk(_.keys(resourceSlots), 2),
(resourceSlotKeys, index) => (
{_.chain(resourceSlots)
.keys()
.chunk(2)
.map((resourceSlotKeys, index) => (
<Row gutter={[16, 16]} key={index}>
{_.map(resourceSlotKeys, (resourceSlotKey) => (
<Col
span={12}
key={resourceSlotKey}
style={{ alignSelf: 'end', marginBottom: token.marginLG }}
>
<FormItemWithUnlimited
unlimitedValue={undefined}
label={
_.get(mergedResourceSlots, resourceSlotKey)
?.description || resourceSlotKey
}
name={['parsedTotalResourceSlots', resourceSlotKey]}
rules={[
{
validator(__, value) {
if (
_.includes(resourceSlotKey, 'mem') &&
value &&
// @ts-ignore
convertBinarySizeUnit(value, 'p').number >
{_.chain(resourceSlotKeys)
.map((resourceSlotKey) => (
<Col
span={12}
key={resourceSlotKey}
style={{
alignSelf: 'end',
marginBottom: token.marginLG,
}}
>
<FormItemWithUnlimited
unlimitedValue={undefined}
label={
_.get(mergedResourceSlots, resourceSlotKey)
?.description || resourceSlotKey
}
name={['parsedTotalResourceSlots', resourceSlotKey]}
rules={[
{
validator(__, value) {
console.log(resourceSlotKey);
if (
_.includes(resourceSlotKey, 'mem') &&
value &&
// @ts-ignore
convertBinarySizeUnit('300p', 'p').number
) {
return Promise.reject(
new Error(
t('resourcePolicy.MemorySizeExceedsLimit'),
),
);
}
return Promise.resolve();
convertBinarySizeUnit(value, 'p').number >
// @ts-ignore
convertBinarySizeUnit('300p', 'p').number
) {
return Promise.reject(
new Error(
t(
'resourcePolicy.MemorySizeExceedsLimit',
),
),
);
}
return Promise.resolve();
},
},
},
]}
>
{_.includes(resourceSlotKey, 'mem') ? (
<DynamicUnitInputNumber />
) : (
<InputNumber
min={0}
step={
_.includes(resourceSlotKey, '.shares') ? 0.1 : 1
}
addonAfter={
_.get(mergedResourceSlots, resourceSlotKey)
?.display_unit
}
/>
)}
</FormItemWithUnlimited>
</Col>
))}
]}
>
{_.includes(resourceSlotKey, 'mem') ? (
<DynamicUnitInputNumber />
) : (
<InputNumber
min={0}
step={
_.includes(resourceSlotKey, '.shares') ? 0.1 : 1
}
addonAfter={
_.get(mergedResourceSlots, resourceSlotKey)
?.display_unit
}
/>
)}
</FormItemWithUnlimited>
</Col>
))
.value()}
</Row>
),
)}
))
.value()}
</Card>
</Form.Item>
<Form.Item label={t('resourcePolicy.Sessions')} required>
Expand Down
20 changes: 17 additions & 3 deletions react/src/components/ProjectResourcePolicySettingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GBToBytes, bytesToGB } from '../helper';
import { SIGNED_32BIT_MAX_INT } from '../helper/const-vars';
import { useSuspendedBackendaiClient } from '../hooks';
import BAIModal, { BAIModalProps } from './BAIModal';
import Flex from './Flex';
Expand Down Expand Up @@ -266,7 +267,11 @@ const ProjectResourcePolicySettingModal: React.FC<Props> = ({
label={t('resourcePolicy.MaxFolderCount')}
style={{ width: '100%', margin: 0 }}
>
<InputNumber min={0} style={{ width: '100%' }} />
<InputNumber
min={0}
max={SIGNED_32BIT_MAX_INT}
style={{ width: '100%' }}
/>
</FormItemWithUnlimited>
) : null}
{supportMaxQuotaScopeSize ? (
Expand All @@ -276,7 +281,12 @@ const ProjectResourcePolicySettingModal: React.FC<Props> = ({
label={t('storageHost.MaxFolderSize')}
style={{ width: '100%', margin: 0 }}
>
<InputNumber min={0} addonAfter="GB" style={{ width: '100%' }} />
<InputNumber
min={0}
max={Number.MAX_SAFE_INTEGER}
addonAfter="GB"
style={{ width: '100%' }}
/>
</FormItemWithUnlimited>
) : null}
{supportMaxNetworkCount ? (
Expand All @@ -286,7 +296,11 @@ const ProjectResourcePolicySettingModal: React.FC<Props> = ({
label={t('resourcePolicy.MaxNetworkCount')}
style={{ width: '100%', margin: 0 }}
>
<InputNumber min={0} style={{ width: '100%' }} />
<InputNumber
min={0}
max={SIGNED_32BIT_MAX_INT}
style={{ width: '100%' }}
/>
</FormItemWithUnlimited>
) : null}
</Flex>
Expand Down
26 changes: 22 additions & 4 deletions react/src/components/UserResourcePolicySettingModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GBToBytes, bytesToGB } from '../helper';
import { SIGNED_32BIT_MAX_INT } from '../helper/const-vars';
import { useSuspendedBackendaiClient } from '../hooks';
import BAIModal, { BAIModalProps } from './BAIModal';
import Flex from './Flex';
Expand Down Expand Up @@ -275,7 +276,11 @@ const UserResourcePolicySettingModal: React.FC<Props> = ({
label={t('resourcePolicy.MaxFolderCount')}
style={{ width: '100%', margin: 0 }}
>
<InputNumber min={0} style={{ width: '100%' }} />
<InputNumber
min={0}
max={SIGNED_32BIT_MAX_INT}
style={{ width: '100%' }}
/>
</FormItemWithUnlimited>
) : null}
{supportMaxQuotaScopeSize ? (
Expand All @@ -285,7 +290,12 @@ const UserResourcePolicySettingModal: React.FC<Props> = ({
label={t('storageHost.MaxFolderSize')}
style={{ width: '100%', margin: 0 }}
>
<InputNumber min={0} addonAfter="GB" style={{ width: '100%' }} />
<InputNumber
min={0}
max={Number.MAX_SAFE_INTEGER}
addonAfter="GB"
style={{ width: '100%' }}
/>
</FormItemWithUnlimited>
) : null}
</Flex>
Expand All @@ -297,7 +307,11 @@ const UserResourcePolicySettingModal: React.FC<Props> = ({
{ required: true, message: t('data.explorer.ValueRequired') },
]}
>
<InputNumber min={0} style={{ width: '100%' }} />
<InputNumber
min={0}
max={SIGNED_32BIT_MAX_INT}
style={{ width: '100%' }}
/>
</Form.Item>
) : null}
{supportMaxCustomizedImageCount ? (
Expand All @@ -308,7 +322,11 @@ const UserResourcePolicySettingModal: React.FC<Props> = ({
{ required: true, message: t('data.explorer.ValueRequired') },
]}
>
<InputNumber min={0} style={{ width: '100%' }} />
<InputNumber
min={0}
max={SIGNED_32BIT_MAX_INT}
style={{ width: '100%' }}
/>
</Form.Item>
) : null}
</Form>
Expand Down
1 change: 1 addition & 0 deletions react/src/helper/const-vars.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const UNLIMITED_MAX_CONTAINERS_PER_SESSIONS = 1000000;
export const UNLIMITED_MAX_CONCURRENT_SESSIONS = 1000000;
export const SIGNED_32BIT_MAX_INT = Math.pow(2, 31) - 1;

0 comments on commit 5d00863

Please sign in to comment.