Skip to content

Commit

Permalink
Various improvements, UI WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc committed Feb 8, 2024
1 parent baf92d2 commit c806755
Show file tree
Hide file tree
Showing 5 changed files with 550 additions and 496 deletions.
57 changes: 35 additions & 22 deletions client/components/Main/CreateNewSubnavDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as actions from '../../actions';
import {eventTemplates} from '../../selectors/events';
import {Dropdown, IDropdownItem} from '../UI/SubNav';
import {showModal} from '@superdesk/common';
import PlanningTemplatesModal from '../../components/PlanningTemplatesModal';
import PlanningTemplatesModal from '../PlanningTemplatesModal/PlanningTemplatesModal';

interface IProps {
addEvent(): void;
Expand All @@ -21,6 +21,8 @@ interface IProps {
calendars: Array<ICalendar>;
}

const MORE_TEMPLATES_THRESHOLD = 5;

class CreateNewSubnavDropdownFn extends React.PureComponent<IProps> {
render() {
const {gettext} = superdeskApi.localization;
Expand All @@ -46,9 +48,17 @@ class CreateNewSubnavDropdownFn extends React.PureComponent<IProps> {
id: 'create_event',
});

this.props.eventTemplates
.sort((templ1, templ2) => templ1.template_name.localeCompare(templ2.template_name))
.slice(0, 5)
/**
* Sort the templates by their name.
*/
const sortedTemplates = this.props.eventTemplates
.sort((templ1, templ2) => templ1.template_name.localeCompare(templ2.template_name));

/**
* Take the first @MORE_TEMPLATES_THRESHOLD templates and display them in the dropdown.
*/
sortedTemplates
.slice(0, MORE_TEMPLATES_THRESHOLD)
.forEach((template) => {
items.push({
label: template.template_name,
Expand All @@ -59,24 +69,27 @@ class CreateNewSubnavDropdownFn extends React.PureComponent<IProps> {
});
});

items.push({
label: gettext('More templates...'),
icon: 'icon-event icon--blue',
group: gettext('From template'),
action: () => {
showModal(({closeModal}) => (
<PlanningTemplatesModal
createEventFromTemplate={createEventFromTemplate}
closeModal={closeModal}
calendars={this.props.calendars}
eventTemplates={this.props.eventTemplates
.sort((templ1, templ2) => templ1.template_name.localeCompare(templ2.template_name))
}
/>
));
},
id: 'more_templates',
});
/**
* If there's no more than @MORE_TEMPLATES_THRESHOLD there's no need to show the button for more templates.
*/
if (sortedTemplates.length > MORE_TEMPLATES_THRESHOLD) {
items.push({
label: gettext('More templates...'),
icon: 'icon-event icon--blue',
group: gettext('From template'),
action: () => {
showModal(({closeModal}) => (
<PlanningTemplatesModal
createEventFromTemplate={createEventFromTemplate}
closeModal={closeModal}
calendars={this.props.calendars}
eventTemplates={sortedTemplates}
/>
));
},
id: 'more_templates',
});
}
}

return items.length === 0 ? null : (
Expand Down
143 changes: 0 additions & 143 deletions client/components/PlanningTemplatesModal.tsx

This file was deleted.

109 changes: 109 additions & 0 deletions client/components/PlanningTemplatesModal/PlanningTemplatesModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import {ICalendar, IEventTemplate} from '../../interfaces';
import React from 'react';
import {SearchBar, Modal, TreeSelect} from 'superdesk-ui-framework/react';
import {superdeskApi} from '../../superdeskApi';
import {TemplatesListView} from './TemplatesListView';

interface IProps {
closeModal: () => void;
calendars: Array<ICalendar>;
eventTemplates: Array<IEventTemplate>;
createEventFromTemplate(template: IEventTemplate): void;
}

interface IState {
activeCalendarFilter?: string;
searchQuery: string;
}

export default class PlanningTemplatesModal extends React.Component<IProps, IState> {
constructor(props) {
super(props);

this.state = {
activeCalendarFilter: null,
searchQuery: '',
};
}

render(): React.ReactNode {
const {gettext} = superdeskApi.localization;
const {closeModal, createEventFromTemplate, calendars, eventTemplates} = this.props;

return (
<Modal
headerTemplate={gettext('Planning templates')}
visible
contentPadding="medium"
contentBg="medium"
size="medium"
onHide={closeModal}
>
<div className="modal__sticky-header">
<SearchBar
value={this.state.searchQuery}
onSubmit={(value: string) => {
this.setState({
searchQuery: value,
});
}}
placeholder={gettext('Search templates')}
boxed
>
<div style={{width: 200}}>
<TreeSelect
fullWidth
zIndex={3000}
value={this.state.activeCalendarFilter
? [this.props.calendars
.find(({qcode}) => this.state.activeCalendarFilter === qcode)]
: []
}
kind="synchronous"
labelHidden
inlineLabel
getOptions={() => calendars.map((calendar) => ({value: calendar}))}
getLabel={(item) => item.name}
getId={(item) => item.qcode}
placeholder={(
<div
style={{
height: '100%',
flexGrow: 1,
whiteSpace: 'nowrap',
alignContent: 'center',
}}
>
{gettext('All Calendars')}
</div>
)}
optionTemplate={(item: any) => <div>{item.name}</div>}
valueTemplate={(item: any, Wrapper) => (
<div style={{height: '100%', flexGrow: 1, whiteSpace: 'nowrap'}}>
<Wrapper>
<span>{gettext('Calendar')}: {item.name}</span>
</Wrapper>
</div>
)}
onChange={([value]) => {
this.setState({
activeCalendarFilter: value?.qcode,
searchQuery: '',
});
}}
/>
</div>
</SearchBar>
<TemplatesListView
calendars={calendars}
createEventFromTemplate={createEventFromTemplate}
eventTemplates={eventTemplates}
searchQuery={this.state.searchQuery}
activeCalendarFilter={this.state.activeCalendarFilter}
closeModal={closeModal}
/>
</div>
</Modal>
);
}
}
Loading

0 comments on commit c806755

Please sign in to comment.