-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
267 additions
and
10 deletions.
There are no files selected for viewing
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
File renamed without changes.
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,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 | ||
}<ag=${gitRef.left}`, | ||
[isFormSubmitted] | ||
); | ||
|
||
const { data: dataMicrobench } = useApiCall( | ||
`${import.meta.env.VITE_API_URL}microbench/compare?rtag=${ | ||
gitRef.right | ||
}<ag=${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.
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,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 }; | ||
}) | ||
} | ||
/> | ||
); | ||
} |
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
Empty file.
File renamed without changes.
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
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