InstallConfig.tsx 34.0 KB
Newer Older
R
Rongfeng Fu 已提交
1
import { intl } from '@/utils/intl';
R
Rongfeng Fu 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
import { useEffect, useState, useRef } from 'react';
import { useModel } from 'umi';
import {
  Space,
  Button,
  Form,
  Tag,
  Table,
  Alert,
  Tooltip,
  Select,
  Modal,
  Spin,
  message,
} from 'antd';
import { ProCard, ProForm, ProFormText } from '@ant-design/pro-components';
import {
  CloseOutlined,
  SafetyCertificateFilled,
  InfoOutlined,
  InfoCircleOutlined,
  CopyOutlined,
} from '@ant-design/icons';
import type { ColumnsType } from 'antd/es/table';
import useRequest from '@/utils/useRequest';
import { queryAllComponentVersions } from '@/services/ob-deploy-web/Components';
import {
R
Rongfeng Fu 已提交
29 30
  getDeployment,
  destroyDeployment,
R
Rongfeng Fu 已提交
31 32
} from '@/services/ob-deploy-web/Deployments';
import { listRemoteMirrors } from '@/services/ob-deploy-web/Mirror';
R
Rongfeng Fu 已提交
33
import { handleQuit, checkLowVersion, getErrorInfo } from '@/utils';
R
Rongfeng Fu 已提交
34 35 36 37 38 39 40 41 42 43 44 45
import NP from 'number-precision';
import copy from 'copy-to-clipboard';
import DeployType from './DeployType';
import DeleteDeployModal from './DeleteDeployModal';
import {
  commonStyle,
  allComponentsName,
  oceanbaseComponent,
  obproxyComponent,
  ocpexpressComponent,
  obagentComponent,
} from '../constants';
R
Rongfeng Fu 已提交
46 47 48 49 50 51
import { getLocale } from 'umi';
import EnStyles from './indexEn.less';
import ZhStyles from './indexZh.less';

const locale = getLocale();
const styles = locale === 'zh-CN' ? ZhStyles : EnStyles;
R
Rongfeng Fu 已提交
52 53 54 55 56 57 58 59 60

interface FormValues {
  type?: string;
}

const appnameReg = /^[a-zA-Z]([a-zA-Z0-9]{0,19})$/;

const componentsGroupInfo = [
  {
R
Rongfeng Fu 已提交
61 62 63 64
    group: intl.formatMessage({
      id: 'OBD.pages.components.InstallConfig.Database',
      defaultMessage: '数据库',
    }),
R
Rongfeng Fu 已提交
65 66 67 68 69 70
    key: 'database',
    content: [
      {
        key: oceanbaseComponent,
        name: 'OceanBase Database',
        onlyAll: false,
R
Rongfeng Fu 已提交
71 72 73 74 75
        desc: intl.formatMessage({
          id: 'OBD.pages.components.InstallConfig.ItIsAFinancialLevel',
          defaultMessage:
            '是金融级分布式数据库,具备数据强一致、高扩展、高可用、高性价比、稳定可靠等特征。',
        }),
R
Rongfeng Fu 已提交
76 77 78 79 80
        doc: 'https://www.oceanbase.com/docs/oceanbase-database-cn',
      },
    ],
  },
  {
R
Rongfeng Fu 已提交
81 82 83 84
    group: intl.formatMessage({
      id: 'OBD.pages.components.InstallConfig.Proxy',
      defaultMessage: '代理',
    }),
R
Rongfeng Fu 已提交
85 86 87 88 89 90 91
    key: 'agency',
    onlyAll: true,
    content: [
      {
        key: obproxyComponent,
        name: 'OBProxy',
        onlyAll: true,
R
Rongfeng Fu 已提交
92 93 94 95 96
        desc: intl.formatMessage({
          id: 'OBD.pages.components.InstallConfig.ItIsAProxyServer',
          defaultMessage:
            '是 OceanBase 数据库专用的代理服务器,可以将用户 SQL 请求转发至最佳目标 OBServer 。',
        }),
R
Rongfeng Fu 已提交
97 98 99 100 101
        doc: 'https://www.oceanbase.com/docs/odp-enterprise-cn',
      },
    ],
  },
  {
R
Rongfeng Fu 已提交
102 103 104 105
    group: intl.formatMessage({
      id: 'OBD.pages.components.InstallConfig.Tools',
      defaultMessage: '工具',
    }),
R
Rongfeng Fu 已提交
106 107 108 109 110
    key: 'tool',
    onlyAll: true,
    content: [
      {
        key: ocpexpressComponent,
R
Rongfeng Fu 已提交
111
        name: 'OCP Express',
R
Rongfeng Fu 已提交
112
        onlyAll: true,
R
Rongfeng Fu 已提交
113 114 115 116 117
        desc: intl.formatMessage({
          id: 'OBD.pages.components.InstallConfig.ItIsAManagementAnd',
          defaultMessage:
            '是专为 OceanBase 设计的管控平台,可实现对集群、租户的监控管理、诊断等核心能力。',
        }),
R
Rongfeng Fu 已提交
118 119 120 121 122 123
        doc: 'https://www.oceanbase.com/docs/common-oceanbase-database-cn-0000000001626262',
      },
      {
        key: obagentComponent,
        name: 'OBAgent',
        onlyAll: true,
R
Rongfeng Fu 已提交
124 125 126 127 128
        desc: intl.formatMessage({
          id: 'OBD.pages.components.InstallConfig.IsAMonitoringAndCollection',
          defaultMessage:
            '是一个监控采集框架。OBAgent 支持推、拉两种数据采集模式,可以满足不同的应用场景。',
        }),
R
Rongfeng Fu 已提交
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
        doc: 'https://www.oceanbase.com/docs/common-oceanbase-database-cn-10000000001576872',
      },
    ],
  },
];

