Skip to content

Commit

Permalink
feat(FR-360): add max_pending_session_count, `max_concurrent_sftp_s…
Browse files Browse the repository at this point in the history
…essions` to keypair resource policy.
  • Loading branch information
agatha197 committed Jan 14, 2025
1 parent 8ab28a8 commit 27be261
Show file tree
Hide file tree
Showing 26 changed files with 286 additions and 149 deletions.
24 changes: 11 additions & 13 deletions react/src/components/FormItemWithUnlimited.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import Flex from './Flex';
import { Form, Checkbox, FormItemProps } from 'antd';
import { CheckboxChangeEvent } from 'antd/es/checkbox';
import React, {
cloneElement,
isValidElement,
useEffect,
useState,
} from 'react';
import React, { cloneElement, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';

interface FormItemWithUnlimitedProps extends FormItemProps {
unlimitedValue?: number | string;
unlimitedValue?: number | string | null;
disableUnlimited?: boolean;
}

const FormItemWithUnlimited: React.FC<FormItemWithUnlimitedProps> = ({
name,
unlimitedValue,
disableUnlimited,
children,
...formItemPropsWithoutNameAndChildren
}) => {
Expand All @@ -30,19 +27,19 @@ const FormItemWithUnlimited: React.FC<FormItemWithUnlimitedProps> = ({
}, [form, name, unlimitedValue]);

// Disable children when isUnlimited is true.
const childrenWithProps = isValidElement(children)
const childrenWithProps = React.isValidElement(children)
? cloneElement(children, {
disabled: isUnlimited,
} as React.Attributes & { disabled?: boolean })
: children;

const childrenWithNullValue =
isUnlimited && isValidElement(children)
const childrenWithUndefinedValue =
isUnlimited && React.isValidElement(children)
? cloneElement(children, {
value: null,
value: undefined,
disabled: isUnlimited,
} as React.Attributes & { value?: any })
: null;
: undefined;

return (
<Flex direction="column" align="start">
Expand All @@ -59,11 +56,12 @@ const FormItemWithUnlimited: React.FC<FormItemWithUnlimitedProps> = ({
style={{ margin: 0 }}
{...formItemPropsWithoutNameAndChildren}
>
{childrenWithNullValue}
{childrenWithUndefinedValue}
</Form.Item>
) : null}
<Checkbox
checked={isUnlimited}
disabled={disableUnlimited}
onChange={(e: CheckboxChangeEvent) => {
const checked = e.target.checked;
setIsUnlimited(checked);
Expand Down
56 changes: 40 additions & 16 deletions react/src/components/KeypairResourcePolicyList.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { localeCompare, numberSorterWithInfinityValue } from '../helper';
import {
UNLIMITED_MAX_CONCURRENT_SESSIONS,
UNLIMITED_MAX_CONTAINERS_PER_SESSIONS,
} from '../helper/const-vars';
localeCompare,
numberSorterWithInfinityValue,
filterEmptyItem,
} from '../helper';
import { SIGNED_32BIT_MAX_INT } from '../helper/const-vars';
import { exportCSVWithFormattingRules } from '../helper/csv-util';
import { useSuspendedBackendaiClient, useUpdatableState } from '../hooks';
import { useHiddenColumnKeysSetting } from '../hooks/useHiddenColumnKeysSetting';
Expand Down Expand Up @@ -67,8 +68,6 @@ const KeypairResourcePolicyList: React.FC<KeypairResourcePolicyListProps> = (
useState<KeypairResourcePolicySettingModalFragment$key | null>();

const baiClient = useSuspendedBackendaiClient();
const enableParsingStoragePermission =
baiClient?.supports('fine-grained-storage-permissions') ?? false;

const { keypair_resource_policies } =
useLazyLoadQuery<KeypairResourcePolicyListQuery>(
Expand All @@ -82,6 +81,8 @@ const KeypairResourcePolicyList: React.FC<KeypairResourcePolicyListProps> = (
max_containers_per_session
idle_timeout
allowed_vfolder_hosts
max_pending_session_count @since(version: "24.03.4")
max_concurrent_sftp_sessions @since(version: "24.03.4")
...KeypairResourcePolicySettingModalFragment
}
}
Expand All @@ -106,7 +107,7 @@ const KeypairResourcePolicyList: React.FC<KeypairResourcePolicyListProps> = (
}
`);

const columns: ColumnsType<KeypairResourcePolicies> = [
const columns: ColumnsType<KeypairResourcePolicies> = filterEmptyItem([
{
title: t('resourcePolicy.Name'),
dataIndex: 'name',
Expand Down Expand Up @@ -146,8 +147,7 @@ const KeypairResourcePolicyList: React.FC<KeypairResourcePolicyListProps> = (
a?.max_concurrent_sessions && b?.max_concurrent_sessions
? a.max_concurrent_sessions - b.max_concurrent_sessions
: 1,
render: (text) =>
text === UNLIMITED_MAX_CONCURRENT_SESSIONS ? '∞' : text,
render: (text) => (text ? text : '∞'),
},
{
title: t('resourcePolicy.ClusterSize'),
Expand All @@ -157,8 +157,7 @@ const KeypairResourcePolicyList: React.FC<KeypairResourcePolicyListProps> = (
a?.max_containers_per_session && b?.max_containers_per_session
? a.max_containers_per_session - b.max_containers_per_session
: 1,
render: (text) =>
text === UNLIMITED_MAX_CONTAINERS_PER_SESSIONS ? '∞' : text,
render: (text) => (text === SIGNED_32BIT_MAX_INT ? '∞' : text),
},
{
title: t('resourcePolicy.IdleTimeout'),
Expand Down Expand Up @@ -187,7 +186,9 @@ const KeypairResourcePolicyList: React.FC<KeypairResourcePolicyListProps> = (
dataIndex: 'allowed_vfolder_hosts',
key: 'allowed_vfolder_hosts',
render: (text, row) => {
const allowedVFolderHosts = enableParsingStoragePermission
const allowedVFolderHosts = baiClient?.supports(
'fine-grained-storage-permissions',
)
? _.keys(JSON.parse(row?.allowed_vfolder_hosts || '{}'))
: JSON.parse(row?.allowed_vfolder_hosts || '{}');
return (
Expand All @@ -199,6 +200,30 @@ const KeypairResourcePolicyList: React.FC<KeypairResourcePolicyListProps> = (
);
},
},
baiClient?.supports('max-pending-session-count') && {
title: t('resourcePolicy.MaxPendingSessionCount'),
dataIndex: 'max_pending_session_count',
key: 'max_pending_session_count',
sorter: (a, b) =>
numberSorterWithInfinityValue(
a?.max_pending_session_count,
b?.max_pending_session_count,
0,
),
render: (text) => (text ? text : '∞'),
},
baiClient?.supports('max-concurrent-sftp-sessions') && {
title: t('resourcePolicy.MaxConcurrentSFTPSessions'),
dataIndex: 'max_concurrent_sftp_sessions',
key: 'max_concurrent_sftp_sessions',
sorter: (a, b) =>
numberSorterWithInfinityValue(
a?.max_concurrent_sftp_sessions,
b?.max_concurrent_sftp_sessions,
0,
),
render: (text) => (text ? text : '∞'),
},
{
title: t('general.Control'),
key: 'control',
Expand Down Expand Up @@ -282,7 +307,7 @@ const KeypairResourcePolicyList: React.FC<KeypairResourcePolicyListProps> = (
</Flex>
),
},
];
]);

const [hiddenColumnKeys, setHiddenColumnKeys] = useHiddenColumnKeysSetting(
'KeypairResourcePolicyList',
Expand Down Expand Up @@ -311,10 +336,9 @@ const KeypairResourcePolicyList: React.FC<KeypairResourcePolicyListProps> = (
{
total_resource_slots: (text) =>
_.isEmpty(text) ? '-' : JSON.stringify(text),
max_concurrent_sessions: (text) =>
text === UNLIMITED_MAX_CONCURRENT_SESSIONS ? '-' : text,
max_concurrent_sessions: (text) => (text ? text : '-'),
max_containers_per_session: (text) =>
text === UNLIMITED_MAX_CONTAINERS_PER_SESSIONS ? '-' : text,
text === SIGNED_32BIT_MAX_INT ? '-' : text,
idle_timeout: (text) => (text ? text : '-'),
max_session_lifetime: (text) => (text ? text : '-'),
allowed_vfolder_hosts: (text) =>
Expand Down
Loading

0 comments on commit 27be261

Please sign in to comment.