Fork me on GitHub
#fulcro
<
2019-04-08
>
exit215:04:19

Does anyone here know why the values (from the server), that I am using as form fields are being removed from the data when I do add-form-config*? Once I edit the field they populate, but the original values (and the key itself) are gone.

exit215:04:31

(defmutation edit-existing-booking
  [{:keys [booking-id]}]
  (action [{:keys [state]}]
          (swap! state
                 (fn [s]
                   (-> s
                       (fs/add-form-config* BookingForm [:booking/by-id booking-id])
                       (fs/entity->pristine* [:booking/by-id booking-id])
                       (fs/mark-complete* [:booking/by-id booking-id])
                       (update-in [:booking/by-id booking-id] assoc :_id booking-id))))))

exit215:04:52

I ended up having to add the _id back in, so my ident could find it - it was also missing

exit215:04:59

Could it be a lack of initial-state or something?

tony.kay15:04:49

@njj not ringing any bells. add-form-config makes a form config based on the entity, it doesn’t touch it. Same with mark-complete and entity->pristine…all of them read it

tony.kay15:04:09

is it in your query?

tony.kay15:04:17

is the server returning it?

tony.kay15:04:45

the server not returning it is the only condition I can think of for it being removed (merge removes fields that were queried but not returned)

exit215:04:36

Yeah, the response is showing under :booking/by-id {"some-id-etc…": {}}, which has tons of fields but for some reason the ones I’m defining as a form field are missing (or seem to have been removed)

exit215:04:16

As you can see in the mutation above, I had to end up adding the booking-id back because it was being removed too

tony.kay15:04:06

The only logic in Fulcro itself that removes things it the mark/sweep merge. If you query if :id and the server does not return it, then Fulcro will remove it from state (since you asked for it and the server just indicated it didn’t exist). Any other removal (or unexpected removal like this) is most likely a bug in your logic. Check your server response.

exit219:04:53

@U0CKQ19AQ This is the entire mutation:

exit219:04:56

(defmethod m/mutation 'update-booking/fetch-booking [{:keys [state reconciler] :as env} _ {:keys [booking-id]}]
  {:remote (m/remote-load env)
   :action (fn []
             (m/load-this! env [:booking] {:booking-id booking-id})
             (swap! state
                    (fn [s]
                      (-> s
                          (fs/add-form-config* BookingForm [:booking/by-id booking-id])
                          (fs/entity->pristine* [:booking/by-id booking-id])
                          (fs/mark-complete* [:booking/by-id booking-id])))))})

tony.kay19:04:35

what is load-this!?

tony.kay19:04:33

I would suggest using load-action, and turn OFF the load marker

tony.kay19:04:05

load markers may be what is getting you…in the latest versions of Fulcro if you use the new client constructor loads default to not having load markers…that is almost certainly what is getting you

exit219:04:59

load-this! is an abstraction made by the previous author, it wraps df/load-field-action, we use it to represent an api-read on the backend

tony.kay19:04:06

make sure load markers are off

exit219:04:33

ok, I’ll give that a try

exit219:04:47

(defn load-this!
  [{:keys [state component ref] :as env} field params & vargs]
  {:pre [(or (vector? params) (map? params) (fn? params)) (util/ident? ref)
         (or (keyword? field) (vector? field))]}

  (doseq [f (if (vector? field) field [field])]
    (apply df/load-field-action
           state component ref f
           (apply concat
                  (merge {:marker false}
                         (dissoc vargs :params)
                         {:params
                          {f (cond
                               (fn? params) (params (get-in @state ref))
                               (vector? params) (-> (get-in @state ref)
                                                    (select-keys (filter keyword? params)))
                               (map? params) params)}}))))
  env)

tony.kay19:04:43

unfortunately I have no further ideas. Use inspect to see what query it is sending, and what response it is getting

exit220:04:02

ok I gave load-action a shot, still seems to be removing the keys defined in form-fields from my data so strange

exit220:04:05

(defmethod m/mutation 'update-booking/fetch-booking [{:keys [state reconciler] :as env} _ {:keys [booking-id]}]
  {:remote (m/remote-load env)
   :action (fn []
             (m/load-this! env [:booking] {:booking-id booking-id})
             (df/load-action env [:booking/by-id booking-id] BookingForm {:marker false
                                                                          :params {:booking-id booking-id}
                                                                          :post-mutation `edit-existing-booking
                                                                          :post-mutation-params {:booking-id booking-id}}))})

exit220:04:08

same as before really

exit220:04:17

I think I’m close, but can’t seem to figure this one out

tony.kay21:04:26

why run both??? If the first is messing it up, aren’t you runnign the risk it still will?

exit221:04:10

Oh so you’re saying use load-action do trigger the remote?

exit221:04:15

And remove the first

exit221:04:19

lemme give that a go

exit218:04:41

@U0CKQ19AQ I got this working, thanks man!

tony.kay18:04:35

good to hear…what was it?

exit216:04:36

I know the response has it, maybe it something thats not lining up with the query and the data so it thinks its not there and it removes it