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

Commit db56cdc

Browse files
author
Noah Lee
authored
Separate the state from the repoLock view (#403)
* Separate the state from the view * Disalbe lint for 'no-empty-interface'
1 parent 1cef57f commit db56cdc

File tree

5 files changed

+45
-24
lines changed

5 files changed

+45
-24
lines changed

Diff for: ui/.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
],
1111
rules: {
1212
"@typescript-eslint/no-explicit-any": "off",
13+
"@typescript-eslint/no-empty-interface": "off"
1314
},
1415
};
1516

Diff for: ui/src/views/Repo.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { init, activate, repoSlice as slice } from '../redux/repo'
1010
import ActivateButton from "../components/ActivateButton"
1111
import Main from './main'
1212
import RepoHome from './repoHome'
13-
import RepoLock from "./RepoLock";
13+
import RepoLock from "./repoLock"
1414
import RepoDeploy from './RepoDeploy'
1515
import RepoRollabck from './RepoRollback'
1616
import RepoSettings from "./repoSettings"

Diff for: ui/src/components/LockList.tsx renamed to ui/src/views/repoLock/LockList.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {
66
import { LockOutlined, UnlockOutlined } from "@ant-design/icons"
77
import moment from 'moment'
88

9-
import { Env, Lock } from "../models"
10-
import UserAvatar from './UserAvatar'
9+
import { Env, Lock } from "../../models"
10+
import UserAvatar from '../../components/UserAvatar'
1111

12-
interface LockListProps {
12+
export interface LockListProps {
1313
envs: Env[]
1414
locks: Lock[]
1515
onClickLock(env: string): void

Diff for: ui/src/views/RepoLock.tsx renamed to ui/src/views/repoLock/index.tsx

+40-19
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import { useParams } from "react-router-dom";
44
import { PageHeader, Button } from 'antd'
55
import { Result } from "antd"
66

7-
import { useAppSelector, useAppDispatch } from "../redux/hooks"
8-
import { fetchConfig, listLocks, lock, unlock, repoLockSlice as slice, setAutoUnlock} from "../redux/repoLock"
9-
import LockList from '../components/LockList'
7+
import { useAppSelector, useAppDispatch } from "../../redux/hooks"
8+
import { fetchConfig, listLocks, lock, unlock, repoLockSlice as slice, setAutoUnlock} from "../../redux/repoLock"
9+
import LockList, { LockListProps } from "./LockList"
1010

11-
interface Params {
12-
namespace: string
13-
name: string
14-
}
11+
export default (): JSX.Element => {
12+
const { namespace, name } = useParams<{
13+
namespace: string
14+
name: string
15+
}>()
1516

16-
export default function RepoLock(): JSX.Element {
17-
const { namespace, name } = useParams<Params>()
1817
const { display, config, locks } = useAppSelector(state => state.repoLock, shallowEqual)
18+
1919
const dispatch = useAppDispatch()
2020

2121
useEffect(() => {
@@ -29,6 +29,18 @@ export default function RepoLock(): JSX.Element {
2929
// eslint-disable-next-line
3030
}, [dispatch])
3131

32+
const onClickLock = (env: string) => {
33+
dispatch(lock(env))
34+
}
35+
36+
const onClickUnlock = (env: string) => {
37+
dispatch(unlock(env))
38+
}
39+
40+
const onChangeExpiredAt = (env: string, expiredAt: Date) => {
41+
dispatch(setAutoUnlock({env, expiredAt}))
42+
}
43+
3244
if (!display) {
3345
return <></>
3446
}
@@ -50,25 +62,34 @@ export default function RepoLock(): JSX.Element {
5062
)
5163
}
5264

53-
const onClickLock = (env: string) => {
54-
dispatch(lock(env))
55-
}
65+
return (
66+
<RepoLock
67+
envs={(config)? config.envs : []}
68+
locks={locks}
69+
onClickLock={onClickLock}
70+
onClickUnlock={onClickUnlock}
71+
onChangeExpiredAt={onChangeExpiredAt}
72+
/>
73+
)
74+
}
5675

57-
const onClickUnlock = (env: string) => {
58-
dispatch(unlock(env))
59-
}
76+
interface RepoLockProps extends LockListProps {}
6077

61-
const onChangeExpiredAt = (env: string, expiredAt: Date) => {
62-
dispatch(setAutoUnlock({env, expiredAt}))
63-
}
78+
function RepoLock({
79+
envs,
80+
locks,
81+
onChangeExpiredAt,
82+
onClickLock,
83+
onClickUnlock
84+
}: RepoLockProps): JSX.Element {
6485

6586
return <div>
6687
<div>
6788
<PageHeader title="Lock" subTitle="Lock the environment."/>
6889
</div>
6990
<div style={{padding: "16px 24px"}}>
7091
<LockList
71-
envs={(config)? config.envs:[]}
92+
envs={envs}
7293
locks={locks}
7394
onClickLock={onClickLock}
7495
onClickUnlock={onClickUnlock}

Diff for: ui/src/views/repoSettings/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export default (): JSX.Element => {
5050
)
5151
}
5252

53-
// eslint-disable-next-line
5453
interface RepoSettingsProps extends SettingFormProps {}
5554

5655
function RepoSettings({

0 commit comments

Comments
 (0)