Skip to content

Commit

Permalink
date picker issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MVarshini committed May 8, 2023
1 parent 32b488e commit fef133b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 21 deletions.
5 changes: 4 additions & 1 deletion dashboard/src/actions/datasetListActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ export const fetchPublicDatasets = (page) => async (dispatch, getState) => {
if (response.status === 200 && response.data) {
const startIdx = (page - 1) * perPage;

if (publicData.length === 0) {
if (
publicData.length === 0 ||
publicData.length !== response.data.total
) {
publicData = new Array(response.data.total);
}
publicData.splice(
Expand Down
52 changes: 33 additions & 19 deletions dashboard/src/modules/components/DatePickerComponent/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,57 @@ import {
Split,
SplitItem,
isValidDate,
yyyyMMddFormat,
} from "@patternfly/react-core";
import React, { useState } from "react";
import { applyFilter, setFilterKeys } from "actions/datasetListActions";
import { useDispatch, useSelector } from "react-redux";

import { getTodayMidnightUTCDate } from "utils/dateFunctions";
import { useDispatch } from "react-redux";

const DatePickerWidget = (props) => {
const [from, setFrom] = useState();
const [to, setTo] = useState(getTodayMidnightUTCDate());
const dispatch = useDispatch();
const { filter } = useSelector((state) => state.datasetlist);

const toValidator = (date) =>
isValidDate(from) && date >= from
? ""
: 'The "to" date must be after the "from" date';
const [isEndDateError, setIsEndDateError] = useState(false);

const fromValidator = (date) =>
date <= getTodayMidnightUTCDate()
? ""
: "The Uploaded date cannot be in the future!";

const toValidator = (date) =>
isValidDate(filter.startDate) && date >= filter.startDate
? ""
: 'The "to" date must be after the "from" date';

const onFromChange = (_str, date) => {
setFrom(new Date(date));
dispatch(setFilterKeys(new Date(date), filter.endDate));
if (filter.endDate) {
checkEndDate(date, filter.endDate);
}
};

const onToChange = (_str, date) => {
if (isValidDate(date)) {
setTo(yyyyMMddFormat(date));
if (isValidDate(new Date(date))) {
dispatch(setFilterKeys(filter.startDate, new Date(date)));
}
checkEndDate(filter.startDate, date);
};
const checkEndDate = (fromDate, toDate) => {
new Date(fromDate) >= new Date(toDate)
? setIsEndDateError(true)
: setIsEndDateError(false);
};

const filterByDate = () => {
if (from) {
dispatch(setFilterKeys(from, new Date(to)));
if (filter.startDate) {
dispatch(applyFilter());
props.setPage(CONSTANTS.START_PAGE_NUMBER);
}
};

return (
<>
<Split>
<Split className="browsing-page-date-picker">
<SplitItem style={{ padding: "6px 12px 0 12px" }}>
Filter by date
</SplitItem>
Expand All @@ -66,16 +73,23 @@ const DatePickerWidget = (props) => {
<SplitItem style={{ padding: "6px 12px 0 12px" }}>to</SplitItem>
<SplitItem>
<DatePicker
value={yyyyMMddFormat(to)}
onChange={onToChange}
isDisabled={!isValidDate(from)}
rangeStart={from}
isDisabled={!isValidDate(filter.startDate)}
rangeStart={filter.startDate}
validators={[toValidator]}
aria-label="End date"
placeholder="YYYY-MM-DD"
helperText={
isEndDateError && `The "to" date must be after the "from" date`
}
/>
</SplitItem>
<Button variant="control" onClick={filterByDate}>
<Button
variant="control"
onClick={filterByDate}
className="filter-btn"
isDisabled={isEndDateError}
>
Update
</Button>
</Split>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.filterInputGroup {
margin-left: 10px;
}
.browsing-page-date-picker {
.pf-c-date-picker__helper-text {
color: #c9190b;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ export const SearchBox = (props) => {
onKeyPress={(e) => handleKeyPress(e)}
onChange={(value) => setSearchKey(value)}
/>
<Button variant="control" onClick={search} aria-label="searchButton">
<Button
variant="control"
onClick={search}
aria-label="searchButton"
className="filter-btn"
>
<SearchIcon />
</Button>
</InputGroup>
Expand Down
3 changes: 3 additions & 0 deletions dashboard/src/modules/components/TableComponent/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ table th {
.searchInputGroup {
width: 25vw !important;
}
.filter-btn {
height: 36px;
}
2 changes: 2 additions & 0 deletions dashboard/src/reducers/datasetListReducer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as CONSTANTS from "assets/constants/browsingPageConstants";
import * as TYPES from "actions/types";

import { getTodayMidnightUTCDate } from "utils/dateFunctions";

const initialState = {
publicData: [],
favoriteRepoNames: [],
Expand Down

0 comments on commit fef133b

Please sign in to comment.