From 7b22e0e76bfe9ecd2233d945134ed60a69984ea3 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 14 Jan 2020 22:40:07 +0200 Subject: [PATCH] RRule: move filtering of empty values to inside the widget. --- src/components/EventEdit.tsx | 11 +---------- src/widgets/RRule.tsx | 10 +++++++++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/components/EventEdit.tsx b/src/components/EventEdit.tsx index 8f55398..bd3c6d8 100644 --- a/src/components/EventEdit.tsx +++ b/src/components/EventEdit.tsx @@ -220,16 +220,7 @@ class EventEdit extends React.PureComponent { } } if (this.state.rrule) { - const rruleData: ICAL.RecurData = {}; - for (const key of Object.keys(this.state.rrule)) { - const value = this.state.rrule[key]; - if ((value === undefined) || (value?.length === 0)) { - continue; - } - - rruleData[key] = value; - } - event.component.updatePropertyWithValue('rrule', new ICAL.Recur(rruleData)); + event.component.updatePropertyWithValue('rrule', new ICAL.Recur(this.state.rrule!)); } event.component.updatePropertyWithValue('last-modified', ICAL.Time.now()); diff --git a/src/widgets/RRule.tsx b/src/widgets/RRule.tsx index 1f95552..e532400 100644 --- a/src/widgets/RRule.tsx +++ b/src/widgets/RRule.tsx @@ -80,7 +80,15 @@ interface PropsType { export default function RRule(props: PropsType) { const options = props.rrule; function updateRule(newOptions: Partial): void { - const updatedOptions = { ...options, ...newOptions }; + const updatedOptions: RRuleOptions = { ...options, ...newOptions }; + + for (const key of Object.keys(updatedOptions)) { + const value = updatedOptions[key]; + if ((value === undefined) || (value?.length === 0)) { + delete updatedOptions[key]; + continue; + } + } props.onChange(updatedOptions); } function getEnds(): Ends {