Skip to content

Commit 0c846fb

Browse files
committed
Merge branch 'challenges-bug-bash' of github.com:topcoder-platform/micro-frontends-challenges-app into issue_124
2 parents 8d03968 + 69dd861 commit 0c846fb

File tree

21 files changed

+258
-105
lines changed

21 files changed

+258
-105
lines changed

config/dev.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,8 @@ module.exports = {
139139
process.env.FILESTACK_SUBMISSION_CONTAINER ||
140140
"topcoder-dev-submissions-dmz",
141141
},
142+
/* Time in MS to wait before refreshing challenge details after register
143+
* and unregister. Used to allow API sufficent time to update.
144+
*/
145+
CHALLENGE_DETAILS_REFRESH_DELAY: 3000,
142146
};

config/prod.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,8 @@ module.exports = {
134134
process.env.FILESTACK_SUBMISSION_CONTAINER ||
135135
"topcoder-dev-submissions-dmz",
136136
},
137+
/* Time in MS to wait before refreshing challenge details after register
138+
* and unregister. Used to allow API sufficent time to update.
139+
*/
140+
CHALLENGE_DETAILS_REFRESH_DELAY: 3000,
137141
};

src/components/DateRangePicker/DateInput/index.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const DateInput = ({
2020
onClickCalendarIcon,
2121
onStartEndDateChange,
2222
placeholder,
23+
enterToSubmit
2324
}) => {
2425
const ref = useRef(null);
2526
const [focused, setFocused] = useState(false);
@@ -125,7 +126,12 @@ const DateInput = ({
125126
size="xs"
126127
value={rangeText}
127128
onChange={(value) => {
128-
onChangeRangeTextDebounced.current(() => onChangeRangeText(value));
129+
if (!enterToSubmit) {
130+
onChangeRangeTextDebounced.current(() => onChangeRangeText(value));
131+
}
132+
}}
133+
onEnterKey={(value) => {
134+
onChangeRangeText(value)
129135
}}
130136
placeholder={placeholder}
131137
/>

src/components/DateRangePicker/helpers.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,39 +50,40 @@ const staticRangeHandler = {
5050
* @return {object[]} list of defined ranges
5151
*/
5252
export function createStaticRanges() {
53-
const now = moment().utcOffset(0);
54-
const pastWeek = now.clone().subtract(1, "week");
55-
const pastMonth = now.clone().subtract(1, "month");
56-
const past6Months = now.clone().subtract(6, "month");
57-
const pastYear = now.clone().subtract(1, "year");
53+
const today = moment();
54+
const endOfToday = today.set({ hour: 23, minute: 59, second: 59, millisecond: 999 });
55+
const pastWeek = endOfToday.clone().subtract(1, "week");
56+
const pastMonth = endOfToday.clone().subtract(1, "month");
57+
const past6Months = endOfToday.clone().subtract(6, "month");
58+
const pastYear = endOfToday.clone().subtract(1, "year");
5859

5960
const ranges = [
6061
{
6162
label: "Past Week",
6263
range: () => ({
6364
startDate: pastWeek.startOf("day").toDate(),
64-
endDate: now.endOf("day").toDate(),
65+
endDate: endOfToday.toDate(),
6566
}),
6667
},
6768
{
6869
label: "Past Month",
6970
range: () => ({
7071
startDate: pastMonth.startOf("day").toDate(),
71-
endDate: now.endOf("day").toDate(),
72+
endDate: endOfToday.toDate(),
7273
}),
7374
},
7475
{
7576
label: "Past 6 Months",
7677
range: () => ({
7778
startDate: past6Months.startOf("day").toDate(),
78-
endDate: now.endOf("day").toDate(),
79+
endDate: endOfToday.toDate(),
7980
}),
8081
},
8182
{
8283
label: "Past Year",
8384
range: () => ({
8485
startDate: pastYear.startOf("day").toDate(),
85-
endDate: now.endOf("day").toDate(),
86+
endDate: endOfToday.toDate(),
8687
}),
8788
},
8889
];

src/components/DateRangePicker/index.jsx

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from "./helpers";
1717

1818
function DateRangePicker(props) {
19-
const { id, range, onChange, placeholder } = props;
19+
const { id, range, onChange, placeholder, enterToSubmit = false } = props;
2020

2121
const [rangeString, setRangeString] = useState({
2222
startDateString: "",
@@ -344,8 +344,19 @@ function DateRangePicker(props) {
344344
const onPreviewChange = (date) => {
345345
if (!(date instanceof Date)) {
346346
setPreview(null);
347-
setActiveDate(null);
348-
setFocusedRange([0, focusedRange[1]]);
347+
348+
// ---
349+
// workaround for fixing issue 132:
350+
// - set the active range's background to transparent color
351+
// to prevent the calendar auto focusing on the day of today by default when no
352+
// start date nor end date are set.
353+
// - does not set focus on the empty selection range when mouse leaves.
354+
// ---
355+
356+
// setActiveDate(null);
357+
if (range.startDate || range.endDate) {
358+
setFocusedRange([0, focusedRange[1]]);
359+
}
349360
return;
350361
}
351362

@@ -485,7 +496,7 @@ function DateRangePicker(props) {
485496
startDate: activeDate,
486497
endDate: activeDate,
487498
key: "active",
488-
color: "#D8FDD8",
499+
color: preview ? "#D8FDD8" : "#D8FDD800",
489500
},
490501
];
491502
}
@@ -538,6 +549,7 @@ function DateRangePicker(props) {
538549
}}
539550
onStartEndDateChange={onStartEndDateChange}
540551
placeholder={placeholder}
552+
enterToSubmit={enterToSubmit}
541553
/>
542554
</div>
543555
<div ref={calendarRef} styleName="calendar-container">
@@ -562,18 +574,29 @@ function DateRangePicker(props) {
562574
preview={preview}
563575
onPreviewChange={onPreviewChange}
564576
/>
565-
<button
566-
type="button"
567-
styleName="reset-button"
568-
onClick={() => {
569-
onDateRangePickerChange({
570-
startDate: null,
571-
endDate: null,
572-
});
573-
}}
574-
>
575-
Reset
576-
</button>
577+
<div styleName="calendar-footer">
578+
<button
579+
type="button"
580+
styleName="calendar-button"
581+
onClick={() => {
582+
onDateRangePickerChange({
583+
startDate: null,
584+
endDate: null,
585+
});
586+
}}
587+
>
588+
Reset
589+
</button>
590+
<button
591+
type="button"
592+
styleName="calendar-button"
593+
onClick={() => {
594+
setIsComponentVisible(false);
595+
}}
596+
>
597+
Close
598+
</button>
599+
</div>
577600
</div>
578601
)}
579602
</div>

src/components/DateRangePicker/style.scss

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ $darkGreen: #0AB88A;;
391391
z-index: 10;
392392

393393
@include phone {
394+
width: 100vw;
394395
position: fixed;
395396
top: 0;
396397
left: 0;
@@ -402,7 +403,15 @@ $darkGreen: #0AB88A;;
402403
border-radius: 0;
403404
}
404405

405-
.reset-button {
406+
.calendar-footer {
407+
width: 100%;
408+
409+
@include phone {
410+
padding: 0 20px;
411+
}
412+
}
413+
414+
.calendar-button {
406415
@include roboto-bold;
407416

408417
width: 71px;
@@ -421,7 +430,7 @@ $darkGreen: #0AB88A;;
421430
height: 26px;
422431
line-height: 27px;
423432
font-size: 12px;
424-
margin: 20px 12px 0;
433+
margin: 0 12px 0;
425434
}
426435
}
427436
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
import IconNotFound from "assets/icons/not-found.png";
3+
4+
import "./styles.scss";
5+
6+
const NotFoundError = ({ message }) => (
7+
<div styleName="not-found-error">
8+
<div>
9+
<img src={IconNotFound} alt="not found" />
10+
</div>
11+
<h1>
12+
404 Not found
13+
</h1>
14+
<p>
15+
Sorry, we couldn’t find that page
16+
</p>
17+
</div>
18+
);
19+
20+
export default NotFoundError;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@import "styles/variables";
2+
3+
.not-found-error {
4+
padding: 16px 24px;
5+
min-height: 136px;
6+
margin-bottom: 35px;
7+
font-size: $font-size-sm;
8+
line-height: 22px;
9+
text-align: center;
10+
background: $white;
11+
border-radius: $border-radius-lg;
12+
13+
h1 {
14+
padding: 15px 0 10px;
15+
margin-bottom: 20px;
16+
}
17+
18+
p {
19+
margin-bottom: 8px;
20+
}
21+
}

src/components/Pagination/index.jsx

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useRef, useState } from "react";
1+
import React, { useRef, useState, useEffect } from "react";
22
import PT from "prop-types";
33
import Dropdown from "../Dropdown";
44
import {
@@ -12,6 +12,20 @@ import "./styles.scss";
1212

1313
const N = PAGINATION_MAX_PAGE_DISPLAY;
1414

15+
const createDisplayPages = (p, n) => {
16+
const pages = [];
17+
for (
18+
let start = utils.clamp(p - N, 0, n),
19+
end = utils.clamp(p + N, 0, n),
20+
i = start;
21+
i < end;
22+
i += 1
23+
) {
24+
pages.push(i);
25+
}
26+
return pages.slice(-N);
27+
};
28+
1529
/**
1630
* Pagination with the first page index being as 0 and the last page index being as `total - 1`
1731
*/
@@ -20,24 +34,6 @@ const Pagination = ({ length, pageIndex, pageSize, onChange }) => {
2034
const perPageOptions = utils.createDropdownOptions(PAGINATION_PER_PAGES);
2135
utils.setSelectedDropdownOption(perPageOptions, `${pageSize}`);
2236

23-
const createDisplayPages = (p, n) => {
24-
const pages = [];
25-
for (
26-
let start = utils.clamp(p - N, 0, n),
27-
end = utils.clamp(p + N, 0, n),
28-
i = start;
29-
i < end;
30-
i += 1
31-
) {
32-
pages.push(i);
33-
}
34-
return pages.slice(-N);
35-
};
36-
37-
const [displayPages, setDisplayPages] = useState(
38-
createDisplayPages(pageIndex, total)
39-
);
40-
4137
const onChangePageSize = (options) => {
4238
const selectedOption = utils.getSelectedDropdownOption(options);
4339
const newPageSize = +selectedOption.label;
@@ -59,33 +55,40 @@ const Pagination = ({ length, pageIndex, pageSize, onChange }) => {
5955
}
6056
};
6157

62-
const latestPropsRef = useRef(null);
63-
latestPropsRef.current = { displayPages, pageIndex };
64-
65-
useEffect(() => {
66-
const newTotal = Math.ceil(length / pageSize);
67-
const _pageIndex = latestPropsRef.current.pageIndex;
68-
setDisplayPages(createDisplayPages(_pageIndex, newTotal));
69-
}, [length, pageSize]);
58+
const previousPropsRef = useRef();
59+
const [displayPages, setDisplayPages] = useState([]);
7060

7161
useEffect(() => {
72-
const _displayPages = latestPropsRef.current.displayPages;
73-
const start = _displayPages[0];
74-
const end = _displayPages[_displayPages.length - 1];
75-
76-
const updateDisplayPages = [];
77-
if (pageIndex < start) {
78-
for (let i = pageIndex; i < pageIndex + N; i += 1) {
79-
updateDisplayPages.push(i);
62+
let _displayPages = displayPages;
63+
64+
if (!previousPropsRef.current
65+
|| previousPropsRef.current.length !== length
66+
|| previousPropsRef.current.pageSize !== pageSize) {
67+
const newTotal = Math.ceil(length / pageSize);
68+
_displayPages = createDisplayPages(pageIndex, newTotal);
69+
setDisplayPages(_displayPages)
8070
}
81-
setDisplayPages(updateDisplayPages);
82-
} else if (pageIndex > end) {
83-
for (let i = pageIndex; i > pageIndex - N; i -= 1) {
84-
updateDisplayPages.unshift(i);
71+
72+
if (!previousPropsRef.current || previousPropsRef.current.pageIndex !== pageIndex) {
73+
const start = _displayPages[0];
74+
const end = _displayPages[_displayPages.length - 1];
75+
76+
const updateDisplayPages = [];
77+
if (pageIndex < start) {
78+
for (let i = pageIndex; i < pageIndex + N; i += 1) {
79+
updateDisplayPages.push(i);
80+
}
81+
setDisplayPages(updateDisplayPages);
82+
} else if (pageIndex > end) {
83+
for (let i = pageIndex; i > pageIndex - N; i -= 1) {
84+
updateDisplayPages.unshift(i);
85+
}
86+
setDisplayPages(updateDisplayPages);
87+
}
8588
}
86-
setDisplayPages(updateDisplayPages);
87-
}
88-
}, [pageIndex]);
89+
90+
previousPropsRef.current = { length, pageSize, pageIndex };
91+
}, [length, pageSize, pageIndex, displayPages, setDisplayPages]);
8992

9093
const formatPage = (p) => `${p + 1}`;
9194

src/components/TextInput/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ function TextInput({
5555
}}
5656
onKeyPress={(e) => {
5757
if (e.key === "Enter") {
58-
onEnterKey();
58+
onEnterKey(e.target.value);
5959
}
6060
}}
6161
/>

0 commit comments

Comments
 (0)