-
Notifications
You must be signed in to change notification settings - Fork 428
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(core): Studio announcements #7515
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
4f0fee8
feat(core): update UpsellDescriptionSerializer to support h3, images …
pedrobonamin 62d06f2
feat(core): studio announcements card and dialog gro-2493, gro-2498
pedrobonamin 450f606
feat(core): add studio announcements telemetry events
pedrobonamin bc867f4
feat(core): add studioAnnouncement provider with unseen modals check
pedrobonamin 716a903
feat(core): add studioAnnouncement menu item to Resources menu items
pedrobonamin bf18f68
chore(core): improvements to studio announcements
pedrobonamin 9ec11ae
chore(core): add tests for studio announcements
pedrobonamin 9e666d5
chore(core): add tests to save seen announcements actions
pedrobonamin 85080f4
feat(core): update telemetry events for studioAnnouncements
pedrobonamin 96d9922
fix(core): update useSeenAnnouncements to handle state reset
pedrobonamin 412c3b4
feat(core): add telemetry logs to announcement viewed and resources m…
pedrobonamin 441c739
chore(core): remove translations resources in tests
pedrobonamin f57bc16
fix(core): update query to check expiry date
pedrobonamin 28ca4fe
feat(core): add studioAnnouncements audienceRole check
pedrobonamin eebccbb
feat(core): replace client.fetch for internal api
pedrobonamin 829bf53
fix(core): move cardSeen telemetry log to card
pedrobonamin 85636cd
fix(core): add h2 to announcement dialog
pedrobonamin c375cc1
chore(core): add divider fade threshold details
pedrobonamin 53c933c
chore(core): refactor announcements provider fetch, use useObservable
pedrobonamin 7886599
chore(core): update useSeenAnnouncements, handle seen and unseen thro…
pedrobonamin 7fedf77
feat(core): update product announcement audience, (greater|less)-than…
pedrobonamin 6b02efd
feat(core): add support for card preHeader
pedrobonamin ef18a1e
fix(core): reduce studio announcements dialog height
pedrobonamin 8d265b1
chore(core): update studio announcements telemetry, add internal_name
pedrobonamin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
packages/sanity/src/_singletons/context/StudioAnnouncementsContext.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,11 @@ | ||
import {createContext} from 'sanity/_createContext' | ||
|
||
import type {StudioAnnouncementsContextValue} from '../../core/studio/studioAnnouncements/types' | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export const StudioAnnouncementContext = createContext<StudioAnnouncementsContextValue | undefined>( | ||
'sanity/_singletons/context/studioAnnouncements', | ||
undefined, | ||
) |
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
62 changes: 62 additions & 0 deletions
62
packages/sanity/src/core/studio/studioAnnouncements/Divider.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,62 @@ | ||
import {Box} from '@sanity/ui' | ||
import {useEffect, useRef, useState} from 'react' | ||
import {styled} from 'styled-components' | ||
|
||
const Hr = styled.hr<{$show: boolean}>` | ||
height: 1px; | ||
background: var(--card-border-color); | ||
width: 100%; | ||
opacity: ${({$show}) => ($show ? 1 : 0)}; | ||
transition: opacity 0.3s ease; | ||
margin: 0; | ||
border: none; | ||
` | ||
|
||
interface DividerProps { | ||
parentRef: React.RefObject<HTMLDivElement> | ||
} | ||
|
||
/** | ||
* This is the threshold for the divider to start fading | ||
* uses a negative value to start fading before reaching the top | ||
* of the parent. | ||
* We want to fade out the divider so it doesn't overlap with the close icon when reaching the top. | ||
* It's the sum of the title height (48px) and the divider padding top (12px) | ||
*/ | ||
const DIVIDER_FADE_THRESHOLD = '-60px 0px 0px 0px' | ||
|
||
/** | ||
* A divider that fades when reaching the top of the parent. | ||
*/ | ||
export function Divider({parentRef}: DividerProps): JSX.Element { | ||
const itemRef = useRef<HTMLHRElement | null>(null) | ||
const [show, setShow] = useState(true) | ||
|
||
useEffect(() => { | ||
const item = itemRef.current | ||
const parent = parentRef.current | ||
|
||
if (!item || !parent) return | ||
const observer = new IntersectionObserver( | ||
([entry]) => { | ||
setShow(entry.isIntersecting) | ||
}, | ||
{root: parent, threshold: 0, rootMargin: DIVIDER_FADE_THRESHOLD}, | ||
) | ||
|
||
observer.observe(item) | ||
|
||
// eslint-disable-next-line consistent-return | ||
return () => { | ||
observer.disconnect() | ||
} | ||
}, [parentRef]) | ||
|
||
return ( | ||
<Box paddingBottom={4}> | ||
<Box paddingY={3} paddingX={3}> | ||
<Hr ref={itemRef} $show={show} /> | ||
</Box> | ||
</Box> | ||
) | ||
} |
167 changes: 167 additions & 0 deletions
167
packages/sanity/src/core/studio/studioAnnouncements/StudioAnnouncementsCard.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,167 @@ | ||
/* eslint-disable camelcase */ | ||
import {RemoveIcon} from '@sanity/icons' | ||
import {useTelemetry} from '@sanity/telemetry/react' | ||
import {Box, Card, Stack, Text} from '@sanity/ui' | ||
// eslint-disable-next-line camelcase | ||
import {getTheme_v2} from '@sanity/ui/theme' | ||
import {useEffect} from 'react' | ||
import {useTranslation} from 'sanity' | ||
import {css, keyframes, styled} from 'styled-components' | ||
|
||
import {Button, Popover} from '../../../ui-components' | ||
import {SANITY_VERSION} from '../../version' | ||
import {ProductAnnouncementCardSeen} from './__telemetry__/studioAnnouncements.telemetry' | ||
|
||
const keyframe = keyframes` | ||
0% { | ||
background-position: 100%; | ||
} | ||
100% { | ||
background-position: -100%; | ||
} | ||
` | ||
|
||
const Root = styled.div((props) => { | ||
const theme = getTheme_v2(props.theme) | ||
const cardHoverBg = theme.color.selectable.default.hovered.bg | ||
const cardNormalBg = theme.color.selectable.default.enabled.bg | ||
|
||
return css` | ||
position: relative; | ||
cursor: pointer; | ||
// hide the close button | ||
#close-floating-button { | ||
opacity: 0; | ||
transition: opacity 0.2s; | ||
} | ||
|
||
&:hover { | ||
> [data-ui='whats-new-card'] { | ||
--card-bg-color: ${cardHoverBg}; | ||
box-shadow: inset 0 0 2px 1px var(--card-skeleton-color-to); | ||
background-image: linear-gradient( | ||
to right, | ||
var(--card-bg-color), | ||
var(--card-bg-color), | ||
${cardNormalBg}, | ||
var(--card-bg-color), | ||
var(--card-bg-color), | ||
var(--card-bg-color) | ||
); | ||
background-position: 100%; | ||
background-size: 200% 100%; | ||
background-attachment: fixed; | ||
animation-name: ${keyframe}; | ||
animation-timing-function: ease-in; | ||
animation-iteration-count: infinite; | ||
animation-duration: 2000ms; | ||
} | ||
#close-floating-button { | ||
opacity: 1; | ||
background: transparent; | ||
|
||
&:hover { | ||
transition: all 0.2s; | ||
box-shadow: 0 0 0 1px ${theme.color.selectable.default.hovered.border}; | ||
} | ||
} | ||
} | ||
` | ||
}) | ||
|
||
const ButtonRoot = styled.div` | ||
z-index: 1; | ||
position: absolute; | ||
top: 4px; | ||
right: 6px; | ||
` | ||
|
||
interface StudioAnnouncementCardProps { | ||
title: string | ||
id: string | ||
name: string | ||
isOpen: boolean | ||
preHeader: string | ||
onCardClick: () => void | ||
onCardDismiss: () => void | ||
} | ||
|
||
/** | ||
* @internal | ||
* @hidden | ||
*/ | ||
export function StudioAnnouncementsCard({ | ||
title, | ||
id, | ||
isOpen, | ||
name, | ||
preHeader, | ||
onCardClick, | ||
onCardDismiss, | ||
}: StudioAnnouncementCardProps) { | ||
const {t} = useTranslation() | ||
const telemetry = useTelemetry() | ||
|
||
useEffect(() => { | ||
if (isOpen) { | ||
telemetry.log(ProductAnnouncementCardSeen, { | ||
announcement_id: id, | ||
announcement_title: title, | ||
announcement_internal_name: name, | ||
source: 'studio', | ||
studio_version: SANITY_VERSION, | ||
}) | ||
} | ||
}, [telemetry, id, title, isOpen, name]) | ||
|
||
return ( | ||
<Popover | ||
open={isOpen} | ||
shadow={3} | ||
portal | ||
style={{ | ||
bottom: 12, | ||
left: 12, | ||
top: 'none', | ||
}} | ||
width={0} | ||
placement="bottom-start" | ||
content={ | ||
<Root data-ui="whats-new-root"> | ||
<Card | ||
data-ui="whats-new-card" | ||
padding={3} | ||
radius={3} | ||
onClick={onCardClick} | ||
role="button" | ||
aria-label={t('announcement.floating-button.open-label')} | ||
> | ||
<Stack space={3}> | ||
<Box marginRight={6}> | ||
<Text as={'h3'} size={1} muted> | ||
{preHeader} | ||
</Text> | ||
</Box> | ||
<Text size={1} weight="medium"> | ||
{title} | ||
</Text> | ||
</Stack> | ||
</Card> | ||
<ButtonRoot> | ||
<Button | ||
id="close-floating-button" | ||
mode="bleed" | ||
onClick={onCardDismiss} | ||
icon={RemoveIcon} | ||
tone="default" | ||
aria-label={t('announcement.floating-button.dismiss-label')} | ||
tooltipProps={{ | ||
content: t('announcement.floating-button.dismiss'), | ||
}} | ||
/> | ||
</ButtonRoot> | ||
</Root> | ||
} | ||
/> | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really nice touch 🙌.