plugin-git-manager 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client.d.ts +3 -0
- package/client.js +1 -0
- package/dist/client/100.e08d760e0b01997c.js +10 -0
- package/dist/client/components/CommitHistory.d.ts +2 -0
- package/dist/client/components/FileExplorer.d.ts +2 -0
- package/dist/client/components/GitManagerSettings.d.ts +2 -0
- package/dist/client/components/GitOperations.d.ts +2 -0
- package/dist/client/components/RepositoryConfig.d.ts +2 -0
- package/dist/client/context/GitManagerContext.d.ts +24 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +10 -0
- package/dist/client/locale.d.ts +2 -0
- package/dist/externalVersion.js +18 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +45 -0
- package/dist/locale/vi-VN.json +45 -0
- package/dist/node_modules/simple-git/dist/cjs/index.js +7399 -0
- package/dist/node_modules/simple-git/dist/esm/index.js +4745 -0
- package/dist/node_modules/simple-git/dist/esm/package.json +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/api.d.ts +13 -0
- package/dist/node_modules/simple-git/dist/src/lib/args/log-format.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-construct-error.d.ts +15 -0
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-error.d.ts +30 -0
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-plugin-error.d.ts +7 -0
- package/dist/node_modules/simple-git/dist/src/lib/errors/git-response-error.d.ts +32 -0
- package/dist/node_modules/simple-git/dist/src/lib/errors/task-configuration-error.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/git-factory.d.ts +15 -0
- package/dist/node_modules/simple-git/dist/src/lib/git-logger.d.ts +21 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-branch-delete.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-branch.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-commit.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-diff-summary.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-fetch.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-list-log-summary.d.ts +6 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-merge.d.ts +11 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-move.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-pull.d.ts +6 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-push.d.ts +4 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-remote-messages.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/src/lib/parsers/parse-remote-objects.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/abort-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/block-unsafe-operations-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/command-config-prefixing-plugin.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/completion-detection.plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/custom-binary.plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/error-detection.plugin.d.ts +7 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/index.d.ts +11 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/plugin-store.d.ts +11 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/progress-monitor-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/simple-git-plugin.d.ts +48 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/spawn-options-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/suffix-paths.plugin.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/plugins/timout-plugin.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/BranchDeleteSummary.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/BranchSummary.d.ts +14 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/CheckIgnore.d.ts +4 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/CleanSummary.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/ConfigList.d.ts +13 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/DiffSummary.d.ts +10 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/FileStatusSummary.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/GetRemoteSummary.d.ts +11 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/InitSummary.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/MergeSummary.d.ts +16 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/PullSummary.d.ts +25 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/StatusSummary.d.ts +19 -0
- package/dist/node_modules/simple-git/dist/src/lib/responses/TagList.d.ts +7 -0
- package/dist/node_modules/simple-git/dist/src/lib/runners/git-executor-chain.d.ts +25 -0
- package/dist/node_modules/simple-git/dist/src/lib/runners/git-executor.d.ts +14 -0
- package/dist/node_modules/simple-git/dist/src/lib/runners/promise-wrapped.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/runners/scheduler.d.ts +11 -0
- package/dist/node_modules/simple-git/dist/src/lib/runners/tasks-pending-queue.d.ts +23 -0
- package/dist/node_modules/simple-git/dist/src/lib/simple-git-api.d.ts +20 -0
- package/dist/node_modules/simple-git/dist/src/lib/task-callback.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/apply-patch.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/branch.d.ts +7 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/change-working-directory.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/check-ignore.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/check-is-repo.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/checkout.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/clean.d.ts +25 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/clone.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/commit.d.ts +4 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/config.d.ts +8 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/count-objects.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/diff-name-status.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/diff.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/fetch.d.ts +4 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/first-commit.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/grep.d.ts +12 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/hash-object.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/init.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/log.d.ts +32 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/merge.d.ts +4 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/move.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/pull.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/push.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/remote.d.ts +8 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/reset.d.ts +11 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/show.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/stash-list.d.ts +4 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/status.d.ts +3 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/sub-module.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/tag.d.ts +18 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/task.d.ts +14 -0
- package/dist/node_modules/simple-git/dist/src/lib/tasks/version.d.ts +9 -0
- package/dist/node_modules/simple-git/dist/src/lib/types/handlers.d.ts +21 -0
- package/dist/node_modules/simple-git/dist/src/lib/types/index.d.ts +136 -0
- package/dist/node_modules/simple-git/dist/src/lib/types/tasks.d.ts +19 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/argument-filters.d.ts +14 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/exit-codes.d.ts +10 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/git-output-streams.d.ts +7 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/index.d.ts +8 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/line-parser.d.ts +15 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/simple-git-options.d.ts +2 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/task-options.d.ts +13 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/task-parser.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/src/lib/utils/util.d.ts +47 -0
- package/dist/node_modules/simple-git/dist/typings/errors.d.ts +5 -0
- package/dist/node_modules/simple-git/dist/typings/index.d.ts +14 -0
- package/dist/node_modules/simple-git/dist/typings/response.d.ts +556 -0
- package/dist/node_modules/simple-git/dist/typings/simple-git.d.ts +1033 -0
- package/dist/node_modules/simple-git/dist/typings/types.d.ts +22 -0
- package/dist/node_modules/simple-git/node_modules/debug/package.json +64 -0
- package/dist/node_modules/simple-git/node_modules/debug/src/browser.js +272 -0
- package/dist/node_modules/simple-git/node_modules/debug/src/common.js +292 -0
- package/dist/node_modules/simple-git/node_modules/debug/src/index.js +10 -0
- package/dist/node_modules/simple-git/node_modules/debug/src/node.js +263 -0
- package/dist/node_modules/simple-git/package.json +1 -0
- package/dist/node_modules/simple-git/promise.js +17 -0
- package/dist/server/actions/git-actions.d.ts +13 -0
- package/dist/server/actions/git-actions.js +354 -0
- package/dist/server/collections/gitRepositories.d.ts +2 -0
- package/dist/server/collections/gitRepositories.js +75 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +48 -0
- package/dist/server/plugin.d.ts +6 -0
- package/dist/server/plugin.js +120 -0
- package/package.json +32 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
- package/src/client/components/CommitHistory.tsx +326 -0
- package/src/client/components/FileExplorer.tsx +329 -0
- package/src/client/components/GitManagerSettings.tsx +123 -0
- package/src/client/components/GitOperations.tsx +195 -0
- package/src/client/components/RepositoryConfig.tsx +188 -0
- package/src/client/context/GitManagerContext.tsx +84 -0
- package/src/client/index.tsx +19 -0
- package/src/client/locale.ts +9 -0
- package/src/index.ts +2 -0
- package/src/locale/en-US.json +45 -0
- package/src/locale/vi-VN.json +45 -0
- package/src/server/actions/git-actions.ts +346 -0
- package/src/server/collections/gitRepositories.ts +45 -0
- package/src/server/index.ts +2 -0
- package/src/server/plugin.ts +81 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import React, { useEffect, useState, useCallback, useRef } from 'react';
|
|
2
|
+
import { Tree, Empty, Spin, Typography, Select, Space, Breadcrumb, Input, theme } from 'antd';
|
|
3
|
+
import {
|
|
4
|
+
FileOutlined,
|
|
5
|
+
FileTextOutlined,
|
|
6
|
+
CodeOutlined,
|
|
7
|
+
FileImageOutlined,
|
|
8
|
+
FileMarkdownOutlined,
|
|
9
|
+
Html5Outlined,
|
|
10
|
+
} from '@ant-design/icons';
|
|
11
|
+
import { useAPIClient } from '@nocobase/client';
|
|
12
|
+
import { useGitManager } from '../context/GitManagerContext';
|
|
13
|
+
import { useT } from '../locale';
|
|
14
|
+
|
|
15
|
+
const { Text } = Typography;
|
|
16
|
+
const { Search } = Input;
|
|
17
|
+
const { useToken } = theme;
|
|
18
|
+
|
|
19
|
+
const FILE_ICONS: Record<string, React.ReactNode> = {
|
|
20
|
+
ts: <CodeOutlined style={{ color: '#3178c6' }} />,
|
|
21
|
+
tsx: <CodeOutlined style={{ color: '#3178c6' }} />,
|
|
22
|
+
js: <CodeOutlined style={{ color: '#f7df1e' }} />,
|
|
23
|
+
jsx: <CodeOutlined style={{ color: '#f7df1e' }} />,
|
|
24
|
+
json: <CodeOutlined style={{ color: '#5b5b5b' }} />,
|
|
25
|
+
md: <FileMarkdownOutlined style={{ color: '#083fa1' }} />,
|
|
26
|
+
html: <Html5Outlined style={{ color: '#e34c26' }} />,
|
|
27
|
+
css: <FileTextOutlined style={{ color: '#563d7c' }} />,
|
|
28
|
+
py: <CodeOutlined style={{ color: '#3572A5' }} />,
|
|
29
|
+
png: <FileImageOutlined style={{ color: '#a85e32' }} />,
|
|
30
|
+
jpg: <FileImageOutlined style={{ color: '#a85e32' }} />,
|
|
31
|
+
svg: <FileImageOutlined style={{ color: '#ffb13b' }} />,
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
function getFileIcon(name: string, type: string) {
|
|
35
|
+
if (type === 'tree') return undefined; // use default folder icons
|
|
36
|
+
const ext = name.split('.').pop()?.toLowerCase() || '';
|
|
37
|
+
return FILE_ICONS[ext] || <FileOutlined />;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getLanguage(filename: string): string {
|
|
41
|
+
const ext = filename.split('.').pop()?.toLowerCase() || '';
|
|
42
|
+
const map: Record<string, string> = {
|
|
43
|
+
ts: 'typescript', tsx: 'typescript', js: 'javascript', jsx: 'javascript',
|
|
44
|
+
json: 'json', md: 'markdown', html: 'html', css: 'css', scss: 'scss',
|
|
45
|
+
py: 'python', sh: 'bash', yml: 'yaml', yaml: 'yaml', sql: 'sql',
|
|
46
|
+
xml: 'xml', java: 'java', go: 'go', rs: 'rust', rb: 'ruby',
|
|
47
|
+
};
|
|
48
|
+
return map[ext] || 'text';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
interface TreeNode {
|
|
52
|
+
key: string;
|
|
53
|
+
title: React.ReactNode;
|
|
54
|
+
icon: React.ReactNode;
|
|
55
|
+
isLeaf: boolean;
|
|
56
|
+
children?: TreeNode[];
|
|
57
|
+
filePath: string;
|
|
58
|
+
fileType: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const FileExplorer: React.FC = () => {
|
|
62
|
+
const t = useT();
|
|
63
|
+
const { token } = useToken();
|
|
64
|
+
const api = useAPIClient();
|
|
65
|
+
const { selectedRepo, branches: branchList, currentBranch, refreshBranches } = useGitManager();
|
|
66
|
+
const [treeData, setTreeData] = useState<TreeNode[]>([]);
|
|
67
|
+
const [loading, setLoading] = useState(false);
|
|
68
|
+
const [fileContent, setFileContent] = useState<string | null>(null);
|
|
69
|
+
const [selectedFile, setSelectedFile] = useState<string | null>(null);
|
|
70
|
+
const [currentRef, setCurrentRef] = useState('HEAD');
|
|
71
|
+
const [searchText, setSearchText] = useState('');
|
|
72
|
+
const [debouncedSearch, setDebouncedSearch] = useState('');
|
|
73
|
+
const [contentLoading, setContentLoading] = useState(false);
|
|
74
|
+
|
|
75
|
+
const loadTree = useCallback(
|
|
76
|
+
async (treePath = '', ref = currentRef) => {
|
|
77
|
+
if (!selectedRepo) return [];
|
|
78
|
+
const { data } = await api.request({
|
|
79
|
+
url: 'gitManager:fileTree',
|
|
80
|
+
params: { repositoryId: selectedRepo.id, ref, treePath },
|
|
81
|
+
});
|
|
82
|
+
const responseData = data?.data || data || [];
|
|
83
|
+
const list = Array.isArray(responseData) ? responseData : (Array.isArray(responseData?.data) ? responseData.data : []);
|
|
84
|
+
|
|
85
|
+
return list.map((item: any) => ({
|
|
86
|
+
key: item.path,
|
|
87
|
+
title: (
|
|
88
|
+
<Text style={{ fontSize: 13 }}>
|
|
89
|
+
{item.name}
|
|
90
|
+
{item.type === 'blob' && item.size > 0 && (
|
|
91
|
+
<Text type="secondary" style={{ fontSize: 11, marginLeft: 8 }}>
|
|
92
|
+
{item.size > 1024 ? `${(item.size / 1024).toFixed(1)}KB` : `${item.size}B`}
|
|
93
|
+
</Text>
|
|
94
|
+
)}
|
|
95
|
+
</Text>
|
|
96
|
+
),
|
|
97
|
+
icon: getFileIcon(item.name, item.type),
|
|
98
|
+
isLeaf: item.type === 'blob',
|
|
99
|
+
filePath: item.path,
|
|
100
|
+
fileType: item.type,
|
|
101
|
+
}));
|
|
102
|
+
},
|
|
103
|
+
[api, selectedRepo, currentRef],
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
const loadRoot = useCallback(async () => {
|
|
107
|
+
setLoading(true);
|
|
108
|
+
try {
|
|
109
|
+
const nodes = await loadTree('', currentRef);
|
|
110
|
+
setTreeData(nodes);
|
|
111
|
+
} finally {
|
|
112
|
+
setLoading(false);
|
|
113
|
+
}
|
|
114
|
+
}, [loadTree, currentRef]);
|
|
115
|
+
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
if (selectedRepo?.status === 'connected') {
|
|
118
|
+
refreshBranches();
|
|
119
|
+
setFileContent(null);
|
|
120
|
+
setSelectedFile(null);
|
|
121
|
+
} else {
|
|
122
|
+
setTreeData([]);
|
|
123
|
+
}
|
|
124
|
+
}, [selectedRepo]);
|
|
125
|
+
|
|
126
|
+
// Sync currentRef when branch data arrives
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
if (currentBranch && currentRef === 'HEAD') {
|
|
129
|
+
setCurrentRef(currentBranch);
|
|
130
|
+
}
|
|
131
|
+
}, [currentBranch]);
|
|
132
|
+
|
|
133
|
+
useEffect(() => {
|
|
134
|
+
if (selectedRepo?.status === 'connected') {
|
|
135
|
+
loadRoot();
|
|
136
|
+
}
|
|
137
|
+
}, [currentRef, selectedRepo]);
|
|
138
|
+
|
|
139
|
+
const onLoadData = async (node: any) => {
|
|
140
|
+
if (node.children) return;
|
|
141
|
+
const children = await loadTree(node.filePath, currentRef);
|
|
142
|
+
setTreeData((prev) => updateTreeData(prev, node.key, children));
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const onSelect = async (_: any, info: any) => {
|
|
146
|
+
const node = info.node;
|
|
147
|
+
if (!node.isLeaf) return;
|
|
148
|
+
setContentLoading(true);
|
|
149
|
+
setSelectedFile(node.filePath);
|
|
150
|
+
try {
|
|
151
|
+
const { data } = await api.request({
|
|
152
|
+
url: 'gitManager:fileContent',
|
|
153
|
+
params: { repositoryId: selectedRepo.id, ref: currentRef, filePath: node.filePath },
|
|
154
|
+
});
|
|
155
|
+
const responseData = data?.data?.data || data?.data;
|
|
156
|
+
setFileContent(responseData?.content || '');
|
|
157
|
+
} catch {
|
|
158
|
+
setFileContent('// Failed to load file content');
|
|
159
|
+
} finally {
|
|
160
|
+
setContentLoading(false);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
// Debounce search text by 300ms
|
|
165
|
+
const debounceRef = useRef<ReturnType<typeof setTimeout>>();
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
debounceRef.current = setTimeout(() => setDebouncedSearch(searchText), 300);
|
|
168
|
+
return () => clearTimeout(debounceRef.current);
|
|
169
|
+
}, [searchText]);
|
|
170
|
+
|
|
171
|
+
if (!selectedRepo) {
|
|
172
|
+
return <Empty description={t('No repository selected')} />;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (selectedRepo.status !== 'connected') {
|
|
176
|
+
return <Empty description={t('Repository not cloned yet')} />;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const filteredTree = debouncedSearch ? filterTree(treeData, debouncedSearch.toLowerCase()) : treeData;
|
|
180
|
+
|
|
181
|
+
return (
|
|
182
|
+
<div style={{ display: 'flex', height: 'calc(100vh - 280px)', gap: 0 }}>
|
|
183
|
+
{/* Left sidebar - file tree */}
|
|
184
|
+
<div
|
|
185
|
+
style={{
|
|
186
|
+
width: 320,
|
|
187
|
+
minWidth: 280,
|
|
188
|
+
borderRight: `1px solid ${token.colorBorderSecondary}`,
|
|
189
|
+
display: 'flex',
|
|
190
|
+
flexDirection: 'column',
|
|
191
|
+
background: token.colorBgContainer,
|
|
192
|
+
}}
|
|
193
|
+
>
|
|
194
|
+
<div style={{ padding: '8px 12px', borderBottom: `1px solid ${token.colorBorderSecondary}` }}>
|
|
195
|
+
<Space direction="vertical" style={{ width: '100%' }} size={6}>
|
|
196
|
+
<Select
|
|
197
|
+
size="small"
|
|
198
|
+
style={{ width: '100%' }}
|
|
199
|
+
value={currentRef}
|
|
200
|
+
onChange={(val) => {
|
|
201
|
+
setCurrentRef(val);
|
|
202
|
+
setFileContent(null);
|
|
203
|
+
setSelectedFile(null);
|
|
204
|
+
}}
|
|
205
|
+
options={branchList.map((b) => ({ label: b, value: b }))}
|
|
206
|
+
placeholder="Branch"
|
|
207
|
+
/>
|
|
208
|
+
<Search
|
|
209
|
+
size="small"
|
|
210
|
+
placeholder="Filter files..."
|
|
211
|
+
allowClear
|
|
212
|
+
onChange={(e) => setSearchText(e.target.value)}
|
|
213
|
+
/>
|
|
214
|
+
</Space>
|
|
215
|
+
</div>
|
|
216
|
+
<div style={{ flex: 1, overflow: 'auto', padding: '4px 0' }}>
|
|
217
|
+
{loading ? (
|
|
218
|
+
<div style={{ textAlign: 'center', padding: 40 }}><Spin /></div>
|
|
219
|
+
) : (
|
|
220
|
+
<Tree
|
|
221
|
+
showIcon
|
|
222
|
+
treeData={filteredTree}
|
|
223
|
+
loadData={onLoadData}
|
|
224
|
+
onSelect={onSelect}
|
|
225
|
+
selectedKeys={selectedFile ? [selectedFile] : []}
|
|
226
|
+
style={{ fontSize: 13 }}
|
|
227
|
+
blockNode
|
|
228
|
+
/>
|
|
229
|
+
)}
|
|
230
|
+
</div>
|
|
231
|
+
</div>
|
|
232
|
+
|
|
233
|
+
{/* Right panel - file content */}
|
|
234
|
+
<div style={{ flex: 1, display: 'flex', flexDirection: 'column', background: token.colorBgLayout }}>
|
|
235
|
+
{selectedFile ? (
|
|
236
|
+
<>
|
|
237
|
+
<div
|
|
238
|
+
style={{
|
|
239
|
+
padding: '6px 16px',
|
|
240
|
+
borderBottom: `1px solid ${token.colorBorderSecondary}`,
|
|
241
|
+
background: token.colorBgContainer,
|
|
242
|
+
display: 'flex',
|
|
243
|
+
alignItems: 'center',
|
|
244
|
+
gap: 8,
|
|
245
|
+
}}
|
|
246
|
+
>
|
|
247
|
+
<Breadcrumb
|
|
248
|
+
items={selectedFile.split('/').map((part, i, arr) => ({
|
|
249
|
+
title: i === arr.length - 1 ? <Text strong>{part}</Text> : part,
|
|
250
|
+
}))}
|
|
251
|
+
/>
|
|
252
|
+
<Text type="secondary" style={{ marginLeft: 'auto', fontSize: 12 }}>
|
|
253
|
+
{getLanguage(selectedFile)}
|
|
254
|
+
</Text>
|
|
255
|
+
</div>
|
|
256
|
+
<div style={{ flex: 1, overflow: 'auto' }}>
|
|
257
|
+
{contentLoading ? (
|
|
258
|
+
<div style={{ textAlign: 'center', padding: 40 }}><Spin /></div>
|
|
259
|
+
) : (
|
|
260
|
+
<pre
|
|
261
|
+
style={{
|
|
262
|
+
margin: 0,
|
|
263
|
+
padding: 16,
|
|
264
|
+
fontSize: 13,
|
|
265
|
+
lineHeight: 1.6,
|
|
266
|
+
fontFamily: "'JetBrains Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace",
|
|
267
|
+
whiteSpace: 'pre-wrap',
|
|
268
|
+
wordBreak: 'break-all',
|
|
269
|
+
background: token.colorBgContainer,
|
|
270
|
+
minHeight: '100%',
|
|
271
|
+
}}
|
|
272
|
+
>
|
|
273
|
+
{(fileContent || '').split('\n').map((line, i) => (
|
|
274
|
+
<div key={i} style={{ display: 'flex' }}>
|
|
275
|
+
<span
|
|
276
|
+
style={{
|
|
277
|
+
display: 'inline-block',
|
|
278
|
+
width: 50,
|
|
279
|
+
textAlign: 'right',
|
|
280
|
+
paddingRight: 16,
|
|
281
|
+
color: token.colorTextQuaternary,
|
|
282
|
+
userSelect: 'none',
|
|
283
|
+
flexShrink: 0,
|
|
284
|
+
}}
|
|
285
|
+
>
|
|
286
|
+
{i + 1}
|
|
287
|
+
</span>
|
|
288
|
+
<span style={{ flex: 1 }}>{line || ' '}</span>
|
|
289
|
+
</div>
|
|
290
|
+
))}
|
|
291
|
+
</pre>
|
|
292
|
+
)}
|
|
293
|
+
</div>
|
|
294
|
+
</>
|
|
295
|
+
) : (
|
|
296
|
+
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', height: '100%' }}>
|
|
297
|
+
<Text type="secondary">Select a file to view its content</Text>
|
|
298
|
+
</div>
|
|
299
|
+
)}
|
|
300
|
+
</div>
|
|
301
|
+
</div>
|
|
302
|
+
);
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
function updateTreeData(list: TreeNode[], key: string, children: TreeNode[]): TreeNode[] {
|
|
306
|
+
return list.map((node) => {
|
|
307
|
+
if (node.key === key) {
|
|
308
|
+
return { ...node, children };
|
|
309
|
+
}
|
|
310
|
+
if (node.children) {
|
|
311
|
+
return { ...node, children: updateTreeData(node.children, key, children) };
|
|
312
|
+
}
|
|
313
|
+
return node;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function filterTree(nodes: TreeNode[], text: string): TreeNode[] {
|
|
318
|
+
return nodes
|
|
319
|
+
.map((node) => {
|
|
320
|
+
if (node.children) {
|
|
321
|
+
const filtered = filterTree(node.children, text);
|
|
322
|
+
if (filtered.length > 0) return { ...node, children: filtered };
|
|
323
|
+
}
|
|
324
|
+
const name = (node.filePath || '').toLowerCase();
|
|
325
|
+
if (name.includes(text)) return node;
|
|
326
|
+
return null;
|
|
327
|
+
})
|
|
328
|
+
.filter(Boolean) as TreeNode[];
|
|
329
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { Tabs, Select, Space, Typography, Tag, theme } from 'antd';
|
|
3
|
+
import { BranchesOutlined, FolderOutlined, HistoryOutlined, ToolOutlined, DatabaseOutlined } from '@ant-design/icons';
|
|
4
|
+
import { GitManagerProvider, useGitManager } from '../context/GitManagerContext';
|
|
5
|
+
import { RepositoryConfig } from './RepositoryConfig';
|
|
6
|
+
import { FileExplorer } from './FileExplorer';
|
|
7
|
+
import { CommitHistory } from './CommitHistory';
|
|
8
|
+
import { GitOperations } from './GitOperations';
|
|
9
|
+
import { useT } from '../locale';
|
|
10
|
+
|
|
11
|
+
const { Text } = Typography;
|
|
12
|
+
const { useToken } = theme;
|
|
13
|
+
|
|
14
|
+
const GitManagerContent: React.FC = () => {
|
|
15
|
+
const t = useT();
|
|
16
|
+
const { token } = useToken();
|
|
17
|
+
const { repos, selectedRepo, setSelectedRepo, refreshRepos } = useGitManager();
|
|
18
|
+
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
refreshRepos();
|
|
21
|
+
}, []);
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<div style={{ height: '100%' }}>
|
|
25
|
+
{/* Repository selector bar */}
|
|
26
|
+
<div
|
|
27
|
+
style={{
|
|
28
|
+
padding: '12px 0',
|
|
29
|
+
marginBottom: 16,
|
|
30
|
+
display: 'flex',
|
|
31
|
+
alignItems: 'center',
|
|
32
|
+
gap: 12,
|
|
33
|
+
borderBottom: `1px solid ${token.colorBorderSecondary}`,
|
|
34
|
+
}}
|
|
35
|
+
>
|
|
36
|
+
<DatabaseOutlined style={{ fontSize: 16 }} />
|
|
37
|
+
<Text strong>Repository:</Text>
|
|
38
|
+
<Select
|
|
39
|
+
style={{ minWidth: 250 }}
|
|
40
|
+
placeholder={t('Select a repository')}
|
|
41
|
+
value={selectedRepo?.id}
|
|
42
|
+
onChange={(id) => {
|
|
43
|
+
const repo = repos.find((r) => r.id === id);
|
|
44
|
+
setSelectedRepo(repo || null);
|
|
45
|
+
}}
|
|
46
|
+
options={repos.map((r) => ({
|
|
47
|
+
label: (
|
|
48
|
+
<Space>
|
|
49
|
+
{r.name}
|
|
50
|
+
<Tag
|
|
51
|
+
color={r.status === 'connected' ? 'green' : 'default'}
|
|
52
|
+
style={{ fontSize: 11 }}
|
|
53
|
+
>
|
|
54
|
+
{r.status === 'connected' ? t('Connected') : t('Disconnected')}
|
|
55
|
+
</Tag>
|
|
56
|
+
</Space>
|
|
57
|
+
),
|
|
58
|
+
value: r.id,
|
|
59
|
+
}))}
|
|
60
|
+
allowClear
|
|
61
|
+
onClear={() => setSelectedRepo(null)}
|
|
62
|
+
/>
|
|
63
|
+
{selectedRepo && (
|
|
64
|
+
<Text type="secondary" style={{ fontSize: 12 }}>
|
|
65
|
+
{selectedRepo.repoUrl}
|
|
66
|
+
</Text>
|
|
67
|
+
)}
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
<Tabs
|
|
71
|
+
type="card"
|
|
72
|
+
defaultActiveKey="repos"
|
|
73
|
+
destroyInactiveTabPane
|
|
74
|
+
items={[
|
|
75
|
+
{
|
|
76
|
+
key: 'repos',
|
|
77
|
+
label: (
|
|
78
|
+
<span>
|
|
79
|
+
<DatabaseOutlined /> {t('Repositories')}
|
|
80
|
+
</span>
|
|
81
|
+
),
|
|
82
|
+
children: <RepositoryConfig />,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
key: 'explorer',
|
|
86
|
+
label: (
|
|
87
|
+
<span>
|
|
88
|
+
<FolderOutlined /> {t('File Explorer')}
|
|
89
|
+
</span>
|
|
90
|
+
),
|
|
91
|
+
children: <FileExplorer />,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
key: 'history',
|
|
95
|
+
label: (
|
|
96
|
+
<span>
|
|
97
|
+
<HistoryOutlined /> {t('History')}
|
|
98
|
+
</span>
|
|
99
|
+
),
|
|
100
|
+
children: <CommitHistory />,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
key: 'operations',
|
|
104
|
+
label: (
|
|
105
|
+
<span>
|
|
106
|
+
<ToolOutlined /> {t('Operations')}
|
|
107
|
+
</span>
|
|
108
|
+
),
|
|
109
|
+
children: <GitOperations />,
|
|
110
|
+
},
|
|
111
|
+
]}
|
|
112
|
+
/>
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export const GitManagerSettings: React.FC = () => {
|
|
118
|
+
return (
|
|
119
|
+
<GitManagerProvider>
|
|
120
|
+
<GitManagerContent />
|
|
121
|
+
</GitManagerProvider>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import React, { useState, useCallback } from 'react';
|
|
2
|
+
import { Button, Space, Card, Typography, Tag, Empty, message, Spin, Descriptions, List, Badge, theme } from 'antd';
|
|
3
|
+
import {
|
|
4
|
+
CloudDownloadOutlined,
|
|
5
|
+
CloudUploadOutlined,
|
|
6
|
+
SyncOutlined,
|
|
7
|
+
BranchesOutlined,
|
|
8
|
+
CheckCircleOutlined,
|
|
9
|
+
WarningOutlined,
|
|
10
|
+
FileAddOutlined,
|
|
11
|
+
EditOutlined,
|
|
12
|
+
DeleteOutlined,
|
|
13
|
+
QuestionCircleOutlined,
|
|
14
|
+
} from '@ant-design/icons';
|
|
15
|
+
import { useAPIClient } from '@nocobase/client';
|
|
16
|
+
import { useGitManager } from '../context/GitManagerContext';
|
|
17
|
+
import { useT } from '../locale';
|
|
18
|
+
|
|
19
|
+
const { Text } = Typography;
|
|
20
|
+
const { useToken } = theme;
|
|
21
|
+
|
|
22
|
+
const FILE_STATUS_MAP: Record<string, { color: string; icon: React.ReactNode; label: string }> = {
|
|
23
|
+
not_added: { color: 'green', icon: <FileAddOutlined />, label: 'New' },
|
|
24
|
+
modified: { color: 'blue', icon: <EditOutlined />, label: 'Modified' },
|
|
25
|
+
deleted: { color: 'red', icon: <DeleteOutlined />, label: 'Deleted' },
|
|
26
|
+
renamed: { color: 'orange', icon: <EditOutlined />, label: 'Renamed' },
|
|
27
|
+
conflicted: { color: 'red', icon: <WarningOutlined />, label: 'Conflict' },
|
|
28
|
+
created: { color: 'green', icon: <FileAddOutlined />, label: 'Created' },
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const GitOperations: React.FC = () => {
|
|
32
|
+
const t = useT();
|
|
33
|
+
const { token } = useToken();
|
|
34
|
+
const api = useAPIClient();
|
|
35
|
+
const { selectedRepo, refreshRepos } = useGitManager();
|
|
36
|
+
const [actionLoading, setActionLoading] = useState<string | null>(null);
|
|
37
|
+
const [statusData, setStatusData] = useState<any>(null);
|
|
38
|
+
const [lastResult, setLastResult] = useState<{ action: string; success: boolean; message: string } | null>(null);
|
|
39
|
+
|
|
40
|
+
const execAction = useCallback(
|
|
41
|
+
async (action: string) => {
|
|
42
|
+
if (!selectedRepo) return;
|
|
43
|
+
setActionLoading(action);
|
|
44
|
+
setLastResult(null);
|
|
45
|
+
try {
|
|
46
|
+
const { data } = await api.request({
|
|
47
|
+
url: `gitManager:${action}`,
|
|
48
|
+
method: 'post',
|
|
49
|
+
params: { repositoryId: selectedRepo.id },
|
|
50
|
+
});
|
|
51
|
+
setLastResult({ action, success: true, message: t('{{action}} completed successfully', { action }) });
|
|
52
|
+
message.success(t('{{action}} completed', { action }));
|
|
53
|
+
if (action === 'status') {
|
|
54
|
+
const responseData = data?.data?.data || data?.data;
|
|
55
|
+
setStatusData(responseData);
|
|
56
|
+
}
|
|
57
|
+
await refreshRepos();
|
|
58
|
+
} catch (err: any) {
|
|
59
|
+
const msg = err?.response?.data?.errors?.[0]?.message || t('{{action}} failed', { action });
|
|
60
|
+
setLastResult({ action, success: false, message: msg });
|
|
61
|
+
message.error(msg);
|
|
62
|
+
} finally {
|
|
63
|
+
setActionLoading(null);
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
[api, selectedRepo, refreshRepos],
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
if (!selectedRepo) {
|
|
70
|
+
return <Empty description={t('No repository selected')} />;
|
|
71
|
+
}
|
|
72
|
+
if (selectedRepo.status !== 'connected') {
|
|
73
|
+
return <Empty description={t('Repository not cloned yet')} />;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const allChangedFiles = statusData
|
|
77
|
+
? [
|
|
78
|
+
...statusData.not_added?.map((f: string) => ({ file: f, status: 'not_added' })) || [],
|
|
79
|
+
...statusData.modified?.map((f: string) => ({ file: f, status: 'modified' })) || [],
|
|
80
|
+
...statusData.deleted?.map((f: string) => ({ file: f, status: 'deleted' })) || [],
|
|
81
|
+
...statusData.renamed?.map((f: any) => ({ file: typeof f === 'string' ? f : f.to, status: 'renamed' })) || [],
|
|
82
|
+
...statusData.conflicted?.map((f: string) => ({ file: f, status: 'conflicted' })) || [],
|
|
83
|
+
...statusData.created?.map((f: string) => ({ file: f, status: 'created' })) || [],
|
|
84
|
+
]
|
|
85
|
+
: [];
|
|
86
|
+
|
|
87
|
+
return (
|
|
88
|
+
<div>
|
|
89
|
+
<Space size="middle" wrap style={{ marginBottom: 24 }}>
|
|
90
|
+
<Button
|
|
91
|
+
size="large"
|
|
92
|
+
icon={<SyncOutlined />}
|
|
93
|
+
loading={actionLoading === 'fetch'}
|
|
94
|
+
onClick={() => execAction('fetch')}
|
|
95
|
+
>
|
|
96
|
+
{t('Fetch')}
|
|
97
|
+
</Button>
|
|
98
|
+
<Button
|
|
99
|
+
size="large"
|
|
100
|
+
type="primary"
|
|
101
|
+
icon={<CloudDownloadOutlined />}
|
|
102
|
+
loading={actionLoading === 'pull'}
|
|
103
|
+
onClick={() => execAction('pull')}
|
|
104
|
+
>
|
|
105
|
+
{t('Pull')}
|
|
106
|
+
</Button>
|
|
107
|
+
<Button
|
|
108
|
+
size="large"
|
|
109
|
+
icon={<CloudUploadOutlined />}
|
|
110
|
+
loading={actionLoading === 'push'}
|
|
111
|
+
onClick={() => execAction('push')}
|
|
112
|
+
>
|
|
113
|
+
{t('Push')}
|
|
114
|
+
</Button>
|
|
115
|
+
<Button
|
|
116
|
+
size="large"
|
|
117
|
+
icon={<BranchesOutlined />}
|
|
118
|
+
loading={actionLoading === 'status'}
|
|
119
|
+
onClick={() => execAction('status')}
|
|
120
|
+
>
|
|
121
|
+
{t('Status')}
|
|
122
|
+
</Button>
|
|
123
|
+
</Space>
|
|
124
|
+
|
|
125
|
+
{lastResult && (
|
|
126
|
+
<Card
|
|
127
|
+
size="small"
|
|
128
|
+
style={{
|
|
129
|
+
marginBottom: 16,
|
|
130
|
+
borderColor: lastResult.success ? token.colorSuccessBorder : token.colorErrorBorder,
|
|
131
|
+
}}
|
|
132
|
+
>
|
|
133
|
+
<Space>
|
|
134
|
+
{lastResult.success ? (
|
|
135
|
+
<CheckCircleOutlined style={{ color: token.colorSuccess }} />
|
|
136
|
+
) : (
|
|
137
|
+
<WarningOutlined style={{ color: token.colorError }} />
|
|
138
|
+
)}
|
|
139
|
+
<Text strong>{lastResult.action}</Text>
|
|
140
|
+
<Text>{lastResult.message}</Text>
|
|
141
|
+
</Space>
|
|
142
|
+
</Card>
|
|
143
|
+
)}
|
|
144
|
+
|
|
145
|
+
{statusData && (
|
|
146
|
+
<Card title={t('Working Directory Status')} size="small">
|
|
147
|
+
<Descriptions column={3} size="small" style={{ marginBottom: 16 }}>
|
|
148
|
+
<Descriptions.Item label="Branch">
|
|
149
|
+
<Tag icon={<BranchesOutlined />} color="blue">{statusData.current}</Tag>
|
|
150
|
+
</Descriptions.Item>
|
|
151
|
+
<Descriptions.Item label="Tracking">
|
|
152
|
+
<Text>{statusData.tracking || 'N/A'}</Text>
|
|
153
|
+
</Descriptions.Item>
|
|
154
|
+
<Descriptions.Item label="Changes">
|
|
155
|
+
<Space>
|
|
156
|
+
{statusData.ahead > 0 && <Badge count={`${statusData.ahead} ahead`} style={{ backgroundColor: token.colorPrimary }} />}
|
|
157
|
+
{statusData.behind > 0 && <Badge count={`${statusData.behind} behind`} style={{ backgroundColor: token.colorWarning }} />}
|
|
158
|
+
{statusData.ahead === 0 && statusData.behind === 0 && (
|
|
159
|
+
<Tag color="green" icon={<CheckCircleOutlined />}>Up to date</Tag>
|
|
160
|
+
)}
|
|
161
|
+
</Space>
|
|
162
|
+
</Descriptions.Item>
|
|
163
|
+
</Descriptions>
|
|
164
|
+
|
|
165
|
+
{allChangedFiles.length > 0 ? (
|
|
166
|
+
<>
|
|
167
|
+
<Text strong style={{ display: 'block', marginBottom: 8 }}>
|
|
168
|
+
{allChangedFiles.length} changed file(s)
|
|
169
|
+
</Text>
|
|
170
|
+
<List
|
|
171
|
+
size="small"
|
|
172
|
+
dataSource={allChangedFiles}
|
|
173
|
+
renderItem={(item: any) => {
|
|
174
|
+
const info = FILE_STATUS_MAP[item.status] || { color: 'default', icon: <QuestionCircleOutlined />, label: item.status };
|
|
175
|
+
return (
|
|
176
|
+
<List.Item style={{ padding: '4px 0' }}>
|
|
177
|
+
<Space>
|
|
178
|
+
<Tag color={info.color} style={{ minWidth: 80, textAlign: 'center' }}>
|
|
179
|
+
{info.icon} {info.label}
|
|
180
|
+
</Tag>
|
|
181
|
+
<Text code style={{ fontSize: 13 }}>{item.file}</Text>
|
|
182
|
+
</Space>
|
|
183
|
+
</List.Item>
|
|
184
|
+
);
|
|
185
|
+
}}
|
|
186
|
+
/>
|
|
187
|
+
</>
|
|
188
|
+
) : (
|
|
189
|
+
<Text type="secondary">Working directory clean</Text>
|
|
190
|
+
)}
|
|
191
|
+
</Card>
|
|
192
|
+
)}
|
|
193
|
+
</div>
|
|
194
|
+
);
|
|
195
|
+
};
|