Skip to content

Commit

Permalink
feat(links): add ability to customize help links (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3r authored and plyr4 committed Nov 14, 2019
1 parent 767998f commit a2be651
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 12 deletions.
17 changes: 12 additions & 5 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# /_/--\ |_| |_|
#

# Vela api server address, typically runs on port :8080 locally.
# Vela API server address, typically runs on port :8080.
# Should match the "VELA_ADDR" value in docker-compose.yml
# when running locally.
VELA_API=http://localhost:8080
Expand All @@ -14,18 +14,25 @@ VELA_SOURCE_URL=
# github oauth app client id
VELA_SOURCE_CLIENT=

# github oauth app client secret
VELA_SOURCE_SECRET=
# customize the location where you want users to provide feedack
# (default) https://github.com/go-vela/ui/issues/new
# VELA_FEEDBACK_URL=

# customize the location where users can review documentation
# (default) https://go-vela.github.io/docs
# VELA_DOCS_URL=

# __ ___ _
# / /\ | |_) | |
# /_/--\ |_| |_|
#

# note: same as used by APP, henced commented out
# These should only be needed if you are running
# the docker compose stack as they are used by the api/server

# note: same as used by APP, henced commented out
# github oauth app client id
# VELA_SOURCE_CLIENT=

# github oauth app client secret
# VELA_SOURCE_SECRET=
VELA_SOURCE_SECRET=
2 changes: 1 addition & 1 deletion docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -eu
for f in /usr/share/nginx/html/*.js
do
# shellcheck disable=SC2016
envsubst '${VELA_API},${VELA_SOURCE_URL},${VELA_SOURCE_CLIENT}' < "$f" > "$f".tmp && mv "$f".tmp "$f"
envsubst '${VELA_API},${VELA_SOURCE_URL},${VELA_SOURCE_CLIENT},${VELA_FEEDBACK_URL},{$VELA_DOCS_URL}' < "$f" > "$f".tmp && mv "$f".tmp "$f"
done

exec "$@"
18 changes: 12 additions & 6 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import Html.Attributes
, value
)
import Html.Events exposing (onClick, onInput)
import Html.Lazy exposing (lazy)
import Html.Lazy exposing (lazy2)
import Http exposing (Error(..))
import Http.Detailed
import Interop
Expand Down Expand Up @@ -103,6 +103,8 @@ type alias Flags =
, velaAPI : String
, velaSourceBaseURL : String
, velaSourceClient : String
, velaFeedbackURL : String
, velaDocsURL : String
, velaSession : Maybe Session
}

Expand All @@ -120,6 +122,8 @@ type alias Model =
, velaAPI : String
, velaSourceBaseURL : String
, velaSourceOauthStartURL : String
, velaFeedbackURL : String
, velaDocsURL : String
, navigationKey : Navigation.Key
, zone : Time.Zone
, time : Time.Posix
Expand Down Expand Up @@ -174,6 +178,8 @@ init flags url navKey =
, UB.string "client_id" flags.velaSourceClient
]
, velaSourceBaseURL = flags.velaSourceBaseURL
, velaFeedbackURL = flags.velaFeedbackURL
, velaDocsURL = flags.velaDocsURL
, navigationKey = navKey
, toasties = Alerting.initialState
, zone = Time.utc
Expand Down Expand Up @@ -664,7 +670,7 @@ view model =
in
{ title = "Vela - " ++ title
, body =
[ lazy viewHeader model.session
[ lazy2 viewHeader model.session { feedbackLink = model.velaFeedbackURL, docsLink = model.velaDocsURL }
, viewNav model
, div [ class "util" ] [ Build.viewBuildHistory model.time model.zone model.page model.builds.org model.builds.repo model.builds.builds ]
, main_ []
Expand Down Expand Up @@ -1088,8 +1094,8 @@ navButton model =
text ""


viewHeader : Maybe Session -> Html Msg
viewHeader maybeSession =
viewHeader : Maybe Session -> { feedbackLink : String, docsLink : String } -> Html Msg
viewHeader maybeSession { feedbackLink, docsLink } =
let
session : Session
session =
Expand All @@ -1115,8 +1121,8 @@ viewHeader maybeSession =
]
]
, div [ class "help-links" ]
[ a [ href "https://github.com/go-vela/ui/issues/new" ] [ text "feedback" ]
, a [ href "https://go-vela.github.io/docs" ] [ text "docs" ]
[ a [ href feedbackLink ] [ text "feedback" ]
, a [ href docsLink ] [ text "docs" ]
, FeatherIcons.terminal |> FeatherIcons.withSize 18 |> FeatherIcons.toHtml []
]
]
Expand Down
4 changes: 4 additions & 0 deletions src/elm/Main/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export type Flags = {
readonly velaSourceBaseURL: string;
/** @property velaSourceClient the "Client ID" for the OAuth app set up in the source management tool */
readonly velaSourceClient: string;
/** @property velaFeedbackURL allows you to customize the destination of the feedback link */
readonly velaFeedbackURL: string;
/** @property velaDocsURL allows you to customize the destination of the docs link */
readonly velaDocsURL: string;
/** @property velaSession used for passsing in an existing Vela session to Elm */
readonly velaSession: Session | null;
};
Expand Down
34 changes: 34 additions & 0 deletions src/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
import { Elm, Flags, App, Config, Session } from "../elm/Main";
import "../scss/style.scss";

// Vela consts
const feedbackURL: string = "https://github.com/go-vela/ui/issues/new";
const docsURL: string = "https://go-vela.github.io/docs";

// setup for session state
const storageKey: string = "vela";
const storedSessionState: string | null = sessionStorage.getItem(storageKey);
Expand All @@ -18,6 +22,14 @@ const flags: Flags = {
velaAPI: process.env.VELA_API || "$VELA_API",
velaSourceBaseURL: process.env.VELA_SOURCE_URL || "$VELA_SOURCE_URL",
velaSourceClient: process.env.VELA_SOURCE_CLIENT || "$VELA_SOURCE_CLIENT",
velaFeedbackURL:
process.env.VELA_FEEDBACK_URL ||
envOrNull("VELA_FEEDBACK_URL", "$VELA_FEEDBACK_URL") ||
feedbackURL,
velaDocsURL:
process.env.VELA_DOCS_URL ||
envOrNull("VELA_DOCS_URL", "$VELA_DOCS_URL") ||
docsURL,
velaSession: currentSessionState || null
};

Expand All @@ -40,3 +52,25 @@ app.ports.storeSession.subscribe(sessionMessage => {

setTimeout(() => app.ports.onSessionChange.send(sessionMessage), 0);
});

/**
* envOrNull is a basic helper that returns a substituted
* environment variable or null
*
* @param env the env variable to be substituted, sans "$" prefix
* @param subst the substituted variable (or not)
*/
function envOrNull(env: string, subst: string): string | null {
// substituted value is empty
if (!subst || !subst.trim()) {
return null;
}

// value was not substituted; ignore
if (subst.indexOf(env) !== -1) {
return null;
}

// value was substituted, return it
return subst;
}

0 comments on commit a2be651

Please sign in to comment.