Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 1871f64
Author: yangon <[email protected]>
Date:   Mon Apr 1 11:14:51 2024 +0800

    Trim string (#276)

    * fix: Trim string fields
    * fix: Disabled delete button
    * fix: Remove backup medium editing
  • Loading branch information
powerfooI committed Apr 1, 2024
1 parent 9ead6d3 commit 2e1904e
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 27 deletions.
22 changes: 18 additions & 4 deletions ui/src/components/TopoComponent/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { intl } from '@/utils/intl';
import type { GraphNodeType } from './helper';
type OperateTypeLabel = { value: string; label: string; disabled?: boolean }[];

const clusterOperate: OperateTypeLabel = [
Expand Down Expand Up @@ -39,6 +40,7 @@ const zoneOperate: OperateTypeLabel = [
id: 'dashboard.Detail.Topo.constants.DeleteZone',
defaultMessage: '删除zone',
}),
disabled: false,
},
];

Expand Down Expand Up @@ -78,7 +80,7 @@ const clusterOperateOfTenant: OperateTypeLabel = [

const getZoneOperateOfTenant = (
haveResourcePool: boolean,
tenantReplicas: API.ReplicaDetailType[]
tenantReplicas: API.ReplicaDetailType[],
): OperateTypeLabel => {
return haveResourcePool
? [
Expand All @@ -88,15 +90,15 @@ const getZoneOperateOfTenant = (
id: 'Dashboard.components.TopoComponent.constants.EditResourcePool',
defaultMessage: '编辑资源池',
}),
disabled: false
disabled: false,
},
{
value: 'deleteResourcePool',
label: intl.formatMessage({
id: 'Dashboard.components.TopoComponent.constants.DeleteAResourcePool',
defaultMessage: '删除资源池',
}),
disabled: tenantReplicas.length <= 2
disabled: tenantReplicas.length <= 2,
},
]
: [
Expand All @@ -106,14 +108,26 @@ const getZoneOperateOfTenant = (
id: 'Dashboard.components.TopoComponent.constants.AddAResourcePool',
defaultMessage: '新增资源池',
}),
disabled: false
disabled: false,
},
];
};

const getZoneOperateOfCluster = (
topoData: GraphNodeType | undefined,
): OperateTypeLabel => {
if (!topoData) return [];
const isDisabled = topoData?.children?.length <= 2;
zoneOperate.forEach((operate) => {
if (operate.value === 'deleteZone') operate.disabled = isDisabled;
});
return zoneOperate;
};

