From 3d9566a19288858b26701ac01c1ee272071d04ee Mon Sep 17 00:00:00 2001 From: Chris Campbell Date: Mon, 26 Sep 2022 11:34:42 -0700 Subject: [PATCH 01/13] feat: checkpoint work on allowing baseline to be changed at runtime --- examples/sample-check-app/src/index.ts | 4 + packages/check-ui-shell/src/app.svelte | 11 ++- .../src/components/header/header-vm.ts | 40 ++++---- .../src/components/header/header.pug | 13 +++ .../src/components/header/header.svelte | 56 ++++++++++- packages/check-ui-shell/src/global.css | 4 +- packages/plugin-check/package.json | 2 + packages/plugin-check/src/plugin.ts | 28 +++++- .../src/vite-config-for-report.ts | 43 ++++++++- .../plugin-check/template-report/src/env.d.ts | 1 + .../plugin-check/template-report/src/index.ts | 92 ++++++++++++++++--- pnpm-lock.yaml | 19 +++- 12 files changed, 270 insertions(+), 43 deletions(-) create mode 100644 packages/check-ui-shell/src/components/header/header.pug diff --git a/examples/sample-check-app/src/index.ts b/examples/sample-check-app/src/index.ts index ccb7a97c..2e008b46 100644 --- a/examples/sample-check-app/src/index.ts +++ b/examples/sample-check-app/src/index.ts @@ -27,4 +27,8 @@ const checkOptions = getConfigOptions(baselineBundle() as Bundle, currentBundle( // Initialize the root Svelte component const appShell = initAppShell(checkOptions, suiteSummary) +document.addEventListener('sde-check-bundle', e => { + console.log(e) +}) + export default appShell diff --git a/packages/check-ui-shell/src/app.svelte b/packages/check-ui-shell/src/app.svelte index ee51fb46..13b6716f 100644 --- a/packages/check-ui-shell/src/app.svelte +++ b/packages/check-ui-shell/src/app.svelte @@ -31,11 +31,12 @@ let viewMode: ViewMode = 'summary' // occurs more frequently in Firefox and Chrome than in Safari.) As a workaround, // observe loading of the font used by the graphs (Roboto Condensed 400) so // that we can wait for it to be loaded before rendering the app. -const graphFont = new FontFaceObserver('Roboto Condensed', { weight: 400 }) -let graphFontReady = false -graphFont.load().then(() => { - graphFontReady = true -}) +// const graphFont = new FontFaceObserver('Roboto Condensed', { weight: 400 }) +// let graphFontReady = false +// graphFont.load().then(() => { +// graphFontReady = true +// }) +const graphFontReady = true // Wait for the fonts to be loaded before we render the app let viewReady = false diff --git a/packages/check-ui-shell/src/components/header/header-vm.ts b/packages/check-ui-shell/src/components/header/header-vm.ts index f586f234..6de57918 100644 --- a/packages/check-ui-shell/src/components/header/header-vm.ts +++ b/packages/check-ui-shell/src/components/header/header-vm.ts @@ -7,6 +7,8 @@ import type { CompareConfig } from '@sdeverywhere/check-core' export interface HeaderViewModel { nameL?: string nameR?: string + bundleNamesL: Writable + bundleNamesR: Writable thresholds?: string[] simplifyScenarios?: Writable } @@ -19,24 +21,26 @@ export function createHeaderViewModel( // Only include the comparison-related header elements if the compare // config is defined - if (compareConfig) { - const thresholds = compareConfig.thresholds - const thresholdStrings: string[] = [] - thresholdStrings.push('no diff') - for (let i = 0; i < 3; i++) { - thresholdStrings.push(`diff < ${thresholds[i]}%`) - } - thresholdStrings.push(`diff >= ${thresholds[2]}%`) + // if (compareConfig) { + const thresholds = compareConfig.thresholds + const thresholdStrings: string[] = [] + thresholdStrings.push('no diff') + for (let i = 0; i < 3; i++) { + thresholdStrings.push(`diff < ${thresholds[i]}%`) + } + thresholdStrings.push(`diff >= ${thresholds[2]}%`) - return { - nameL: compareConfig.bundleL.name, - nameR: compareConfig.bundleR.name, - thresholds: thresholdStrings, - simplifyScenarios - } - } else { - return { - simplifyScenarios - } + return { + nameL: compareConfig.bundleL.name, + nameR: compareConfig.bundleR.name, + bundleNamesL: writable([compareConfig.bundleL.name, 'Baseline 2']), + bundleNamesR: writable([compareConfig.bundleR.name, 'Baseline 2']), + thresholds: thresholdStrings, + simplifyScenarios } + // } else { + // return { + // simplifyScenarios + // } + // } } diff --git a/packages/check-ui-shell/src/components/header/header.pug b/packages/check-ui-shell/src/components/header/header.pug new file mode 100644 index 00000000..def4ff28 --- /dev/null +++ b/packages/check-ui-shell/src/components/header/header.pug @@ -0,0 +1,13 @@ +//- Copyright (c) 2021-2022 Climate Interactive / New Venture Fund + +//- Note: These mixins are kept in an external pug file to work around a +//- Svelte issue related to `each` and TypeScript, see: +//- https://github.com/sveltejs/svelte-preprocess/issues/207 + +mixin optionsL + +each(`$bundleNamesL as name`) + option { name } + +mixin optionsR + +each(`$bundleNamesR as name`) + option { name } diff --git a/packages/check-ui-shell/src/components/header/header.svelte b/packages/check-ui-shell/src/components/header/header.svelte index 78830fa8..4ece422e 100644 --- a/packages/check-ui-shell/src/components/header/header.svelte +++ b/packages/check-ui-shell/src/components/header/header.svelte @@ -11,6 +11,8 @@ import type { HeaderViewModel } from './header-vm' export let viewModel: HeaderViewModel const simplifyScenarios = viewModel.simplifyScenarios const thresholds = viewModel.thresholds +const bundleNamesL = viewModel.bundleNamesL +const bundleNamesR = viewModel.bundleNamesR const dispatch = createEventDispatcher() @@ -18,6 +20,30 @@ function onHome() { dispatch('command', { cmd: 'show-summary' }) } +function onSelectBundleL(e: Event) { + const target = e.target as HTMLSelectElement + console.log(target.value) + const changeEvent = new CustomEvent('sde-check-bundle', { + detail: { + kind: 'left', + name: target.value + } + }) + document.dispatchEvent(changeEvent) +} + +function onSelectBundleR(e: Event) { + const target = e.target as HTMLSelectElement + console.log(target.value) + const changeEvent = new CustomEvent('sde-check-bundle', { + detail: { + kind: 'right', + name: target.value + } + }) + document.dispatchEvent(changeEvent) +} + @@ -26,6 +52,8 @@ function onHome() {