This repository was archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathindex.tsx
145 lines (130 loc) · 3.34 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import { useEffect, useState } from 'react';
import { shallowEqual } from 'react-redux';
import { Helmet } from 'react-helmet';
import { useAppSelector, useAppDispatch } from '../../redux/hooks';
import {
perPage,
activitiesSlice,
searchDeployments,
} from '../../redux/activities';
import Main from '../main';
import SearchActivities, {
SearchActivitiesProps,
SearchActivitiesValues,
} from './SearchActivities';
import ActivityHistory, { ActivityHistoryProps } from './ActivityHistory';
import Pagination, { PaginationProps } from '../../components/Pagination';
import Spin from '../../components/Spin';
const { actions } = activitiesSlice;
export default (): JSX.Element => {
const { loading, deployments, page } = useAppSelector(
(state) => state.activities,
shallowEqual
);
const dispatch = useAppDispatch();
useEffect(() => {
dispatch(
searchDeployments({
productionOnly: false,
})
);
// eslint-disable-next-line
}, [dispatch]);
const [searchOptions, setSearchOptions] = useState<SearchActivitiesValues>(
{}
);
const search = () =>
dispatch(
searchDeployments({
start: searchOptions.period
? searchOptions.period[0].toDate()
: undefined,
end: searchOptions.period
? searchOptions.period[1].toDate()
: undefined,
productionOnly: searchOptions.productionOnly
? searchOptions.productionOnly
: false,
})
);
const onClickSearch = (values: SearchActivitiesValues) => {
setSearchOptions(values);
search();
};
const onClickPrev = () => {
dispatch(actions.decreasePage());
search();
};
const onClickNext = () => {
dispatch(actions.increasePage());
search();
};
return (
<Main>
<Activities
onClickSearch={onClickSearch}
loading={loading}
deployments={deployments}
disabledPrev={page <= 1}
disabledNext={deployments.length != perPage}
onClickPrev={onClickPrev}
onClickNext={onClickNext}
/>
</Main>
);
};
interface ActivitiesProps
extends SearchActivitiesProps,
ActivityHistoryProps,
PaginationProps {
loading: boolean;
}
function Activities({
// Properties to search.
initialValues,
onClickSearch,
// Properties for the deployment history.
loading,
deployments,
// Pagination for the pagination.
disabledPrev,
disabledNext,
onClickPrev,
onClickNext,
}: ActivitiesProps): JSX.Element {
return (
<>
<Helmet>
<title>Activities</title>
</Helmet>
<h1>Activities</h1>
<div style={{ marginTop: 30 }}>
<h2>Search</h2>
<SearchActivities
initialValues={initialValues}
onClickSearch={onClickSearch}
/>
</div>
<div style={{ marginTop: 50 }}>
<h2>History</h2>
<div style={{ marginTop: 30 }}>
{loading ? (
<div style={{ textAlign: 'center' }}>
<Spin />
</div>
) : (
<ActivityHistory deployments={deployments} />
)}
</div>
</div>
<div style={{ marginTop: 30, textAlign: 'center' }}>
<Pagination
disabledPrev={disabledPrev}
disabledNext={disabledNext}
onClickPrev={onClickPrev}
onClickNext={onClickNext}
/>
</div>
</>
);
}