Skip to content

Commit

Permalink
Merge pull request #87 from metafacture/79-showVersions
Browse files Browse the repository at this point in the history
Show dependency versions in UI
  • Loading branch information
katauber authored Feb 24, 2022
2 parents 50cad45 + b5ef733 commit 3589cd5
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 88 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ chmod a+x ~/bin/lein
### Install Metafacture Fix

This project depends on [metafacture-fix](https://github.com/metafacture/metafacture-fix), which is work in progress.
It is possible to display the current version of dependencies in the UI. To display the version, please read this [section](#show-dependency-versions-in-ui). This is especially reasonable when installing on a server.

Clone and install metafacture-fix:
```bash
Expand Down Expand Up @@ -80,6 +81,22 @@ Run workflows on the web server, passing `data`, `flux`, and `fix`:

[http://localhost:3000/process?data='1'{'a': '5', 'z': 10}&flux=as-lines|decode-formeta|fix|encode-formeta(style="multiline")&fix=map(a,b) map(_else)](http://localhost:3000/process?data=%271%27{%27a%27:%20%275%27,%20%27z%27:%2010}&flux=as-lines|decode-formeta|fix|encode-formeta(style=%22multiline%22)&fix=map(a,c)%20map(_else))

### Show dependency versions in UI

When installing the Metafacture Playground to a server it's important for users to know which version of Metafacture Core and Metafacture Fix are used to process the workflows in the playground.

![Display versions of dependencies](/resources/img/displayVersions.JPG)

To display these versions (or any other dependency of the playground) you have to put a file with the corresponding dependency name into the folder ```resources/versions```, e.g. the dependency of Metafacture Fix is named ```org.metafacture/metafix``` in the project.clj, so we need a file named ```metafix``` in the folder ```resources/versions``` to display the version used in the project.clj in the UI.
The content of this file is a URI that should link to the corresponding version or branch commit and should be adapted manually. In the future the content of these files should be adapted automatically when installing Metafacture Fix or Metafacture Core on the server where the playground is running.
To display the Metafacture Core dependency we use ```org.metafacture/metafacture-framework```.

#### Use a release version
If a released version is used, the content of the file contains the link to the release, e.g. [https://github.com/metafacture/metafacture-core/releases/tag/metafacture-core-5.3.1](https://github.com/metafacture/metafacture-core/releases/tag/metafacture-core-5.3.1).

#### Use Master/Main or other branch
If the master/main or another branch is used, the content of the file should contain a link to the commit like [https://github.com/metafacture/metafacture-fix/commit/b36fcb9](https://github.com/metafacture/metafacture-fix/commit/b36fcb9) (Please use the short hash link).

### Run tests

### clj tests
Expand Down
92 changes: 30 additions & 62 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
[org.metafacture/metafacture-json "5.3.1"]
[org.metafacture/metafacture-linkeddata "5.3.1"]
[org.metafacture/metafacture-flux "5.3.1"]
[org.metafacture/metafacture-framework "5.3.1"]
[org.metafacture/metafacture-runner "5.3.1"]
[org.metafacture/metamorph-api "5.3.1"]
[org.metafacture/metamorph "5.3.1"]
Expand Down
Binary file added resources/img/displayVersions.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions resources/versions/metafacture-framework
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/metafacture/metafacture-core/releases/tag/metafacture-core-5.3.1
1 change: 1 addition & 0 deletions resources/versions/metafix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://github.com/metafacture/metafacture-fix/tree/master
44 changes: 35 additions & 9 deletions src/clj/metafacture_playground/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,47 @@
(catch Exception e
(exception-handler e uri))))

(defn- files-content [dir]
(let [files (->> (io/file dir)
.listFiles
(filter #(.isFile %)))]
(reduce
(fn [result file]
(assoc result (.getName file) (slurp file)))
{}
files)))

(defn- versions-from-files []
(let [dependencies (-> "project.clj" slurp read-string (nth 6))]
(reduce
(fn [result [file-name file-content]]
(if-let [matching-label (-> (filter #(= (-> % first name)
file-name)
dependencies)
first
second)]
(assoc result file-name {:version-label matching-label
:link file-content})
result))
{}
(files-content "resources/versions/"))))

(defroutes routes
(GET "/" [] (resource-response "index.html" {:root "public"}))
(GET "/process" [data flux fix morph uri]
(process-request data flux fix morph uri))
(GET "/examples" request
(try
(let [files (->> (io/file "resources/examples/")
.listFiles
(filter #(.isFile %)))
files-content (reduce
(fn [result file]
(assoc result (.getName file) (slurp file)))
{}
files)]
(response (json/write-str files-content)))
(-> (files-content "resources/examples/")
json/write-str
response)
(catch Exception e
(exception-handler e (:uri request)))))
(GET "/versions" request
(try
(-> (versions-from-files)
json/write-str
response)
(catch Exception e
(exception-handler e (:uri request)))))
(POST "/process" request
Expand Down
55 changes: 41 additions & 14 deletions src/cljs/metafacture_playground/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[lambdaisland.uri :refer [uri join assoc-query* query-encode]]
[com.degel.re-frame.storage]
[clojure.string :as clj-str]
[clojure.walk :as walk]
[cognitect.transit :as transit]
[goog.object :as g]))

Expand Down Expand Up @@ -172,12 +173,12 @@
{:db (-> db
(assoc :result nil)
(assoc-in [:ui :dropdown :active-item] dropdown-value))
:dispatch-n (conj
(mapv
(fn [editor]
[::edit-input-value editor (get sample editor "")])
[:data :flux :fix :morph])
[::switch-editor (:active-editor sample)])
:fx (conj
(mapv
(fn [editor]
[:dispatch [::edit-input-value editor (get sample editor "")]])
[:data :flux :fix :morph])
[:dispatch [::switch-editor (:active-editor sample)]])
:storage/set {:session? true
:name (->storage-key [:ui :dropdown :active-item])
:value dropdown-value}})
Expand Down Expand Up @@ -541,6 +542,30 @@
::load-samples
load-samples)

(defn versions-response
[{db :db} [_ {:keys [body]}]]
(let [body (-> (transit/read (transit/reader :json) body)
walk/keywordize-keys)]
{:db (assoc db :versions body)}))

(re-frame/reg-event-fx
::versions-response
versions-response)

(defn get-backend-versions
[{db :db} _]
{:db db
:fetch {:method :get
:url "versions"
:timeout 10000
:response-content-types {#"application/.*json" :json}
:on-success [::versions-response]
:on-failure [::bad-response]}})

(re-frame/reg-event-fx
::get-backend-versions
get-backend-versions)

(defn deep-merge [a & maps]
(if (map? a)
(apply merge-with deep-merge a maps)
Expand All @@ -563,16 +588,18 @@
db/default-db
(restore-db web-storage)
{:ui {:height window-height}})
:dispatch [::load-samples]}
:fx [[:dispatch [::load-samples]]
[:dispatch [::get-backend-versions]]]}
{:db (-> db/default-db
(assoc-in [:ui :height] window-height))
:dispatch-n (cond->
(mapv
(fn [editor]
[::edit-input-value editor (get query-params editor "")])
[:data :flux :fix :morph])
true (conj [::load-samples])
(get query-params :active-editor) (conj [::switch-editor (-> query-params :active-editor keyword)]))
:fx (cond->
(mapv
(fn [editor]
[:dispatch [::edit-input-value editor (get query-params editor "")]])
[:data :flux :fix :morph])
true (conj [:dispatch [::load-samples]])
true (conj [:dispatch [::get-backend-versions]])
(get query-params :active-editor) (conj [:dispatch [::switch-editor (-> query-params :active-editor keyword)]]))
:storage/set {:session? true
:pairs (-> (assoc-query-params {} query-params)
generate-pairs)}
Expand Down
5 changes: 5 additions & 0 deletions src/cljs/metafacture_playground/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@
::result-loading?
(fn [db _]
(get-in db [:result :loading?])))

(re-frame/reg-sub
::backend-versions
(fn [db _]
(get db :versions)))
13 changes: 12 additions & 1 deletion src/cljs/metafacture_playground/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@

;;; Utils

(defn link-label [name href]
[:> label {:content name
:as "a"
:href href
:target "_blank"}])

(defn title-label [name]
[:> menu-item
{:id (str name "-label")
Expand Down Expand Up @@ -155,7 +161,12 @@
[:> image {:alt "Metafacture Ant"
:src "images/metafacture-logo.png"}]
"Metafacture Playground"
[:> label {:color color :content "beta"}]])
[:> label {:color color
:content "beta"}]
(let [backend-versions (re-frame/subscribe [::subs/backend-versions])]
(for [[version-name {:keys [version-label link]}] @backend-versions]
^{:key version-name}
[link-label (str (name version-name) " " version-label) link]))])

;;; Message Panel

Expand Down
Loading

0 comments on commit 3589cd5

Please sign in to comment.