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; history?: History;
theme: Theme; theme: Theme;
collectionsTaskList: EteSync.CollectionInfo[]; 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> { class PimMain extends React.PureComponent<PropsType> {

@ -110,7 +110,7 @@ type CollectionRoutesPropsType = RouteComponentProps<{}> & {
componentEdit: any; componentEdit: any;
componentView: any; componentView: any;
items: {[key: string]: PimType}; 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; onItemDelete: (item: PimType, journalUid: string) => void;
onItemCancel: () => void; onItemCancel: () => void;
classes: any; classes: any;
@ -144,6 +144,7 @@ const CollectionRoutes = withStyles(styles)(withRouter(
collections={props.collections} collections={props.collections}
onSave={props.onItemSave} onSave={props.onItemSave}
onCancel={props.onItemCancel} onCancel={props.onItemCancel}
history={props.history}
/> />
</Container> </Container>
)} )}
@ -161,6 +162,7 @@ const CollectionRoutes = withStyles(styles)(withRouter(
onSave={props.onItemSave} onSave={props.onItemSave}
onDelete={props.onItemDelete} onDelete={props.onItemDelete}
onCancel={props.onItemCancel} onCancel={props.onItemCancel}
history={props.history}
/> />
} }
</Container> </Container>
@ -238,11 +240,11 @@ class Pim extends React.PureComponent {
this.onItemSave = this.onItemSave.bind(this); 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); const syncJournal = this.props.syncInfo.get(journalUid);
if (syncJournal === undefined) { if (syncJournal === undefined) {
return; return Promise.reject();
} }
const journal = syncJournal.journal; const journal = syncJournal.journal;
@ -254,7 +256,7 @@ class Pim extends React.PureComponent {
if (last) { if (last) {
prevUid = last.uid; 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[]>) => { .then((entriesAction: Action<EteSync.Entry[]>) => {
last = entriesAction.payload!.slice(-1).pop() as EteSync.Entry; last = entriesAction.payload!.slice(-1).pop() as EteSync.Entry;
@ -263,13 +265,10 @@ class Pim extends React.PureComponent {
prevUid = last.uid; prevUid = last.uid;
} }
const saveEvent = store.dispatch( return store.dispatch(
addJournalEntry( addJournalEntry(
this.props.etesync, this.props.userInfo, journal, this.props.etesync, this.props.userInfo, journal,
prevUid, action, item.toIcal())); 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 { ContactType } from '../pim-types';
import { History } from 'history';
const telTypes = [ const telTypes = [
{ type: 'Home' }, { type: 'Home' },
{ type: 'Work' }, { type: 'Work' },
@ -48,7 +50,7 @@ const imppTypes = [
]; ];
const TypeSelector = (props: any) => { const TypeSelector = (props: any) => {
const types = props.types as Array<{type: string}>; const types = props.types as Array<{ type: string }>;
return ( return (
<Select <Select
@ -77,7 +79,7 @@ interface ValueTypeComponentProps {
type?: string; type?: string;
style?: object; style?: object;
types: Array<{type: string}>; types: Array<{ type: string }>;
name: string; name: string;
placeholder: string; placeholder: string;
value: ValueType; value: ValueType;
@ -116,9 +118,10 @@ interface PropsType {
collections: EteSync.CollectionInfo[]; collections: EteSync.CollectionInfo[];
initialCollection?: string; initialCollection?: string;
item?: ContactType; 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; onDelete: (contact: ContactType, journalUid: string) => void;
onCancel: () => void; onCancel: () => void;
history: History<any>;
} }
class ContactEdit extends React.PureComponent<PropsType> { class ContactEdit extends React.PureComponent<PropsType> {
@ -312,7 +315,10 @@ class ContactEdit extends React.PureComponent<PropsType> {
setProperty('title', this.state.title); setProperty('title', this.state.title);
setProperty('note', this.state.note); 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() { public onDeleteRequest() {

@ -38,15 +38,17 @@ import { getCurrentTimezone } from '../helpers';
import { EventType, timezoneLoadFromName } from '../pim-types'; import { EventType, timezoneLoadFromName } from '../pim-types';
import RRule, { RRuleOptions } from '../widgets/RRule'; import RRule, { RRuleOptions } from '../widgets/RRule';
import { History } from 'history';
interface PropsType { interface PropsType {
collections: EteSync.CollectionInfo[]; collections: EteSync.CollectionInfo[];
initialCollection?: string; initialCollection?: string;
item?: EventType; 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; onDelete: (event: EventType, journalUid: string) => void;
onCancel: () => void; onCancel: () => void;
location: Location; location: Location;
history: History;
} }
class EventEdit extends React.PureComponent<PropsType> { class EventEdit extends React.PureComponent<PropsType> {
@ -234,7 +236,10 @@ class EventEdit extends React.PureComponent<PropsType> {
event.component.updatePropertyWithValue('last-modified', ICAL.Time.now()); 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() { public onDeleteRequest() {

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

@ -26,7 +26,7 @@ interface PropsType {
entries: TaskType[]; entries: TaskType[];
collections: EteSync.CollectionInfo[]; collections: EteSync.CollectionInfo[];
onItemClick: (entry: TaskType) => void; 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) { export default React.memo(function TaskList(props: PropsType) {

Loading…
Cancel
Save