Skip to content

Commit

Permalink
refator: rename prop name formItemPropsWithoutNameAndChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
yomybaby authored and agatha197 committed May 24, 2024
1 parent c74f4dd commit 8180a53
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
9 changes: 6 additions & 3 deletions react/src/components/FormItemWithUnlimited.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const FormItemWithUnlimited: React.FC<FormItemWithUnlimitedProps> = ({
name,
unlimitedValue,
children,
...formItemProps
...formItemPropsWithoutNameAndChildren
}) => {
const { t } = useTranslation();
const [isUnlimited, setIsUnlimited] = useState<boolean>(false);
Expand Down Expand Up @@ -45,12 +45,15 @@ const FormItemWithUnlimited: React.FC<FormItemWithUnlimitedProps> = ({
style={{ margin: 0 }}
name={name}
hidden={isUnlimited}
{...formItemProps}
{...formItemPropsWithoutNameAndChildren}
>
{childrenWithProps}
</Form.Item>
{isUnlimited ? (
<Form.Item style={{ margin: 0 }} {...formItemProps}>
<Form.Item
style={{ margin: 0 }}
{...formItemPropsWithoutNameAndChildren}
>
{childrenWithUndefinedValue}
</Form.Item>
) : null}
Expand Down
35 changes: 17 additions & 18 deletions react/src/components/UserResourcePolicyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { useLocalStorageState } from 'ahooks';
import { App, Button, Popconfirm, Table, theme, Typography } from 'antd';
import { AnyObject } from 'antd/es/_util/type';
import { ColumnsType, ColumnType } from 'antd/es/table';
import { ColumnType } from 'antd/es/table';
import graphql from 'babel-plugin-relay/macro';
import dayjs from 'dayjs';
import _ from 'lodash';
Expand Down Expand Up @@ -67,9 +67,12 @@ const UserResourcePolicyList: React.FC<UserResourcePolicyListProps> = () => {
id
name
created_at
# follows version of https://github.com/lablup/backend.ai/pull/1993
# --------------- START --------------------
max_vfolder_count @since(version: "23.09.6")
max_quota_scope_size @since(version: "24.03.1")
max_session_count_per_model_session @since(version: "23.09.10")
# ---------------- END ---------------------
max_quota_scope_size @since(version: "24.03.1")
max_customized_image_count @since(version: "24.03.0")
...UserResourcePolicySettingModalFragment
}
Expand All @@ -95,56 +98,52 @@ const UserResourcePolicyList: React.FC<UserResourcePolicyListProps> = () => {
}
`);

const columns: ColumnsType<UserResourcePolicies> = _.filter([
const columns = _.filter<ColumnType<UserResourcePolicies>>([
{
title: t('resourcePolicy.Name'),
dataIndex: 'name',
key: 'name',
fixed: 'left',
sorter: (a: UserResourcePolicies, b: UserResourcePolicies) =>
localeCompare(a?.name, b?.name),
sorter: (a, b) => localeCompare(a?.name, b?.name),
},
supportMaxVfolderCount && {
title: t('resourcePolicy.MaxVFolderCount'),
dataIndex: 'max_vfolder_count',
render: (text: UserResourcePolicies) =>
_.toNumber(text) === 0 ? '∞' : text,
sorter: (a: UserResourcePolicies, b: UserResourcePolicies) =>
render: (text) => (_.toNumber(text) === 0 ? '∞' : text),
sorter: (a, b) =>
(a?.max_vfolder_count ?? 0) - (b?.max_vfolder_count ?? 0),
},
supportMaxSessionCountPerModelSession && {
title: t('resourcePolicy.MaxSessionCountPerModelSession'),
dataIndex: 'max_session_count_per_model_session',
sorter: (a: UserResourcePolicies, b: UserResourcePolicies) =>
sorter: (a, b) =>
(a?.max_session_count_per_model_session ?? 0) -
(b?.max_session_count_per_model_session ?? 0),
},
supportMaxQuotaScopeSize && {
title: t('resourcePolicy.MaxQuotaScopeSize'),
dataIndex: 'max_quota_scope_size',
render: (text: number) => (text === -1 ? '∞' : bytesToGB(text)),
sorter: (a: UserResourcePolicies, b: UserResourcePolicies) =>
render: (text) => (text === -1 ? '∞' : bytesToGB(text)),
sorter: (a, b) =>
(a?.max_quota_scope_size ?? 0) - (b?.max_quota_scope_size ?? 0),
},
supportMaxCustomizedImageCount && {
title: t('resourcePolicy.MaxCustomizedImageCount'),
dataIndex: 'max_customized_image_count',
sorter: (a: UserResourcePolicies, b: UserResourcePolicies) =>
sorter: (a, b) =>
(a?.max_customized_image_count ?? 0) -
(b?.max_customized_image_count ?? 0),
},
{
title: 'ID',
dataIndex: 'id',
sorter: (a: UserResourcePolicies, b: UserResourcePolicies) =>
localeCompare(a?.id, b?.id),
sorter: (a, b) => localeCompare(a?.id, b?.id),
},
{
title: t('resourcePolicy.CreatedAt'),
dataIndex: 'created_at',
render: (text: string) => dayjs(text).format('lll'),
sorter: (a: UserResourcePolicies, b: UserResourcePolicies) =>
localeCompare(a?.created_at, b?.created_at),
render: (text) => dayjs(text).format('lll'),
sorter: (a, b) => localeCompare(a?.created_at, b?.created_at),
},
{
title: t('general.Control'),
Expand Down Expand Up @@ -269,7 +268,7 @@ const UserResourcePolicyList: React.FC<UserResourcePolicyListProps> = () => {
rowKey="id"
showSorterTooltip={false}
columns={
columns.filter((column) =>
_.filter(columns, (column) =>
displayedColumnKeys?.includes(_.toString(column.key)),
) as ColumnType<AnyObject>[]
}
Expand Down
39 changes: 31 additions & 8 deletions react/src/components/UserResourcePolicySettingModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,18 @@ import {
ModifyUserResourcePolicyInput,
UserResourcePolicySettingModalModifyMutation,
} from './__generated__/UserResourcePolicySettingModalModifyMutation.graphql';
import { Form, Input, Alert, App, InputNumber, theme } from 'antd';
import {
Form,
Input,
Alert,
App,
InputNumber,
theme,
FormInstance,
} from 'antd';
import graphql from 'babel-plugin-relay/macro';
import _ from 'lodash';
import React, { useMemo } from 'react';
import React, { useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useFragment, useMutation } from 'react-relay';

Expand All @@ -34,7 +42,7 @@ const UserResourcePolicySettingModal: React.FC<Props> = ({
const { t } = useTranslation();
const { token } = theme.useToken();
const { message } = App.useApp();
const [form] = Form.useForm();
const formRef = useRef<FormInstance>(null);

const baiClient = useSuspendedBackendaiClient();
const supportMaxVfolderCount = baiClient?.supports(
Expand All @@ -53,9 +61,12 @@ const UserResourcePolicySettingModal: React.FC<Props> = ({
fragment UserResourcePolicySettingModalFragment on UserResourcePolicy {
id
name
# follows version of https://github.com/lablup/backend.ai/pull/1993
# --------------- START --------------------
max_vfolder_count @since(version: "23.09.6")
max_quota_scope_size @since(version: "24.03.1")
max_session_count_per_model_session @since(version: "23.09.10")
# ---------------- END ---------------------
max_quota_scope_size @since(version: "24.03.1")
max_customized_image_count @since(version: "24.03.0")
}
`,
Expand Down Expand Up @@ -119,8 +130,8 @@ const UserResourcePolicySettingModal: React.FC<Props> = ({
]);

const handleOk = (e: React.MouseEvent<HTMLElement>) => {
return form
.validateFields()
return formRef?.current
?.validateFields()
.then((values) => {
const props:
| CreateUserResourcePolicyInput
Expand All @@ -134,6 +145,18 @@ const UserResourcePolicySettingModal: React.FC<Props> = ({
values?.max_session_count_per_model_session,
max_customized_image_count: values?.max_customized_image_count,
};
if (!supportMaxVfolderCount) {
delete props.max_vfolder_count;
}
if (!supportMaxQuotaScopeSize) {
delete props.max_quota_scope_size;
}
if (!supportMaxSessionCountPerModelSession) {
delete props.max_session_count_per_model_session;
}
if (!supportMaxCustomizedImageCount) {
delete props.max_customized_image_count;
}
if (userResourcePolicy === null) {
commitCreateUserResourcePolicy({
variables: {
Expand Down Expand Up @@ -201,10 +224,10 @@ const UserResourcePolicySettingModal: React.FC<Props> = ({
message={t('storageHost.BeCarefulToSetUserResourcePolicy')}
type="warning"
showIcon
style={{ marginTop: token.marginMD, marginBottom: token.marginMD }}
style={{ marginBottom: token.marginMD }}
/>
<Form
form={form}
ref={formRef}
layout="vertical"
requiredMark="optional"
initialValues={initialValues}
Expand Down

0 comments on commit 8180a53

Please sign in to comment.