Skip to content

Commit

Permalink
Assignments day filter (#2016)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Jul 5, 2024
1 parent d010b54 commit ffa4080
Show file tree
Hide file tree
Showing 14 changed files with 481 additions and 383 deletions.
27 changes: 27 additions & 0 deletions client/actions/assignments/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const loadAssignments = ({
filterBy = 'Desk',
searchQuery = null,
orderByField = 'Scheduled',
dayField = null,
filterByType = null,
filterByPriority = null,
selectedDeskId = null,
Expand All @@ -34,6 +35,7 @@ const loadAssignments = ({
filterBy,
searchQuery,
orderByField,
dayField,
filterByType,
filterByPriority,
selectedDeskId,
Expand Down Expand Up @@ -304,6 +306,7 @@ const changeListSettings = ({
filterBy = 'Desk',
searchQuery = null,
orderByField = 'Scheduled',
dayField = null,
filterByType = null,
filterByPriority = null,
selectedDeskId = null,
Expand All @@ -314,6 +317,7 @@ const changeListSettings = ({
filterBy,
searchQuery,
orderByField,
dayField,
filterByType,
filterByPriority,
selectedDeskId,
Expand Down Expand Up @@ -805,6 +809,27 @@ const changeSortField = (field, savePreference = true) => (
}
);

/**
* Action dispatcher to set the day field filter for all lists
* @param {String} value - the value to set the field to
*/
const setDayField = (value) => ({
type: ASSIGNMENTS.ACTIONS.SET_DAY_FIELD,
payload: value,
});

const changeDayField = (value, savePreference = true) => (
(dispatch) => {
dispatch(self.setDayField(value));

// if (savePreference) {
// dispatch(actions.users.setAssignmentSortField());
// }

return dispatch(self.reloadAssignments(null, false));
}
);

/**
* Action dispatcher to load the current users' preferred sort field and list orders
* (This assumes the users' preferences have already been loaded into redux)
Expand Down Expand Up @@ -897,6 +922,8 @@ const self = {
setListSortOrder,
changeListSortOrder,
setSortField,
setDayField,
changeDayField,
loadDefaultListSort,
changeSortField,
validateStartWorkingOnScheduledUpdate,
Expand Down
92 changes: 53 additions & 39 deletions client/apps/Assignments/AssignmentsSubNav.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import PropTypes from 'prop-types';
import {connect} from 'react-redux';

import * as selectors from '../../selectors';
Expand All @@ -9,7 +8,46 @@ import {WORKSPACE, ASSIGNMENTS} from '../../constants';
import {SubNavBar, FiltersBar} from '../../components/Assignments';
import {ArchiveItem} from '../../components/Archive';

export class AssignmentsSubNavComponent extends React.Component {
interface IReduxStateProps {
filterBy?: string;
selectedDeskId?: string;
currentDeskId?: string;
myAssignmentsCount?: number;
orderByField?: string;
dayField?: string;
searchQuery?: string;
assignmentListSingleGroupView?: string;
filterByType?: string;
filterByPriority?: string;
assignmentsInTodoCount?: number;
assignmentsInInProgressCount?: number;
assignmentsInCompletedCount?: number;
assignmentCounts?: any;
userDesks?: Array<any>;
workspace?: string;
listGroups?: Array<any>;
privileges?: any;
}

interface IReduxDispatchProps {
fetchMyAssignmentsCount?: () => any;
changeAssignmentListSingleGroupView?: (groupKey: string) => any;
loadAssignments: (filters: any) => any;
changeSortField?: (field: string, saveSortPreferences?: boolean) => any;
changeDayField?: (value: string) => any;
}

interface IOwnProps {
archiveItem?: any;
withArchiveItem?: boolean;
showAllDeskOption?: boolean;
saveSortPreferences?: boolean;
ignoreScheduledUpdates?: boolean;
}

type IProps = IOwnProps & IReduxStateProps & IReduxDispatchProps;

export class AssignmentsSubNavComponent extends React.Component<IProps> {
constructor(props) {
super(props);

Expand Down Expand Up @@ -40,6 +78,7 @@ export class AssignmentsSubNavComponent extends React.Component {
const {
filterBy,
orderByField,
dayField,
loadAssignments,
filterByType,
filterByPriority,
Expand All @@ -51,6 +90,7 @@ export class AssignmentsSubNavComponent extends React.Component {
filterBy,
searchQuery,
orderByField,
dayField,
filterByType,
filterByPriority,
selectedDeskId,
Expand All @@ -68,12 +108,14 @@ export class AssignmentsSubNavComponent extends React.Component {
filterByType,
filterByPriority,
ignoreScheduledUpdates,
dayField
} = this.props;

loadAssignments({
filterBy,
searchQuery,
orderByField,
dayField,
filterByType,
filterByPriority,
selectedDeskId,
Expand All @@ -82,7 +124,7 @@ export class AssignmentsSubNavComponent extends React.Component {
}

changeSortField(field) {
const {changeSortField, saveSortPreferences} = this.props;
const {changeSortField, saveSortPreferences = true} = this.props;

changeSortField(field, saveSortPreferences);
}
Expand All @@ -102,6 +144,7 @@ export class AssignmentsSubNavComponent extends React.Component {
filterBy,
myAssignmentsCount,
orderByField,
dayField,
searchQuery,
assignmentListSingleGroupView,
changeAssignmentListSingleGroupView,
Expand All @@ -111,8 +154,9 @@ export class AssignmentsSubNavComponent extends React.Component {
workspace,
userDesks,
currentDeskId,
showAllDeskOption,
showAllDeskOption = false,
privileges,
changeDayField,
} = this.props;

// Show the Desk selection if we're in Fulfil Assignment or Custom Workspace
Expand All @@ -137,6 +181,8 @@ export class AssignmentsSubNavComponent extends React.Component {
myAssignmentsCount={myAssignmentsCount}
orderByField={orderByField}
changeFilter={this.changeFilter}
dayField={dayField}
changeDayField={changeDayField}
selectedDeskId={selectedDeskId}
userDesks={showDeskSelection ? userDesks : []}
selectAssignmentsFrom={this.selectAssignmentsFrom}
Expand All @@ -150,46 +196,13 @@ export class AssignmentsSubNavComponent extends React.Component {
}
}

AssignmentsSubNavComponent.propTypes = {
filterBy: PropTypes.string,
selectedDeskId: PropTypes.string,
myAssignmentsCount: PropTypes.number,
orderByField: PropTypes.string,
fetchMyAssignmentsCount: PropTypes.func,
searchQuery: PropTypes.string,
assignmentListSingleGroupView: PropTypes.string,
changeAssignmentListSingleGroupView: PropTypes.func,
loadAssignments: PropTypes.func.isRequired,
filterByType: PropTypes.string,
filterByPriority: PropTypes.string,
assignmentsInTodoCount: PropTypes.number,
assignmentsInInProgressCount: PropTypes.number,
assignmentsInCompletedCount: PropTypes.number,
archiveItem: PropTypes.object,
withArchiveItem: PropTypes.bool,
userDesks: PropTypes.array,
workspace: PropTypes.string,
currentDeskId: PropTypes.string,
listGroups: PropTypes.array,
assignmentCounts: PropTypes.object,
showAllDeskOption: PropTypes.bool,
changeSortField: PropTypes.func,
saveSortPreferences: PropTypes.bool,
ignoreScheduledUpdates: PropTypes.bool,
privileges: PropTypes.object,
};

AssignmentsSubNavComponent.defaultProps = {
showAllDeskOption: false,
saveSortPreferences: true,
};

const mapStateToProps = (state) => ({
filterBy: selectors.getFilterBy(state),
selectedDeskId: selectors.getSelectedDeskId(state),
currentDeskId: selectors.general.currentDeskId(state),
myAssignmentsCount: selectors.getMyAssignmentsCount(state),
orderByField: selectors.getOrderByField(state),
dayField: selectors.getDayField(state),

searchQuery: selectors.getSearchQuery(state),
assignmentListSingleGroupView: selectors.getAssignmentListSingleGroupView(state),
Expand Down Expand Up @@ -222,12 +235,13 @@ const mapDispatchToProps = (dispatch) => ({
)
),
loadAssignments: (filters) => dispatch(actions.assignments.ui.loadAssignments(filters)),
changeDayField: (value) => dispatch(actions.assignments.ui.changeDayField(value)),
changeSortField: (field, saveSortPreferences) => (
dispatch(actions.assignments.ui.changeSortField(field, saveSortPreferences))
),
});

export const AssignmentsSubNav = connect(
export const AssignmentsSubNav = connect<IReduxStateProps, IReduxDispatchProps, IOwnProps>(
mapStateToProps,
mapDispatchToProps
)(AssignmentsSubNavComponent);
Loading

0 comments on commit ffa4080

Please sign in to comment.