Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ui): add sidebar panel #226

Merged
merged 11 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
"@testing-library/jest-dom": "^5.16.2",
"@testing-library/react": "^12.1.4",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.6.2",
"date-fns": "^2.28.0",
"http-proxy-middleware": "^2.0.4",
"prettier": "^2.7.1",
"prop-types": "^15.8.1",
"react": "^17.0.2",
"react-datepicker": "^4.8.0",
"react-dom": "^17.0.2",
Expand Down
276 changes: 138 additions & 138 deletions web/src/Components/HistoryTasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,150 +15,150 @@ import 'react-datepicker/dist/react-datepicker.css';
import { useErrorContext } from '../ErrorContext';

function HistoryTasks() {
const [searchParams, setSearchParams] = useSearchParams();
const { setError, setSuccess } = useErrorContext();
const { tasks, sortField, setSortField, refreshTasksInRange, clearTasks } =
useTasks({ setError, setSuccess });
const [currentApplication, setCurrentApplication] = useState(
searchParams.get('app') ?? null,
);
const [dateRange, setDateRange] = useState([
Number(searchParams.get('start'))
? new Date(Number(searchParams.get('start')) * 1000)
: startOfDay(new Date()),
Number(searchParams.get('end'))
? new Date(Number(searchParams.get('end')) * 1000)
: startOfDay(new Date()),
]);
const [startDate, endDate] = dateRange;
const [currentPage, setCurrentPage] = useState(
searchParams.get('page') ? Number(searchParams.get('page')) : 1,
);
const [searchParams, setSearchParams] = useSearchParams();
const { setError, setSuccess } = useErrorContext();
const { tasks, sortField, setSortField, refreshTasksInRange, clearTasks } =
useTasks({ setError, setSuccess });
const [currentApplication, setCurrentApplication] = useState(
searchParams.get('app') ?? null,
);
const [dateRange, setDateRange] = useState([
Number(searchParams.get('start'))
? new Date(Number(searchParams.get('start')) * 1000)
: startOfDay(new Date()),
Number(searchParams.get('end'))
? new Date(Number(searchParams.get('end')) * 1000)
: startOfDay(new Date()),
]);
const [startDate, endDate] = dateRange;
const [currentPage, setCurrentPage] = useState(
searchParams.get('page') ? Number(searchParams.get('page')) : 1,
);

const updateSearchParameters = (start, end, application, page) => {
setSearchParams({
app: application ?? '',
start: Math.floor(start.getTime() / 1000),
end: Math.floor(end.getTime() / 1000),
page,
});
};
const updateSearchParameters = (start, end, application, page) => {
setSearchParams({
app: application ?? '',
start: Math.floor(start.getTime() / 1000),
end: Math.floor(end.getTime() / 1000),
page,
});
};

const refreshWithFilters = (start, end, application, page) => {
if (start && end) {
refreshTasksInRange(
Math.floor(startOfDay(start).getTime() / 1000),
Math.floor(endOfDay(end).getTime() / 1000),
application,
);
updateSearchParameters(start, end, application, page);
} else {
clearTasks();
}
};
const refreshWithFilters = (start, end, application, page) => {
if (start && end) {
refreshTasksInRange(
Math.floor(startOfDay(start).getTime() / 1000),
Math.floor(endOfDay(end).getTime() / 1000),
application,
);
updateSearchParameters(start, end, application, page);
} else {
clearTasks();
}
};

useEffect(() => {
refreshWithFilters(startDate, endDate, currentApplication, currentPage);
}, []);
useEffect(() => {
refreshWithFilters(startDate, endDate, currentApplication, currentPage);
}, []);

const DateRangePickerCustomInput = forwardRef(({ value, onClick }, ref) => (
<TextField
size="small"
sx={{ minWidth: '220px' }}
onClick={onClick}
ref={ref}
value={value}
label={'Date range'}
/>
));
const DateRangePickerCustomInput = forwardRef(({ value, onClick }, ref) => (
<TextField
size="small"
sx={{ minWidth: '220px' }}
onClick={onClick}
ref={ref}
value={value}
label={'Date range'}
/>
));

return (
<Container maxWidth="xl">
<Stack
direction={{ xs: 'column', md: 'row' }}
spacing={2}
alignItems="center"
sx={{ mb: 2 }}
>
<Typography
variant="h5"
gutterBottom
component="div"
sx={{
flexGrow: 1,
display: 'flex',
gap: '10px',
m: 0,
alignItems: 'center',
}}
>
<Box>History tasks</Box>
<Box sx={{ fontSize: '10px' }}>UTC</Box>
</Typography>
<Stack direction="row" spacing={2}>
<Box>
<ApplicationsFilter
value={currentApplication}
onChange={value => {
setCurrentApplication(value);
setCurrentPage(1);
refreshWithFilters(startDate, endDate, value, 1);
}}
setError={setError}
setSuccess={setSuccess}
/>
</Box>
<Box>
<DatePicker
selectsRange={true}
startDate={startDate}
endDate={endDate}
onChange={update => {
setDateRange(update);
setCurrentPage(1);
refreshWithFilters(update[0], update[1], currentApplication, 1);
}}
maxDate={new Date()}
isClearable={false}
customInput={<DateRangePickerCustomInput />}
required
/>
</Box>
<Box>
<IconButton
edge="start"
color={'primary'}
title={'Reload table'}
onClick={() => {
setCurrentPage(1);
refreshWithFilters(startDate, endDate, currentApplication, 1);
}}
return (
<Container maxWidth="xl">
<Stack
direction={{ xs: 'column', md: 'row' }}
spacing={2}
alignItems="center"
sx={{ mb: 2 }}
>
<RefreshIcon />
</IconButton>
</Box>
</Stack>
</Stack>
<Box sx={{ boxShadow: 2, borderRadius: 2, p: 2 }}>
<TasksTable
tasks={tasks}
sortField={sortField}
setSortField={setSortField}
relativeDate={false}
page={currentPage}
onPageChange={page => {
setCurrentPage(page);
updateSearchParameters(
startDate,
endDate,
currentApplication,
page,
);
}}
/>
</Box>
</Container>
);
<Typography
variant="h5"
gutterBottom
component="div"
sx={{
flexGrow: 1,
display: 'flex',
gap: '10px',
m: 0,
alignItems: 'center',
}}
>
<Box>History tasks</Box>
<Box sx={{ fontSize: '10px' }}>UTC</Box>
</Typography>
<Stack direction="row" spacing={2}>
<Box>
<ApplicationsFilter
value={currentApplication}
onChange={value => {
setCurrentApplication(value);
setCurrentPage(1);
refreshWithFilters(startDate, endDate, value, 1);
}}
setError={setError}
setSuccess={setSuccess}
/>
</Box>
<Box>
<DatePicker
selectsRange={true}
startDate={startDate}
endDate={endDate}
onChange={update => {
setDateRange(update);
setCurrentPage(1);
refreshWithFilters(update[0], update[1], currentApplication, 1);
}}
maxDate={new Date()}
isClearable={false}
customInput={<DateRangePickerCustomInput />}
required
/>
</Box>
<Box>
<IconButton
edge="start"
color={'primary'}
title={'Reload table'}
onClick={() => {
setCurrentPage(1);
refreshWithFilters(startDate, endDate, currentApplication, 1);
}}
>
<RefreshIcon />
</IconButton>
</Box>
</Stack>
</Stack>
<Box sx={{ boxShadow: 2, borderRadius: 2, p: 2 }}>
<TasksTable
tasks={tasks}
sortField={sortField}
setSortField={setSortField}
relativeDate={false}
page={currentPage}
onPageChange={page => {
setCurrentPage(page);
updateSearchParameters(
startDate,
endDate,
currentApplication,
page,
);
}}
/>
</Box>
</Container>
);
}

export default HistoryTasks;
Loading
Loading