Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 3e193b8

Browse files
author
Noah Lee
authored
Refactoring the repoSettings view (#398)
1 parent fe704f7 commit 3e193b8

File tree

4 files changed

+125
-61
lines changed

4 files changed

+125
-61
lines changed

ui/src/views/Repo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import RepoHome from './RepoHome'
1313
import RepoLock from "./RepoLock";
1414
import RepoDeploy from './RepoDeploy'
1515
import RepoRollabck from './RepoRollback'
16-
import RepoSettings from "./RepoSettings"
16+
import RepoSettings from "./repoSettings"
1717

1818
interface Params {
1919
namespace: string

ui/src/views/RepoSettings.tsx

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { shallowEqual } from "react-redux";
2+
import { Form, Input, Button, Space, Typography } from "antd"
3+
4+
import { useAppSelector, useAppDispatch } from "../../redux/hooks"
5+
import { save, deactivate, repoSettingsSlice as slice } from "../../redux/repoSettings"
6+
import { RequestStatus } from "../../models"
7+
8+
export default function RepoSettingForm(): JSX.Element {
9+
const { repo, saving } = useAppSelector(state => state.repoSettings, shallowEqual)
10+
const dispatch = useAppDispatch()
11+
12+
const layout = {
13+
labelCol: { span: 5},
14+
wrapperCol: { span: 12 },
15+
};
16+
17+
const submitLayout = {
18+
wrapperCol: { offset: 5, span: 12 },
19+
};
20+
21+
const onClickFinish = (values: any) => {
22+
dispatch(slice.actions.setConfigPath(values.config))
23+
dispatch(save())
24+
}
25+
26+
const onClickDeactivate = () => {
27+
dispatch(deactivate())
28+
}
29+
30+
const initialValues = {
31+
"config": repo?.configPath
32+
}
33+
34+
return (
35+
<Form
36+
name="setting"
37+
initialValues={initialValues}
38+
onFinish={onClickFinish}
39+
>
40+
<Form.Item
41+
label="Config"
42+
{...layout}
43+
>
44+
<Space>
45+
<Form.Item
46+
name="config"
47+
rules={[{required: true}]}
48+
noStyle
49+
>
50+
<Input />
51+
</Form.Item>
52+
<Typography.Link target="_blank" href={`/link/${repo?.namespace}/${repo?.name}/config`}>
53+
Link
54+
</Typography.Link>
55+
</Space>
56+
</Form.Item>
57+
<Form.Item {...submitLayout}>
58+
<Form.Item noStyle>
59+
<Button
60+
loading={saving === RequestStatus.Pending}
61+
type="primary"
62+
htmlType="submit"
63+
>
64+
Submit
65+
</Button>
66+
</Form.Item>
67+
</Form.Item>
68+
<Form.Item {...submitLayout}>
69+
<Form.Item noStyle>
70+
<Space>
71+
<Button
72+
danger
73+
type="primary"
74+
onClick={onClickDeactivate}
75+
>
76+
DEACTIVATE
77+
</Button>
78+
</Space>
79+
</Form.Item>
80+
</Form.Item>
81+
</Form>
82+
)
83+
}

ui/src/views/repoSettings/index.tsx

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { useEffect } from "react";
2+
import { useParams } from "react-router-dom";
3+
import { shallowEqual } from "react-redux";
4+
import { PageHeader } from "antd"
5+
6+
import { useAppSelector, useAppDispatch } from "../../redux/hooks"
7+
import { init } from "../../redux/repoSettings"
8+
9+
import SettingsForm from "./SettingsForm"
10+
11+
interface Params {
12+
namespace: string
13+
name: string
14+
}
15+
16+
export default function RepoSettings(): JSX.Element {
17+
const { namespace, name } = useParams<Params>()
18+
const { repo } = useAppSelector(state => state.repoSettings, shallowEqual)
19+
const dispatch = useAppDispatch()
20+
21+
useEffect(() => {
22+
const f = async () => {
23+
await dispatch(init({namespace, name}))
24+
}
25+
f()
26+
// eslint-disable-next-line
27+
}, [dispatch])
28+
29+
return (
30+
<div>
31+
<div>
32+
<PageHeader title="Settings"/>
33+
</div>
34+
<div>
35+
{(repo)?
36+
<SettingsForm />
37+
:<></>}
38+
</div>
39+
</div>
40+
)
41+
}

0 commit comments

Comments
 (0)