-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #159 from duckduckgo/shane/debugger-screens
debugger: make it possible to debug initial screens
- Loading branch information
Showing
6 changed files
with
254 additions
and
131 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
import { h, render } from 'preact' | ||
import { Debugger, PlatformToggles, Selector } from './debugger' | ||
|
||
import google from '../schema/__fixtures__/request-data-google.json' | ||
import cnn from '../schema/__fixtures__/request-data-cnn.json' | ||
import { createDataStates } from '../shared/js/ui/views/tests/generate-data.mjs' | ||
import { Settings } from './settings' | ||
|
||
const states = createDataStates(/** @type {any} */ (google), /** @type {any} */ (cnn)) | ||
|
||
let searchParams = new URL(window.location.href).searchParams | ||
const settings = new Settings() | ||
.withState(searchParams.get('state')) | ||
.withScreen(searchParams.get('screen')) | ||
.withPlatforms(searchParams.get('platforms')) | ||
.withRequests(searchParams.getAll('requests')) | ||
|
||
function updateStateParam(value) { | ||
let reflectList = ['screen', 'requests'] | ||
const url = new URL(window.location.href) | ||
|
||
// remove existing reflected params | ||
for (let key of reflectList) { | ||
url.searchParams.delete(key) | ||
} | ||
|
||
// set the new state (as chosen in the dropdown) | ||
url.searchParams.set('state', value) | ||
const selected = states[value] | ||
|
||
// reflect explicit url params | ||
for (let [key, value] of Object.entries(selected.urlParams)) { | ||
url.searchParams.set(key, String(value)) | ||
} | ||
|
||
// reload the page with all new URL | ||
window.location.href = url.href | ||
} | ||
|
||
function updatePlatformsParam(value) { | ||
const url = new URL(window.location.href) | ||
url.searchParams.set('platforms', value.join(',')) | ||
window.location.href = url.href | ||
} | ||
|
||
function updateScreenParam(value) { | ||
const url = new URL(window.location.href) | ||
url.searchParams.set('screen', value) | ||
window.location.href = url.href | ||
} | ||
|
||
/** | ||
* @param {string[]} values | ||
*/ | ||
function updateRequestsParam(values) { | ||
const url = new URL(window.location.href) | ||
url.searchParams.delete('requests') | ||
for (let value of values) { | ||
url.searchParams.append('requests', value) | ||
} | ||
window.location.href = url.href | ||
} | ||
|
||
render( | ||
<Debugger | ||
selectedRequests={settings.requests} | ||
platforms={settings.platforms} | ||
initialState={settings.state} | ||
reflectParams={settings.reflectParams} | ||
states={states} | ||
items={settings.items} | ||
updateRequests={updateRequestsParam} | ||
toggles={ | ||
<div> | ||
<div> | ||
<Selector label={'States'} options={states} selected={settings.state} onChange={updateStateParam} /> | ||
</div> | ||
<div> | ||
<Selector label={'Screen'} options={settings.screens} selected={settings.screen} onChange={updateScreenParam} /> | ||
</div> | ||
<PlatformToggles selected={settings.platforms} onChange={updatePlatformsParam} items={settings.items} /> | ||
</div> | ||
} | ||
/>, | ||
/** @type {HTMLDivElement} */ (document.querySelector('#app')) | ||
) |
Oops, something went wrong.