Skip to content

Commit

Permalink
feat: use profiles from production and staging
Browse files Browse the repository at this point in the history
instead of hardcoded profiles use the profiles from staging and
production for the dev tools to make it easier to select a profile to
test on
and add the url that the profile is referring to as well
  • Loading branch information
milafrerichs committed Feb 5, 2021
1 parent 65118c3 commit 893648f
Showing 1 changed file with 44 additions and 23 deletions.
67 changes: 44 additions & 23 deletions src/js/dev-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,54 @@ function changeHost(value) {
sessionStorage.setItem('wazi-hostname', value);
window.location.reload(false);
}
let tools = [
{ type: 'select',
title: 'Hostname',
callback: changeHost,
values: [
{title: 'Youthexplorer', value: 'beta.youthexplorer.org.za'},
{title: 'GCRO', value: 'gcro.openup.org.za'},
{title: 'Sifar', value: 'sifar-wazi.openup.org.za'},
{title: 'Vulekamali', value: 'geo.vulekamali.gov.za'},
{title: 'Public - 2011 SA Boundaries', value: 'wazimap-ng.africa'},
{title: 'GIZ', value: 'giz-projects.openup.org.za'},
{title: 'Cape Town Against Covid-19', value: 'capetownagainstcovid19.openup.org.za'},
{title: 'Covid-Wazi', value: 'covid-wazi.openup.org.za'},
{title: 'mapyourcity', value: 'mapyourcity.org.za'}
]
},
{ type: 'input',
title: 'Hostname',
callback: changeHost,
values: 'Hostname'

function tools(profiles) {
let hostnames = profiles.map((profile) => {
if(profile.configuration && profile.configuration.urls) {
return profile.configuration.urls.map((url) => {
return { title: `${profile.name} - ${url}`, value: url }
})
}
}).flat(1).filter(v => v)
let tools = [
{ type: 'select',
title: 'Hostname',
callback: changeHost,
values: hostnames
},
{ type: 'input',
title: 'Hostname',
callback: changeHost,
values: 'Hostname'
}
]
return tools;
}

async function getProfileData(profileUrl) {
let next = true;
let data = []
while(next) {
const response = await fetch(profileUrl)
const profileJson = await response.json();
if(profileJson["next"]) {
profileUrl = profileJson["next"];
} else { next = false; }
data = data.concat(profileJson["results"])
}
]
export function install() {
return data;
}

export async function install() {
let data = []
let profileUrl = 'https://production.wazimap-ng.openup.org.za/api/v1/profiles';
let stagingProfileUrl = 'https://staging.wazimap-ng.openup.org.za/api/v1/profiles';
data = data.concat(await getProfileData(profileUrl))
data = data.concat(await getProfileData(stagingProfileUrl))
const devtools = new DevTools({
target: document.body,
props: {
tools: tools,
tools: tools(data),
env: process.env.NODE_ENV
}
});
Expand Down

0 comments on commit 893648f

Please sign in to comment.