   (reify
     om/IDidUpdate
     (did-update [_ prev-props prev-state]
-      (let [{:keys [programmes projects active-components]} tables]
-        ;;(println "Active Components: " active-components)
-        ))
+      (let [{:keys [programmes projects active-components]} tables
+            new-programme-id (:programmes active-components)]
+
+        ;; handle selection in programme table
+        (when-not new-programme-id
+          (om/update! projects :data [])
+          (om/update! projects :selected nil))
+
+        ;; get the data if we have a new id
+        (if (and new-programme-id
+                   (not (= (:programme-id projects) new-programme-id)))
+          (GET (str "/4/programmes/" new-programme-id "/projects/")
+               {:handler  (fn [x]
+                            (println "Fetching projects for programme: " new-programme-id)
+                            (om/update! projects :data x)
+                            (om/update! projects :selected nil))
+                ;; TODO: Add Error Handler
+                :headers {"Accept" "application/edn"}
+                :response-format :text})
+          (println "Not fetching projects!"))
+
+        ;; update our current id with the new one
+        (om/update! projects :programme-id new-programme-id)
+
+        ;; handle selection in projects table
+        (om/update! projects :selected (:projects active-components))))
     om/IRender
     (render [_]
       (let [{:keys [programmes projects active-components]} tables


(defn programmes-div [tables owner]
  (reify
    om/IRender
    (render [_]
      (let [programmes (-> tables :programmes)]
        (html
         ;; hide div if we've already chosen something
         [:div {:id "programmes-div"}
          [:h1 "Programmes"]
          (om/build programmes-table programmes)])))))

        (html
         [:table {:className "table table-hover"}
          [:thead
           [:tr [:th "Address"] [:th "Region"] [:th "Country"]]]
          [:tbody
           (for [row (sort-by :address-street-two (:data properties))]
             (let [{:keys [id address-street-two address-country address-region]} row]
               [:tr {:onClick (fn [_ _]
                                (om/update! properties :selected id)
                                (history/update-token-ids! history :properties id)
                                (fixed-scroll-to-element "devices-div"))
                     :className (if (= id (:selected properties)) "success")
                     :id (str table-id "-selected")}
                [:td address-street-two]
                [:td address-region]
                [:td address-country]]))]])))))

(defn properties-div [tables owner]
  (reify
    om/IDidUpdate
    (did-update [_ prev-props prev-state]
      (let [{:keys [projects properties active-components]} tables
            new-project-id (:projects active-components)]

        (println "Active Components: " active-components)

        ;; handle selection in projects table
        (when-not new-project-id
          (println "Cleaering projects data.")
          (om/update! properties :data [])
          (om/update! properties :selected nil))
        
        (if (and new-project-id
                 (not (= (:project-id properties) new-project-id)))
          (GET (str "/4/projects/" new-project-id "/properties/")
               {:handler  (fn [x]
                            (println "Fetching properties for project: " new-project-id)
                            (om/update! properties :data x)
                            (om/update! properties :selected nil))
                ;; TODO: Add Error Handler
                :headers {"Accept" "application/edn"}
                :response-format :text})
          (println "Not fetching properties!"))
        (om/update! properties :project-id new-project-id)

        ;; handle selection on properties table
        (om/update! properties :selected (:properties active-components))))
    om/IRender
    (render [_]
      (let [{:keys [programmes projects properties active-components]} tables
