From 605042fb38e38ee4ad276a200dad14473a52f1da Mon Sep 17 00:00:00 2001 From: Denis Papec Date: Thu, 28 Sep 2023 23:24:37 +0100 Subject: [PATCH] Added config for first day in week for calendar widget (#2080) --- src/utils/config/service-helpers.js | 2 ++ src/widgets/calendar/monthly-view.jsx | 11 ++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/utils/config/service-helpers.js b/src/utils/config/service-helpers.js index 543bf5ee4..91e5b75c0 100644 --- a/src/utils/config/service-helpers.js +++ b/src/utils/config/service-helpers.js @@ -358,6 +358,7 @@ export function cleanServiceGroups(groups) { mappings, // customapi widget refreshInterval, integrations, // calendar widget + firstDayInWeek, } = cleanedService.widget; let fieldsList = fields; @@ -443,6 +444,7 @@ export function cleanServiceGroups(groups) { } if (type === "calendar") { if (integrations) cleanedService.widget.integrations = integrations; + if (firstDayInWeek) cleanedService.widget.firstDayInWeek = firstDayInWeek; } } diff --git a/src/widgets/calendar/monthly-view.jsx b/src/widgets/calendar/monthly-view.jsx index 383d9881d..d273dd13e 100644 --- a/src/widgets/calendar/monthly-view.jsx +++ b/src/widgets/calendar/monthly-view.jsx @@ -98,13 +98,13 @@ export default function MonthlyView({ service }) { const dayNames = Info.weekdays("short", { locale: i18n.language }); - const firstDayInCalendar = widget?.firstDayInCalendar ? widget?.firstDayInCalendar?.toLowerCase() : "monday"; - for (let i = 1; i < dayInWeekId[firstDayInCalendar]; i+=1) { + const firstDayInWeekCalendar = widget?.firstDayInWeek ? widget?.firstDayInWeek?.toLowerCase() : "monday"; + for (let i = 1; i < dayInWeekId[firstDayInWeekCalendar]; i+=1) { dayNames.push(dayNames.shift()); } - const daysInWeek = useMemo(() => [ ...Array(7).keys() ].map( i => i + dayInWeekId[firstDayInCalendar] - ), [(firstDayInCalendar)]); + const daysInWeek = useMemo(() => [ ...Array(7).keys() ].map( i => i + dayInWeekId[firstDayInWeekCalendar] + ), [firstDayInWeekCalendar]); if (!showDate) { return
; @@ -112,8 +112,9 @@ export default function MonthlyView({ service }) { const firstWeek = DateTime.local(showDate.year, showDate.month, 1).setLocale(i18n.language); + const weekIncrementChange = dayInWeekId[firstDayInWeekCalendar] > firstWeek.weekday ? -1 : 0; let weekNumbers = [ ...Array(Math.ceil(5) + 1).keys() ] - .map(i => firstWeek.weekNumber+i); + .map(i => firstWeek.weekNumber + weekIncrementChange + i); if (weekNumbers.includes(55)) { // if we went too far with the weeks, it's the beginning of the year