<commit_before>(ns swarmpit.component.service.list
  (:require [material.component :as comp]
            [swarmpit.component.state :as state]
            [swarmpit.routes :as routes]
            [clojure.string :as string]
            [rum.core :as rum]))

(enable-console-print!)

(def cursor [:page :service :list :filter])

(def headers ["Name" "Image" "Mode" "Replicas" "Status" "Updates"])

(def form-replicas-style
  {:backgroundColor "rgb(245, 245, 245)"
   :border          "1px solid rgb(224, 228, 231)"})

(def form-replicas-label-style
  {:fontSize "13px"})

(defn- form-replicas [value]
  (comp/chip {:style      form-replicas-style
              :labelStyle form-replicas-label-style} value))

(defn- form-updates [value]
  (let [status (if value "loading" "ready")]
    (comp/loader
      {:status status
       :top    0})))

(defn- form-state [value]
  (case value
    "running" (comp/label-green value)
    "not running" (comp/label-grey value)
    "partly running" (comp/label-yellow value)))

(defn- filter-items
  "Filter list `items` based on `name` & `cranky?` flag"
  [items name cranky?]
  (let [is-running (fn [item] (= "running" (:state item)))
        is-updating (fn [item] (get-in item [:status :update]))]
    (if cranky?
      (filter #(and (string/includes? (:serviceName %) name)
                    (and (not (is-running %))
                         (not (is-updating %)))) items)
      (filter #(string/includes? (:serviceName %) name) items))))

(def render-item-keys
  [[:serviceName] [:repository :image] [:mode] [:status :info] [:state] [:status :update]])

(defn- render-item
  [item]
  (let [value (val item)]
    (case (key item)
      :state (form-state value)
      :info (form-replicas value)
      :update (form-updates value)
      value)))

(defn- onclick-handler
  [item]
  (routes/path-for-frontend :service-info (select-keys item [:id])))

(rum/defc service-list < rum/reactive [items]
  (let [{:keys [serviceName cranky]} (state/react cursor)
        filtered-items (filter-items items serviceName cranky)]
    [:div
     [:div.form-panel
      [:div.form-panel-left<commit_msg>form replicas -> single label instead of chip ..<commit_after>(ns swarmpit.component.service.list
  (:require [material.component :as comp]
            [swarmpit.component.state :as state]
            [swarmpit.routes :as routes]
            [clojure.string :as string]
            [rum.core :as rum]))

(enable-console-print!)

(def cursor [:page :service :list :filter])

(def headers ["Name" "Image" "Mode" "Replicas" "Status" "Updates"])

(defn- form-updates [value]
  (let [status (if value "loading" "ready")]
    (comp/loader
      {:status status
       :top    0})))

(defn- form-state [value]
  (case value
    "running" (comp/label-green value)
    "not running" (comp/label-grey value)
    "partly running" (comp/label-yellow value)))

(defn- filter-items
  "Filter list `items` based on `name` & `cranky?` flag"
  [items name cranky?]
  (let [is-running (fn [item] (= "running" (:state item)))
        is-updating (fn [item] (get-in item [:status :update]))]
    (if cranky?
      (filter #(and (string/includes? (:serviceName %) name)
                    (and (not (is-running %))
                         (not (is-updating %)))) items)
      (filter #(string/includes? (:serviceName %) name) items))))

(def render-item-keys
  [[:serviceName] [:repository :image] [:mode] [:status :info] [:state] [:status :update]])

(defn- render-item
  [item]
  (let [value (val item)]
    (case (key item)
      :state (form-state value)
      :info (comp/label-info value)
      :update (form-updates value)
      value)))

(defn- onclick-handler
  [item]
  (routes/path-for-frontend :service-info (select-keys item [:id])))

(rum/defc service-list < rum/reactive [items]
  (let [{:keys [serviceName cranky]} (state/react cursor)
        filtered-items (filter-items items serviceName cranky)]
    [:div
     [:div.form-panel
      [:div.form-panel-left
{'fraction_non_alphanumeric': 0.16583040642247868, 'fraction_numerical': 0.00577019568489714, 'mean_word_length': 2.9358341559723593, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3861578', 'n_tokens_mistral': 1409, 'n_tokens_neox': 1347, 'n_words': 361}