Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/2.7' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek committed Jul 18, 2024
2 parents fa1da72 + 1fb931f commit 464c5f1
Show file tree
Hide file tree
Showing 24 changed files with 314 additions and 253 deletions.
12 changes: 1 addition & 11 deletions client/apps/Planning/PlanningList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,7 @@ export class PlanningListComponent extends React.PureComponent<IProps> {
<React.Fragment>
<PlanningListSubNav />
<ListPanel
groups={(() => {
const dateFilter = currentSearch.advancedSearch?.dates?.start?.toDate() ?? new Date();

dateFilter.setUTCHours(0, 0, 0, 0); // group date is UTC 00:00:00

return groups.filter((group) => {
const groupDate = new Date(group.date);

return groupDate >= dateFilter;
});
})()}
groups={groups}
onItemClick={openPreview}
onDoubleClick={edit}
agendas={agendas}
Expand Down
13 changes: 9 additions & 4 deletions client/selectors/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {createSelector} from 'reselect';
import {get, sortBy} from 'lodash';

import {appConfig} from 'appConfig';
import {IEventItem, IEventState, IEventTemplate, IPlanningAppState, LIST_VIEW_TYPE} from '../interfaces';
import {IEventItem, IEventState, IEventTemplate, IPlanningAppState, JUMP_INTERVAL, LIST_VIEW_TYPE} from '../interfaces';

import {currentPlanning, storedPlannings} from './planning';
import {agendas, userPreferences} from './general';
Expand All @@ -13,6 +13,11 @@ import {EVENTS, MAIN, SPIKED_STATE} from '../constants';
function getCurrentListViewType(state?: IPlanningAppState) {
return state?.main?.listViewType ?? LIST_VIEW_TYPE.SCHEDULE;
}

function getCurrentViewInterval(state?: IPlanningAppState): JUMP_INTERVAL {
return state?.main?.search?.EVENTS?.jumpInterval ?? JUMP_INTERVAL.WEEK;
}

export const storedEvents = (state) => get(state, 'events.events', {});
export const eventIdsInList = (state) => get(state, 'events.eventsInList', []);
export const eventHistory = (state) => get(state, 'events.eventHistoryItems');
Expand All @@ -36,8 +41,8 @@ export const eventsInList = createSelector(
* the associated events.
*/
export const orderedEvents = createSelector(
[eventsInList, currentSearch, getCurrentListViewType],
(events, search, viewType) => {
[eventsInList, currentSearch, getCurrentListViewType, getCurrentViewInterval],
(events, search, viewType, viewInterval) => {
if (!events?.length) {
return [];
} else if (viewType === LIST_VIEW_TYPE.LIST) {
Expand All @@ -47,7 +52,7 @@ export const orderedEvents = createSelector(
}];
}

const dateRange = getSearchDateRange(search, appConfig.start_of_week);
const dateRange = getSearchDateRange(search, appConfig.start_of_week, viewInterval);

return eventUtils.getEventsByDate(events, dateRange.startDate, dateRange.endDate);
}
Expand Down
20 changes: 16 additions & 4 deletions client/selectors/eventsplanning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {createSelector} from 'reselect';
import {get, keyBy, sortBy, uniq} from 'lodash';

import {appConfig} from 'appConfig';
import {IPlanningAppState, LIST_VIEW_TYPE} from '../interfaces';
import {IPlanningAppState, JUMP_INTERVAL, LIST_VIEW_TYPE} from '../interfaces';

import {storedEvents} from './events';
import {storedPlannings} from './planning';
Expand All @@ -13,6 +13,11 @@ import {userPreferences} from './general';
function getCurrentListViewType(state?: IPlanningAppState) {
return state?.main?.listViewType ?? LIST_VIEW_TYPE.SCHEDULE;
}

function getCurrentViewInterval(state?: IPlanningAppState): JUMP_INTERVAL {
return state?.main?.search?.COMBINED?.jumpInterval ?? JUMP_INTERVAL.WEEK;
}

export const getEventsPlanningList = (state) => get(state, 'eventsPlanning.eventsAndPlanningInList', []);
export const getRelatedPlanningsList = (state) => get(state, 'eventsPlanning.relatedPlannings', {});
export const currentSearch = (state) => get(state, 'main.search.COMBINED.currentSearch');
Expand Down Expand Up @@ -44,8 +49,15 @@ export const eventsPlannignViewFilters = createSelector(
* @type {Reselect.Selector<any, any>}
*/
export const orderedEventsPlanning = createSelector(
[storedEvents, storedPlannings, getEventsPlanningList, currentSearch, getCurrentListViewType],
(events, plannings, eventPlanningList, search, viewType) => {
[
storedEvents,
storedPlannings,
getEventsPlanningList,
currentSearch,
getCurrentListViewType,
getCurrentViewInterval,
],
(events, plannings, eventPlanningList, search, viewType, viewInterval) => {
if (!eventPlanningList?.length) {
return [];
} else if (viewType === LIST_VIEW_TYPE.LIST) {
Expand All @@ -59,7 +71,7 @@ export const orderedEventsPlanning = createSelector(

const eventsList = [];
const planningList = [];
const dateRange = getSearchDateRange(search, appConfig.start_of_week);
const dateRange = getSearchDateRange(search, appConfig.start_of_week, viewInterval);

eventPlanningList.forEach((_id) => {
if (_id in events) {
Expand Down
20 changes: 16 additions & 4 deletions client/selectors/planning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {createSelector} from 'reselect';
import {cloneDeep, get} from 'lodash';

import {appConfig} from 'appConfig';
import {IPlanningAppState, IPlanningItem, LIST_VIEW_TYPE} from '../interfaces';
import {IPlanningAppState, IPlanningItem, JUMP_INTERVAL, LIST_VIEW_TYPE} from '../interfaces';

import {session, userPreferences} from './general';
import {getSearchDateRange, lockUtils, planningUtils} from '../utils';
Expand All @@ -11,6 +11,11 @@ import {AGENDA, SPIKED_STATE} from '../constants';
function getCurrentListViewType(state?: IPlanningAppState) {
return state?.main?.listViewType ?? LIST_VIEW_TYPE.SCHEDULE;
}

function getCurrentViewInterval(state?: IPlanningAppState): JUMP_INTERVAL {
return state?.main?.search?.PLANNING?.jumpInterval ?? JUMP_INTERVAL.WEEK;
}

const storedEvents = (state) => get(state, 'events.events', {});

export const planningHistory = (state) => get(state, 'planning.planningHistoryItems');
Expand Down Expand Up @@ -71,8 +76,15 @@ export const plansInList = createSelector(
);

export const orderedPlanningList = createSelector(
[currentAgenda, plansInList, storedEvents, currentSearch, getCurrentListViewType],
(currentAgenda, plansInList, events, search, viewType) => {
[
currentAgenda,
plansInList,
storedEvents,
currentSearch,
getCurrentListViewType,
getCurrentViewInterval,
],
(currentAgenda, plansInList, events, search, viewType, viewInterval) => {
if (!plansInList?.length) {
return [];
} if (viewType === LIST_VIEW_TYPE.LIST) {
Expand All @@ -82,7 +94,7 @@ export const orderedPlanningList = createSelector(
}];
}

const dateRange = getSearchDateRange(search, appConfig.start_of_week);
const dateRange = getSearchDateRange(search, appConfig.start_of_week, viewInterval);

return planningUtils.getPlanningByDate(
plansInList, events, dateRange.startDate, dateRange.endDate
Expand Down
118 changes: 102 additions & 16 deletions client/selectors/tests/events_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as selectors from '../index';
import moment from 'moment';
import {keyBy} from 'lodash';

const ids = (day) => day.events.map((e) => e._id);

describe('selectors', () => {
const dateFormat = 'YYYY-MM-DDTHH:mm:ss';
Expand Down Expand Up @@ -32,22 +33,40 @@ describe('selectors', () => {
end: moment('2017-01-17T14:00:00', dateFormat),
},
},
event4: {
_id: 'event4',
name: 'event4',
dates: {
start: moment('2024-07-16T13:00:00+0000'),
end: moment('2024-07-17T00:00:00+0000'),
no_end_time: true,
},
},
event5: {
_id: 'event5',
name: 'event5',
dates: {
start: moment('2024-07-15T00:00:00+0000'),
end: moment('2024-07-18T00:00:00+0000'),
all_day: true,
},
}
},
eventsInList: ['event1', 'event2', 'event3'],
eventsInList: ['event1', 'event2', 'event3', 'event4', 'event5'],
},
session: {identity: {_id: 'user1'}},
});

const setAdvancedSearchDates = (state, startDate, endate) => {
const setAdvancedSearchDates = (state, startDate, endate?) => {
state.main = {
filter: 'EVENTS',
search: {
EVENTS: {
currentSearch: {
advancedSearch: {
dates: {
start: startDate ? moment(startDate, dateFormat) : null,
end: endate ? moment(endate, dateFormat) : null,
start: startDate ? moment(startDate) : null,
end: endate ? moment(endate) : null,
},
},
},
Expand All @@ -60,7 +79,7 @@ describe('selectors', () => {
it('all events', () => {
const state = getState();

setAdvancedSearchDates(state, '2017-01-10T00:00:00');
setAdvancedSearchDates(state, '2017-01-10T00:00:00+0000');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
Expand All @@ -87,7 +106,7 @@ describe('selectors', () => {

state.events.events.event2.dates.start = moment('2017-01-17T08:00:00', dateFormat);
state.events.events.event2.dates.end = moment('2017-01-17T14:00:00', dateFormat);
setAdvancedSearchDates(state, '2017-01-10T00:00:00');
setAdvancedSearchDates(state, '2017-01-10T00:00:00+0000');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
Expand All @@ -112,7 +131,7 @@ describe('selectors', () => {
it('for today 2017-01-15', () => {
const state = getState();

setAdvancedSearchDates(state, '2017-01-15T00:00:00+0000', '2017-01-15T23:59:59+0000');
setAdvancedSearchDates(state, '2017-01-15T00:00:00', '2017-01-15T23:59:59');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
Expand All @@ -126,7 +145,7 @@ describe('selectors', () => {
it('from 2017-01-15 11:00 to 2017-01-16T14:00:00+0000', () => {
const state = getState();

setAdvancedSearchDates(state, '2017-01-15T11:00:00+0000', '2017-01-16T14:00:00+0000');
setAdvancedSearchDates(state, '2017-01-15T11:00:00', '2017-01-16T14:00:00');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
Expand All @@ -145,21 +164,22 @@ describe('selectors', () => {
it('from 2017-01-16T06:00:00+0000 to 2017-01-16T07:00:00+0000', () => {
const state = getState();

setAdvancedSearchDates(state, '2017-01-16T06:00:00+0000', '2017-01-16T07:00:00+0000');
setAdvancedSearchDates(state, '2017-01-16T06:00:00', '2017-01-16T07:00:00');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
'2017-01-16',
]);

expect(events['2017-01-16'].events.length).toBe(1);
expect(events['2017-01-16'].events.length).toBe(2);
expect(events['2017-01-16'].events[0]._id).toBe('event3');
expect(events['2017-01-16'].events[1]._id).toBe('event2');
});

it('from 2017-01-16T06:00:00+0000 to 2017-01-16T10:00:00+0000', () => {
const state = getState();

setAdvancedSearchDates(state, '2017-01-16T06:00:00+0000', '2017-01-16T10:00:00+0000');
setAdvancedSearchDates(state, '2017-01-16T06:00:00', '2017-01-16T10:00:00');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
Expand All @@ -171,10 +191,10 @@ describe('selectors', () => {
expect(events['2017-01-16'].events[1]._id).toBe('event2');
});

it('from 2017-01-16T13:59:59+0000 to 2017-01-17T08:00:00+0000', () => {
it('from 2017-01-16T13:59:59 to 2017-01-17T08:00:00', () => {
const state = getState();

setAdvancedSearchDates(state, '2017-01-16T13:59:59+0000', '2017-01-17T08:00:00+0000');
setAdvancedSearchDates(state, '2017-01-16T13:59:59', '2017-01-17T08:00:00');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual(['2017-01-16', '2017-01-17']);
Expand All @@ -187,7 +207,7 @@ describe('selectors', () => {
it('from 2017-01-17T06:00:00+0000', () => {
const state = getState();

setAdvancedSearchDates(state, '2017-01-17T06:00:00+0000');
setAdvancedSearchDates(state, '2017-01-17T06:00:00');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
Expand All @@ -198,13 +218,79 @@ describe('selectors', () => {
expect(events['2017-01-17'].events[0]._id).toBe('event3');
});

it('from 2017-01-17T14:00:01+0000', () => {
it('from 2017-01-18T00:00:00+0000', () => {
const state = getState();

setAdvancedSearchDates(state, '2017-01-17T14:00:01+0000');
setAdvancedSearchDates(state, '2017-01-18T00:00:00');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events).length).toBe(0);
});

it('from 2024-07-14', () => {
const state = getState();

setAdvancedSearchDates(state, '2024-07-14T12:00:00');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
'2024-07-15',
'2024-07-16',
'2024-07-17',
'2024-07-18',
]);

expect(ids(events['2024-07-15'])).toEqual(['event5']);
expect(ids(events['2024-07-16'])).toEqual(['event5', 'event4']);
expect(ids(events['2024-07-17'])).toEqual(['event5', 'event4']);
expect(ids(events['2024-07-18'])).toEqual(['event5']);
});

it('from 2024-07-17', () => {
const state = getState();

setAdvancedSearchDates(state, '2024-07-17T12:00:00');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
'2024-07-17',
'2024-07-18',
]);

expect(ids(events['2024-07-17'])).toEqual(['event5', 'event4']);
});

it('from 2024-07-14 Toronto timezone', () => {
moment.tz.setDefault('America/Toronto');
const state = getState();

setAdvancedSearchDates(state, '2024-07-14T12:00:00');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
'2024-07-15',
'2024-07-16',
'2024-07-17',
'2024-07-18',
]);

expect(ids(events['2024-07-15'])).toEqual(['event5']);
expect(ids(events['2024-07-16'])).toEqual(['event5', 'event4']);
expect(ids(events['2024-07-17'])).toEqual(['event5', 'event4']);
expect(ids(events['2024-07-18'])).toEqual(['event5']);
});

it('from 2024-07-17 Toronto timezone', () => {
moment.tz.setDefault('America/Toronto');
const state = getState();

setAdvancedSearchDates(state, '2024-07-17T05:00:00');
const events = keyBy(selectors.events.orderedEvents(state), 'date');

expect(Object.keys(events)).toEqual([
'2024-07-17',
'2024-07-18',
]);
});
});
});
5 changes: 4 additions & 1 deletion client/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ Object.assign(appConfig, {
planning_auto_assign_to_workflow: true,
});

moment.tz.setDefault('Australia/Sydney');
updateConfigAfterLoad();

beforeEach(() => {
moment.tz.setDefault('Australia/Sydney');
});

var testsContext = require.context('.', true, /_test.[j|t]sx?$/);

testsContext.keys().forEach(testsContext);
Loading

0 comments on commit 464c5f1

Please sign in to comment.