Pim: changes how onItemSave handles post-save action

onItemSave used to automatically "go back" after saving. New behavior is
onItemSave returns a promise that resolves to the history object. This object
can then be used to go back if needed. This allows for more granular control
over post-save actions.
master
Andrew P Maney 5 years ago committed by Tom Hacohen
parent b4ef6e641d
commit 632ec9cacf

@ -40,7 +40,7 @@ interface PropsType {
history?: History;
theme: Theme;
collectionsTaskList: EteSync.CollectionInfo[];
onItemSave: (item: PimType, journalUid: string, originalItem?: PimType) => void;
onItemSave: (item: PimType, journalUid: string, originalItem?: PimType) => Promise<void>;
}
class PimMain extends React.PureComponent<PropsType> {

@ -110,7 +110,7 @@ type CollectionRoutesPropsType = RouteComponentProps<{}> & {
componentEdit: any;
componentView: any;
items: {[key: string]: PimType};
onItemSave: (item: PimType, journalUid: string, originalItem?: PimType) => void;
onItemSave: (item: PimType, journalUid: string, originalItem?: PimType) => Promise<void>;
onItemDelete: (item: PimType, journalUid: string) => void;
onItemCancel: () => void;
classes: any;
@ -144,6 +144,7 @@ const CollectionRoutes = withStyles(styles)(withRouter(
collections={props.collections}
onSave={props.onItemSave}
onCancel={props.onItemCancel}
history={props.history}
/>
</Container>
)}
@ -161,6 +162,7 @@ const CollectionRoutes = withStyles(styles)(withRouter(
onSave={props.onItemSave}
onDelete={props.onItemDelete}
onCancel={props.onItemCancel}
history={props.history}
/>
}
</Container>
@ -238,11 +240,11 @@ class Pim extends React.PureComponent {
this.onItemSave = this.onItemSave.bind(this);
}
public onItemSave(item: PimType, journalUid: string, originalEvent?: PimType) {
public onItemSave(item: PimType, journalUid: string, originalEvent?: PimType): Promise<void> {
const syncJournal = this.props.syncInfo.get(journalUid);
if (syncJournal === undefined) {
return;
return Promise.reject();
}
const journal = syncJournal.journal;
@ -254,7 +256,7 @@ class Pim extends React.PureComponent {
if (last) {
prevUid = last.uid;
}
store.dispatch<any>(fetchEntries(this.props.etesync, journal.uid, prevUid))
return store.dispatch<any>(fetchEntries(this.props.etesync, journal.uid, prevUid))
.then((entriesAction: Action<EteSync.Entry[]>) => {
last = entriesAction.payload!.slice(-1).pop() as EteSync.Entry;
@ -263,13 +265,10 @@ class Pim extends React.PureComponent {
prevUid = last.uid;
}
const saveEvent = store.dispatch(
return store.dispatch(
addJournalEntry(
this.props.etesync, this.props.userInfo, journal,
prevUid, action, item.toIcal()));
(saveEvent as any).then(() => {
this.props.history.goBack();
});
});
}

@ -26,6 +26,8 @@ import * as EteSync from 'etesync';
import { ContactType } from '../pim-types';
import { History } from 'history';
const telTypes = [
{ type: 'Home' },
{ type: 'Work' },
@ -48,7 +50,7 @@ const imppTypes = [
];
const TypeSelector = (props: any) => {
const types = props.types as Array<{type: string}>;
const types = props.types as Array<{ type: string }>;
return (
<Select
@ -77,7 +79,7 @@ interface ValueTypeComponentProps {
type?: string;
style?: object;
types: Array<{type: string}>;
types: Array<{ type: string }>;
name: string;
placeholder: string;
value: ValueType;
@ -116,9 +118,10 @@ interface PropsType {
collections: EteSync.CollectionInfo[];
initialCollection?: string;
item?: ContactType;
onSave: (contact: ContactType, journalUid: string, originalContact?: ContactType) => void;
onSave: (contact: ContactType, journalUid: string, originalContact?: ContactType) => Promise<void>;
onDelete: (contact: ContactType, journalUid: string) => void;
onCancel: () => void;
history: History<any>;
}
class ContactEdit extends React.PureComponent<PropsType> {
@ -271,7 +274,7 @@ class ContactEdit extends React.PureComponent<PropsType> {
this.props.item.clone()
:
new ContactType(new ICAL.Component(['vcard', [], []]))
;
;
const comp = contact.comp;
comp.updatePropertyWithValue('prodid', '-//iCal.js EteSync Web');
@ -312,7 +315,10 @@ class ContactEdit extends React.PureComponent<PropsType> {
setProperty('title', this.state.title);
setProperty('note', this.state.note);
this.props.onSave(contact, this.state.journalUid, this.props.item);
this.props.onSave(contact, this.state.journalUid, this.props.item)
.then(() => {
this.props.history.goBack();
});
}
public onDeleteRequest() {
@ -526,7 +532,7 @@ class ContactEdit extends React.PureComponent<PropsType> {
onOk={() => this.props.onDelete(this.props.item!, this.props.initialCollection!)}
onCancel={() => this.setState({ showDeleteDialog: false })}
>
Are you sure you would like to delete this contact?
Are you sure you would like to delete this contact?
</ConfirmationDialog>
</React.Fragment>
);

@ -38,15 +38,17 @@ import { getCurrentTimezone } from '../helpers';
import { EventType, timezoneLoadFromName } from '../pim-types';
import RRule, { RRuleOptions } from '../widgets/RRule';
import { History } from 'history';
interface PropsType {
collections: EteSync.CollectionInfo[];
initialCollection?: string;
item?: EventType;
onSave: (event: EventType, journalUid: string, originalEvent?: EventType) => void;
onSave: (event: EventType, journalUid: string, originalEvent?: EventType) => Promise<void>;
onDelete: (event: EventType, journalUid: string) => void;
onCancel: () => void;
location: Location;
history: History;
}
class EventEdit extends React.PureComponent<PropsType> {
@ -213,7 +215,7 @@ class EventEdit extends React.PureComponent<PropsType> {
this.props.item.clone()
:
new EventType()
;
;
event.uid = this.state.uid;
event.summary = this.state.title;
@ -234,7 +236,10 @@ class EventEdit extends React.PureComponent<PropsType> {
event.component.updatePropertyWithValue('last-modified', ICAL.Time.now());
this.props.onSave(event, this.state.journalUid, this.props.item);
this.props.onSave(event, this.state.journalUid, this.props.item)
.then(() => {
this.props.history.goBack();
});
}
public onDeleteRequest() {

@ -37,14 +37,17 @@ import { getCurrentTimezone } from '../../helpers';
import { TaskType, TaskStatusType, timezoneLoadFromName } from '../../pim-types';
import { History } from 'history';
interface PropsType {
collections: EteSync.CollectionInfo[];
initialCollection?: string;
item?: TaskType;
onSave: (item: TaskType, journalUid: string, originalItem?: TaskType) => void;
onSave: (item: TaskType, journalUid: string, originalItem?: TaskType) => Promise<void>;
onDelete: (item: TaskType, journalUid: string) => void;
onCancel: () => void;
location: Location;
history: History<any>;
}
class TaskEdit extends React.PureComponent<PropsType> {
@ -205,7 +208,10 @@ class TaskEdit extends React.PureComponent<PropsType> {
event.component.updatePropertyWithValue('last-modified', ICAL.Time.now());
this.props.onSave(event, this.state.journalUid, this.props.item);
this.props.onSave(event, this.state.journalUid, this.props.item)
.then(() => {
this.props.history.goBack();
});
}
public onDeleteRequest() {

@ -26,7 +26,7 @@ interface PropsType {
entries: TaskType[];
collections: EteSync.CollectionInfo[];
onItemClick: (entry: TaskType) => void;
onItemSave: (item: PimType, journalUid: string, originalItem?: PimType) => void;
onItemSave: (item: PimType, journalUid: string, originalItem?: PimType) => Promise<void>;
}
export default React.memo(function TaskList(props: PropsType) {

Loading…
Cancel
Save