Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS: Remove all references to global URL constants #1781

Merged
merged 2 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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";
yuvipanda marked this conversation as resolved.
Show resolved Hide resolved

/**
* @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