From cecfcb1d5696894ac76bf00522da6ba3a7cbefcb Mon Sep 17 00:00:00 2001 From: Rares Mardare Date: Thu, 13 Oct 2022 15:03:27 +0300 Subject: [PATCH] avatar fix --- .../src/pages/schedule/Schedule.helpers.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/grafana-plugin/src/pages/schedule/Schedule.helpers.ts b/grafana-plugin/src/pages/schedule/Schedule.helpers.ts index 1f9e98e5..bd23489c 100644 --- a/grafana-plugin/src/pages/schedule/Schedule.helpers.ts +++ b/grafana-plugin/src/pages/schedule/Schedule.helpers.ts @@ -2,7 +2,7 @@ import dayjs from 'dayjs'; import { findColor } from 'containers/Rotations/Rotations.helpers'; import { getLayersFromStore, getOverridesFromStore, getShiftsFromStore } from 'models/schedule/schedule.helpers'; -import { Event } from 'models/schedule/schedule.types'; +import { Event, Layer } from 'models/schedule/schedule.types'; import { Timezone } from 'models/timezone/timezone.types'; import { RootStore } from 'state'; @@ -18,7 +18,6 @@ export const getDateTime = (date: string) => { return dayjs(date); }; - export const getColorSchemeMappingForUsers = ( store: RootStore, scheduleId: string, @@ -26,15 +25,19 @@ export const getColorSchemeMappingForUsers = ( ): { [userId: string]: Set } => { const usersColorSchemeHash: { [userId: string]: Set } = {}; - const shifts = getShiftsFromStore(store, scheduleId, startMoment); - const layers = getLayersFromStore(store, scheduleId, startMoment); + const layers: Layer[] = getLayersFromStore(store, scheduleId, startMoment); const overrides = getOverridesFromStore(store, scheduleId, startMoment); - if (!shifts?.length || !layers?.length) { + if (!layers?.length) { return usersColorSchemeHash; } - shifts.forEach(({ shiftId, events }) => populateUserHashSet(events, shiftId)); + const shiftsFromLayers = layers.reduce((prev, current) => { + prev.push(...current.shifts); + return prev; + }, []); + + shiftsFromLayers.forEach(({ shiftId, events }) => populateUserHashSet(events, shiftId)); return usersColorSchemeHash; @@ -49,4 +52,4 @@ export const getColorSchemeMappingForUsers = ( }); }); } -} +};