-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into fix/add-suspense-viewer
- Loading branch information
Showing
32 changed files
with
504 additions
and
116 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
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
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
12 changes: 12 additions & 0 deletions
12
packages/atlas/src/components/_ypp/YppStatusPill/YppStatusPill.stories.tsx
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,12 @@ | ||
import { Meta, StoryFn } from '@storybook/react' | ||
|
||
import { YppStatusPill } from '@/components/_ypp/YppStatusPill/YppStatusPill' | ||
|
||
export default { | ||
title: 'components/YppStatusPill', | ||
component: YppStatusPill, | ||
} as Meta | ||
|
||
const Template: StoryFn = () => <YppStatusPill /> | ||
|
||
export const Default = Template.bind({}) |
70 changes: 70 additions & 0 deletions
70
packages/atlas/src/components/_ypp/YppStatusPill/YppStatusPill.styles.ts
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,70 @@ | ||
import { css, keyframes } from '@emotion/react' | ||
import styled from '@emotion/styled' | ||
|
||
import { cVar, sizes } from '@/styles' | ||
|
||
export const Container = styled.div` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
gap: ${sizes(2)}; | ||
background-color: ${cVar('colorCoreNeutral800Lighten')}; | ||
padding: ${sizes(2)} ${sizes(4)}; | ||
border-radius: 99px; | ||
width: fit-content; | ||
` | ||
|
||
type DotProps = { | ||
status: 'operational' | 'delayed' | 'stopped' | ||
} | ||
|
||
const getStatusDotStyles = ({ status }: DotProps) => { | ||
switch (status) { | ||
case 'delayed': | ||
return css` | ||
background: linear-gradient(#f1c804, #947b01); | ||
box-shadow: 0 0 0 5px #caa80280; | ||
` | ||
case 'stopped': | ||
return css` | ||
background: linear-gradient(#ff695f, #bf0c00); | ||
box-shadow: 0 0 0 5px #ff695f80; | ||
` | ||
case 'operational': | ||
return css` | ||
background: linear-gradient(#0ebe57, #096c34); | ||
box-shadow: 0 0 0 5px #0c984680; | ||
` | ||
} | ||
} | ||
|
||
const getDotAnimation = ({ status }: DotProps) => keyframes` | ||
0% { | ||
box-shadow: none; | ||
} | ||
10% { | ||
box-shadow: 0 0 0 3px ${status === 'stopped' ? '#ff695f80' : status === 'delayed' ? '#caa80280' : '#0c984680'}; | ||
} | ||
20%, 100% { | ||
box-shadow: none; | ||
} | ||
` | ||
|
||
export const StatusDot = styled.div<DotProps>` | ||
width: 10px; | ||
height: 10px; | ||
border-radius: 50%; | ||
${getStatusDotStyles}; | ||
animation: 10s ease-out ${getDotAnimation} infinite; | ||
` | ||
|
||
export const TooltipBox = styled.div` | ||
padding: ${sizes(1)}; | ||
display: grid; | ||
gap: ${sizes(2)}; | ||
` |
74 changes: 74 additions & 0 deletions
74
packages/atlas/src/components/_ypp/YppStatusPill/YppStatusPill.tsx
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,74 @@ | ||
import { useRef } from 'react' | ||
import { useQuery } from 'react-query' | ||
|
||
import { axiosInstance } from '@/api/axios' | ||
import { Text } from '@/components/Text' | ||
import { Tooltip } from '@/components/Tooltip' | ||
import { atlasConfig } from '@/config' | ||
import { ConsoleLogger } from '@/utils/logs' | ||
|
||
import { Container, StatusDot, TooltipBox } from './YppStatusPill.styles' | ||
|
||
export type YppStatusType = 'operational' | 'delayed' | 'stopped' | ||
|
||
const getTooltipText = (status: YppStatusType) => { | ||
switch (status) { | ||
case 'delayed': | ||
return ['OPERATING WITH DELAYS', 'We are experiencing a bigger amount of network traffic right now.'] | ||
case 'operational': | ||
return ['FULLY OPERATIONAL', 'Everything works as expected!'] | ||
case 'stopped': | ||
return ['ON HOLD', 'The sync network experienced a major outage - we are currently working on fixing the issue.'] | ||
} | ||
} | ||
|
||
const YOUTUBE_BACKEND_URL = atlasConfig.features.ypp.youtubeSyncApiUrl | ||
const YPP_DELAY_THRESHOLD = atlasConfig.features.ypp.yppDelayThreshold ?? 500 | ||
|
||
type YppStatusDto = { | ||
version: string | ||
syncStatus: string | ||
syncBacklog: number | ||
} | ||
|
||
export const YppStatusPill = () => { | ||
const statusRef = useRef<HTMLDivElement>(null) | ||
const { data, isLoading } = useQuery('ypp-status', () => | ||
axiosInstance<YppStatusDto>(`${YOUTUBE_BACKEND_URL}/status`).catch(() => | ||
ConsoleLogger.warn('Failed to fetch YPP status') | ||
) | ||
) | ||
|
||
if (!data || isLoading) { | ||
return null | ||
} | ||
|
||
const isDelayed = data.data.syncBacklog > YPP_DELAY_THRESHOLD | ||
const status: YppStatusType = isDelayed ? 'delayed' : data.data.syncStatus === 'enabled' ? 'operational' : 'stopped' | ||
const [tooltipTitle, tooltipText] = getTooltipText(status) | ||
|
||
return ( | ||
<> | ||
<Container ref={statusRef}> | ||
<Text variant="t200" as="p"> | ||
YPP Sync Status: | ||
</Text> | ||
<StatusDot status={status} /> | ||
</Container> | ||
<Tooltip | ||
reference={statusRef} | ||
placement="bottom-start" | ||
customContent={ | ||
<TooltipBox> | ||
<Text variant="h100" as="h1" color="colorTextStrong"> | ||
{tooltipTitle} | ||
</Text> | ||
<Text variant="t100" as="p" color="colorTextStrong"> | ||
{tooltipText} | ||
</Text> | ||
</TooltipBox> | ||
} | ||
/> | ||
</> | ||
) | ||
} |
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 @@ | ||
export * from './YppStatusPill' |
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
Oops, something went wrong.