Skip to content

Commit

Permalink
Melon Head: Improve file opening (#112)
Browse files Browse the repository at this point in the history
This makes file opening more robust.

Since we need tokens in url we need to get them from keycloak (object).
Previously this was done while rendering the DOM which is not optimal.
Now we get the token only in click handler and open new tab using
binding to JS function
  • Loading branch information
turboMaCk authored and ICTGuerrilla committed Oct 5, 2023
1 parent e8bd9f9 commit 973db30
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions melon-head/src/App/ApplicationDetail.res
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@module external styles: {..} = "./ApplicationDetail/styles.module.scss"

@send external focus: Dom.element => unit = "focus"
@scope("window") @val external window_open: (string, string) => unit = "open"

open Belt
open RemoteData
Expand Down Expand Up @@ -184,12 +185,21 @@ let viewSignature = (~api: Api.t, signature: option<Data.file>) => {

let viewFile = (~api: Api.t, file) => {
let fileName = file.name ++ "." ++ file.fileType
let fileUrl =
api.host ++ "/files/" ++ file.id->Uuid.toString ++ "?token=" ++ api.keycloak->Keycloak.getToken

let openFile = _ => {
let fileUrl =
api.host ++
"/files/" ++
file.id->Uuid.toString ++
"?token=" ++
api.keycloak->Keycloak.getToken

window_open(fileUrl, "_blank")
}

<tr key={file.id->Uuid.toString}>
<td>
<a href=fileUrl target="_blank"> {React.string(fileName)} </a>
<a href="#" onClick=openFile> {React.string(fileName)} </a>
</td>
<td> {file.createdAt->Js.Date.toLocaleString->React.string} </td>
</tr>
Expand Down Expand Up @@ -499,7 +509,9 @@ module Actions = {
<Modal.Content>
<p>
{React.string("Are you shure you want to ")}
<strong> {React.string("move this application back to processing to be re-evaluated")} </strong>
<strong>
{React.string("move this application back to processing to be re-evaluated")}
</strong>
{React.string(" again?")}
</p>
{switch error {
Expand All @@ -510,7 +522,9 @@ module Actions = {
<Button onClick={_ => Modal.Interface.closeModal(modal)}>
{React.string("Cancel")}
</Button>
<Button btnType=Button.Danger onClick=doUnReject> {React.string("Move Back to Processing")} </Button>
<Button btnType=Button.Danger onClick=doUnReject>
{React.string("Move Back to Processing")}
</Button>
</Button.Panel>
</Modal.Content>
}
Expand Down

0 comments on commit 973db30

Please sign in to comment.