export {
clusterOperate,
clusterOperateOfTenant,
getZoneOperateOfCluster,
getZoneOperateOfTenant,
serverOperate,
zoneOperate,
Expand Down
2 changes: 1 addition & 1 deletion ui/src/components/TopoComponent/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type TooltipInfo = {
minIops: number;
};

type GraphNodeType = {
export type GraphNodeType = {
id: string;
label: string;
status: string;
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/TopoComponent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import {
clusterOperate,
clusterOperateOfTenant,
getZoneOperateOfTenant,
getZoneOperateOfCluster,
serverOperate,
zoneOperate,
} from './constants';
import { appenAutoShapeListener,checkIsSame,getServerNumber,haveDisabledOperate } from './helper';

Expand Down Expand Up @@ -107,7 +107,7 @@ export default function TopoComponent({
getZoneOperateOfTenant(haveResourcePool, tenantReplicas),
);
} else {
setOprateList(zoneOperate);
setOprateList(getZoneOperateOfCluster(originTopoData?.topoData));
}
chooseZoneName.current = zone;
break;
Expand Down
4 changes: 2 additions & 2 deletions ui/src/pages/Cluster/Detail/Overview/ZoneTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function ZoneTable({
})}
</Button>
<Button
style={clusterStatus !== 'failed' ? { color: '#ff4b4b' } : {}}
style={(clusterStatus !== 'failed' && zones.length > 2) ? { color: '#ff4b4b' } : {}}
onClick={() => {
showDeleteConfirm({
onOk: () => remove(record.zone),
Expand All @@ -110,7 +110,7 @@ export default function ZoneTable({
}),
});
}}
disabled={clusterStatus === 'failed'}
disabled={clusterStatus === 'failed' || zones.length <= 2}
type="link"
>
{intl.formatMessage({
Expand Down
3 changes: 2 additions & 1 deletion ui/src/pages/Cluster/New/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PageContainer } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';
import { useRequest } from 'ahooks';
import { Button,Form,Row,message } from 'antd';
import { strTrim } from '@/utils/helper';
import { useState } from 'react';

import { MODE_MAP } from '@/constants';
Expand Down Expand Up @@ -44,7 +45,7 @@ export default function New() {
values.clusterId = new Date().getTime() % 4294901759;
values.rootPassword = encryptText(values.rootPassword, publicKey) as string;

const res = await createClusterReportWrap({...values});
const res = await createClusterReportWrap({...strTrim(values)});
if (res.successful) {
message.success(res.message, 3);
form.resetFields();
Expand Down
15 changes: 0 additions & 15 deletions ui/src/pages/Tenant/Detail/Backup/BackupConfiguration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,21 +76,6 @@ export default function BackupConfiguration({
id: 'Dashboard.Detail.Backup.BackupConfiguration.BackupMediaType',
defaultMessage: '备份介质类型',
}),
editRender: (
<Select
style={{ width: 216 }}
options={[
{
label: 'OSS',
value: 'OSS',
},
{
label: 'NFS',
value: 'NFS',
},
]}
/>
),
},
};
if (backupPolicy.ossAccessSecret) {
Expand Down
3 changes: 2 additions & 1 deletion ui/src/pages/Tenant/Detail/NewBackup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useNavigate } from '@umijs/max';
import { useRequest } from 'ahooks';
import { Button, Card, Col, Form, Input, Row, Select, message } from 'antd';
import { checkScheduleDatesHaveFull, formatBackupForm } from '../../helper';
import { strTrim } from '@/utils/helper';
import BasicInfo from '../Overview/BasicInfo';
import AdvancedConfiguration from './AdvancedConfiguration';
import BakMethodsList from './BakMethodsList';
Expand Down Expand Up @@ -39,7 +40,7 @@ export default function NewBackup() {
const res = await createBackupReportWrap({
ns,
name,
...formatBackupForm(values, publicKey)
...formatBackupForm(strTrim(values), publicKey)
});
if (res.successful) {
message.success(
Expand Down
3 changes: 2 additions & 1 deletion ui/src/pages/Tenant/New/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { intl } from '@/utils/intl';
import { PageContainer } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';
import { useRequest, useUpdateEffect } from 'ahooks';
import { strTrim } from '@/utils/helper';
import { Button, Col, Form, Row, message } from 'antd';
import { useEffect, useState } from 'react';
import { formatNewTenantForm } from '../helper';
Expand Down Expand Up @@ -46,7 +47,7 @@ export default function New() {
const essentialParameter = essentialParameterRes?.data;

const onFinish = async (values: any) => {
const reqData = formatNewTenantForm(values, clusterName, publicKey);
const reqData = formatNewTenantForm(strTrim(values), clusterName, publicKey);
if (!reqData.pools?.length) {
message.warning(
intl.formatMessage({
Expand Down
13 changes: 13 additions & 0 deletions ui/src/utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ type StatisticStatus = 'running' | 'deleting' | 'operating' | 'failed';

type StatisticDataType = { status: StatisticStatus; count: number }[];

type ObjType = { [key: string]: any };

export const getInitialObjOfKeys = (targetObj: any, keys: string[]) => {
return keys.reduce((pre, cur) => {
pre[cur] = targetObj[cur];
Expand Down Expand Up @@ -73,6 +75,17 @@ export const formatPatchPoolData = (
return newOriginUnitData;
};


export const strTrim = (obj: ObjType): ObjType => {
Object.keys(obj).forEach((key: keyof ObjType) => {
if (typeof obj[key] === 'string') {
obj[key] = obj[key].trim();
} else if (typeof obj[key] === 'object' && obj[key] !== null) {
strTrim(obj[key]);
}
});
return obj;
};
export const getAppInfoFromStorage = async (): Promise<API.AppInfo> => {
try {
let appInfo: API.AppInfo = JSON.parse(sessionStorage.getItem('appInfo'));
Expand Down

0 comments on commit 2e1904e

Please sign in to comment.