schedule changes on the helper methods
This commit is contained in:
parent
d9827337b0
commit
c744d73aef
7 changed files with 32 additions and 26 deletions
|
|
@ -47,11 +47,11 @@ class ScheduleFinal extends Component<ScheduleFinalProps, ScheduleOverridesState
|
|||
|
||||
const currentTimeX = diff / base;
|
||||
|
||||
const shifts = getShiftsFromStore(store, scheduleId, startMoment, false);
|
||||
const shifts = getShiftsFromStore(store, scheduleId, startMoment);
|
||||
|
||||
const layers = getLayersFromStore(store, scheduleId, startMoment);
|
||||
|
||||
const overrides = getOverridesFromStore(store, scheduleId, startMoment, true);
|
||||
const overrides = getOverridesFromStore(store, scheduleId, startMoment);
|
||||
|
||||
const currentTimeHidden = currentTimeX < 0 || currentTimeX > 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -10,8 +10,13 @@ import TimelineMarks from 'components/TimelineMarks/TimelineMarks';
|
|||
import Rotation from 'containers/Rotation/Rotation';
|
||||
import { RotationCreateData } from 'containers/RotationForm/RotationForm.types';
|
||||
import ScheduleOverrideForm from 'containers/RotationForm/ScheduleOverrideForm';
|
||||
import { getFromString, getOverrideColor, getShiftsFromStore } from 'models/schedule/schedule.helpers';
|
||||
import { Event, Schedule, Shift } from 'models/schedule/schedule.types';
|
||||
import {
|
||||
getFromString,
|
||||
getOverrideColor,
|
||||
getOverridesFromStore,
|
||||
getShiftsFromStore,
|
||||
} from 'models/schedule/schedule.helpers';
|
||||
import { Event, Schedule, Shift, ShiftEvents } from 'models/schedule/schedule.types';
|
||||
import { Timezone } from 'models/timezone/timezone.types';
|
||||
import { WithStoreProps } from 'state/types';
|
||||
import { withMobXProviderContext } from 'state/withStore';
|
||||
|
|
@ -49,7 +54,7 @@ class ScheduleOverrides extends Component<ScheduleOverridesProps, ScheduleOverri
|
|||
this.props;
|
||||
const { shiftMomentToShowOverrideForm } = this.state;
|
||||
|
||||
const shifts = getShiftsFromStore(store, scheduleId, startMoment, true);
|
||||
const shifts = getOverridesFromStore(store, scheduleId, startMoment) as ShiftEvents[];
|
||||
|
||||
const base = 7 * 24 * 60; // in minutes
|
||||
const diff = dayjs().tz(currentTimezone).diff(startMoment, 'minutes');
|
||||
|
|
|
|||
|
|
@ -13,8 +13,6 @@ import Text from 'components/Text/Text';
|
|||
import { findColor } from 'containers/Rotations/Rotations.helpers';
|
||||
import { IsOncallIcon } from 'icons';
|
||||
import {
|
||||
getColor,
|
||||
getFromString,
|
||||
getLayersFromStore,
|
||||
getOverrideColor,
|
||||
getOverridesFromStore,
|
||||
|
|
@ -33,6 +31,7 @@ interface UsersTimezonesProps {
|
|||
userIds: Array<User['pk']>;
|
||||
tz: Timezone;
|
||||
onCallNow: Array<Partial<User>>;
|
||||
scheduleId: Schedule['id'];
|
||||
|
||||
onTzChange: (tz: Timezone) => void;
|
||||
}
|
||||
|
|
@ -46,8 +45,7 @@ const jLimit = 24 / hoursToSplit;
|
|||
const UsersTimezones: FC<UsersTimezonesProps> = (props) => {
|
||||
const store = useStore();
|
||||
|
||||
const { userIds, tz, onTzChange, onCallNow } = props;
|
||||
const { scheduleId } = store.scheduleStore;
|
||||
const { userIds, tz, onTzChange, onCallNow, scheduleId } = props;
|
||||
|
||||
useEffect(() => {
|
||||
userIds.forEach((userId) => {
|
||||
|
|
@ -313,13 +311,13 @@ const AvatarGroup = (props: AvatarGroupProps) => {
|
|||
};
|
||||
|
||||
function getColorSchemeMappingForUsers(store: RootStore, scheduleId: string): { [userId: string]: Set<string> } {
|
||||
const usersColorSchemeHash: { [userId: string]: Set<string> } = {};
|
||||
|
||||
const startMoment = getStartOfWeek(store.currentTimezone);
|
||||
|
||||
const shifts = getShiftsFromStore(store, scheduleId, startMoment, false);
|
||||
const shifts = getShiftsFromStore(store, scheduleId, startMoment);
|
||||
const layers = getLayersFromStore(store, scheduleId, startMoment);
|
||||
const overrides = getOverridesFromStore(store, scheduleId, startMoment, false);
|
||||
|
||||
const usersColorSchemeHash: { [userId: string]: Set<string> } = {};
|
||||
const overrides = getOverridesFromStore(store, scheduleId, startMoment);
|
||||
|
||||
if (!shifts?.length || !layers?.length) {
|
||||
return usersColorSchemeHash;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import dayjs from 'dayjs';
|
||||
import { RootStore } from 'state';
|
||||
|
||||
import { Event, Layer, Schedule, ScheduleType, Shift } from './schedule.types';
|
||||
import { Event, Layer, Schedule, ScheduleType, Shift, ShiftEvents } from './schedule.types';
|
||||
|
||||
export const getFromString = (moment: dayjs.Dayjs) => {
|
||||
return moment.format('YYYY-MM-DD');
|
||||
|
|
@ -62,12 +62,10 @@ export const getShiftsFromStore = (
|
|||
store: RootStore,
|
||||
scheduleId: Schedule['id'],
|
||||
startMoment: dayjs.Dayjs,
|
||||
isOverridePreview: boolean,
|
||||
): Array<{ shiftId: string; events: Event[], isPreview?: boolean; }> => {
|
||||
const source = isOverridePreview ? store.scheduleStore.overridePreview : store.scheduleStore.finalPreview;
|
||||
return source
|
||||
): ShiftEvents[] => {
|
||||
return store.scheduleStore.finalPreview
|
||||
? store.scheduleStore.finalPreview
|
||||
: (store.scheduleStore.events[scheduleId]?.[isOverridePreview ? 'override' : 'final']?.[getFromString(startMoment)] as any);
|
||||
: (store.scheduleStore.events[scheduleId]?.['final']?.[getFromString(startMoment)] as any);
|
||||
};
|
||||
|
||||
export const getLayersFromStore = (store: RootStore, scheduleId: Schedule['id'], startMoment: dayjs.Dayjs): Layer[] => {
|
||||
|
|
@ -80,7 +78,6 @@ export const getOverridesFromStore = (
|
|||
store: RootStore,
|
||||
scheduleId: Schedule['id'],
|
||||
startMoment: dayjs.Dayjs,
|
||||
isOverridePreview: boolean
|
||||
):
|
||||
| Layer[]
|
||||
| {
|
||||
|
|
@ -89,10 +86,9 @@ export const getOverridesFromStore = (
|
|||
isPreview?: boolean;
|
||||
}[] => {
|
||||
|
||||
const source = isOverridePreview ? store.scheduleStore.overridePreview : store.scheduleStore.rotationPreview;
|
||||
return source
|
||||
? store.scheduleStore.rotationPreview
|
||||
: (store.scheduleStore.events[scheduleId]?.[isOverridePreview ? 'override' : 'rotation']?.[getFromString(startMoment)] as Layer[]);
|
||||
return store.scheduleStore.overridePreview
|
||||
? store.scheduleStore.overridePreview
|
||||
: (store.scheduleStore.events[scheduleId]?.['override']?.[getFromString(startMoment)] as Layer[]);
|
||||
};
|
||||
|
||||
export const splitToLayers = (
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import {
|
|||
splitToLayers,
|
||||
splitToShiftsAndFillGaps,
|
||||
} from './schedule.helpers';
|
||||
import { Events, Rotation, RotationType, Schedule, ScheduleEvent, Shift, Event, Layer } from './schedule.types';
|
||||
import { Events, Rotation, RotationType, Schedule, ScheduleEvent, Shift, Event, Layer, ShiftEvents } from './schedule.types';
|
||||
|
||||
const DEFAULT_FORMAT = 'YYYY-MM-DDTHH:mm:ss';
|
||||
|
||||
|
|
@ -54,7 +54,7 @@ export class ScheduleStore extends BaseStore {
|
|||
events: {
|
||||
[scheduleId: string]: {
|
||||
[type: string]: {
|
||||
[startMoment: string]: Array<{ shiftId: string; events: Event[]; isPreview?: boolean }> | Layer[];
|
||||
[startMoment: string]: ShiftEvents[] | Layer[];
|
||||
};
|
||||
};
|
||||
} = {};
|
||||
|
|
|
|||
|
|
@ -95,3 +95,9 @@ export interface Layer {
|
|||
priority: Shift['priority_level'];
|
||||
shifts: Array<{ shiftId: Shift['id']; isPreview?: boolean; events: Event[] }>;
|
||||
}
|
||||
|
||||
export interface ShiftEvents {
|
||||
shiftId: string;
|
||||
events: Event[];
|
||||
isPreview?: boolean;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,6 +141,7 @@ class SchedulePage extends React.Component<SchedulePageProps, SchedulePageState>
|
|||
}
|
||||
tz={currentTimezone}
|
||||
onTzChange={this.handleTimezoneChange}
|
||||
scheduleId={scheduleId}
|
||||
/>
|
||||
</div>
|
||||
<div className={cx('controls')}>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue