Skip to content

feat(site): add template insights page #8722

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

Merged
merged 29 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1f7120f
Add insights page
BrunoQuaresma Jul 24, 2023
ed5784e
Add experiment
BrunoQuaresma Jul 24, 2023
c5efc1e
fix(site): fix error 'Reduce of empty array with no initial value'
BrunoQuaresma Jul 24, 2023
a1a9952
Merge branch 'bq/fix-js-error' into bq/insights-page
BrunoQuaresma Jul 24, 2023
fdcf23f
Show or not insights page
BrunoQuaresma Jul 24, 2023
dfd2f03
Set basic grid for the panels
BrunoQuaresma Jul 24, 2023
b40bdae
Add DAU panel
BrunoQuaresma Jul 24, 2023
6679ae3
Add avatar url into user latency insihgts
BrunoQuaresma Jul 24, 2023
e35a3b5
List latency by user
BrunoQuaresma Jul 24, 2023
544590d
Add user avatar to the list
BrunoQuaresma Jul 24, 2023
fb32677
Merge branch 'main' into bq/insights-page
BrunoQuaresma Jul 25, 2023
1a32402
Use avatar url
BrunoQuaresma Jul 25, 2023
5274733
Fix icon url
BrunoQuaresma Jul 25, 2023
864c6dd
Add apps and IDE usage
BrunoQuaresma Jul 25, 2023
7ea9a26
Fix title
BrunoQuaresma Jul 25, 2023
2aafcee
Add load and empty states
BrunoQuaresma Jul 25, 2023
941671b
Update date range
BrunoQuaresma Jul 25, 2023
37da9b1
Fix loading and not available data
BrunoQuaresma Jul 25, 2023
b8ce94a
Fix data empty
BrunoQuaresma Jul 25, 2023
06178c9
feat(site): add terminal icon
BrunoQuaresma Jul 25, 2023
117aa82
Merge branch 'main' into bq/insights-page
BrunoQuaresma Jul 25, 2023
e91ca19
Merge branch 'bq/add-terminal-icon' into bq/insights-page
BrunoQuaresma Jul 25, 2023
8be0e42
Consume DAUs from insights
BrunoQuaresma Jul 25, 2023
e2768e3
Apply minor improvements
BrunoQuaresma Jul 25, 2023
9236240
Minor improvements
BrunoQuaresma Jul 25, 2023
f147a4d
Fix deps
BrunoQuaresma Jul 25, 2023
03cb386
Merge branch 'main' into bq/insights-page
BrunoQuaresma Jul 25, 2023
8ed5ca3
Add storybook
BrunoQuaresma Jul 25, 2023
3bc6e6b
Fix deploy settings page
BrunoQuaresma Jul 26, 2023
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
Prev Previous commit
Next Next commit
Add load and empty states
  • Loading branch information
BrunoQuaresma committed Jul 25, 2023
commit 2aafcee66649aab5af9a854a84fd764745cdac6f
6 changes: 4 additions & 2 deletions site/src/components/Loader/Loader.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import Box from "@mui/material/Box"
import Box, { BoxProps } from "@mui/material/Box"
import CircularProgress from "@mui/material/CircularProgress"
import { FC } from "react"

export const Loader: FC<React.PropsWithChildren<{ size?: number }>> = ({
export const Loader: FC<{ size?: number } & BoxProps> = ({
size = 26,
...boxProps
}) => {
return (
<Box
Expand All @@ -13,6 +14,7 @@ export const Loader: FC<React.PropsWithChildren<{ size?: number }>> = ({
alignItems="center"
justifyContent="center"
data-testid="loader"
{...boxProps}
>
<CircularProgress size={size} />
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import chroma from "chroma-js"
import { colors } from "theme/colors"
import { Helmet } from "react-helmet-async"
import { getTemplatePageTitle } from "../utils"
import { Loader } from "components/Loader/Loader"

export default function TemplateInsightsPage() {
const { template } = useTemplateLayoutContext()
Expand Down Expand Up @@ -64,7 +65,11 @@ const DailyUsersPanel = (props: BoxProps) => {
</HelpTooltipText>
</HelpTooltip>
</PanelHeader>
<PanelContent>{data && <DAUChart daus={data} />}</PanelContent>
<PanelContent>
{!data && <Loader sx={{ height: "100%" }} />}
{data && data.entries.length === 0 && <NoDataAvailable />}
{data && <DAUChart daus={data} />}
</PanelContent>
</Panel>
)
}
Expand All @@ -81,15 +86,18 @@ const UserLatencyPanel = (props: BoxProps) => {
}),
})
const theme = useTheme()
const users = data?.report.users

return (
<Panel {...props} sx={{ overflowY: "auto", ...props.sx }}>
<PanelHeader sx={{ display: "flex", alignItems: "center", gap: 1 }}>
Latency by user
</PanelHeader>
<PanelContent>
{data &&
data.report.users
{!data && <Loader sx={{ height: "100%" }} />}
{users && users.length === 0 && <NoDataAvailable />}
{users &&
users
.sort((a, b) => b.latency_ms.p95 - a.latency_ms.p95)
.map((row) => (
<Box
Expand Down Expand Up @@ -145,11 +153,15 @@ const TemplateUsagePanel = (props: BoxProps) => {
.scale([colors.green[8], colors.blue[8]])
.mode("lch")
.colors(data?.report.apps_usage.length ?? 0)
// The API returns a row for each app, even if the user didn't use it.
const hasDataAvailable = data?.report.apps_usage.some((u) => u.seconds > 0)
return (
<Panel {...props}>
<PanelHeader>App&lsquo;s & IDE usage</PanelHeader>
<PanelContent>
{data && (
{!data && <Loader sx={{ height: 200 }} />}
{!hasDataAvailable && <NoDataAvailable sx={{ height: 200 }} />}
{data && hasDataAvailable && (
<Box sx={{ display: "flex", flexDirection: "column", gap: 3 }}>
{data.report.apps_usage
.sort((a, b) => b.seconds - a.seconds)
Expand Down Expand Up @@ -237,6 +249,26 @@ const PanelContent = styled(Box)(({ theme }) => ({
flex: 1,
}))

const NoDataAvailable = (props: BoxProps) => {
return (
<Box
{...props}
sx={{
fontSize: 13,
color: (theme) => theme.palette.text.secondary,
textAlign: "center",
height: "100%",
display: "flex",
alignItems: "center",
justifyContent: "center",
...props.sx,
}}
>
No data available
</Box>
)
}

function getTimeFor7DaysAgo(): Date {
const sevenDaysAgo = new Date()
sevenDaysAgo.setDate(sevenDaysAgo.getDate() - 7)
Expand Down