Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FR-360): add max_pending_session_count, max_concurrent_sftp_sessions to keypair resource policy. #3025

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading