Skip to content

Commit

Permalink
Compare Page migration
Browse files Browse the repository at this point in the history
  • Loading branch information
marsian83 committed Oct 12, 2023
1 parent c7c38f0 commit ef3c457
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 10 deletions.
4 changes: 4 additions & 0 deletions website/src/assets/styles/tailwind.css
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
@apply m-0 p-0;
}

:root {
@apply duration-700;
}

/* Declaring Themes */
:root {
--color-primary: 231 112 2;
Expand Down
File renamed without changes.
194 changes: 194 additions & 0 deletions website/src/pages/ComparePage/ComparePage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
/*
Copyright 2023 The Vitess Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
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.
*/

import React, { useState, useEffect } from "react";
import { useNavigate } from "react-router-dom";
import RingLoader from "react-spinners/RingLoader";
import { SwiperSlide } from "swiper/react";
import useApiCall from "../../utils/Hook";

import Macrobench from "../../components/MacroComponents/Macrobench/Macrobench";
import MacrobenchMobile from "../../components/MacroComponents/MacrobenchMobile/MacrobenchMobile";
import Microbench from "../../components/Microbench/Microbench";
import Hero from "./components/Hero";

export default function Compare() {
const urlParams = new URLSearchParams(window.location.search);
// The following code sets up state variables `gitRef.left` and `gitRef.right` using the `useState` hook.
// The values of these variables are based on the query parameters extracted from the URL.

// If the 'ltag' query parameter is null or undefined, set the initial value of `gitRef.left` to 'Left',
// otherwise, use the value of the 'ltag' query parameter.
const [gitRef, setGitRef] = useState({
left: urlParams.get("ltag") || "Left",
right: urlParams.get("rtag") || "Right",
});
const [currentSlideIndexMobile, setCurrentSlideIndexMobile] = useState(
urlParams.get("ptagM") || "0"
);
const [isFormSubmitted, setIsFormSubmitted] = useState(false);

const {
data: dataMacrobench,
isLoading: isMacrobenchLoading,
error: macrobenchError,
textLoading: macroTextLoading,
} = useApiCall(
`${import.meta.env.VITE_API_URL}macrobench/compare?rtag=${
gitRef.right
}&ltag=${gitRef.left}`,
[isFormSubmitted]
);

const { data: dataMicrobench } = useApiCall(
`${import.meta.env.VITE_API_URL}microbench/compare?rtag=${
gitRef.right
}&ltag=${gitRef.left}`,
[isFormSubmitted]
);

// Changing the URL relative to the reference of a selected benchmark.
// Storing the carousel position as a URL parameter.
const navigate = useNavigate();

useEffect(() => {
navigate(
`?ltag=${gitRef.left}&rtag=${gitRef.right}&ptagM=${currentSlideIndexMobile}`
);
}, [gitRef.left, gitRef.right, currentSlideIndexMobile]);

const handleInputChangeLeft = (e) => {
setgitRef.left(e.target.value);
};

const handleInputChangeRight = (e) => {
setgitRef.right(e.target.value);
};

const handleSlideChange = (swiper) => {
setCurrentSlideIndexMobile(swiper.realIndex);
};

const handleSubmit = (e) => {
e.preventDefault();
setIsFormSubmitted((prevState) => !prevState);
};

return (
<div className="compare">
<div className="compare__top">
<Hero
gitRef={gitRef}
setGitRef={setGitRef}
handleSubmit={handleSubmit}
/>

{macrobenchError ? (
<div className="apiError">{macrobenchError}</div>
) : isMacrobenchLoading ? (
<div className="loadingSpinner">
<RingLoader
loading={isMacrobenchLoading}
color="#E77002"
size={300}
/>
</div>
) : (
<>
<h3 className="compare__macrobench__title">Macro Benchmarks</h3>
<div className="compare__macrobench__Container flex">
<div className="compare__carousel__container">
{dataMacrobench.map((macro, index) => {
return (
<div key={index}>
<Macrobench
data={macro}
textLoading={macroTextLoading}
gitRefLeft={gitRef.left.slice(0, 8)}
gitRefRight={gitRef.right.slice(0, 8)}
swiperSlide={SwiperSlide}
commitHashLeft={gitRef.left}
commitHashRight={gitRef.right}
/>
<MacrobenchMobile
data={macro}
gitRefLeft={gitRef.left.slice(0, 8)}
gitRefRight={gitRef.right.slice(0, 8)}
swiperSlide={SwiperSlide}
textLoading={macroTextLoading}
handleSlideChange={handleSlideChange}
setCurrentSlideIndexMobile={setCurrentSlideIndexMobile}
currentSlideIndexMobile={currentSlideIndexMobile}
commitHashLeft={gitRef.left}
commitHashRight={gitRef.right}
/>
</div>
);
})}
</div>
</div>

<div className="compare__micro__container">
<h3>Micro benchmarks</h3>
<div className="micro__thead space--between">
<span className="width--12em">Package</span>
<span className="width--14em">Benchmark Name</span>
<span className="width--18em hiddenMobile">
Number of Iterations
</span>
<span className="width--18em hiddenTablet">Time/op</span>
<span className="width--6em">More</span>
</div>
<figure className="micro__thead__line"></figure>
<div className="space--between--flex data__top hiddenMobile">
<div className="width--12em"></div>
<div className="width--14em"></div>
<div className="width--18em space--between--flex">
<span className="width--100">{gitRef.left.slice(0, 8)}</span>
<span className="width--100">{gitRef.right.slice(0, 8)}</span>
<span className="width--100">Diff %</span>
</div>
<div className="width--18em space--between--flex hiddenTablet">
<span className="width--100">{gitRef.left.slice(0, 8)}</span>
<span className="width--100">{gitRef.right.slice(0, 8)}</span>
<span className="width--100">Diff %</span>
</div>
<div className="width--6em"></div>
</div>
{dataMicrobench.length > 0 &&
dataMicrobench[0].PkgName !== "" &&
dataMicrobench[0].Name !== "" &&
dataMicrobench[0].SubBenchmarkName !== "" &&
dataMicrobench.map((micro, index) => {
const isEvenIndex = index % 2 === 0;
const backgroundGrey = isEvenIndex ? "grey--background" : "";
return (
<Microbench
data={micro}
key={index}
className={backgroundGrey}
gitRefLeft={gitRef.left.slice(0, 8)}
gitRefRight={gitRef.right.slice(0, 8)}
/>
);
})}
</div>
</>
)}
</div>
</div>
);
}
File renamed without changes.
45 changes: 45 additions & 0 deletions website/src/pages/ComparePage/components/Hero.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from "react";
import { twMerge } from "tailwind-merge";

export default function Hero(props) {
const { gitRef, setGitRef } = props;

return (
<div className="flex flex-col h-[35vh] justify-center items-center">
<h1 className="mb-3 text-front text-opacity-70">Enter SHAs to compare commits</h1>
<div className="flex overflow-hidden bg-gradient-to-br from-primary to-accent p-[2px] rounded-full">
<ComparisonInput
name="left"
className="rounded-l-full"
setGitRef={setGitRef}
/>
<ComparisonInput
name="right"
className="rounded-r-full "
setGitRef={setGitRef}
/>
</div>
</div>
);
}

function ComparisonInput(props) {
const { className, setGitRef, name } = props;

return (
<input
type="text"
name={name}
className={twMerge(
className,
"relative text-xl px-6 py-2 bg-background focus:border-none focus:outline-none border border-primary"
)}
placeholder={`${name} commit SHA`}
onChange={(event) =>
setGitRef((p) => {
return { ...p, [name]: event.target.value };
})
}
/>
);
}
9 changes: 8 additions & 1 deletion website/src/pages/DailyPage/DailyPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ export default function DailyPage() {
navigate(`?type=${benchmarkType}`);
}, [benchmarkType]);

