Skip to content

Commit

Permalink
Adds info banner for unsupported rules
Browse files Browse the repository at this point in the history
Some rules aren't supported during event creation/editing.
This commit adds an info banner warning about losing rules if user edits
and event with unsupported rules.

Co-authored-by: André Dias <[email protected]>
  • Loading branch information
2 people authored and tutao-mac committed Feb 3, 2025
1 parent 9073423 commit ad42294
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
incrementByRepeatPeriod,
} from "../../../../common/calendar/date/CalendarUtils.js"
import { assertNotNull, clone, filterInt, incrementDate, noOp, TIMESTAMP_ZERO_YEAR } from "@tutao/tutanota-utils"
import { CalendarEvent, CalendarRepeatRule } from "../../../../common/api/entities/tutanota/TypeRefs.js"
import { AdvancedRepeatRule, CalendarEvent, CalendarRepeatRule } from "../../../../common/api/entities/tutanota/TypeRefs.js"
import { Stripped } from "../../../../common/api/common/utils/EntityUtils.js"
import { EndType, RepeatPeriod } from "../../../../common/api/common/TutanotaConstants.js"
import { createDateWrapper, createRepeatRule, RepeatRule } from "../../../../common/api/entities/sys/TypeRefs.js"
Expand Down Expand Up @@ -256,6 +256,10 @@ export class CalendarEventWhenModel {
return this.repeatRule ? (this.repeatRule.frequency as RepeatPeriod) : null
}

get advancedRules(): AdvancedRepeatRule[] {
return this.repeatRule?.advancedRules ?? []
}

set repeatPeriod(repeatPeriod: RepeatPeriod | null) {
if (this.repeatRule?.frequency === repeatPeriod) {
// repeat null => we will return if repeatPeriod is null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import stream from "mithril/stream"
import { Divider } from "../../../../common/gui/Divider.js"
import { theme } from "../../../../common/gui/theme.js"
import { isApp } from "../../../../common/api/common/Env.js"
import { ByRule } from "../../../../common/calendar/import/ImportExportUtils.js"
import { BannerType, InfoBanner, InfoBannerAttrs } from "../../../../common/gui/base/InfoBanner.js"
import { Icons } from "../../../../common/gui/base/icons/Icons.js"

export type RepeatRuleEditorAttrs = {
model: CalendarEventWhenModel
Expand All @@ -30,7 +33,7 @@ export class RepeatRuleEditor implements Component<RepeatRuleEditorAttrs> {
private repeatInterval: number = 0
private intervalOptions: stream<IntervalOption[]> = stream([])
private intervalExpanded: boolean = false

private hasUnsupportedRules: boolean = false
private numberValues: IntervalOption[] = createIntervalValues()

private occurrencesOptions: stream<IntervalOption[]> = stream([])
Expand All @@ -47,6 +50,11 @@ export class RepeatRuleEditor implements Component<RepeatRuleEditorAttrs> {

this.repeatInterval = attrs.model.repeatInterval
this.repeatOccurrences = attrs.model.repeatEndOccurrences
this.hasUnsupportedRules = attrs.model.advancedRules.some((rule) => {
const isValidRule =
(attrs.model.repeatPeriod === RepeatPeriod.WEEKLY || attrs.model.repeatPeriod === RepeatPeriod.MONTHLY) && rule.ruleType === ByRule.BYDAY
return !isValidRule
})
}

private getRepeatType(period: RepeatPeriod, interval: number, endTime: EndType) {
Expand All @@ -57,6 +65,15 @@ export class RepeatRuleEditor implements Component<RepeatRuleEditorAttrs> {
return period
}

private renderUnsupportedAdvancedRulesWarning(): Children {
return m(InfoBanner, {
message: () => m(".small.selectable", lang.get("unsupportedAdvancedRules_msg")),
icon: Icons.Sync,
type: BannerType.Info,
buttons: [],
} satisfies InfoBannerAttrs)
}

view({ attrs }: Vnode<RepeatRuleEditorAttrs>): Children {
const customRuleOptions = customFrequenciesOptions.map((option) => ({
...option,
Expand All @@ -72,6 +89,7 @@ export class RepeatRuleEditor implements Component<RepeatRuleEditorAttrs> {
},
},
[
this.hasUnsupportedRules ? this.renderUnsupportedAdvancedRulesWarning() : null,
m(
Card,
{
Expand Down
29 changes: 29 additions & 0 deletions src/common/misc/TranslationKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1889,6 +1889,35 @@ export type TranslationKeyType =
| "yourMessage_label"
| "you_label"
| "emptyString_msg"
| "monday_label"
| "tuesday_label"
| "wednesday_label"
| "thursday_label"
| "friday_label"
| "saturday_label"
| "sunday_label"
| "january_label"
| "february_label"
| "march_label"
| "april_label"
| "may_label"
| "june_label"
| "july_label"
| "august_label"
| "september_label"
| "october_label"
| "november_label"
| "december_label"
| "firstOfPeriod_label"
| "lastOfPeriod_label"
| "onNDayOfPeriod_label"
| "inMonths_label"
| "onDays_label"
| "inWeek_label"
| "afterStartOfPeriod_label"
| "and_label"
| "beforeEndOfPeriod_label"
| "unsupportedAdvancedRules_msg"
// Put in temporarily, will be removed soon
| "localAdminGroup_label"
| "assignAdminRightsToLocallyAdministratedUserError_msg"
Expand Down
31 changes: 31 additions & 0 deletions src/mail-app/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,37 @@ export default {
"yourFolders_action": "YOUR FOLDERS",
"yourMessage_label": "Your message",
"you_label": "You",
"monday_label": "Monday",
"tuesday_label": "Tuesday",
"wednesday_label": "Wednesday",
"thursday_label": "Thursday",
"friday_label": "Friday",
"saturday_label": "Saturday",
"sunday_label": "Sunday",
"january_label": "January",
"february_label": "February",
"march_label": "March",
"april_label": "April",
"may_label": "May",
"june_label": "June",
"july_label": "July",
"august_label": "August",
"september_label": "September",
"october_label": "October",
"november_label": "November",
"december_label": "December",
"firstOfPeriod_label": "First {day} of the {period}",
"lastOfPeriod_label": "Last {day} of the {period}",
"onNDayOfPeriod_label": "on {day} of {period}",
"theYear_label": "the Year",
"theMonth_label": "the Month",
"inMonths_label": "in {months}",
"onDays_label": "on {days}",
"inWeek_label": "in weeks {weeks}",
"afterStartOfPeriod_label": "{days} occurrence after start of the {period}",
"and_label": "and",
"beforeEndOfPeriod_label": "{days} occurrence before end of the {period}",
"unsupportedAdvancedRules_msg": "This event contains one or more unsupported Advanced Recurrence Rules, any changes will result in the loss of these rules",
// Put in temporarily, will be removed soon
"localAdminGroup_label": "Local admin group",
"assignAdminRightsToLocallyAdministratedUserError_msg": "You can't assign global admin rights to a locally administrated user.",
Expand Down

0 comments on commit ad42294

Please sign in to comment.