Przeglądaj źródła

event api method mutations should always succeed

Adam Shaw 7 lat temu
rodzic
commit
d6512788de
3 zmienionych plików z 22 dodań i 6 usunięć
  1. 2 1
      src/api/EventApi.ts
  2. 19 4
      src/reducers/eventStore.ts
  3. 1 1
      src/reducers/types.ts

+ 2 - 1
src/api/EventApi.ts

@@ -210,7 +210,8 @@ export default class EventApi implements EventTuple {
       this.calendar.dispatch({
         type: 'MUTATE_EVENTS',
         instanceId: instance.instanceId,
-        mutation
+        mutation,
+        fromApi: true
       })
 
       let eventStore = this.calendar.state.eventStore

+ 19 - 4
src/reducers/eventStore.ts

@@ -17,6 +17,7 @@ import { EventSourceHash, EventSource } from '../structs/event-source'
 import { DateRange } from '../datelib/date-range'
 import { DateProfile } from '../DateProfileGenerator'
 import { DateEnv } from '../datelib/env'
+import { EventUiHash } from '../component/event-ui'
 
 
 export default function(eventStore: EventStore, action: Action, eventSources: EventSourceHash, dateProfile: DateProfile, calendar: Calendar): EventStore {
@@ -54,7 +55,7 @@ export default function(eventStore: EventStore, action: Action, eventSources: Ev
       return rezoneDates(eventStore, action.oldDateEnv, calendar.dateEnv)
 
     case 'MUTATE_EVENTS':
-      return applyMutationToRelated(eventStore, action.instanceId, action.mutation, calendar)
+      return applyMutationToRelated(eventStore, action.instanceId, action.mutation, action.fromApi, calendar)
 
     case 'REMOVE_EVENT_INSTANCES':
       return excludeInstances(eventStore, action.instances)
@@ -155,10 +156,24 @@ function rezoneDates(eventStore: EventStore, oldDateEnv: DateEnv, newDateEnv: Da
 }
 
 
-function applyMutationToRelated(eventStore: EventStore, instanceId: string, mutation: EventMutation, calendar: Calendar): EventStore {
+function applyMutationToRelated(eventStore: EventStore, instanceId: string, mutation: EventMutation, fromApi: boolean, calendar: Calendar): EventStore {
   let relevant = getRelevantEvents(eventStore, instanceId)
-
-  relevant = applyMutationToEventStore(relevant, calendar.eventUiBases, mutation, calendar)
+  let eventConfigBase = fromApi ?
+    { '': { // HACK. always allow API to mutate events
+      startEditable: true,
+      durationEditable: true,
+      constraints: [],
+      overlap: null,
+      allows: [],
+      backgroundColor: '',
+      borderColor: '',
+      textColor: '',
+      classNames: []
+    } } as EventUiHash:
+    calendar.eventUiBases
+
+
+  relevant = applyMutationToEventStore(relevant, eventConfigBase, mutation, calendar)
 
   return mergeEventStores(eventStore, relevant)
 }

+ 1 - 1
src/reducers/types.ts

@@ -57,7 +57,7 @@ export type Action =
 
   { type: 'ADD_EVENTS', eventStore: EventStore } |
   { type: 'MERGE_EVENTS', eventStore: EventStore } |
-  { type: 'MUTATE_EVENTS', instanceId: string, mutation: EventMutation } |
+  { type: 'MUTATE_EVENTS', instanceId: string, mutation: EventMutation, fromApi?: boolean } |
   { type: 'REMOVE_EVENT_DEF', defId: string } |
   { type: 'REMOVE_EVENT_INSTANCES', instances: EventInstanceHash } |
   { type: 'REMOVE_ALL_EVENTS' } |