<commit_before>(ns swarmpit.component.service.form-mounts
  (:require [material.component :as comp]
            [swarmpit.component.state :as state]
            [swarmpit.component.handler :as handler]
            [swarmpit.routes :as routes]
            [rum.core :as rum]))

(enable-console-print!)

(def cursor [:page :service :wizard :mounts])

(defonce volumes (atom []))

(defn volumes-handler
  []
  (handler/get
    (routes/path-for-backend :volumes)
    {:on-success (fn [response]
                   (reset! volumes response))}))

(def headers [{:name  "Type"
               :width "15%"}
              {:name  "Container path"
               :width "35%"}
              {:name  "Host (path/volume)"
               :width "35%"}
              {:name  "Read only"
               :width "5%"}])

(def empty-info
  (comp/form-value "No mounts defined for the service."))

(defn- form-container [value index]
  (comp/form-list-textfield<commit_msg>added normalize method -> fill optional data about mount resources (assure consistency)<commit_after>(ns swarmpit.component.service.form-mounts
  (:require [material.component :as comp]
            [swarmpit.component.state :as state]
            [swarmpit.component.handler :as handler]
            [swarmpit.routes :as routes]
            [rum.core :as rum]))

(enable-console-print!)

(def cursor [:page :service :wizard :mounts])

(defonce volumes (atom []))

(defn volumes-handler
  []
  (handler/get
    (routes/path-for-backend :volumes)
    {:on-success (fn [response]
                   (reset! volumes response))}))

(defn- normalize-volume
  "Associate volumes with optional data (driver, labels)"
  [volume]
  (let [volume-data (first
                      (filter #(= (:host volume)
                                  (:volumeName %)) @volumes))]
    (-> volume
        (assoc-in [:volumeOptions :labels] (:labels volume-data))
        (assoc-in [:volumeOptions :driver :name] (:driver volume-data))
        (assoc-in [:volumeOptions :driver :options] (:options volume-data)))))

(defn normalize
  "Associate mounts with optional data required for consistency"
  []
  (->> (state/get-value cursor)
       (map (fn [mount] (if (= "volume" (:type mount))
                          (normalize-volume mount)
                          mount)))
       (into [])))

(def headers [{:name  "Type"
               :width "15%"}
              {:name  "Container path"
               :width "35%"}
              {:name  "Host (path/volume)"
               :width "35%"}
              {:name  "Read only"
               :width "5%"}])

(def empty-info
  (comp/form-value "No mounts defined for the service."))

(defn- form-container [value index]
  (comp/form-list-textfield
{'fraction_non_alphanumeric': 0.14416727806309612, 'fraction_numerical': 0.005135730007336757, 'mean_word_length': 2.167247386759582, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6535966', 'n_tokens_mistral': 849, 'n_tokens_neox': 808, 'n_words': 216}