useEffect(()=>{
console.log(dataDailySummary)
console.log("\n\ndataDaily")
console.log(dataDaily)
console.log("\n\ndataDailySummary")
},[dataDaily,dataDailySummary])

const TPSData = [
{
id: "TPS",
Expand Down Expand Up @@ -239,7 +246,7 @@ export default function DailyPage() {

{dataDaily && dataDailySummary && (
<>
<div className="flex p-page ">
<div className="flex p-page">
{dataDailySummary.map((dailySummary, index) => {
return (
<DailySummary
Expand Down
Empty file.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import React, { useState, useEffect } from "react";
import useApiCall from "../../utils/Hook";
import RingLoader from "react-spinners/RingLoader";

import "../PR/PR.css";

import { errorApi } from "../../utils/Utils";
import PRGitInfo from "../../components/PRcomponents/PRGitInfo";

Expand Down
8 changes: 4 additions & 4 deletions website/src/pages/PublicRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import Macro from "./Macro/Macro";
import Micro from "./Micro/Micro";
import Search from "./Search/Search";
import MacroQueriesCompare from "./MacroQueriesCompare/MacroQueriesCompare";
import Compare from "./Compare/Compare";
import PR from "./PR/PR";
import ComparePage from "./ComparePage/ComparePage";
import PRPage from "./PRPage/PRPage";
import SinglePR from "./SinglePR/SinglePR";
import HomePage from "./HomePage/HomePage";
import StatusPage from "./StatusPage/StatusPage";
Expand All @@ -41,14 +41,14 @@ const PublicRoute = () => {
<Route path="/status" element={<StatusPage />} />
<Route path="/Daily" element={<DailyPage />} />
<Route path="/search" element={<Search />} />
<Route path="/compare" element={<Compare />} />
<Route path="/compare" element={<ComparePage />} />
<Route path="/macro" element={<Macro />} />
<Route
path="/macrobench/queries/compare"
element={<MacroQueriesCompare />}
/>
<Route path="/micro" element={<Micro />} />
<Route path="/pr" element={<PR />} />
<Route path="/pr" element={<PRPage />} />
<Route path="/pr/:pull_nb" element={<SinglePR />} />

<Route path="*" element={<Error />} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ export default function PreviousExecutions(props) {

newData["Source"] = entry.source;

newData["Started"] = formatDate(entry.started_at);
newData["Started"] = formatDate(entry.started_at) || "N/A";

newData["Finished"] = formatDate(entry.finished_at);
newData["Finished"] = formatDate(entry.finished_at) || "In Progress";

newData["Type"] = entry.type_of;

Expand Down
11 changes: 10 additions & 1 deletion website/src/utils/Utils.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,16 @@ export const getStatusClass = (status) => {

// FORMATDATE
export const formatDate = (date) => {
return moment(date).format("MM/DD/YYYY HH:mm");
if (!date || date === 0) return null;

date = new Date(date);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, "0");
const day = String(date.getDate()).padStart(2, "0");
const hours = String(date.getHours()).padStart(2, "0");
const minutes = String(date.getMinutes()).padStart(2, "0");

return `${month}/${day}/${year} ${hours}:${minutes}`;
};

//FORMATTING BYTES TO GB
Expand Down

0 comments on commit ef3c457

Please sign in to comment.