Skip to content

Commit

Permalink
Sort calendar items alphabetically, add a no-calendar group to handle…
Browse files Browse the repository at this point in the history
… templates without calendars field data (#1914)
  • Loading branch information
thecalcc authored Feb 13, 2024
1 parent 0b747b4 commit 3300dbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class PlanningTemplatesModal extends React.Component<IProps, ISta
const {gettext} = superdeskApi.localization;
const {closeModal, createEventFromTemplate, calendars, eventTemplates} = this.props;
const allCalendarsLabel = gettext('All Calendars');
const calendarDropdownItems = [];
const calendarDropdownItems: Array<{label: string; onSelect: () => void;}> = [];
const activeCalendarName = this.props.calendars
.find((cal) => cal.qcode === this.state.activeCalendarFilter)?.name;
const dropdownLabel = this.state.activeCalendarFilter
Expand Down Expand Up @@ -85,7 +85,7 @@ export default class PlanningTemplatesModal extends React.Component<IProps, ISta
maxHeight={300}
append
zIndex={2001}
items={calendarDropdownItems}
items={calendarDropdownItems.sort((cal1, cal2) => cal1.label.localeCompare(cal2.label))}
>
{dropdownLabel}
</Dropdown>
Expand Down
11 changes: 10 additions & 1 deletion client/components/PlanningTemplatesModal/TemplatesListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,17 @@ export const TemplatesListView: React.FC<ITemplatesListViewProps> = ({
.map((_calendar) => ({
calendar: _calendar,
templates: searchQueryTemplateMatches
.filter((template) => template.data.calendars.find(({qcode}) => qcode === _calendar.qcode)),
.filter((template) => (template.data.calendars ?? []).find(({qcode}) => qcode === _calendar.qcode)),
}))
.concat({
calendar: {
name: gettext('No calendar'),
qcode: 'no-calendar',
},

// Get the templates without calendar
templates: searchQueryTemplateMatches.filter((template) => (template.data.calendars?.length ?? 0) < 1)
})
.filter((group) => activeCalendarFilter
? group.calendar.qcode === activeCalendarFilter
: group.templates.length > 0
Expand Down

0 comments on commit 3300dbe

Please sign in to comment.