From a7276659ab08906bb0762b027654202b2bc5bbdc Mon Sep 17 00:00:00 2001 From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com> Date: Sun, 11 Aug 2024 15:38:03 +0200 Subject: [PATCH 01/13] 2000: Adjusted scheduling component --- src/components/util/schedule/schedule-util.js | 13 +- src/components/util/schedule/schedule.jsx | 113 ++++++++---------- src/translations/da/common.json | 15 ++- 3 files changed, 61 insertions(+), 80 deletions(-) diff --git a/src/components/util/schedule/schedule-util.js b/src/components/util/schedule/schedule-util.js index f2a778d7..1a51e354 100644 --- a/src/components/util/schedule/schedule-util.js +++ b/src/components/util/schedule/schedule-util.js @@ -56,7 +56,7 @@ const createNewSchedule = () => { const newSchedule = { id: ulid(nowTimestamp), - duration: 60 * 60 * 24, // Default one day. + duration: 60 * 60, // Default 1 hour. freq: RRule.WEEKLY, // For evaluation with the RRule library we pretend that "now" is in UTC instead of the local timezone. // That is 9:00 in Europe/Copenhagen time will be evaluated as if it was 9:00 in UTC. @@ -124,7 +124,7 @@ const createScheduleFromRRule = (id, duration, rruleString) => { * @param {number | null} count - The max number of occurrences. * @returns {Array} - The occurrences. */ -const getNextOccurrences = (rrule, count = 5) => { +const getNextOccurrences = (rrule, duration = null, count = 5) => { const occurrences = []; const newRrule = new RRule(rrule.origOptions); @@ -133,6 +133,7 @@ const getNextOccurrences = (rrule, count = 5) => { occurrences.push({ key: `occurrence${occurrences.length}`, text: dayjs(d).utc().locale("da").format("LLLL"), + end: duration !== null ? dayjs(d).utc().add(duration, 'second').locale("da").format("LLLL") : null, }); return true; }); @@ -156,12 +157,8 @@ const getFreqOptions = (t) => { }, { title: t("schedule.weekly"), value: RRule.WEEKLY, key: "rrule.weekly" }, { title: t("schedule.daily"), value: RRule.DAILY, key: "rrule.daily" }, - { title: t("schedule.hourly"), value: RRule.HOURLY, key: "rrule.hourly" }, - { - title: t("schedule.minutely"), - value: RRule.MINUTELY, - key: "rrule.minutely", - }, +// { title: t("schedule.hourly"), value: RRule.HOURLY, key: "rrule.hourly" }, +// { title: t("schedule.minutely"), value: RRule.MINUTELY, key: "rrule.minutely" }, ]; }; diff --git a/src/components/util/schedule/schedule.jsx b/src/components/util/schedule/schedule.jsx index 50e86fe8..fa5e710e 100644 --- a/src/components/util/schedule/schedule.jsx +++ b/src/components/util/schedule/schedule.jsx @@ -188,7 +188,19 @@ function Schedule({ schedules, onChange }) { localSchedules.map((schedule, index) => (
- {t("schedule.plan")} #{index + 1} +
+
+ {t("schedule.plan")} #{index + 1} +
+
+ +
+
@@ -198,21 +210,10 @@ function Schedule({ schedules, onChange }) { label={t("schedule.dtstart")} value={getDateValue(schedule.dtstart)} name="dtstart" - onChange={({ target }) => setDateValue(schedule.id, target)} + onChange={({target}) => setDateValue(schedule.id, target)} type="datetime-local" />
-
- setDateValue(schedule.id, target)} - type="datetime-local" - /> -
-
-
-
- setTimeValue(schedule.id, target)} - value={getTimeValue(schedule.byhour, schedule.byminute)} - label={t("schedule.bytime")} - type="time" - name="bytime" - /> -
changeSchedule(schedule.id, target.id, target.value) @@ -263,7 +271,7 @@ function Schedule({ schedules, onChange }) { allowNull={false} />
-
+
setPositiveNumberOrNull(schedule.id, target)} value={schedule.count ?? ''} @@ -273,7 +281,7 @@ function Schedule({ schedules, onChange }) { name="count" />
-
+
setPositiveNumberOrNull(schedule.id, target)} value={schedule.interval ?? ''} @@ -282,15 +290,17 @@ function Schedule({ schedules, onChange }) { name="interval" />
-
- setTimeValue(schedule.id, target)} - value={getTimeValue(schedule.byhour, schedule.byminute)} - label={t("schedule.bytime")} - type="time" - name="bytime" - /> -
+ {schedule.byhour && ( +
+ setTimeValue(schedule.id, target)} + value={getTimeValue(schedule.byhour, schedule.byminute)} + label={t("schedule.bytime")} + type="time" + name="bytime" + /> +
+ )}
diff --git a/src/translations/da/common.json b/src/translations/da/common.json index 842be6d5..b93968ad 100644 --- a/src/translations/da/common.json +++ b/src/translations/da/common.json @@ -777,7 +777,7 @@ "minutely": "Minut", "rrulestring": "RRule", "dtstart": "Start", - "until": "Gentagelsernes sluttidspunkt", + "until": "Planlægningens sluttidspunkt", "next-occurrences": "Næste 5 forekomster", "all-selected": "Alle er valgt", "clear-selection": "Ryd valg", @@ -788,7 +788,9 @@ "end": "Slut", "count": "Antal gentagelser", "count-placeholder": "Ubegrænset", - "interval": "Interval" + "interval": "Interval", + "help1": "Start/slut definerer længden, starttidspunkt på dagen og første mulige dato for gentagelserne.", + "help2": "Hvis gentagelsesreglerne ikke inkluderer starttidspunktet, kommer det ikke med." }, "duration": { "hours": "t.", From e3a6d5b68e011bda4d3e162967e114defe31e13f Mon Sep 17 00:00:00 2001 From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com> Date: Sun, 11 Aug 2024 17:41:05 +0200 Subject: [PATCH 06/13] 2000: Updated changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3a1a11b..011383a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +- Refactored scheduling to increase user experience. +- Added interval and count to rrule inputs. - [#252](https://github.com/os2display/display-admin-client/pull/252) - Reverted change in https://github.com/os2display/display-admin-client/commit/65762066c708f541305a48fbd6b28264dca593b5 regarding rrule dtstart. - Added comments about how rrules are handled. From fde37d275b8cdd64029ddaab4030a5c705808d33 Mon Sep 17 00:00:00 2001 From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com> Date: Sun, 11 Aug 2024 17:56:18 +0200 Subject: [PATCH 07/13] 2000: Added isNaN checks for hiding byhour:byminute when not defined --- src/components/util/schedule/schedule.jsx | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/util/schedule/schedule.jsx b/src/components/util/schedule/schedule.jsx index ab97e492..61537680 100644 --- a/src/components/util/schedule/schedule.jsx +++ b/src/components/util/schedule/schedule.jsx @@ -168,8 +168,16 @@ function Schedule({ schedules, onChange }) { const { value } = target; const split = value.split(":"); - changeSchedule(scheduleId, "byhour", parseInt(split[0], 10)); - changeSchedule(scheduleId, "byminute", parseInt(split[1], 10)); + const hour = parseInt(split[0], 10); + const minute = parseInt(split[1], 10); + + if (isNaN(hour) || isNaN(minute)) { + changeSchedule(scheduleId, "byhour", null); + changeSchedule(scheduleId, "byminute", null); + } else { + changeSchedule(scheduleId, "byhour", hour); + changeSchedule(scheduleId, "byminute", minute); + } }; const setDuration = (scheduleId, schedule, target) => { @@ -259,7 +267,7 @@ function Schedule({ schedules, onChange }) {
-
+
- changeSchedule(schedule.id, target.id, target.value) - } - value={schedule.freq} - label={t("schedule.freq")} - name="freq" - options={freqOptions} - allowNull={false} - /> -
-
- setPositiveNumberOrNull(schedule.id, target)} - value={schedule.count ?? ''} - label={t("schedule.count")} - placeholder={t('schedule.count-placeholder')} - type="search" - name="count" - /> -
-
- setPositiveNumberOrNull(schedule.id, target)} - value={schedule.interval ?? ''} - label={t("schedule.interval")} - type="search" - name="interval" - /> -
- {!isNaN(schedule.byhour) && ( -
- setTimeValue(schedule.id, target)} - value={getTimeValue(schedule.byhour, schedule.byminute)} - label={t("schedule.bytime")} - type="time" - name="bytime" - /> +
+
+
+
+ { const newSchedules = schedules.map((schedule) => @@ -206,6 +209,40 @@ function Schedule({ schedules, onChange }) { } } + const isRepeatingEvent = (schedule) => { + return !(schedule.duration === 60 * 60 && + schedule.freq === RRule.DAILY && + schedule.count === 1 && + schedule.until === undefined && + schedule.interval === undefined && + schedule.byhour === undefined && + schedule.byminute === undefined && + schedule.byweekday === undefined && + schedule.bymonth === undefined && + schedule.byweekno === undefined); + } + + const toggleRepeat = (schedule) => { + if ((isRepeatingEvent(schedule) || repeatActivated)) { + // Disable repeating schedule. + setRepeatActivated(false); + changeSchedule(schedule.id, 'duration', 60 * 60); + changeSchedule(schedule.id, 'freq', RRule.DAILY); + changeSchedule(schedule.id, 'count', 1); + changeSchedule(schedule.id, 'interval', null); + changeSchedule(schedule.id, 'until', null); + changeSchedule(schedule.id, 'byhour', null); + changeSchedule(schedule.id, 'byminute', null); + changeSchedule(schedule.id, 'byweekday', null); + changeSchedule(schedule.id, 'bymonth', null); + changeSchedule(schedule.id, 'byweekno', null); + } else { + // Activate repeating schedule. + setRepeatActivated(true); + changeSchedule(schedule.id, 'count', null); + } + } + return (
@@ -255,173 +293,190 @@ function Schedule({ schedules, onChange }) { onChange={({target}) => setDuration(schedule.id, schedule, target)} type="datetime-local" className={durationError ? 'border-danger' : ''} + tooltip={t('schedule.end-tooltip')} /> + {durationError && {t('schedule.duration-error')}}
-
-
- {t('schedule.helptext')} -
-
- {durationError && {t('schedule.duration-error')}} -
-
-
+
-
-
- + changeSchedule(schedule.id, target.id, target.value) + } + value={schedule.freq} + label={t("schedule.freq")} + name="freq" + options={freqOptions} + allowNull={false} + tooltip={t('schedule.frequency-tooltip')} + /> +
+
+ setPositiveNumberOrNull(schedule.id, target)} + value={schedule.interval ?? ''} + label={t("schedule.interval")} + type="search" + name="interval" + tooltip={t('schedule.interval-tooltip')} + /> +
+
+ setPositiveNumberOrNull(schedule.id, target)} + value={schedule.count ?? ''} + label={t("schedule.count")} + placeholder={t('schedule.count-placeholder')} + type="search" + name="count" + tooltip={t('schedule.count-tooltip')} + /> +
+ {!isNaN(schedule.byhour) && ( +
+ setTimeValue(schedule.id, target)} + value={getTimeValue(schedule.byhour, schedule.byminute)} + label={t("schedule.bytime")} + type="time" + name="bytime" + tooltip={t('schedule.bytime-tooltip')} + /> +
+ )}
- )} -
-
-
- - - - byWeekdayOptions.find( - (weekDay) => weekDay.value === weekdayNumber +
+
+ + + + + byWeekdayOptions.find( + (weekDay) => weekDay.value === weekdayNumber + ) + ) + : [] + } + name="byweekday" + disableSearch + overrideStrings={{ + allItemsAreSelected: t("schedule.all-selected"), + clearSelected: t("schedule.clear-selection"), + selectAll: t("schedule.selected-all"), + selectSomeItems: t("schedule.select-some-options"), + }} + labelledBy="Select" + onChange={(value) => { + changeSchedule( + schedule.id, + "byweekday", + value.map((v) => v.value) + ); + }} + /> + +
+
+ + + + + changeSchedule( + schedule.id, + "bymonth", + values.map((v) => v.value) ) - ) - : [] - } - name="byweekday" - disableSearch - overrideStrings={{ - allItemsAreSelected: t("schedule.all-selected"), - clearSelected: t("schedule.clear-selection"), - selectAll: t("schedule.selected-all"), - selectSomeItems: t("schedule.select-some-options"), - }} - labelledBy="Select" - onChange={(value) => { - changeSchedule( - schedule.id, - "byweekday", - value.map((v) => v.value) - ); - }} - /> - -
-
- - - - changeSchedule( - schedule.id, - "bymonth", - values.map((v) => v.value) - ) - } - /> - -
-
- -
-
- setDateValue(schedule.id, target)} - type="datetime-local" - /> -
- {schedule.freq === RRule.YEARLY && ( -
- - changeSchedule(schedule.id, target.id, target.value) - } - name="byweekno" - type="number" - min="0" - max="52" - /> + } + /> + +
- )} -
+
+
+ setDateValue(schedule.id, target)} + type="datetime-local" + tooltip={t('schedule.until-tooltip')} + /> +
+ {schedule.freq === RRule.YEARLY && ( +
+ + changeSchedule(schedule.id, target.id, target.value) + } + name="byweekno" + type="number" + min="0" + max="52" + tooltip={t('schedule.byweekno-tooltip')} + /> +
+ )} +
+ + )}
-
-
-
- {t("schedule.next-occurrences")}: - {getNextOccurrences(schedule.rruleObject, schedule.duration, schedule.count ? Math.min(schedule.count, 5) : 5).map( - (occurrence) => (
- {occurrence.text} - - - {occurrence.end} -
) - )} + {(isRepeatingEvent(schedule) || repeatActivated) && ( +
+
+
+ {t("schedule.next-occurrences")}: + {getNextOccurrences(schedule.rruleObject, schedule.duration, schedule.count ? Math.min(schedule.count, 5) : 5).map( + (occurrence) => (
+ {occurrence.text} + - + {occurrence.end} +
) + )} +
+ + {t('schedule.repetition')}: {schedule.rruleObject.toText()} +
- - {t('schedule.repetition')}: {schedule.rruleObject.toText()} - -
+ )}
diff --git a/src/components/util/tooltip.jsx b/src/components/util/tooltip.jsx new file mode 100644 index 00000000..8c2ecbac --- /dev/null +++ b/src/components/util/tooltip.jsx @@ -0,0 +1,19 @@ +import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"; +import {faQuestionCircle} from "@fortawesome/free-solid-svg-icons"; +import {Tooltip as ReactTooltip} from "react-tooltip"; +import {React} from "react"; + +function Tooltip({ id, content }) { + return <> + + + + + ; +} + +export default Tooltip; diff --git a/src/translations/da/common.json b/src/translations/da/common.json index b7c63ef4..28a19043 100644 --- a/src/translations/da/common.json +++ b/src/translations/da/common.json @@ -789,8 +789,18 @@ "count": "Antal gentagelser", "count-placeholder": "Ubegrænset", "interval": "Interval", - "helptext": "Start/slut definerer længden, tidspunkt på dagen og første mulige dato for gentagelserne.", - "repetition": "RRule" + "dtstart-tooltip": "Start definerer tidspunkt på dagen og første mulige dato for gentagelserne, hvis dette aktiveres.", + "end-tooltip": "Forskellen imellem start og slut definerer længden på en gentagelse.", + "repetition": "RRule", + "enable-repeat": "Gentag planlægning", + "enable-repeat-tooltip": "Når gentagelse aktiveres bestemmer reglerne man vælger, hvornår spillelisten bliver vist.", + "frequency-tooptip": "Hvordan planlægningen skal gentages?", + "interval-tooltip": "Skal der være spring imellem gentagelse? Afhænger af frekvensen. F.eks. hver 3 dag.", + "count-tooltip": "Hvor mange gange skal planlægningen gentages? Tom værdi betyder ubegrænset.", + "tooltip-byweekday": "På hvilke dage skal reglen gælde?", + "tooltip-bymonth": "I hvilke månender skal reglen gælde?", + "tooltip-byweekno": "Hvilket ugenummer skal reglen gælde for?", + "until-tooltip": "Hvornår skal gentagelserne afsluttes? Dette tidspunkt påvirker starttidspunktet på en gentagelse, ikke sluttidspunktet." }, "duration": { "hours": "t.", diff --git a/yarn.lock b/yarn.lock index 0792a1cc..b4095835 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1243,6 +1243,26 @@ minimatch "^3.0.4" strip-json-comments "^3.1.1" +"@floating-ui/core@^1.6.0": + version "1.6.7" + resolved "https://registry.yarnpkg.com/@floating-ui/core/-/core-1.6.7.tgz#7602367795a390ff0662efd1c7ae8ca74e75fb12" + integrity sha512-yDzVT/Lm101nQ5TCVeK65LtdN7Tj4Qpr9RTXJ2vPFLqtLxwOrpoxAHAJI8J3yYWUc40J0BDBheaitK5SJmno2g== + dependencies: + "@floating-ui/utils" "^0.2.7" + +"@floating-ui/dom@^1.6.1": + version "1.6.10" + resolved "https://registry.yarnpkg.com/@floating-ui/dom/-/dom-1.6.10.tgz#b74c32f34a50336c86dcf1f1c845cf3a39e26d6f" + integrity sha512-fskgCFv8J8OamCmyun8MfjB1Olfn+uZKjOKZ0vhYF3gRmEUXcGOjxWL8bBr7i4kIuPZ2KD2S3EUIOxnjC8kl2A== + dependencies: + "@floating-ui/core" "^1.6.0" + "@floating-ui/utils" "^0.2.7" + +"@floating-ui/utils@^0.2.7": + version "0.2.7" + resolved "https://registry.yarnpkg.com/@floating-ui/utils/-/utils-0.2.7.tgz#d0ece53ce99ab5a8e37ebdfe5e32452a2bfc073e" + integrity sha512-X8R8Oj771YRl/w+c1HqAC1szL8zWQRwFvgDwT129k9ACdBoud/+/rX9V0qiMl6LWUdP9voC2nDVZYPMQQsb6eA== + "@foliojs-fork/fontkit@^1.9.1": version "1.9.1" resolved "https://registry.npmjs.org/@foliojs-fork/fontkit/-/fontkit-1.9.1.tgz" @@ -3761,6 +3781,11 @@ class-utils@^0.3.5: isobject "^3.0.0" static-extend "^0.1.1" +classnames@^2.3.0: + version "2.5.1" + resolved "https://registry.yarnpkg.com/classnames/-/classnames-2.5.1.tgz#ba774c614be0f016da105c858e7159eae8e7687b" + integrity sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow== + classnames@^2.3.1: version "2.3.1" resolved "https://registry.npmjs.org/classnames/-/classnames-2.3.1.tgz" @@ -11112,6 +11137,14 @@ react-toastify@^8.1.0: dependencies: clsx "^1.1.1" +react-tooltip@^5.28.0: + version "5.28.0" + resolved "https://registry.yarnpkg.com/react-tooltip/-/react-tooltip-5.28.0.tgz#c7b5343ab2d740a428494a3d8315515af1f26f46" + integrity sha512-R5cO3JPPXk6FRbBHMO0rI9nkUG/JKfalBSQfZedZYzmqaZQgq7GLzF8vcCWx6IhUCKg0yPqJhXIzmIO5ff15xg== + dependencies: + "@floating-ui/dom" "^1.6.1" + classnames "^2.3.0" + react-transition-group@^4.3.0, react-transition-group@^4.4.1: version "4.4.2" resolved "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.2.tgz" From 4d38df73ede23dbbcc5e4c6d7d535a9cc9dee662 Mon Sep 17 00:00:00 2001 From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com> Date: Wed, 14 Aug 2024 09:35:05 +0200 Subject: [PATCH 11/13] 2000: Fixed repeat active checkbox ui flow --- src/components/util/schedule/schedule.jsx | 17 ++++++++++------- src/translations/da/common.json | 3 ++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/components/util/schedule/schedule.jsx b/src/components/util/schedule/schedule.jsx index 1ac62b3b..22748bcd 100644 --- a/src/components/util/schedule/schedule.jsx +++ b/src/components/util/schedule/schedule.jsx @@ -39,7 +39,6 @@ function Schedule({ schedules, onChange }) { const byMonthOptions = getByMonthOptions(t); const [localSchedules, setLocalSchedules] = useState([]); const [durationError, setDurationError] = useState(false); - const [repeatActivated, setRepeatActivated] = useState(false); useEffect(() => { const newSchedules = schedules.map((schedule) => @@ -223,9 +222,9 @@ function Schedule({ schedules, onChange }) { } const toggleRepeat = (schedule) => { - if ((isRepeatingEvent(schedule) || repeatActivated)) { + if ((isRepeatingEvent(schedule) || schedule.repeatActivated)) { // Disable repeating schedule. - setRepeatActivated(false); + changeSchedule(schedule.id, 'repeatActivated', false); changeSchedule(schedule.id, 'duration', 60 * 60); changeSchedule(schedule.id, 'freq', RRule.DAILY); changeSchedule(schedule.id, 'count', 1); @@ -238,7 +237,7 @@ function Schedule({ schedules, onChange }) { changeSchedule(schedule.id, 'byweekno', null); } else { // Activate repeating schedule. - setRepeatActivated(true); + changeSchedule(schedule.id, 'repeatActivated', true); changeSchedule(schedule.id, 'count', null); } } @@ -254,6 +253,10 @@ function Schedule({ schedules, onChange }) { {t("schedule.add-schedule-button-text")} +
+ {t('schedule.helptext')} +
+ {localSchedules && localSchedules.map((schedule, index) => (
@@ -304,13 +307,13 @@ function Schedule({ schedules, onChange }) { onChange={() => toggleRepeat(schedule)} name="enableRepeat" type="checkbox" - value={(isRepeatingEvent(schedule) || repeatActivated)} + value={(isRepeatingEvent(schedule) || schedule.repeatActivated)} label={t('schedule.enable-repeat')} formGroupClasses="d-inline-block mb-2" /> - {(isRepeatingEvent(schedule) || repeatActivated) && ( + {(isRepeatingEvent(schedule) || schedule.repeatActivated) && ( <>
@@ -457,7 +460,7 @@ function Schedule({ schedules, onChange }) { )}
- {(isRepeatingEvent(schedule) || repeatActivated) && ( + {(isRepeatingEvent(schedule) || schedule.repeatActivated) && (
diff --git a/src/translations/da/common.json b/src/translations/da/common.json index 28a19043..a2ca48d0 100644 --- a/src/translations/da/common.json +++ b/src/translations/da/common.json @@ -800,7 +800,8 @@ "tooltip-byweekday": "På hvilke dage skal reglen gælde?", "tooltip-bymonth": "I hvilke månender skal reglen gælde?", "tooltip-byweekno": "Hvilket ugenummer skal reglen gælde for?", - "until-tooltip": "Hvornår skal gentagelserne afsluttes? Dette tidspunkt påvirker starttidspunktet på en gentagelse, ikke sluttidspunktet." + "until-tooltip": "Hvornår skal gentagelserne afsluttes? Dette tidspunkt påvirker starttidspunktet på en gentagelse, ikke sluttidspunktet.", + "helptext": "Når minimum én planlægning er tilføjet, bliver spillelisten kun vist i planlægningsintervallet." }, "duration": { "hours": "t.", From 36f00f456bbd78276a91ff7372a086cc8d343920 Mon Sep 17 00:00:00 2001 From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com> Date: Wed, 14 Aug 2024 10:38:20 +0200 Subject: [PATCH 12/13] 2000: Minor fixes --- src/components/util/schedule/schedule.jsx | 30 +++++++++++++++-------- src/translations/da/common.json | 13 +++++----- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/components/util/schedule/schedule.jsx b/src/components/util/schedule/schedule.jsx index 22748bcd..7e931d4e 100644 --- a/src/components/util/schedule/schedule.jsx +++ b/src/components/util/schedule/schedule.jsx @@ -39,6 +39,7 @@ function Schedule({ schedules, onChange }) { const byMonthOptions = getByMonthOptions(t); const [localSchedules, setLocalSchedules] = useState([]); const [durationError, setDurationError] = useState(false); + const [activatedRepeatIds, setActivatedRepeatIds] = useState({}); useEffect(() => { const newSchedules = schedules.map((schedule) => @@ -209,7 +210,7 @@ function Schedule({ schedules, onChange }) { } const isRepeatingEvent = (schedule) => { - return !(schedule.duration === 60 * 60 && + return !( schedule.freq === RRule.DAILY && schedule.count === 1 && schedule.until === undefined && @@ -221,11 +222,19 @@ function Schedule({ schedules, onChange }) { schedule.byweekno === undefined); } + const displayRepeat = (schedule) => { + return isRepeatingEvent(schedule) || activatedRepeatIds[schedule.id] === true; + } + + const updateActivatedRepeats = (id, value) => { + const updated = {...activatedRepeatIds}; + updated[id] = value; + setActivatedRepeatIds(updated); + } + const toggleRepeat = (schedule) => { - if ((isRepeatingEvent(schedule) || schedule.repeatActivated)) { + if (displayRepeat(schedule)) { // Disable repeating schedule. - changeSchedule(schedule.id, 'repeatActivated', false); - changeSchedule(schedule.id, 'duration', 60 * 60); changeSchedule(schedule.id, 'freq', RRule.DAILY); changeSchedule(schedule.id, 'count', 1); changeSchedule(schedule.id, 'interval', null); @@ -235,10 +244,11 @@ function Schedule({ schedules, onChange }) { changeSchedule(schedule.id, 'byweekday', null); changeSchedule(schedule.id, 'bymonth', null); changeSchedule(schedule.id, 'byweekno', null); + updateActivatedRepeats(schedule.id, false); } else { // Activate repeating schedule. - changeSchedule(schedule.id, 'repeatActivated', true); changeSchedule(schedule.id, 'count', null); + updateActivatedRepeats(schedule.id, true); } } @@ -307,13 +317,13 @@ function Schedule({ schedules, onChange }) { onChange={() => toggleRepeat(schedule)} name="enableRepeat" type="checkbox" - value={(isRepeatingEvent(schedule) || schedule.repeatActivated)} + value={displayRepeat(schedule)} label={t('schedule.enable-repeat')} formGroupClasses="d-inline-block mb-2" /> - {(isRepeatingEvent(schedule) || schedule.repeatActivated) && ( + {displayRepeat(schedule) && ( <>
@@ -367,7 +377,7 @@ function Schedule({ schedules, onChange }) {
- + {t("schedule.bymonth")} - + )}
- {(isRepeatingEvent(schedule) || schedule.repeatActivated) && ( + {displayRepeat(schedule) && (
diff --git a/src/translations/da/common.json b/src/translations/da/common.json index a2ca48d0..406f1720 100644 --- a/src/translations/da/common.json +++ b/src/translations/da/common.json @@ -789,17 +789,18 @@ "count": "Antal gentagelser", "count-placeholder": "Ubegrænset", "interval": "Interval", - "dtstart-tooltip": "Start definerer tidspunkt på dagen og første mulige dato for gentagelserne, hvis dette aktiveres.", - "end-tooltip": "Forskellen imellem start og slut definerer længden på en gentagelse.", "repetition": "RRule", "enable-repeat": "Gentag planlægning", "enable-repeat-tooltip": "Når gentagelse aktiveres bestemmer reglerne man vælger, hvornår spillelisten bliver vist.", - "frequency-tooptip": "Hvordan planlægningen skal gentages?", + "end-tooltip": "Forskellen imellem start og slut definerer længden på en gentagelse.", + "dtstart-tooltip": "Start definerer tidspunkt på dagen og første mulige dato for gentagelserne, hvis dette aktiveres.", + "frequency-tooltip": "Hvordan planlægningen skal gentages?", "interval-tooltip": "Skal der være spring imellem gentagelse? Afhænger af frekvensen. F.eks. hver 3 dag.", "count-tooltip": "Hvor mange gange skal planlægningen gentages? Tom værdi betyder ubegrænset.", - "tooltip-byweekday": "På hvilke dage skal reglen gælde?", - "tooltip-bymonth": "I hvilke månender skal reglen gælde?", - "tooltip-byweekno": "Hvilket ugenummer skal reglen gælde for?", + "bytime-tooltip": "På hvilke dage skal reglen gælde?", + "byweekday-tooltip": "På hvilke dage skal reglen gælde?", + "bymonth-tooltip": "I hvilke månender skal reglen gælde?", + "byweekno-tooltip": "Hvilket ugenummer skal reglen gælde for?", "until-tooltip": "Hvornår skal gentagelserne afsluttes? Dette tidspunkt påvirker starttidspunktet på en gentagelse, ikke sluttidspunktet.", "helptext": "Når minimum én planlægning er tilføjet, bliver spillelisten kun vist i planlægningsintervallet." }, From 149430eaedb2ff1a138336b0dbed84dbe73cddf8 Mon Sep 17 00:00:00 2001 From: Troels Ugilt Jensen <6103205+tuj@users.noreply.github.com> Date: Thu, 15 Aug 2024 13:14:48 +0200 Subject: [PATCH 13/13] 1859: Removed commented out code --- src/components/util/schedule/schedule-util.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/components/util/schedule/schedule-util.js b/src/components/util/schedule/schedule-util.js index 14e6a10c..e5f3fadf 100644 --- a/src/components/util/schedule/schedule-util.js +++ b/src/components/util/schedule/schedule-util.js @@ -160,8 +160,6 @@ const getFreqOptions = (t) => { }, { title: t("schedule.weekly"), value: RRule.WEEKLY, key: "rrule.weekly" }, { title: t("schedule.daily"), value: RRule.DAILY, key: "rrule.daily" }, -// { title: t("schedule.hourly"), value: RRule.HOURLY, key: "rrule.hourly" }, -// { title: t("schedule.minutely"), value: RRule.MINUTELY, key: "rrule.minutely" }, ]; };