Skip to content

Commit

Permalink
JS: Remove all references to global URL constants
Browse files Browse the repository at this point in the history
Instead they are passed in wherever needed. Cleaner code,
and path towards everything being more testable
  • Loading branch information
yuvipanda committed Oct 20, 2023
1 parent af81d7f commit c0b1e50
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
24 changes: 23 additions & 1 deletion 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
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 @@ -23,10 +21,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 c0b1e50

Please sign in to comment.