Skip to content

Commit

Permalink
Merge pull request #1781 from yuvipanda/noglobals
Browse files Browse the repository at this point in the history
JS: Remove all references to global URL constants
  • Loading branch information
yuvipanda authored Oct 23, 2023
2 parents dcabc6d + e889659 commit c1c5af6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 31 deletions.
28 changes: 25 additions & 3 deletions binderhub/static/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,32 @@ import "bootstrap/dist/css/bootstrap-theme.min.css";
import "../index.css";
import { setUpLog } from "./src/log";
import { updateUrls } from "./src/urls";
import { BASE_URL, BADGE_BASE_URL } from "./src/constants";
import { getBuildFormValues } from "./src/form";
import { updateRepoText } from "./src/repo";

/**
* @type {URL}
* Base URL of this binderhub installation.
*
* Guaranteed to have a leading & trailing slash by the binderhub python configuration.
*/
const BASE_URL = new URL(
document.getElementById("base-url").dataset.url,
document.location.origin,
);

const badge_base_url = document.getElementById("badge-base-url").dataset.url;
/**
* @type {URL}
* Base URL to use for both badge images as well as launch links.
*
* If not explicitly set, will default to BASE_URL. Primarily set up different than BASE_URL
* when used as part of a federation
*/
const BADGE_BASE_URL = badge_base_url
? new URL(badge_base_url, document.location.origin)
: BASE_URL;

async function build(providerSpec, log, fitAddon, path, pathType) {
updateFavicon(new URL("favicon_building.ico", BASE_URL));
// split provider prefix off of providerSpec
Expand Down Expand Up @@ -128,7 +150,7 @@ function indexMain() {

$("#provider_prefix-selected").text($(this).text());
$("#provider_prefix").val($(this).attr("value"));
updateRepoText();
updateRepoText(BASE_URL);
updateUrls(BADGE_BASE_URL);
});

Expand All @@ -142,7 +164,7 @@ function indexMain() {
updateUrls(BADGE_BASE_URL);
});
updatePathText();
updateRepoText();
updateRepoText(BASE_URL);

$("#repository").on("keyup paste change", function () {
updateUrls(BADGE_BASE_URL);
Expand Down
24 changes: 0 additions & 24 deletions binderhub/static/js/src/constants.js

This file was deleted.

8 changes: 4 additions & 4 deletions binderhub/static/js/src/repo.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { BASE_URL } from "./constants";

/**
* Dict holding cached values of API request to _config endpoint
*/
Expand All @@ -21,10 +19,12 @@ function setLabels() {

/**
* Update labels for various inputboxes based on user selection of repo provider
*
* @param {URL} baseUrl Base URL to use for constructing path to _config endpoint
*/
export function updateRepoText() {
export function updateRepoText(baseUrl) {
if (Object.keys(configDict).length === 0) {
const configUrl = new URL("_config", BASE_URL);
const configUrl = new URL("_config", baseUrl);
fetch(configUrl).then((resp) => {
resp.json().then((data) => {
configDict = data;
Expand Down

0 comments on commit c1c5af6

Please sign in to comment.