Skip to content

Commit

Permalink
feat: updated git detail page
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Jun 19, 2024
1 parent bfa60bc commit 8b7ff92
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 104 deletions.
21 changes: 11 additions & 10 deletions src/components/file/FileTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { ElMessage } from 'element-plus';
import { useI18n } from 'vue-i18n';
const props = defineProps<{
ns: ListStoreNamespace,
activeId: string,
content: string,
navItems: FileNavItem[],
activeNavItem?: FileNavItem,
services: FileServices<BaseModel>,
defaultFilePaths: string[],
ns: ListStoreNamespace;
activeId: string;
content: string;
navItems: FileNavItem[];
activeNavItem?: FileNavItem;
services: FileServices<BaseModel>;
defaultFilePaths: string[];
}>();
// i18n
Expand Down Expand Up @@ -87,7 +87,7 @@ const onNavItemDbClick = async (item: FileNavItem) => {
const onNavItemDrop = async (
draggingItem: FileNavItem,
dropItem: FileNavItem,
dropItem: FileNavItem
) => {
const { activeId } = props;
const dirPath = dropItem.path !== '~' ? dropItem.path : '';
Expand Down Expand Up @@ -152,15 +152,15 @@ const onDropFiles = async (files: InputFile[]) => {
await Promise.all(
files.map(f => {
return saveFileBinary(activeId, f.path as string, f as File);
}),
})
);
await listRootDir(activeId);
};
const onCreateWithAi = async (
name: string,
sourceCode: string,
item?: FileNavItem,
item?: FileNavItem
) => {
const { activeId } = props;
let path = `${pathSep}${name}`;
Expand Down Expand Up @@ -198,6 +198,7 @@ onBeforeUnmount(() => {
const { ns } = props;
store.commit(`${ns}/resetFileContent`);
store.commit(`${ns}/resetDefaultFilePaths`);
store.commit(`${ns}/resetFileNavItems`);
});
</script>

Expand Down
5 changes: 5 additions & 0 deletions src/i18n/lang/en/components/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const git: LComponentsGit = {
},
},
},
branches: {
new: 'New Branch',
local: 'Local',
remote: 'Remote',
},
actions: {
title: 'Git Actions',
label: {
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/lang/zh/components/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const git: LComponentsGit = {
},
},
},
branches: {
new: '新建分支',
local: '本地',
remote: '远程',
},
actions: {
title: 'Git 操作',
label: {
Expand Down
5 changes: 5 additions & 0 deletions src/interfaces/i18n/components/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ interface LComponentsGit {
};
};
};
branches: {
new: string;
local: string;
remote: string;
};
actions: {
title: string;
label: {
Expand Down
5 changes: 2 additions & 3 deletions src/interfaces/store/modules/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type GitStoreModule = BaseModule<

interface GitStoreState extends BaseStoreState<Git>, BaseFileStoreState {
gitData?: GitData;
gitCurrentBranchLoading: boolean;
gitDataLoading: boolean;
gitChangeSelection: TableData<GitChange>;
gitRemoteRefs: GitRef[];
gitBranches: GitRef[];
Expand All @@ -24,9 +24,9 @@ interface GitStoreGetters extends BaseStoreGetters<Git> {
interface GitStoreMutations
extends BaseStoreMutations<Git>,
BaseFileStoreMutations<GitStoreState> {
resetAll: StoreMutation<GitStoreState>;
setGitData: StoreMutation<GitStoreState, GitData>;
resetGitData: StoreMutation<GitStoreState>;
setGitDataLoading: StoreMutation<GitStoreState, boolean>;
setGitChangeSelection: StoreMutation<GitStoreState, GitChange[]>;
resetGitChangeSelection: StoreMutation<GitStoreState>;
setGitRemoteRefs: StoreMutation<GitStoreState, GitRef[]>;
Expand All @@ -35,7 +35,6 @@ interface GitStoreMutations
resetGitBranches: StoreMutation<GitStoreState>;
setGitTags: StoreMutation<GitStoreState, GitRef[]>;
resetGitTags: StoreMutation<GitStoreState>;
setGitCurrentBranchLoading: StoreMutation<GitStoreState, boolean>;
}

interface GitStoreActions
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/store/utils/file.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface BaseFileStoreState {

interface BaseFileStoreMutations<S> {
setFileNavItems: StoreMutation<S, FileNavItem[]>;
resetFileNavItems: StoreMutation<S>;
setActiveFileNavItem: StoreMutation<S, FileNavItem>;
resetActiveFileNavItem: StoreMutation<S>;
setFileContent: StoreMutation<S, string>;
Expand Down
21 changes: 6 additions & 15 deletions src/store/modules/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ const state = {
{ id: TAB_NAME_IGNORE, title: t('common.tabs.ignore') },
],
gitData: undefined,
gitDataLoading: false,
gitChangeSelection: [],
gitRemoteRefs: [],
gitBranches: [],
gitTags: [],
gitCurrentBranchLoading: false,
} as GitStoreState;

const getters = {
Expand All @@ -72,22 +72,16 @@ const getters = {
const mutations = {
...getDefaultStoreMutations<Git>(),
...getBaseFileStoreMutations<GitStoreState>(),
resetAll: (state: GitStoreState) => {
state.gitData = {};
state.gitChangeSelection = [];
state.gitRemoteRefs = [];
state.gitBranches = [];
state.gitTags = [];
state.gitCurrentBranchLoading = false;
},
setGitData(state: GitStoreState, gitData: GitData) {
state.gitData = gitData;
},
resetGitData: (state: GitStoreState) => {
state.gitData = {};
},
setGitDataLoading: (state: GitStoreState, loading: boolean) => {
state.gitDataLoading = loading;
},
setGitChangeSelection: (state: GitStoreState, selection: GitChange[]) => {
debugger;
state.gitChangeSelection = selection;
},
resetGitChangeSelection: (state: GitStoreState) => {
Expand All @@ -111,9 +105,6 @@ const mutations = {
resetGitTags: (state: GitStoreState) => {
state.gitTags = [];
},
setGitCurrentBranchLoading: (state: GitStoreState, loading: boolean) => {
state.gitCurrentBranchLoading = loading;
},
} as GitStoreMutations;

const actions = {
Expand All @@ -123,13 +114,13 @@ const actions = {
{ commit }: StoreActionContext<GitStoreState>,
{ id }: { id: string }
) => {
commit('setGitDataLoading', true);
try {
commit('setGitCurrentBranchLoading', true);
const res = await get(`${endpoint}/${id}/git`);
commit('setGitData', res?.data || {});
return res;
} finally {
commit('setGitCurrentBranchLoading', false);
commit('setGitDataLoading', false);
}
},
cloneGit: async (
Expand Down
3 changes: 3 additions & 0 deletions src/store/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ export const getBaseFileStoreMutations = <
setFileNavItems: (state: S, navItems: FileNavItem[]) => {
state.fileNavItems = navItems;
},
resetFileNavItems: (state: S) => {
state.fileNavItems = [];
},
setActiveFileNavItem: (state: S, navItem: FileNavItem) => {
state.activeNavItem = navItem;
},
Expand Down
8 changes: 8 additions & 0 deletions src/views/git/detail/GitDetail.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<script setup lang="ts">
import { onBeforeUnmount } from 'vue';
import { useStore } from 'vuex';
import useGitDetail from '@/views/git/detail/useGitDetail';
const { activeTabName } = useGitDetail();
const ns = 'git';
const store = useStore();
onBeforeUnmount(() => store.commit(`${ns}/resetGitData`));
onBeforeUnmount(() => store.commit(`${ns}/resetGitBranches`));
</script>

<template>
Expand Down
112 changes: 82 additions & 30 deletions src/views/git/detail/actions/GitDetailActionsCommon.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { translate } from '@/utils';
import useGitDetail from '@/views/git/detail/useGitDetail';
import { ElMessage } from 'element-plus';
import { GIT_STATUS_READY } from '@/constants';
import ClFormItem from '@/components/form/FormItem.vue';
const t = translate;
Expand All @@ -23,13 +24,22 @@ const isDisabled = computed<boolean>(
const {
gitCurrentBranch,
gitCurrentBranchLoading,
gitDataLoading,
gitLocalBranches,
gitLocalBranchesDict,
gitRemoteBranches,
gitRemoteBranchesDict,
onClickPull,
onClickCommit,
} = useGitDetail();
const isBranchClicked = ref<boolean>(false);
const getRemoteBranchFromLocalBranch = (localBranch: GitRef) => {
if (!localBranch.hash) return;
return gitRemoteBranchesDict.value[localBranch.hash]?.name;
};
const onBranchClick = () => {
isBranchClicked.value = true;
};
Expand Down Expand Up @@ -64,6 +74,71 @@ const onAutoPullChange = async () => {
:status="gitForm.status"
:error="gitForm.error"
/>
<div class="branch">
<!-- <cl-tag-->
<!-- class-name="current-branch"-->
<!-- type="primary"-->
<!-- :icon="['fa', 'code-branch']"-->
<!-- size="large"-->
<!-- :label="gitCurrentBranch"-->
<!-- @click="onBranchClick"-->
<!-- >-->
<!-- <template #tooltip>-->
<!-- <span>{{ t('components.git.common.currentBranch') }}:</span>-->
<!-- <span style="color: #409eff; margin-left: 5px; font-weight: bolder">-->
<!-- {{ gitCurrentBranch }}-->
<!-- </span>-->
<!-- </template>-->
<!-- </cl-tag>-->
<el-select
class="current-branch"
:model-value="gitCurrentBranch"
:disabled="isDisabled || gitDataLoading"
:placeholder="t('common.status.loading')"
>
<template #label="{ label, value }">
<div
style="
display: flex;
align-items: center;
justify-content: space-between;
"
>
<span style="flex: 0; margin-right: 10px">
<cl-icon :icon="['fa', 'code-branch']" />
</span>
<span style="flex: 1">{{ label }}</span>
</div>
</template>
<el-option
v-for="branch in gitLocalBranches"
:key="branch.hash"
:label="branch.name"
:value="branch.name"
>
<div
style="
display: flex;
align-items: center;
justify-content: space-between;
gap: 24px;
"
>
<span>{{ branch.name }}</span>
<span
style="color: var(--cl-disabled-color); font-weight: normal"
>
{{ getRemoteBranchFromLocalBranch(branch) }}
</span>
</div>
</el-option>
<template #footer>
<cl-button type="default">
{{ t('components.git.branches.new') }}
</cl-button>
</template>
</el-select>
</div>
<cl-fa-icon-button
:icon="['fa', 'download']"
:tooltip="t('components.git.actions.tooltip.pull')"
Expand All @@ -78,34 +153,6 @@ const onAutoPullChange = async () => {
:disabled="isDisabled"
@click="onClickCommit"
/>
<div v-if="gitCurrentBranch || gitCurrentBranchLoading" class="branch">
<cl-tag
v-if="gitCurrentBranchLoading"
class-name="current-branch-loading"
type="warning"
:label="t('components.git.common.status.loading.label')"
:tooltip="t('components.git.common.status.loading.tooltip')"
:icon="['fa', 'spinner']"
spinning
size="large"
/>
<cl-tag
v-else
class-name="current-branch"
type="primary"
:icon="['fa', 'code-branch']"
size="large"
:label="gitCurrentBranch"
@click="onBranchClick"
>
<template #tooltip>
<span>{{ t('components.git.common.currentBranch') }}:</span>
<span style="color: #409eff; margin-left: 5px; font-weight: bolder">
{{ gitCurrentBranch }}
</span>
</template>
</cl-tag>
</div>
<!-- <cl-switch-->
<!-- v-model="gitForm.auto_pull"-->
<!-- :active-text="t('components.git.form.autoPull')"-->
Expand All @@ -116,4 +163,9 @@ const onAutoPullChange = async () => {
</cl-nav-action-group>
</template>

<style scoped lang="scss"></style>
<style scoped lang="scss">
.current-branch {
width: 120px;
margin-right: 10px;
}
</style>
Loading

0 comments on commit 8b7ff92

Please sign in to comment.