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

feat(server): add compare different url #457

Merged
merged 4 commits into from
Oct 12, 2020
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
11 changes: 8 additions & 3 deletions packages/server/src/ui/routes/build-view/build-view.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
*/

.build-view--with-lhr-link-hover .lhr-comparison__scores-and-dropdowns .dropdown--url {
.build-view--with-lhr-base-link-hover .lhr-comparison__scores-and-dropdowns .dropdown--base-url,
.build-view--with-lhr-compare-link-hover .lhr-comparison__scores-and-dropdowns .dropdown--compare-url {
background: var(--compare-secondary-highlight-color);
}

.build-view--with-lhr-link-hover
.build-view--with-lhr-base-link-hover
.lhr-comparison__scores-and-dropdowns
.dropdown--url
.dropdown--base-url
.dropdown__label,
.build-view--with-lhr-compare-link-hover
.lhr-comparison__scores-and-dropdowns
.dropdown--compare-url
.dropdown__label {
padding-left: calc(var(--base-spacing) / 4);
margin-right: calc(var(--base-spacing) / 4);
Expand Down
63 changes: 43 additions & 20 deletions packages/server/src/ui/routes/build-view/build-view.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,24 @@ function computeSelectedUrl(props, compareRuns) {
return urlsInBothRuns[0] || fallbackUrl;
}

/** @param {{project: LHCI.ServerCommand.Project, build: LHCI.ServerCommand.Build, ancestorBuild: LHCI.ServerCommand.Build | null, runs: Array<LHCI.ServerCommand.Run>, compareUrl?: string, hasBaseOverride: boolean}} props */
/** @param {{project: LHCI.ServerCommand.Project, build: LHCI.ServerCommand.Build, ancestorBuild: LHCI.ServerCommand.Build | null, runs: Array<LHCI.ServerCommand.Run>, baseUrl?: string, compareUrl?: string, hasBaseOverride: boolean}} props */
const BuildView_ = props => {
const [openBuildHash, setOpenBuild] = useState(/** @type {null|'base'|'compare'} */ (null));
const [isOpenLhrLinkHovered, setLhrLinkHover] = useState(false);
const [isOpenLhrBaseLinkHovered, setLhrBaseLinkHover] = useState(false);
const [isOpenLhrCompareLinkHovered, setLhrCompareLinkHover] = useState(false);
const buildHashSelectorCloseFn = useCallback(() => setOpenBuild(null), [setOpenBuild]);

const compareRuns = props.runs.filter(run => run.buildId === props.build.id);
const selectedUrl = computeSelectedUrl(props, compareRuns);
const compareUrl = props.compareUrl || computeSelectedUrl(props, compareRuns);
const baseUrl = props.baseUrl || compareUrl
const availableUrls = [...new Set(compareRuns.map(run => run.url))];
const run = compareRuns.find(run => run.url === selectedUrl);
const run = compareRuns.find(run => run.url === compareUrl);

const ancestorBuildId = props.ancestorBuild && props.ancestorBuild.id;
const baseRuns = props.runs.filter(run => run.buildId === ancestorBuildId);
const baseRun = baseRuns.find(run => run.url === selectedUrl);
const baseRun = baseRuns.find(run => run.url === baseUrl);

const availableUrlOptions = availableUrls.map(url => ({value: url, label: url}))

/** @type {LH.Result|undefined} */
let lhr;
Expand Down Expand Up @@ -117,7 +121,7 @@ const BuildView_ = props => {
lhr={baseLhr}
isDimmed={openBuildHash === 'compare'}
isOpen={openBuildHash === 'base'}
setLhrLinkHover={setLhrLinkHover}
setLhrLinkHover={setLhrBaseLinkHover}
onClick={() => setOpenBuild(openBuildHash === 'base' ? null : 'base')}
/>
<BuildSelectorHeaderSection
Expand All @@ -126,7 +130,7 @@ const BuildView_ = props => {
lhr={lhr}
isDimmed={openBuildHash === 'base'}
isOpen={openBuildHash === 'compare'}
setLhrLinkHover={setLhrLinkHover}
setLhrLinkHover={setLhrCompareLinkHover}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice split 👍

onClick={() => setOpenBuild(openBuildHash === 'compare' ? null : 'compare')}
/>
</Fragment>
Expand Down Expand Up @@ -159,33 +163,51 @@ const BuildView_ = props => {
<LhrComparison
lhr={lhr}
baseLhr={baseLhr}
className={clsx({'build-view--with-lhr-link-hover': isOpenLhrLinkHovered})}
className={clsx({
'build-view--with-lhr-base-link-hover': isOpenLhrBaseLinkHovered,
'build-view--with-lhr-compare-link-hover': isOpenLhrCompareLinkHovered
})}
hookElements={{
warnings: computeWarnings(warningProps).hasWarning ? (
<BuildViewWarnings {...warningProps} />
) : (
undefined
),
dropdowns: (
<Dropdown
label="URL"
className="dropdown--url"
value={selectedUrl}
setValue={url => {
const to = new URL(window.location.href);
to.searchParams.set('compareUrl', url);
route(`${to.pathname}${to.search}`);
}}
options={availableUrls.map(url => ({value: url, label: url}))}
/>
<Fragment>
<Dropdown
label="Base URL"
className="dropdown--url dropdown--base-url"
value={baseUrl}
setValue={url => {
const to = new URL(window.location.href);
to.searchParams.set('baseUrl', url);
to.searchParams.set('compareUrl', compareUrl);
route(`${to.pathname}${to.search}`);
}}
options={availableUrlOptions}
/>
<Dropdown
label="Compare URL"
className="dropdown--url dropdown--compare-url"
value={compareUrl}
setValue={url => {
const to = new URL(window.location.href);
to.searchParams.set('baseUrl', baseUrl);
to.searchParams.set('compareUrl', url);
route(`${to.pathname}${to.search}`);
}}
options={availableUrlOptions}
/>
</Fragment>
),
}}
/>
</Page>
);
};

/** @param {{projectSlug: string, partialBuildId: string, baseBuild?: string, compareUrl?: string}} props */
/** @param {{projectSlug: string, partialBuildId: string, baseBuild?: string, baseUrl?: string, compareUrl?: string}} props */
export const BuildView = props => {
const projectLoadingData = useProjectBySlug(props.projectSlug);
const projectId = projectLoadingData[1] && projectLoadingData[1].id;
Expand Down Expand Up @@ -232,6 +254,7 @@ export const BuildView = props => {
<BuildView_
project={project}
build={build}
baseUrl={props.baseUrl}
compareUrl={props.compareUrl}
ancestorBuild={ancestorBuild}
runs={runs.concat(baseRuns)}
Expand Down