Skip to content

Commit

Permalink
fix: disable branch and mr tabs when repo is empty (#2975)
Browse files Browse the repository at this point in the history
* fix: disable branch and mr tabs when repo is empty

* chore: remove log

* fix: select value maybe null
  • Loading branch information
daskyrk authored Feb 19, 2022
1 parent 94b86f3 commit 9fdfb19
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
5 changes: 3 additions & 2 deletions shell/app/common/components/render-form-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions shell/app/modules/application/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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) => {
Expand All @@ -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'),
};

Expand Down
1 change: 0 additions & 1 deletion shell/app/modules/project/pages/apps/app-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ const CreationForm = () => {
}
return item;
});
console.log('mode', mode);

const fieldsList = [
{
Expand Down

0 comments on commit 9fdfb19

Please sign in to comment.