Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit aebce9b

Browse files
authored
Merge pull request #23 from MadOPcode/feature/work-periods-part-2
Fixes for issues mentioned in feedback
2 parents 593f99e + ceef619 commit aebce9b

File tree

17 files changed

+78
-108
lines changed

17 files changed

+78
-108
lines changed

src/components/Checkbox/styles.module.scss

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ input.checkbox {
5656
border-radius: 3px;
5757
line-height: 18px;
5858
user-select: none;
59+
background-color: #fff;
5960
color: transparent;
6061

6162
&::before {

src/components/ProjectName/index.jsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
import React, { useContext, useEffect } from "react";
1+
import React, { memo, useContext, useEffect } from "react";
22
import PT from "prop-types";
33
import cn from "classnames";
44
import { ProjectNameContext } from "components/ProjectNameContextProvider";
55
import styles from "./styles.module.scss";
66

77
const ProjectName = ({ className, projectId }) => {
88
const [getName, fetchName] = useContext(ProjectNameContext);
9+
910
useEffect(() => {
1011
fetchName(projectId);
1112
}, [fetchName, projectId]);
1213

14+
const projectName = getName(projectId) || projectId;
15+
1316
return (
14-
<span className={cn(styles.container, className)}>
15-
{getName(projectId) || projectId}
17+
<span className={cn(styles.container, className)} title={projectName}>
18+
{projectName}
1619
</span>
1720
);
1821
};
@@ -22,4 +25,4 @@ ProjectName.propTypes = {
2225
projectId: PT.number.isRequired,
2326
};
2427

25-
export default ProjectName;
28+
export default memo(ProjectName);
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
@import "styles/mixins";
22

33
.container {
4+
display: block;
5+
max-width: 20em;
6+
overflow: hidden;
7+
text-overflow: ellipsis;
8+
white-space: nowrap;
49
@include roboto-medium;
510
}

src/components/SearchHandleField/styles.module.scss

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@import "styles/mixins";
33

44
.container {
5+
z-index: 3;
56
position: relative;
67
display: flex;
78
align-items: center;

src/routes/WorkPeriods/components/PeriodDetails/index.jsx

+1-21
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
hideWorkPeriodDetails,
1313
setBillingAccount,
1414
setDetailsHidePastPeriods,
15-
// setDetailsLockWorkingDays,
1615
} from "store/actions/workPeriods";
1716
import styles from "./styles.module.scss";
1817
import { updateWorkPeriodBillingAccount } from "store/thunks/workPeriods";
@@ -42,7 +41,6 @@ const PeriodDetails = ({ className, details, isDisabled, isFailed }) => {
4241
periodsVisible,
4342
periodsIsLoading,
4443
hidePastPeriods,
45-
// lockWorkingDays,
4644
} = details;
4745

4846
const onHideDetailsBtnClick = useCallback(() => {
@@ -56,13 +54,6 @@ const PeriodDetails = ({ className, details, isDisabled, isFailed }) => {
5654
[dispatch, periodId]
5755
);
5856

59-
// const onChangeLockWorkingDays = useCallback(
60-
// (lock) => {
61-
// dispatch(setDetailsLockWorkingDays(periodId, lock));
62-
// },
63-
// [dispatch, periodId]
64-
// );
65-
6657
const onChangeBillingAccount = useCallback(
6758
(value) => {
6859
dispatch(setBillingAccount(periodId, value));
@@ -113,16 +104,6 @@ const PeriodDetails = ({ className, details, isDisabled, isFailed }) => {
113104
</div>
114105
</div>
115106
</div>
116-
{/* <div className={styles.lockWorkingDaysSection}>
117-
<div className={styles.sectionLabel}>Lock Working Days</div>
118-
<Toggle
119-
size="small"
120-
className={styles.lockWorkingDaysToggle}
121-
name={`rb_lck_wd_${periodId}`}
122-
onChange={onChangeLockWorkingDays}
123-
isOn={lockWorkingDays}
124-
/>
125-
</div> */}
126107
<div className={styles.billingAccountSection}>
127108
<div className={styles.sectionLabel}>Billing Account</div>
128109
<SelectField
@@ -188,7 +169,7 @@ PeriodDetails.propTypes = {
188169
billingAccounts: PT.arrayOf(
189170
PT.shape({
190171
label: PT.string.isRequired,
191-
value: PT.string.isRequired,
172+
value: PT.number.isRequired,
192173
})
193174
),
194175
billingAccountsError: PT.string,
@@ -197,7 +178,6 @@ PeriodDetails.propTypes = {
197178
periodsVisible: PT.array.isRequired,
198179
periodsIsLoading: PT.bool.isRequired,
199180
hidePastPeriods: PT.bool.isRequired,
200-
lockWorkingDays: PT.bool.isRequired,
201181
}).isRequired,
202182
isDisabled: PT.bool.isRequired,
203183
isFailed: PT.bool.isRequired,

src/routes/WorkPeriods/components/PeriodDetails/styles.module.scss

-8
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,6 @@
6969
color: #e90c5a;
7070
}
7171

72-
.lockWorkingDaysSection {
73-
margin-top: 19px;
74-
}
75-
76-
.lockWorkingDaysToggle {
77-
margin-top: 6px;
78-
}
79-
8072
.billingAccountSection {
8173
margin-top: 13px;
8274
}

src/routes/WorkPeriods/components/PeriodItem/index.jsx

+3-7
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,12 @@ PeriodItem.propTypes = {
166166
billingAccountId: PT.number.isRequired,
167167
billingAccounts: PT.arrayOf(
168168
PT.shape({
169-
value: PT.string.isRequired,
170169
label: PT.string.isRequired,
170+
value: PT.number.isRequired,
171171
})
172-
),
172+
).isRequired,
173173
billingAccountsIsLoading: PT.bool.isRequired,
174-
periods: PT.arrayOf(
175-
PT.shape({
176-
id: PT.string.isRequired,
177-
})
178-
),
174+
periods: PT.array.isRequired,
179175
periodsIsLoading: PT.bool.isRequired,
180176
}),
181177
};

src/routes/WorkPeriods/components/PeriodsHistoryItem/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ PeriodsHistoryItem.propTypes = {
105105
endDate: PT.oneOfType([PT.string, PT.number]).isRequired,
106106
paymentStatus: PT.string.isRequired,
107107
payments: PT.array,
108-
weeklyRate: PT.number.isRequired,
108+
weeklyRate: PT.number,
109109
workingDays: PT.number.isRequired,
110110
}).isRequired,
111111
currentStartDate: PT.oneOfType([PT.string, PT.number, PT.object]).isRequired,

src/routes/WorkPeriods/components/PeriodsSelectionMessage/index.jsx

+5-10
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,20 @@ const PeriodsSelectionMessage = ({ className }) => {
2929
dispatch(toggleWorkingPeriodsAll());
3030
}, [dispatch]);
3131

32-
const infoText = isSelectedAll
33-
? `All ${totalCount} Records are selected. `
34-
: `All ${pageSize} Records on this page are selected. `;
35-
const btnText = isSelectedAll
36-
? "Deselect"
37-
: `Select all ${totalCount} Records`;
38-
3932
return (
4033
<div className={cn(styles.container, className)}>
41-
{isSelectedVisible && (
34+
{isSelectedVisible && totalCount > pageSize && (
4235
<span className={styles.message}>
43-
{infoText}
36+
{isSelectedAll
37+
? `All ${totalCount} Records are selected. `
38+
: `All ${pageSize} Records on this page are selected. `}
4439
<span
4540
className={styles.button}
4641
onClick={onBtnClick}
4742
role="button"
4843
tabIndex={0}
4944
>
50-
{btnText}
45+
{isSelectedAll ? "Deselect" : `Select all ${totalCount} Records`}
5146
</span>
5247
</span>
5348
)}

src/routes/WorkPeriods/components/ToastPaymentsWarning/index.jsx

+8-16
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@ import styles from "./styles.module.scss";
88
* payments have been scheduled or failed to schedule.
99
*
1010
* @param {Object} props component properties
11+
* @param {number} props.resourcesSucceededCount the number of resources
12+
* for which payments have been successfully scheduled
13+
* @param {Array} [props.resourcesFailed] array with data for resources
14+
* for which payments were failed to be scheduled
15+
* @param {number} props.resourcesFailedCount the number of resources
16+
* for which payments were failed to be scheduled
17+
* @param {() => void} [props.remove] function that must be called
18+
* on toast message removal intent
1119
* @returns {JSX.Element}
1220
*/
1321
const ToastPaymentsWarning = ({
14-
resourcesSucceeded,
1522
resourcesSucceededCount,
1623
resourcesFailed,
1724
resourcesFailedCount,
@@ -23,15 +30,6 @@ const ToastPaymentsWarning = ({
2330
<div className={styles.sectionTitle}>
2431
Payment scheduled for {resourcesSucceededCount} resources
2532
</div>
26-
{resourcesSucceeded && resourcesSucceeded.length && (
27-
<div className={styles.periodsSucceeded}>
28-
{resourcesSucceeded.map((period) => (
29-
<div key={period.workPeriodId} className={styles.periodSucceeded}>
30-
{period.workPeriodId}
31-
</div>
32-
))}
33-
</div>
34-
)}
3533
</div>
3634
<div className={styles.sectionFailed}>
3735
<div className={styles.sectionTitle}>
@@ -53,12 +51,6 @@ const ToastPaymentsWarning = ({
5351
};
5452

5553
ToastPaymentsWarning.propTypes = {
56-
resourcesSucceeded: PT.arrayOf(
57-
PT.shape({
58-
workPeriodId: PT.string.isRequired,
59-
amount: PT.number,
60-
})
61-
),
6254
resourcesSucceededCount: PT.number.isRequired,
6355
resourcesFailed: PT.arrayOf(
6456
PT.shape({

src/routes/WorkPeriods/components/ToastPaymentsWarning/styles.module.scss

+1-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,5 @@
33
}
44

55
.sectionSucceeded {
6-
margin-bottom: 10px;
7-
background: #1dcfa0;
8-
}
9-
10-
.sectionFailed {
11-
background: #ff7b7b;
6+
margin-bottom: 5px;
127
}

src/routes/WorkPeriods/utils/toasts.jsx

-2
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ export function makeToastPaymentsSuccess(resourceCount) {
4444
* payments were successfully scheduled
4545
* @param {number} props.resourcesFailedCount the number of periods for which
4646
* payments were failed to be scheduled
47-
* @param {Array} [props.resourcesSucceeded] periods for which payments were
48-
* successfully scheduled
4947
* @param {Array} [props.resourcesFailed] periods for which payments were failed
5048
* to be scheduled
5149
*/

src/services/workPeriods.js

+14
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,20 @@ export const postWorkPeriodsPayments = (payments) => {
142142
* @returns {Promise}
143143
*/
144144
export const postWorkPeriodsPaymentsAll = (query) => {
145+
for (let key in query) {
146+
let value = query[key];
147+
if (typeof value !== "number" && !value) {
148+
delete query[key];
149+
continue;
150+
}
151+
if (Array.isArray(value)) {
152+
if (value.length) {
153+
query[key] = value.join(",");
154+
} else {
155+
delete query[key];
156+
}
157+
}
158+
}
145159
return axios
146160
.post(`${PAYMENTS_API_URL}/query`, { query })
147161
.then(extractResponseData);

src/store/actionTypes/workPeriods.js

-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ export const WP_SET_BILLING_ACCOUNT = "WP_SET_BILLING_ACCOUNT";
1717
export const WP_SET_DETAILS_WORKING_DAYS = "WP_SET_DETAILS_WORKING_DAYS";
1818
export const WP_SET_DETAILS_HIDE_PAST_PERIODS =
1919
"WP_SET_DETAILS_HIDE_PAST_PERIODS";
20-
export const WP_SET_DETAILS_LOCK_WORKING_DAYS =
21-
"WP_SET_DETAILS_LOCK_WORKING_DAYS";
2220
export const WP_SET_PAGE_NUMBER = "WP_SET_PAGE_NUMBER";
2321
export const WP_SET_PAGE_SIZE = "WP_SET_PAGE_SIZE";
2422
export const WP_SET_DATE_RANGE = "WP_SET_DATE_RANGE";

src/store/actions/workPeriods.js

-5
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ export const setDetailsHidePastPeriods = (periodId, hide) => ({
185185
payload: { periodId, hide },
186186
});
187187

188-
export const setDetailsLockWorkingDays = (periodId, lock) => ({
189-
type: ACTION_TYPE.WP_SET_DETAILS_LOCK_WORKING_DAYS,
190-
payload: { periodId, lock },
191-
});
192-
193188
/**
194189
* Creates an action to reset working periods' filters.
195190
*

src/store/reducers/workPeriods.js

+26-22
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ const initPeriodDetails = (
5959
periodsVisible: [],
6060
periodsIsLoading: true,
6161
hidePastPeriods: false,
62-
lockWorkingDays: false,
6362
});
6463

6564
const initialState = {
@@ -375,21 +374,6 @@ const actionHandlers = {
375374
periodsDetails,
376375
};
377376
},
378-
[ACTION_TYPE.WP_SET_DETAILS_LOCK_WORKING_DAYS]: (
379-
state,
380-
{ periodId, lock }
381-
) => {
382-
const periodsDetails = { ...state.periodsDetails };
383-
let periodDetails = periodsDetails[periodId];
384-
if (!periodDetails) {
385-
return state;
386-
}
387-
periodsDetails[periodId] = { ...periodDetails, lockWorkingDays: lock };
388-
return {
389-
...state,
390-
periodsDetails,
391-
};
392-
},
393377
[ACTION_TYPE.WP_SET_DETAILS_WORKING_DAYS]: (
394378
state,
395379
{ parentPeriodId, periodId, workingDays }
@@ -455,7 +439,15 @@ const actionHandlers = {
455439
delete periodsSelected[periodId];
456440
}
457441
}
458-
if (Object.keys(periodsSelected).length === state.pagination.pageSize) {
442+
const selectedCount = Object.keys(periodsSelected).length;
443+
const pageSize = state.pagination.pageSize;
444+
const totalCount = state.pagination.totalCount;
445+
if (totalCount > pageSize) {
446+
if (selectedCount === pageSize) {
447+
isSelectedPeriodsVisible = true;
448+
}
449+
} else if (selectedCount === totalCount) {
450+
isSelectedPeriodsAll = true;
459451
isSelectedPeriodsVisible = true;
460452
}
461453
return {
@@ -549,7 +541,15 @@ const actionHandlers = {
549541
const isSelected = !periodsSelected[periodId];
550542
if (isSelected) {
551543
periodsSelected[periodId] = true;
552-
if (Object.keys(periodsSelected).length === state.pagination.pageSize) {
544+
const selectedCount = Object.keys(periodsSelected).length;
545+
const pageSize = state.pagination.pageSize;
546+
const totalCount = state.pagination.totalCount;
547+
if (totalCount > pageSize) {
548+
if (selectedCount === pageSize) {
549+
isSelectedPeriodsVisible = true;
550+
}
551+
} else if (selectedCount === totalCount) {
552+
isSelectedPeriodsAll = true;
553553
isSelectedPeriodsVisible = true;
554554
}
555555
} else {
@@ -580,18 +580,22 @@ const actionHandlers = {
580580
};
581581
},
582582
[ACTION_TYPE.WP_TOGGLE_PERIODS_VISIBLE]: (state, on) => {
583-
const isSelected = on === null ? !state.isSelectedPeriodsVisible : on;
583+
let isSelectedPeriodsAll = false;
584+
const isSelectedPeriodsVisible =
585+
on === null ? !state.isSelectedPeriodsVisible : on;
584586
const periodsSelected = {};
585-
if (isSelected) {
587+
if (isSelectedPeriodsVisible) {
586588
for (let period of state.periods) {
587589
periodsSelected[period.id] = true;
588590
}
591+
isSelectedPeriodsAll =
592+
state.periods.length === state.pagination.totalCount;
589593
}
590594
return {
591595
...state,
592596
periodsSelected,
593-
isSelectedPeriodsAll: false,
594-
isSelectedPeriodsVisible: isSelected,
597+
isSelectedPeriodsAll,
598+
isSelectedPeriodsVisible,
595599
};
596600
},
597601
[ACTION_TYPE.WP_TOGGLE_PROCESSING_PAYMENTS]: (state, on) => {

0 commit comments

Comments
 (0)