const mirrors = ['oceanbase.community.stable', 'oceanbase.development-kit'];

export default function InstallConfig() {
  const {
    initAppName,
    setCurrentStep,
    configData,
    setConfigData,
    currentType,
    setCurrentType,
    lowVersion,
    isFirstTime,
    setIsFirstTime,
    isDraft,
    setIsDraft,
    componentsVersionInfo,
    setComponentsVersionInfo,
    handleQuitProgress,
    getInfoByName,
    setLowVersion,
R
Rongfeng Fu 已提交
155 156 157
    setErrorVisible,
    errorsList,
    setErrorsList,
R
Rongfeng Fu 已提交
158 159 160 161 162 163 164
  } = useModel('global');
  const { components, home_path } = configData || {};
  const { oceanbase } = components || {};
  const [existNoVersion, setExistNoVersion] = useState(false);
  const [obVersionValue, setOBVersionValue] = useState<string | undefined>(
    undefined,
  );
R
Rongfeng Fu 已提交
165

R
Rongfeng Fu 已提交
166 167 168 169 170 171 172 173 174
  const [hasDraft, setHasDraft] = useState(false);
  const [deleteLoadingVisible, setDeleteLoadingVisible] = useState(false);
  const [deleteName, setDeleteName] = useState('');
  const [installMemory, setInstallMemory] = useState(0);
  const [form] = ProForm.useForm();
  const [unavailableList, setUnavailableList] = useState<string[]>([]);
  const [componentLoading, setComponentLoading] = useState(false);
  const draftNameRef = useRef();

R
Rongfeng Fu 已提交
175 176 177 178 179 180 181 182 183 184 185 186 187 188
  const { run: fetchDeploymentInfo, loading } = useRequest(getDeployment, {
    onError: (e: any) => {
      const errorInfo = getErrorInfo(e);
      setErrorVisible(true);
      setErrorsList([...errorsList, errorInfo]);
    },
  });
  const { run: handleDeleteDeployment } = useRequest(destroyDeployment, {
    onError: (e: any) => {
      const errorInfo = getErrorInfo(e);
      setErrorVisible(true);
      setErrorsList([...errorsList, errorInfo]);
    },
  });
R
Rongfeng Fu 已提交
189 190 191 192
  const { run: fetchListRemoteMirrors } = useRequest(listRemoteMirrors, {
    onSuccess: () => {
      setComponentLoading(false);
    },
R
Rongfeng Fu 已提交
193
    onError: ({ response, data, type }: any) => {
R
Rongfeng Fu 已提交
194 195 196 197 198
      if (response?.status === 503) {
        setTimeout(() => {
          fetchListRemoteMirrors();
        }, 1000);
      } else {
R
Rongfeng Fu 已提交
199 200 201
        const errorInfo = getErrorInfo({ response, data, type });
        setErrorVisible(true);
        setErrorsList([...errorsList, errorInfo]);
R
Rongfeng Fu 已提交
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
        setComponentLoading(false);
      }
    },
  });

  const judgVersions = (type: string, source: API.ComponentsVersionInfo) => {
    if (type === 'all') {
      if (Object.keys(source).length !== allComponentsName.length) {
        setExistNoVersion(true);
      } else {
        setExistNoVersion(false);
      }
    } else {
      if (
        !(source?.[oceanbaseComponent] && source?.[oceanbaseComponent]?.version)
      ) {
        setExistNoVersion(true);
      } else {
        setExistNoVersion(false);
      }
    }
  };

  const { run: fetchAllComponentVersions, loading: versionLoading } =
    useRequest(queryAllComponentVersions, {
      onSuccess: async ({
        success,
        data,
      }: API.OBResponseDataListComponent_) => {
        if (success) {
          const newComponentsVersionInfo = {};
          data?.items?.forEach((item) => {
            if (allComponentsName.includes(item.name)) {
              if (item?.info?.length) {
                const initVersionInfo = item?.info[0] || {};
                if (item.name === oceanbaseComponent) {
                  const newSelectedVersionInfo = item.info.filter(
                    (item) => item.md5 === oceanbase?.package_hash,
                  )?.[0];
                  const currentSelectedVersionInfo =
                    newSelectedVersionInfo || initVersionInfo;
                  setOBVersionValue(
                    `${currentSelectedVersionInfo?.version}-${currentSelectedVersionInfo?.release}-${currentSelectedVersionInfo?.md5}`,
                  );
R
Rongfeng Fu 已提交
246

R
Rongfeng Fu 已提交
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
                  newComponentsVersionInfo[item.name] = {
                    ...currentSelectedVersionInfo,
                    dataSource: item.info || [],
                  };
                } else {
                  newComponentsVersionInfo[item.name] = {
                    ...initVersionInfo,
                    dataSource: item.info || [],
                  };
                }
              }
            }
          });

          const noVersion =
            Object.keys(newComponentsVersionInfo).length !==
            allComponentsName.length;
          judgVersions(currentType, newComponentsVersionInfo);
          setComponentsVersionInfo(newComponentsVersionInfo);

          if (noVersion) {
            const { success: mirrorSuccess, data: mirrorData } =
              await fetchListRemoteMirrors();
            if (mirrorSuccess) {
              const nameList: string[] = [];
              if (mirrorData?.total < 2) {
                const mirrorName = mirrorData?.items?.map(
                  (item: API.Mirror) => item.section_name,
                );
R
Rongfeng Fu 已提交
276

R
Rongfeng Fu 已提交
277 278 279 280
                const noDataName = [...mirrorName, ...mirrors].filter(
                  (name) =>
                    mirrors.includes(name) && !mirrorName.includes(name),
                );
R
Rongfeng Fu 已提交
281

R
Rongfeng Fu 已提交
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
                noDataName.forEach((name) => {
                  nameList.push(name);
                });
              }
              if (mirrorData?.total) {
                mirrorData?.items?.forEach((item: API.Mirror) => {
                  if (!item.available) {
                    nameList.push(item.section_name);
                  }
                });
              }
              setUnavailableList(nameList);
            }
          } else {
            setComponentLoading(false);
          }
        }
      },
R
Rongfeng Fu 已提交
300
      onError: ({ response, data, type }: any) => {
R
Rongfeng Fu 已提交
301 302 303 304 305
        if (response?.status === 503) {
          setTimeout(() => {
            fetchAllComponentVersions();
          }, 1000);
        } else {
R
Rongfeng Fu 已提交
306 307 308
          const errorInfo = getErrorInfo({ response, data, type });
          setErrorVisible(true);
          setErrorsList([...errorsList, errorInfo]);
R
Rongfeng Fu 已提交
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
          setComponentLoading(false);
        }
      },
    });

  const onValuesChange = (values: FormValues) => {
    if (values?.type) {
      setCurrentType(values?.type);
      judgVersions(values?.type, componentsVersionInfo);
    }
  };

  const nameValidator = async (_: any, value: string) => {
    if (value) {
      if (hasDraft || isDraft) {
        return Promise.resolve();
      }
      if (!appnameReg.test(value)) {
        return Promise.reject(
R
Rongfeng Fu 已提交
328 329 330 331 332 333
          new Error(
            intl.formatMessage({
              id: 'OBD.pages.components.InstallConfig.TheInitialLetterIsEnglish',
              defaultMessage: '首字母英文且仅支持英文、数字,长度不超过20',
            }),
          ),
R
Rongfeng Fu 已提交
334 335 336 337 338 339 340 341 342
        );
      }
      try {
        const { success, data } = await getInfoByName({ name: value });
        if (success) {
          if (['CONFIGURED', 'DESTROYED'].includes(data?.status)) {
            return Promise.resolve();
          }
          return Promise.reject(
R
Rongfeng Fu 已提交
343 344 345 346 347 348 349 350 351
            new Error(
              intl.formatMessage(
                {
                  id: 'OBD.pages.components.InstallConfig.ADeploymentNameWithValue',
                  defaultMessage: '已存在为 {value} 的部署名称,请指定新名称',
                },
                { value: value },
              ),
            ),
R
Rongfeng Fu 已提交
352 353 354
          );
        }
        return Promise.resolve();
R
Rongfeng Fu 已提交
355
      } catch ({ response, data, type }: any) {
R
Rongfeng Fu 已提交
356 357 358
        if (response?.status === 404) {
          return Promise.resolve();
        } else {
R
Rongfeng Fu 已提交
359 360 361
          const errorInfo = getErrorInfo({ response, data, type });
          setErrorVisible(true);
          setErrorsList([...errorsList, errorInfo]);
R
Rongfeng Fu 已提交
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
        }
      }
    }
  };

  const nextStep = () => {
    form.validateFields().then((values) => {
      const lastAppName = oceanbase?.appname || initAppName;
      let newHomePath = home_path;
      if (values?.appname !== lastAppName && home_path) {
        const firstHalfHomePath = home_path.split(`/${lastAppName}`)[0];
        newHomePath = `${firstHalfHomePath}/${values?.appname}`;
      }
      let newComponents: API.Components = {
        oceanbase: {
          ...(components?.oceanbase || {}),
          component:
            componentsVersionInfo?.[oceanbaseComponent]?.version_type === 'ce'
              ? 'oceanbase-ce'
              : 'oceanbase',
          appname: values?.appname,
          version: componentsVersionInfo?.[oceanbaseComponent]?.version,
          release: componentsVersionInfo?.[oceanbaseComponent]?.release,
          package_hash: componentsVersionInfo?.[oceanbaseComponent]?.md5,
        },
      };
      if (currentType === 'all') {
        newComponents.obproxy = {
          ...(components?.obproxy || {}),
          component:
            componentsVersionInfo?.[obproxyComponent]?.version_type === 'ce'
              ? 'obproxy-ce'
              : 'obproxy',
          version: componentsVersionInfo?.[obproxyComponent]?.version,
          release: componentsVersionInfo?.[obproxyComponent]?.release,
          package_hash: componentsVersionInfo?.[obproxyComponent]?.md5,
        };
        if (!lowVersion) {
          newComponents.ocpexpress = {
            ...(components?.ocpexpress || {}),
            component: ocpexpressComponent,
            version: componentsVersionInfo?.[ocpexpressComponent]?.version,
            release: componentsVersionInfo?.[ocpexpressComponent]?.release,
            package_hash: componentsVersionInfo?.[ocpexpressComponent]?.md5,
          };
        }
        newComponents.obagent = {
          ...(components?.obagent || {}),
          component: obagentComponent,
          version: componentsVersionInfo?.[obagentComponent]?.version,
          release: componentsVersionInfo?.[obagentComponent]?.release,
          package_hash: componentsVersionInfo?.[obagentComponent]?.md5,
        };
      }
      setConfigData({
        ...configData,
        components: newComponents,
        home_path: newHomePath,
      });
      setCurrentStep(2);
      setIsFirstTime(false);
R
Rongfeng Fu 已提交
423 424 425
      setErrorVisible(false);
      setErrorsList([]);
      window.scrollTo(0, 0);
R
Rongfeng Fu 已提交
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
    });
  };

  const onVersionChange = (
    value: string,
    dataSource: API.service_model_components_ComponentInfo[],
  ) => {
    const md5 = value.split('-')[2];
    setOBVersionValue(value);
    const newSelectedVersionInfo = dataSource.filter(
      (item) => item.md5 === md5,
    )[0];
    setComponentsVersionInfo({
      ...componentsVersionInfo,
      [oceanbaseComponent]: {
        ...componentsVersionInfo[oceanbaseComponent],
        ...newSelectedVersionInfo,
      },
    });
    setLowVersion(
      !!(
        newSelectedVersionInfo.version &&
        checkLowVersion(newSelectedVersionInfo.version.split('')[0])
      ),
    );
  };

  const directTo = (url: string) => {
    // 在新的标签页中打开
    const blankWindow = window.open('about:blank');
    if (blankWindow) {
      blankWindow.location.href = url;
    } else {
      // 兜底逻辑,在当前标签页打开
      window.location.href = url;
    }
  };

  const getColumns = (group: string) => {
    const columns: ColumnsType<API.TableComponentInfo> = [
      {
        title: group,
        dataIndex: 'name',
        width: 195,
        render: (text, record) => {
          if (currentType === 'all') {
            return (
              <>
                {text}
                {record.key === ocpexpressComponent && lowVersion ? (
R
Rongfeng Fu 已提交
476 477 478 479 480 481 482
                  <Tooltip
                    title={intl.formatMessage({
                      id: 'OBD.pages.components.InstallConfig.OcpExpressOnlySupportsAnd',
                      defaultMessage:
                        'OCP Express 仅支持 4.0 及以上版本 OceanBase Database。',
                    })}
                  >
R
Rongfeng Fu 已提交
483 484 485 486 487
                    <span className={`${styles.iconContainer} warning-color`}>
                      <InfoOutlined className={styles.icon} />
                    </span>
                  </Tooltip>
                ) : !componentsVersionInfo[record.key]?.version ? (
R
Rongfeng Fu 已提交
488 489 490 491 492 493
                  <Tooltip
                    title={intl.formatMessage({
                      id: 'OBD.pages.components.InstallConfig.UnableToObtainTheInstallation',
                      defaultMessage: '无法获取安装包,请检查安装程序配置。',
                    })}
                  >
R
Rongfeng Fu 已提交
494 495 496 497 498 499 500 501 502 503 504 505
                    <span className={`${styles.iconContainer} error-color`}>
                      <CloseOutlined className={styles.icon} />
                    </span>
                  </Tooltip>
                ) : null}
              </>
            );
          }
          return text;
        },
      },
      {
R
Rongfeng Fu 已提交
506 507 508 509
        title: intl.formatMessage({
          id: 'OBD.pages.components.InstallConfig.Version',
          defaultMessage: '版本',
        }),
R
Rongfeng Fu 已提交
510
        dataIndex: 'version',
R
Rongfeng Fu 已提交
511
        width: locale === 'zh-CN' ? 130 : 154,
R
Rongfeng Fu 已提交
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534
        render: (_, record) => {
          const versionInfo = componentsVersionInfo[record.key] || {};
          if (record?.key === oceanbaseComponent) {
            return (
              <Select
                value={obVersionValue}
                optionLabelProp="data_value"
                style={{ width: 100 }}
                onChange={(value) =>
                  onVersionChange(value, versionInfo?.dataSource)
                }
                popupClassName={styles?.popupClassName}
              >
                {versionInfo?.dataSource?.map(
                  (item: API.service_model_components_ComponentInfo) => (
                    <Select.Option
                      value={`${item.version}-${item?.release}-${item.md5}`}
                      data_value={item.version}
                      key={`${item.version}-${item?.release}-${item.md5}`}
                    >
                      {item.version}
                      {item?.release ? `-${item?.release}` : ''}
                      {item.version_type === 'ce' ? (
R
Rongfeng Fu 已提交
535 536 537 538 539 540
                        <Tag className="default-tag ml-8">
                          {intl.formatMessage({
                            id: 'OBD.pages.components.InstallConfig.CommunityEdition',
                            defaultMessage: '社区版',
                          })}
                        </Tag>
R
Rongfeng Fu 已提交
541
                      ) : (
R
Rongfeng Fu 已提交
542 543 544 545 546 547
                        <Tag className="blue-tag ml-8">
                          {intl.formatMessage({
                            id: 'OBD.pages.components.InstallConfig.CommercialEdition',
                            defaultMessage: '商业版',
                          })}
                        </Tag>
R
Rongfeng Fu 已提交
548 549 550 551 552
                      )}

                      {item?.type === 'local' ? (
                        <span className={styles.localTag}>
                          <SafetyCertificateFilled />
R
Rongfeng Fu 已提交
553 554 555 556
                          {intl.formatMessage({
                            id: 'OBD.pages.components.InstallConfig.LocalImage',
                            defaultMessage: '本地镜像',
                          })}
R
Rongfeng Fu 已提交
557 558 559 560 561 562 563 564 565 566 567 568 569
                        </span>
                      ) : (
                        ''
                      )}
                    </Select.Option>
                  ),
                )}
              </Select>
            );
          } else {
            return versionInfo?.version ? (
              <>
                {versionInfo?.version}
R
Rongfeng Fu 已提交
570 571 572 573 574 575
                <Tag className="default-tag ml-8">
                  {intl.formatMessage({
                    id: 'OBD.pages.components.InstallConfig.Latest',
                    defaultMessage: '最新',
                  })}
                </Tag>
R
Rongfeng Fu 已提交
576 577 578 579 580 581 582 583
              </>
            ) : (
              '-'
            );
          }
        },
      },
      {
R
Rongfeng Fu 已提交
584 585 586 587
        title: intl.formatMessage({
          id: 'OBD.pages.components.InstallConfig.Description',
          defaultMessage: '描述',
        }),
R
Rongfeng Fu 已提交
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
        dataIndex: 'desc',
        render: (text, record) => {
          let disabled = false;
          if (
            (record.key === ocpexpressComponent && lowVersion) ||
            (currentType === 'ob' && record.onlyAll)
          ) {
            disabled = true;
          }
          return (
            <>
              {text || '-'}
              <a
                className={styles.learnMore}
                onClick={() => {
                  if (!disabled) directTo(record.doc);
                }}
                target="_blank"
              >
R
Rongfeng Fu 已提交
607 608 609 610
                {intl.formatMessage({
                  id: 'OBD.pages.components.InstallConfig.LearnMore',
                  defaultMessage: '了解更多',
                })}
R
Rongfeng Fu 已提交
611 612 613 614 615 616
              </a>
            </>
          );
        },
      },
    ];
R
Rongfeng Fu 已提交
617

R
Rongfeng Fu 已提交
618 619 620 621 622
    return columns;
  };

  const handleCopy = (content: string) => {
    copy(content);
R
Rongfeng Fu 已提交
623 624 625 626 627 628
    message.success(
      intl.formatMessage({
        id: 'OBD.pages.components.InstallConfig.CopiedSuccessfully',
        defaultMessage: '复制成功',
      }),
    );
R
Rongfeng Fu 已提交
629 630 631 632 633 634 635 636 637 638 639 640 641
  };

  useEffect(() => {
    setComponentLoading(true);
    if (isFirstTime) {
      fetchAllComponentVersions();
      fetchDeploymentInfo({ task_status: 'DRAFT' }).then(
        ({ success: draftSuccess, data: draftData }: API.OBResponse) => {
          if (draftSuccess && draftData?.items?.length) {
            const defaultValue = draftData?.items[0]?.name;
            draftNameRef.current = defaultValue;
            setHasDraft(true);
            Modal.confirm({
R
Rongfeng Fu 已提交
642 643 644 645 646 647 648 649 650 651 652 653
              title: intl.formatMessage({
                id: 'OBD.pages.components.InstallConfig.TheFollowingHistoricalConfigurationsOf',
                defaultMessage: '检测到系统中存在以下部署失败的历史配置',
              }),
              okText: intl.formatMessage({
                id: 'OBD.pages.components.InstallConfig.ContinueDeployment',
                defaultMessage: '继续部署',
              }),
              cancelText: intl.formatMessage({
                id: 'OBD.pages.components.InstallConfig.Ignore',
                defaultMessage: '忽略',
              }),
R
Rongfeng Fu 已提交
654 655 656 657 658
              closable: true,
              width: 424,
              content: (
                <Space direction="vertical" size="middle">
                  <div style={{ color: '#5C6B8A' }}>
R
Rongfeng Fu 已提交
659 660 661 662 663
                    {intl.formatMessage({
                      id: 'OBD.pages.components.InstallConfig.ContinuingDeploymentWillCleanUp',
                      defaultMessage:
                        '继续部署将先清理失败的历史部署环境,是否继续历史部署流程?',
                    })}
R
Rongfeng Fu 已提交
664 665 666 667 668 669 670 671 672 673 674 675 676 677
                  </div>
                  <Select
                    style={commonStyle}
                    onChange={(value) => (draftNameRef.current = value)}
                    defaultValue={defaultValue}
                  >
                    {draftData?.items?.map((item) => (
                      <Select.Option key={item.name} value={item.name}>
                        {item.name}
                      </Select.Option>
                    ))}
                  </Select>
                </Space>
              ),
R
Rongfeng Fu 已提交
678

R
Rongfeng Fu 已提交
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736
              onOk: () => {
                return new Promise<void>(async (resolve) => {
                  try {
                    const { success: deleteSuccess } =
                      await handleDeleteDeployment({
                        name: draftNameRef.current,
                      });
                    if (deleteSuccess) {
                      resolve();
                      setDeleteName(draftNameRef.current);
                      setDeleteLoadingVisible(true);
                    }
                  } catch {
                    setIsDraft(false);
                    resolve();
                  }
                });
              },
              onCancel: () => {
                setIsDraft(false);
                setHasDraft(false);
              },
            });
          } else {
            setIsDraft(false);
          }
        },
      );
    } else {
      fetchAllComponentVersions();
    }
  }, []);

  useEffect(() => {
    let newInstallMemory = 0;
    if (currentType === 'ob') {
      newInstallMemory =
        componentsVersionInfo?.[oceanbaseComponent]?.estimated_size;
    } else {
      const keys = Object.keys(componentsVersionInfo);
      keys.forEach((key) => {
        newInstallMemory =
          newInstallMemory + componentsVersionInfo[key]?.estimated_size;
      });
    }
    setInstallMemory(newInstallMemory);
  }, [componentsVersionInfo, currentType]);

  useEffect(() => {
    form.setFieldsValue({ type: currentType });
  }, [currentType]);

  useEffect(() => {
    form.setFieldsValue({
      appname: configData?.components?.oceanbase?.appname || initAppName,
    });
  }, [configData]);

R
Rongfeng Fu 已提交
737 738
  const size = NP.divide(NP.divide(installMemory, 1024), 1024).toFixed(2);

R
Rongfeng Fu 已提交
739 740 741 742
  return (
    <Spin spinning={loading}>
      <Space className={styles.spaceWidth} direction="vertical" size="middle">
        <ProCard className={styles.pageCard} split="horizontal">
R
Rongfeng Fu 已提交
743 744 745 746 747 748 749
          <ProCard
            title={intl.formatMessage({
              id: 'OBD.pages.components.InstallConfig.DeploymentConfiguration',
              defaultMessage: '部署配置',
            })}
            className="card-padding-bottom-24"
          >
R
Rongfeng Fu 已提交
750 751 752 753 754 755 756 757 758 759 760
            <ProForm
              form={form}
              submitter={false}
              initialValues={{
                appname: oceanbase?.appname || initAppName,
                type: currentType,
              }}
              onValuesChange={onValuesChange}
            >
              <ProFormText
                name="appname"
R
Rongfeng Fu 已提交
761 762 763 764
                label={intl.formatMessage({
                  id: 'OBD.pages.components.InstallConfig.ClusterName',
                  defaultMessage: '集群名称',
                })}
R
Rongfeng Fu 已提交
765
                fieldProps={{ style: commonStyle }}
R
Rongfeng Fu 已提交
766 767 768 769
                placeholder={intl.formatMessage({
                  id: 'OBD.pages.components.InstallConfig.EnterAClusterName',
                  defaultMessage: '请输入集群名称',
                })}
R
Rongfeng Fu 已提交
770 771 772 773 774
                validateTrigger={['onBlur', 'onChange']}
                disabled={isDraft}
                rules={[
                  {
                    required: true,
R
Rongfeng Fu 已提交
775 776 777 778
                    message: intl.formatMessage({
                      id: 'OBD.pages.components.InstallConfig.EnterAClusterName',
                      defaultMessage: '请输入集群名称',
                    }),
R
Rongfeng Fu 已提交
779 780 781 782
                    validateTrigger: 'onChange',
                  },
                  {
                    pattern: appnameReg,
R
Rongfeng Fu 已提交
783 784 785 786 787
                    message: intl.formatMessage({
                      id: 'OBD.pages.components.InstallConfig.TheInitialLetterIsEnglish',
                      defaultMessage:
                        '首字母英文且仅支持英文、数字,长度不超过20',
                    }),
R
Rongfeng Fu 已提交
788 789 790 791 792
                    validateTrigger: 'onChange',
                  },
                  { validator: nameValidator, validateTrigger: 'onBlur' },
                ]}
              />
R
Rongfeng Fu 已提交
793

R
Rongfeng Fu 已提交
794 795
              <Form.Item
                name="type"
R
Rongfeng Fu 已提交
796 797 798 799
                label={intl.formatMessage({
                  id: 'OBD.pages.components.InstallConfig.DeploymentType',
                  defaultMessage: '部署类型',
                })}
R
Rongfeng Fu 已提交
800 801 802 803 804 805 806 807 808
                className="form-item-no-bottom"
              >
                <DeployType />
              </Form.Item>
            </ProForm>
          </ProCard>
          <ProCard
            title={
              <>
R
Rongfeng Fu 已提交
809 810 811 812 813
                {intl.formatMessage({
                  id: 'OBD.pages.components.InstallConfig.DeployComponents',
                  defaultMessage: '部署组件',
                })}

R
Rongfeng Fu 已提交
814
                <span className={styles.titleExtra}>
R
Rongfeng Fu 已提交
815 816 817 818 819 820 821 822
                  <InfoCircleOutlined />{' '}
                  {intl.formatMessage(
                    {
                      id: 'OBD.pages.components.InstallConfig.EstimatedInstallationRequiresSizeMb',
                      defaultMessage: '预计安装需要 {size}MB 空间',
                    },
                    { size: size },
                  )}
R
Rongfeng Fu 已提交
823 824 825 826 827 828 829 830 831 832 833 834 835 836 837
                </span>
              </>
            }
            className="card-header-padding-top-0 card-padding-bottom-24  card-padding-top-0"
          >
            <Space
              className={styles.spaceWidth}
              direction="vertical"
              size="middle"
            >
              {existNoVersion ? (
                unavailableList?.length ? (
                  <Alert
                    message={
                      <>
R
Rongfeng Fu 已提交
838 839 840 841 842
                        {intl.formatMessage({
                          id: 'OBD.pages.components.InstallConfig.IfTheCurrentEnvironmentCannot',
                          defaultMessage:
                            '如当前环境无法正常访问外网,建议使用 OceanBase 离线安装包进行安装部署。',
                        })}
R
Rongfeng Fu 已提交
843 844 845 846
                        <a
                          href="https://open.oceanbase.com/softwareCenter/community"
                          target="_blank"
                        >
R
Rongfeng Fu 已提交
847 848 849 850
                          {intl.formatMessage({
                            id: 'OBD.pages.components.InstallConfig.GoToDownloadOfflineInstallation',
                            defaultMessage: '前往下载离线安装',
                          })}
R
Rongfeng Fu 已提交
851 852 853 854 855 856 857 858 859 860 861
                        </a>
                      </>
                    }
                    type="error"
                    showIcon
                    style={{ marginTop: '16px' }}
                  />
                ) : (
                  <Alert
                    message={
                      <>
R
Rongfeng Fu 已提交
862 863 864 865 866
                        {intl.formatMessage({
                          id: 'OBD.pages.components.InstallConfig.IfTheCurrentEnvironmentHas',
                          defaultMessage:
                            '如当前环境可正常访问外网,可启动 OceanBase 在线镜像仓库,或联系您的镜像仓库管理员。',
                        })}
R
Rongfeng Fu 已提交
867 868 869 870
                        <Tooltip
                          overlayClassName={styles.commandTooltip}
                          title={
                            <div>
R
Rongfeng Fu 已提交
871 872 873 874 875
                              {intl.formatMessage({
                                id: 'OBD.pages.components.InstallConfig.RunTheCommandOnThe',
                                defaultMessage:
                                  '请在主机上执行一下命令启用在线镜像仓库',
                              })}
R
Rongfeng Fu 已提交
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
                              <br /> obd mirror enable
                              oceanbase.community.stable
                              oceanbase.development-kit
                              <a>
                                <CopyOutlined
                                  onClick={() =>
                                    handleCopy(
                                      'obd mirror enable oceanbase.community.stable oceanbase.development-kit',
                                    )
                                  }
                                />
                              </a>
                            </div>
                          }
                        >
R
Rongfeng Fu 已提交
891 892 893 894 895 896
                          <a>
                            {intl.formatMessage({
                              id: 'OBD.pages.components.InstallConfig.HowToEnableOnlineImage',
                              defaultMessage: '如何启用在线镜像仓库',
                            })}
                          </a>
R
Rongfeng Fu 已提交
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
                        </Tooltip>
                      </>
                    }
                    type="error"
                    showIcon
                    style={{ marginTop: '16px' }}
                  />
                )
              ) : null}
              <Spin spinning={componentLoading}>
                {componentsGroupInfo.map((info) => (
                  <ProCard
                    type="inner"
                    className={`${styles.componentCard} ${
                      currentType === 'ob' && info.onlyAll
                        ? styles.disabledCard
                        : ''
                    }`}
                    key={info.group}
                  >
                    <Table
                      className={styles.componentTable}
                      columns={getColumns(info.group)}
                      rowKey="key"
                      dataSource={info.content}
                      pagination={false}
                      rowClassName={(record) => {
                        if (
                          (record.key === ocpexpressComponent && lowVersion) ||
                          (currentType === 'ob' && record?.onlyAll)
                        ) {
                          return styles.disabledRow;
                        }
                      }}
                    />
                  </ProCard>
                ))}
              </Spin>
            </Space>
          </ProCard>
        </ProCard>
        <footer className={styles.pageFooterContainer}>
          <div className={styles.pageFooter}>
            <Space className={styles.foolterAction}>
              <Button
                onClick={() => handleQuit(handleQuitProgress, setCurrentStep)}
                data-aspm-click="c307507.d317381"
R
Rongfeng Fu 已提交
944 945 946 947
                data-aspm-desc={intl.formatMessage({
                  id: 'OBD.pages.components.InstallConfig.DeploymentConfigurationExit',
                  defaultMessage: '部署配置-退出',
                })}
R
Rongfeng Fu 已提交
948 949 950
                data-aspm-param={``}
                data-aspm-expo
              >
R
Rongfeng Fu 已提交
951 952 953 954
                {intl.formatMessage({
                  id: 'OBD.pages.components.InstallConfig.Exit',
                  defaultMessage: '退出',
                })}
R
Rongfeng Fu 已提交
955 956 957 958 959 960 961 962 963 964 965
              </Button>
              <Button
                type="primary"
                onClick={nextStep}
                disabled={
                  lowVersion ||
                  existNoVersion ||
                  versionLoading ||
                  componentLoading
                }
                data-aspm-click="c307507.d317280"
R
Rongfeng Fu 已提交
966 967 968 969
                data-aspm-desc={intl.formatMessage({
                  id: 'OBD.pages.components.InstallConfig.DeploymentConfigurationNextStep',
                  defaultMessage: '部署配置-下一步',
                })}
R
Rongfeng Fu 已提交
970 971 972
                data-aspm-param={``}
                data-aspm-expo
              >
R
Rongfeng Fu 已提交
973 974 975 976
                {intl.formatMessage({
                  id: 'OBD.pages.components.InstallConfig.NextStep',
                  defaultMessage: '下一步',
                })}
R
Rongfeng Fu 已提交
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992
              </Button>
            </Space>
          </div>
        </footer>
        {deleteLoadingVisible && (
          <DeleteDeployModal
            visible={deleteLoadingVisible}
            name={deleteName}
            onCancel={() => setDeleteLoadingVisible(false)}
            setOBVersionValue={setOBVersionValue}
          />
        )}
      </Space>
    </Spin>
  );
}