From 9fdfb1942f93f619001eea754f323cd56b543c27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9A=8F=E9=A3=8E?= Date: Sat, 19 Feb 2022 10:28:00 +0800 Subject: [PATCH] fix: disable branch and mr tabs when repo is empty (#2975) * fix: disable branch and mr tabs when repo is empty * chore: remove log * fix: select value maybe null --- shell/app/common/components/render-form-item/index.tsx | 5 +++-- shell/app/modules/application/tabs.tsx | 9 +++++++-- shell/app/modules/project/pages/apps/app-form.tsx | 1 - 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/shell/app/common/components/render-form-item/index.tsx b/shell/app/common/components/render-form-item/index.tsx index f3c2c451db..4184f289e3 100644 --- a/shell/app/common/components/render-form-item/index.tsx +++ b/shell/app/common/components/render-form-item/index.tsx @@ -398,8 +398,9 @@ interface SelectCompProps { const SelectComp = ({ value, onChange, options, size, optionRender, ...restItemProps }: SelectCompProps) => { const fixOptions = (typeof options === 'function' ? options() : options)?.filter?.((item: IOption) => item.fix) || []; const optionType = typeof (typeof options === 'function' ? options() : options)?.[0]?.value; - const valueType = typeof (Array.isArray(value) ? value[0] : value); - if (optionType !== 'undefined' && valueType !== 'undefined' && optionType !== valueType) { + const firstValue = Array.isArray(value) ? value[0] : value; + const valueType = typeof firstValue; + if (optionType !== 'undefined' && valueType !== 'undefined' && firstValue !== null && optionType !== valueType) { console.error( 'Warning: The value type accepted by the select does not match the value type of the options.The wrong options is ', options, diff --git a/shell/app/modules/application/tabs.tsx b/shell/app/modules/application/tabs.tsx index e694780364..ef856f6f68 100644 --- a/shell/app/modules/application/tabs.tsx +++ b/shell/app/modules/application/tabs.tsx @@ -21,6 +21,7 @@ import { appMode } from './common/config'; import { filter } from 'lodash'; import { HeadAppSelector } from './common/app-selector'; import { goTo } from 'app/common/utils'; +import repoStore from './stores/repo'; interface ITab { show?: boolean; @@ -30,10 +31,11 @@ interface ITab { } export const APP_TABS = () => { const repoMenu = layoutStore.useStore((s) => s.subList.repo); - const [repoKey, commitKey, branchKey, mrKey] = repoMenu?.length + const [, commitKey, branchKey, mrKey] = repoMenu?.length ? repoMenu.map((a: { tabKey: string }) => a.tabKey) : ['repo', 'repo/commits', 'repo/branches', 'repo/mr/open']; const appDetail = appStore.useStore((s) => s.detail); + const repoInfo = repoStore.useStore((s) => s.info); const { mode, isExternalRepo } = appDetail; const perm = usePerm((s) => s.app); @@ -44,7 +46,7 @@ export const APP_TABS = () => { }; const repo = { show: perm.repo.read.pass, - key: repoKey, + key: 'repo', // keep as root path, prevent no branch error when switch to an empty repo split: true, name: i18n.t('dop:code'), isActive: (activeKey: string) => { @@ -56,18 +58,21 @@ export const APP_TABS = () => { show: perm.repo.read.pass, key: commitKey, name: i18n.t('dop:commits'), + disabled: repoInfo.empty, isActive: (activeKey: string) => activeKey.startsWith('repo/commits'), }; const branch = { show: perm.repo.read.pass, key: branchKey, name: i18n.t('dop:branch'), + disabled: repoInfo.empty, isActive: (activeKey: string) => activeKey.startsWith('repo/branches'), }; const mr = { show: perm.repo.read.pass, key: mrKey, name: i18n.t('dop:merge request'), + disabled: repoInfo.empty, isActive: (activeKey: string) => activeKey.startsWith('repo/mr'), }; diff --git a/shell/app/modules/project/pages/apps/app-form.tsx b/shell/app/modules/project/pages/apps/app-form.tsx index d192c8cbd9..cdf095b3b4 100644 --- a/shell/app/modules/project/pages/apps/app-form.tsx +++ b/shell/app/modules/project/pages/apps/app-form.tsx @@ -127,7 +127,6 @@ const CreationForm = () => { } return item; }); - console.log('mode', mode); const fieldsList = [ {