 (defonce app-state 
   (atom {:ready? false
          :deployments {}
-         :deployment {:jobs []
+         :deployment {:tracking-id nil
+                      :jobs []
                       :selected-job nil
-                      :entries []}}))
+                      :message-id-max nil
+                      :entries {}}}))
 
 (let [{:keys [chsk ch-recv send-fn state]}
       (sente/make-channel-socket! "/chsk" {:type :auto})]

                       (apply (partial b/dropdown {:bs-style "primary" 
                                                   :title (or (:id deployment) 
                                                              "Deployments")})
                              (for [[id info] deployments]
                                (b/menu-item {:key id
                                              :on-select (fn [_] 
                                                           ;(stop-tracking! id)
                                                           (start-tracking! id))} 
                                             id)))))))

(defn entry-for-job? [job-id entry]
  (if-let [entry-job-id (if (= (:fn entry) :submit-job)
                          (:id entry)
                          (:job-id entry))]
    (= entry-job-id job-id)))

(defcomponent deployment-entries [{:keys [selected-job entries]} owner]
  (render [_]
          ;(println "ENTRY INFO:" (count (map :message-id entries))  (count (set (map :message-id entries))))
          (let [filtered-entries nil #_(filter (partial entry-for-job? selected-job) entries)] 
            (table {:striped? true :bordered? true :condensed? true :hover? true}
                   (dom/thead
                     (dom/tr


(defcomponent job-info [{:keys [selected-job jobs]} owner]
  (render [_]
          (if-let [job (and selected-job jobs (jobs selected-job))]
            (dom/div 
              (dom/div (str (om/value job)))
              (if-let [catalog (:catalog job)]
                (om/build catalog-view catalog {}))))))

(defn msg-controller [type msg]
  (swap! app-state 
         (fn [state]
           (if-let [tracking-id (:tracking-id msg)] 
             (cond (= tracking-id (get-in state [:deployment :tracking-id]))
                   (case type
                     ;:deployment/replica
                     ;(assoc-in state [:deployment :replica] recv-msg)
                     :job/completed-task
                     (do (println "Task completed: " msg)
                         state)
                     :job/submitted-job 
                     (assoc-in state [:deployment :jobs (:id msg)] msg)
                     :job/entry
                     (update-in state [:deployment] (fn [deployment]
                                                      (-> deployment
                                                          (assoc :message-id-max (max (:message-id msg)
                                                                                      (:message-id-max deployment)))
                                                          (assoc-in [:entries (:message-id msg)] msg))))
                     state)
                   :else state)
             (if (= :deployment/listing type)
               (assoc-in state [:deployments] msg)
               state)))))

(defn event-handler [{:keys [event]}]
  (let [[msg-type msg] event]
