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

Commit 0d53b64

Browse files
author
Noah Lee
authored
Separate the state from the repoRollback view (#405)
* Separate the state from the repoRollback view * Add the todo comment * Separate the state from the repo view
1 parent 81592e9 commit 0d53b64

File tree

4 files changed

+93
-40
lines changed

4 files changed

+93
-40
lines changed

ui/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from "react-router-dom";
77

88
import Home from "./views/home"
9-
import Repo from "./views/Repo"
9+
import Repo from "./views/repo"
1010
import Deployment from "./views/deployment"
1111
import Settings from "./views/settings"
1212
import Members from "./views/members"

ui/src/views/Repo.tsx renamed to ui/src/views/repo/index.tsx

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ import { shallowEqual } from "react-redux";
44
import { useEffect } from "react";
55
import { Helmet } from "react-helmet"
66

7-
import { useAppSelector, useAppDispatch } from '../redux/hooks'
8-
import { init, activate, repoSlice as slice } from '../redux/repo'
7+
import { useAppSelector, useAppDispatch } from '../../redux/hooks'
8+
import { init, activate, repoSlice as slice } from '../../redux/repo'
99

10-
import ActivateButton from "../components/ActivateButton"
11-
import Main from './main'
12-
import RepoHome from './repoHome'
13-
import RepoLock from "./repoLock"
14-
import RepoDeploy from './repoDeploy'
15-
import RepoRollabck from './RepoRollback'
16-
import RepoSettings from "./repoSettings"
10+
import ActivateButton from "../../components/ActivateButton"
11+
import Main from '../main'
12+
import RepoHome from '../repoHome'
13+
import RepoLock from "../repoLock"
14+
import RepoDeploy from '../repoDeploy'
15+
import RepoRollabck from '../repoRollback'
16+
import RepoSettings from "../repoSettings"
1717

1818
interface Params {
1919
namespace: string
2020
name: string
2121
tab: string
2222
}
2323

24-
export default function Repo(): JSX.Element {
24+
export default (): JSX.Element => {
2525
const { namespace, name, tab } = useParams<Params>()
2626
const { display, repo } = useAppSelector(state => state.repo, shallowEqual)
2727
const dispatch = useAppDispatch()
@@ -39,23 +39,51 @@ export default function Repo(): JSX.Element {
3939
dispatch(activate())
4040
}
4141

42-
const active = (repo?.active)? true : false
43-
4442
if (!display) {
45-
return <Main>
46-
<div />
47-
</Main>
43+
return (
44+
<Main>
45+
<div />
46+
</Main>
47+
)
4848
} else if (display && !repo) {
49-
return <Main>
50-
<Result
51-
style={{paddingTop: '120px'}}
52-
status="warning"
53-
title="The page is not found."
54-
subTitle="Please check the URL."
55-
/>
56-
</Main>
49+
return (
50+
<Main>
51+
<Result
52+
style={{paddingTop: '120px'}}
53+
status="warning"
54+
title="The page is not found."
55+
subTitle="Please check the URL."
56+
/>
57+
</Main>
58+
)
5759
}
5860

61+
return (
62+
<Repo
63+
namespace={namespace}
64+
name={name}
65+
tab={tab}
66+
active={(repo?.active)? true : false}
67+
onClickActivate={onClickActivate}
68+
/>
69+
)
70+
}
71+
72+
interface RepoProps {
73+
namespace: string
74+
name: string
75+
tab: string
76+
active: boolean
77+
onClickActivate(): void
78+
}
79+
80+
function Repo({
81+
namespace,
82+
name,
83+
tab,
84+
active,
85+
onClickActivate
86+
}: RepoProps): JSX.Element {
5987
const styleActivateButton: React.CSSProperties = {
6088
display: (!active)? "" : "none",
6189
marginTop: "20px",

ui/src/components/RollbackForm.tsx renamed to ui/src/views/repoRollback/RollbackForm.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import { Form, Select, Button, Avatar } from 'antd'
22
import moment from 'moment'
33

4-
import { Deployment, Env } from "../models"
5-
import DeploymentRefCode from './DeploymentRefCode'
4+
import { Deployment, Env } from "../../models"
5+
import DeploymentRefCode from '../../components/DeploymentRefCode'
66

7-
interface RollbackFormProps {
7+
// TODO: Remove the set functions and
8+
// change it so that the component returns a value when submitting.
9+
export interface RollbackFormProps {
810
envs: Env[]
911
onSelectEnv(env: Env): void
1012
deployments: Deployment[]

ui/src/views/RepoRollback.tsx renamed to ui/src/views/repoRollback/index.tsx

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,34 @@ import { useParams } from "react-router-dom";
33
import { PageHeader, Result, Button } from 'antd'
44
import { shallowEqual } from "react-redux";
55

6-
import { useAppDispatch, useAppSelector } from "../redux/hooks"
6+
import { useAppDispatch, useAppSelector } from "../../redux/hooks"
77
import {
88
repoRollbackSlice,
99
fetchConfig,
1010
fetchDeployments,
1111
searchCandidates,
1212
fetchUser,
1313
rollback,
14-
} from "../redux/repoRollback"
15-
16-
import { Deployment, RequestStatus, Env } from '../models'
17-
import RollbackForm from "../components/RollbackForm";
14+
} from "../../redux/repoRollback"
15+
import { Deployment, RequestStatus, Env } from "../../models"
16+
import RollbackForm, { RollbackFormProps } from "./RollbackForm"
1817

1918
const { actions } = repoRollbackSlice
2019

21-
export interface Params {
22-
namespace: string
23-
name: string
24-
}
20+
export default ():JSX.Element => {
21+
const { namespace, name } = useParams<{
22+
namespace: string
23+
name: string
24+
}>()
2525

26-
export default function RepoHome(): JSX.Element {
27-
const { namespace, name } = useParams<Params>()
2826
const {
2927
display,
3028
config,
3129
envs,
3230
deployments,
33-
deploying } = useAppSelector(state => state.repoRollback, shallowEqual)
31+
deploying
32+
} = useAppSelector(state => state.repoRollback, shallowEqual)
33+
3434
const dispatch = useAppDispatch()
3535

3636
useEffect(() => {
@@ -82,6 +82,29 @@ export default function RepoHome(): JSX.Element {
8282
)
8383
}
8484

85+
return (
86+
<RepoRollback
87+
envs={envs}
88+
onSelectEnv={onSelectEnv}
89+
deployments={deployments}
90+
onSelectDeployment={onSelectDeployment}
91+
onClickRollback={onClickRollback}
92+
deploying={deploying === RequestStatus.Pending}
93+
/>
94+
)
95+
}
96+
97+
interface RepoRollbackProps extends RollbackFormProps {}
98+
99+
function RepoRollback({
100+
envs,
101+
onSelectEnv,
102+
deployments,
103+
onSelectDeployment,
104+
onClickRollback,
105+
deploying
106+
}: RepoRollbackProps): JSX.Element {
107+
85108
return (
86109
<div>
87110
<div>
@@ -96,7 +119,7 @@ export default function RepoHome(): JSX.Element {
96119
deployments={deployments}
97120
onSelectDeployment={onSelectDeployment}
98121
onClickRollback={onClickRollback}
99-
deploying={deploying === RequestStatus.Pending}
122+
deploying={deploying}
100123
/>
101124
</div>
102125
</div>

0 commit comments

Comments
 (0)