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

Commit 81592e9

Browse files
author
Noah Lee
authored
Separate the state from the repoDeploy view (#404)
1 parent db56cdc commit 81592e9

File tree

5 files changed

+99
-34
lines changed

5 files changed

+99
-34
lines changed

ui/src/views/Repo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ActivateButton from "../components/ActivateButton"
1111
import Main from './main'
1212
import RepoHome from './repoHome'
1313
import RepoLock from "./repoLock"
14-
import RepoDeploy from './RepoDeploy'
14+
import RepoDeploy from './repoDeploy'
1515
import RepoRollabck from './RepoRollback'
1616
import RepoSettings from "./repoSettings"
1717

ui/src/components/DeployForm.tsx renamed to ui/src/views/repoDeploy/DeployForm.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
import { useState } from "react"
22
import { Form, Select, Radio, Button, Typography, Avatar, Tag as AntdTag } from "antd"
33

4-
import { Branch, Commit, Tag, Deployment, DeploymentType, Status, Env } from "../models"
4+
import { Branch, Commit, Tag, Deployment, DeploymentType, Status, Env } from "../../models"
55

6-
import CreatableSelect, {Option as Op} from "./CreatableSelect"
7-
import StatusStateIcon from "./StatusStateIcon"
6+
import CreatableSelect, {Option as Op} from "../../components/CreatableSelect"
7+
import StatusStateIcon from "../../components/StatusStateIcon"
88
import moment from "moment"
99

1010
export type Option = Op
1111

1212
const { Text } = Typography
1313

14-
interface DeployFormProps {
14+
// TODO: Remove the set functions and
15+
// change it so that the component returns a value when submitting.
16+
export interface DeployFormProps {
1517
envs: Env[]
1618
onSelectEnv(env: Env): void
1719
onChangeType(type: DeploymentType): void

ui/src/components/DynamicPayloadModal.tsx renamed to ui/src/views/repoDeploy/DynamicPayloadModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Modal, Form, Select, Input, InputNumber, Checkbox } from "antd"
22

3-
import { Env, DynamicPayloadInput, DynamicPayloadInputTypeEnum } from "../models"
3+
import { Env, DynamicPayloadInput, DynamicPayloadInputTypeEnum } from "../../models"
44

55
export interface DynamicPayloadModalProps {
66
visible: boolean

ui/src/views/RepoDeploy.tsx renamed to ui/src/views/repoDeploy/index.tsx

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

6-
import { useAppSelector, useAppDispatch } from "../redux/hooks"
7-
import { DeploymentType, Branch, Commit, Tag, RequestStatus, Env } from "../models";
6+
import { useAppSelector, useAppDispatch } from "../../redux/hooks"
7+
import { DeploymentType, Branch, Commit, Tag, RequestStatus, Env } from "../../models";
88
import {
99
fetchConfig,
1010
repoDeploySlice,
@@ -21,20 +21,18 @@ import {
2121
searchCandidates,
2222
fetchUser,
2323
deploy
24-
} from "../redux/repoDeploy"
25-
26-
import DeployForm, {Option} from "../components/DeployForm"
27-
import DynamicPayloadModal from "../components/DynamicPayloadModal";
24+
} from "../../redux/repoDeploy"
25+
import DeployForm, { DeployFormProps, Option} from "./DeployForm"
26+
import DynamicPayloadModal, { DynamicPayloadModalProps } from "./DynamicPayloadModal"
2827

2928
const { actions } = repoDeploySlice
3029

31-
interface Params {
32-
namespace: string
33-
name: string
34-
}
30+
export default (): JSX.Element => {
31+
const { namespace, name } = useParams<{
32+
namespace: string
33+
name: string
34+
}>()
3535

36-
export default function RepoDeploy(): JSX.Element {
37-
const { namespace, name } = useParams<Params>()
3836
const {
3937
display,
4038
config,
@@ -48,9 +46,8 @@ export default function RepoDeploy(): JSX.Element {
4846
tags,
4947
tagStatuses,
5048
deploying } = useAppSelector(state => state.repoDeploy, shallowEqual)
51-
const dispatch = useAppDispatch()
5249

53-
const [payloadModalVisible, setPayloadModalVisible] = useState(false);
50+
const dispatch = useAppDispatch()
5451

5552
useEffect(() => {
5653
const f = async () => {
@@ -104,20 +101,11 @@ export default function RepoDeploy(): JSX.Element {
104101
}
105102

106103
const onClickDeploy = () => {
107-
if (env?.dynamicPayload?.enabled) {
108-
setPayloadModalVisible(true)
109-
} else {
110-
dispatch(deploy(null))
111-
}
104+
dispatch(deploy(null))
112105
}
113106

114107
const onClickDeployWithPayload = (values: any) => {
115108
dispatch(deploy(values))
116-
setPayloadModalVisible(false)
117-
}
118-
119-
const onClickCancel = () => {
120-
setPayloadModalVisible(false)
121109
}
122110

123111
if (!display) {
@@ -140,6 +128,81 @@ export default function RepoDeploy(): JSX.Element {
140128
/>
141129
)
142130
}
131+
return (
132+
<RepoDeploy
133+
envs={envs}
134+
onSelectEnv={onSelectEnv}
135+
onChangeType={onChangeType}
136+
currentDeployment={currentDeployment}
137+
branches={branches}
138+
onSelectBranch={onSelectBranch}
139+
onClickAddBranch={onClickAddBranch}
140+
branchStatuses={branchStatuses}
141+
commits={commits}
142+
onSelectCommit={onSelectCommit}
143+
onClickAddCommit={onClickAddCommit}
144+
commitStatuses={commitStatuses}
145+
tags={tags}
146+
onSelectTag={onSelectTag}
147+
onClickAddTag={onClickAddTag}
148+
tagStatuses={tagStatuses}
149+
deploying={deploying === RequestStatus.Pending}
150+
onClickDeploy={onClickDeploy}
151+
env={env}
152+
onClickOk={onClickDeployWithPayload}
153+
/>
154+
)
155+
}
156+
157+
interface RepoDeployProps extends
158+
DeployFormProps,
159+
Omit<DynamicPayloadModalProps, "visible" | "env" | "onClickCancel"> {
160+
env?: Env
161+
}
162+
163+
function RepoDeploy({
164+
// Properities for the DeployForm component.
165+
envs,
166+
onSelectEnv,
167+
onChangeType,
168+
currentDeployment,
169+
branches,
170+
onSelectBranch,
171+
onClickAddBranch,
172+
branchStatuses,
173+
commits,
174+
onSelectCommit,
175+
onClickAddCommit,
176+
commitStatuses,
177+
tags,
178+
onSelectTag,
179+
onClickAddTag,
180+
tagStatuses,
181+
deploying,
182+
onClickDeploy,
183+
// Properties for the DynamicPayloadModal component.
184+
env,
185+
onClickOk,
186+
}: RepoDeployProps): JSX.Element {
187+
188+
const [payloadModalVisible, setPayloadModalVisible] = useState(false);
189+
190+
const _onClickDeploy = () => {
191+
if (env?.dynamicPayload?.enabled) {
192+
setPayloadModalVisible(true)
193+
} else {
194+
onClickDeploy()
195+
}
196+
}
197+
198+
const _onClickOk = (values: any) => {
199+
onClickOk(values)
200+
setPayloadModalVisible(false)
201+
}
202+
203+
const onClickCancel = () => {
204+
setPayloadModalVisible(false)
205+
}
143206

144207
return (
145208
<div>
@@ -166,14 +229,14 @@ export default function RepoDeploy(): JSX.Element {
166229
onSelectTag={onSelectTag}
167230
onClickAddTag={onClickAddTag}
168231
tagStatuses={tagStatuses}
169-
deploying={deploying === RequestStatus.Pending}
170-
onClickDeploy={onClickDeploy}
232+
deploying={deploying}
233+
onClickDeploy={_onClickDeploy}
171234
/>
172235
{(env)?
173236
<DynamicPayloadModal
174237
visible={payloadModalVisible}
175238
env={env}
176-
onClickOk={onClickDeployWithPayload}
239+
onClickOk={_onClickOk}
177240
onClickCancel={onClickCancel}
178241
/>
179242
:

ui/src/views/repoHome/ActivityLogs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function ActivityLogs({ deployments }: ActivityLogsProps): JSX.El
2020
const dot = (d.status === DeploymentStatusEnum.Running)?
2121
<SyncOutlined style={{color: "purple"}} spin />
2222
:
23-
<></>
23+
null
2424
const avatar = <UserAvatar user={d.deployer} />
2525

2626
return (

0 commit comments

Comments
 (0)