fix issues

pull/330/head
vapao 2021-03-26 19:35:42 +08:00
parent ae55a617d0
commit c5b72a090b
3 changed files with 46 additions and 36 deletions

View File

@ -15,59 +15,64 @@ export default observer(function () {
const [form] = Form.useForm(); const [form] = Form.useForm();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [fetching, setFetching] = useState(true); const [fetching, setFetching] = useState(true);
const [git_type, setGitType] = useState(lds.get(store.deploy, 'extra.0', 'branch')); const [git_type, setGitType] = useState();
const [extra1, setExtra1] = useState(lds.get(store.deploy, 'extra.1')); const [extra, setExtra] = useState();
const [extra2, setExtra2] = useState(lds.get(store.deploy, 'extra.2')); const [extra1, setExtra1] = useState();
const [extra2, setExtra2] = useState();
const [versions, setVersions] = useState({}); const [versions, setVersions] = useState({});
useEffect(() => { useEffect(() => {
fetchVersions(); fetchVersions();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []) }, [])
useEffect(() => { function _setDefault(type, new_extra, new_versions) {
if (extra1 === undefined) { const now_extra = new_extra || extra;
const {branches, tags} = versions; const now_versions = new_versions || versions;
let [extra1, extra2] = [undefined, undefined]; const {branches, tags} = now_versions;
if (git_type === 'branch') { if (type === 'branch') {
if (branches) { let [branch, commit] = [now_extra[1], null];
extra1 = _getDefaultBranch(branches); if (branches[branch]) {
extra2 = lds.get(branches[extra1], '0.id') commit = lds.get(branches[branch], '0.id')
}
} else { } else {
if (tags) { branch = lds.get(Object.keys(branches), 0)
extra1 = lds.get(Object.keys(tags), 0) commit = lds.get(branches, `${branch}.0.id`)
}
setExtra1(branch)
setExtra2(commit)
} else {
setExtra1(lds.get(Object.keys(tags), 0))
}
}
function _initial(versions) {
const {branches, tags} = versions;
if (branches && tags) {
for (let item of store.records) {
if (item.deploy_id === store.deploy.id) {
const type = item.extra[0];
setExtra(item.extra);
setGitType(type);
_setDefault(type, item.extra, versions)
break
}
} }
} }
setExtra1(extra1)
setExtra2(extra2)
} }
}, [versions, git_type, extra1])
function fetchVersions() { function fetchVersions() {
setFetching(true); setFetching(true);
http.get(`/api/app/deploy/${store.deploy.id}/versions/`, {timeout: 120000}) http.get(`/api/app/deploy/${store.deploy.id}/versions/`, {timeout: 120000})
.then(res => setVersions(res)) .then(res => {
setVersions(res);
_initial(res)
})
.finally(() => setFetching(false)) .finally(() => setFetching(false))
} }
function _getDefaultBranch(branches) {
branches = Object.keys(branches);
let branch = branches[0];
for (let item of store.records) {
if (item['deploy_id'] === store.record['deploy_id']) {
const b = lds.get(item, 'extra.1');
if (branches.includes(b)) {
branch = b
}
break
}
}
return branch
}
function switchType(v) { function switchType(v) {
setExtra1(undefined); setGitType(v);
setGitType(v) _setDefault(v)
} }
function switchExtra1(v) { function switchExtra1(v) {

View File

@ -48,7 +48,7 @@ function ComTable() {
auth="config.env.add" auth="config.env.add"
type="primary" type="primary"
icon={<PlusOutlined/>} icon={<PlusOutlined/>}
onClick={() => store.addVisible = true}>新建</AuthButton> onClick={store.showForm}>新建</AuthButton>
]} ]}
pagination={{ pagination={{
showSizeChanger: true, showSizeChanger: true,

View File

@ -34,6 +34,11 @@ class Store {
.finally(() => this.isFetching = false) .finally(() => this.isFetching = false)
}; };
showForm = () => {
this.record = {};
this.addVisible = true
};
confirmAdd = (deploy) => { confirmAdd = (deploy) => {
this.deploy = deploy; this.deploy = deploy;
this.formVisible = true; this.formVisible = true;