Skip to content
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(COREL): update types to bundle + add create bundle functionality #7047

Merged
merged 29 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
808647c
refactor(sanity): update types to bundle
RitaDias Jul 1, 2024
4e3b76a
feat(sanity): add ability to create releases from dialog + update types
RitaDias Jul 2, 2024
932dea8
feat(sanity): update list on global and document to use store
RitaDias Jul 2, 2024
c0f8cf4
feat(sanity): update types, add icon and hue picker to bundles, updat…
RitaDias Jul 2, 2024
dfd5d40
feat(sanity): add date picker to bundleform
RitaDias Jul 3, 2024
8aa727a
refactor(sanity): update publishAt fields in menus
RitaDias Jul 3, 2024
263b2ca
refactor(sanity): update type in dummyGetter
RitaDias Jul 3, 2024
269f279
chore(sanity): remove BUNDLES const
RitaDias Jul 3, 2024
4d9cb73
chore(sanity): update LATEST type to Partial
RitaDias Jul 3, 2024
c233a70
chore(sanity): update validation for bundle date creation
RitaDias Jul 3, 2024
f8794fc
chore(sanity): clean up code
RitaDias Jul 3, 2024
e3c762d
refactor(sanity): add archived filter
RitaDias Jul 3, 2024
8feccd4
refactor(sanity): make single bundle menu + clean up
RitaDias Jul 3, 2024
42feacd
chore(sanity): add missing properties
RitaDias Jul 3, 2024
810f692
feat(sanity): add loading & remove unused code
RitaDias Jul 3, 2024
d7515f5
feat(sanity): add loading to document version, update filter
RitaDias Jul 3, 2024
788cf21
chore(sanity): rename VersionBadge to BundleBadge
RitaDias Jul 3, 2024
0181e4d
chore(sanity): clean up methods and style
RitaDias Jul 3, 2024
b5b7a6f
Merge branch 'corel' into corel-35
RitaDias Jul 3, 2024
f58b961
Merge branch 'corel' into corel-35
RitaDias Jul 3, 2024
af68e88
chore(sanity): remove unused import
RitaDias Jul 3, 2024
9ab6d65
refactor(sanity): use Bundle provider instead of store
RitaDias Jul 3, 2024
62ffd3e
chore(sanity): update bundleRow to use the new name for badge
RitaDias Jul 3, 2024
acdb5ce
chore(sanity): clean up code
RitaDias Jul 4, 2024
e904eed
refactor(sanity): re-add oncancel and oncreate props in dialog
RitaDias Jul 4, 2024
dc9ca47
refactor(sanity): add scroll to bundle menu
RitaDias Jul 4, 2024
12abc2b
refactor(sanity): move from archived to archivedAt
RitaDias Jul 4, 2024
b7a8c61
refactor(sanity): only show the list of bundles if it has more than p…
RitaDias Jul 4, 2024
a9f31a4
chore(sanity): remove warnings comments
RitaDias Jul 4, 2024
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
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const config = {

// Ignore i18n in releases files. TODO: Remove this before moving releases to GA.
{
files: ['**/*/core/releases/**/*'],
files: ['**/*/core/releases/**/*', '**/*/core/versions/**/*'],
RitaDias marked this conversation as resolved.
Show resolved Hide resolved
rules: {
'i18next/no-literal-string': 'off',
'@sanity/i18n/no-attribute-string-literals': 'off',
Expand Down
30 changes: 17 additions & 13 deletions packages/sanity/src/_singletons/core/form/VersionContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
// eslint-disable-next-line import/consistent-type-specifier-style
import {createContext, type ReactElement} from 'react'

import type {Version} from '../../../core/versions/types'
import {BUNDLES, LATEST} from '../../../core/versions/util/const'
import {useBundlesStore} from '../../../core/store/bundles'
RitaDias marked this conversation as resolved.
Show resolved Hide resolved
import type {BundleDocument} from '../../../core/store/bundles/types'
import {LATEST} from '../../../core/versions/util/const'
import {useRouter} from '../../../router'

export interface VersionContextValue {
currentVersion: Version
currentVersion: Partial<BundleDocument>
isDraft: boolean
setCurrentVersion: (version: Version) => void
setCurrentVersion: (bundle: Partial<BundleDocument>) => void
}

export const VersionContext = createContext<VersionContextValue>({
Expand All @@ -27,22 +28,25 @@ interface VersionProviderProps {

export function VersionProvider({children}: VersionProviderProps): JSX.Element {
const router = useRouter()
const setCurrentVersion = (version: Version) => {
const {data: bundles} = useBundlesStore()

const setCurrentVersion = (version: Partial<BundleDocument>) => {
const {name} = version
if (name === 'drafts') {
router.navigateStickyParam('perspective', '')
} else {
router.navigateStickyParam('perspective', `bundle.${name}`)
}
}
const selectedVersion = router.stickyParams?.perspective
? BUNDLES.find((bundle) => {
return (
`bundle.${bundle.name}`.toLocaleLowerCase() ===
router.stickyParams.perspective?.toLocaleLowerCase()
)
})
: LATEST
const selectedVersion =
router.stickyParams?.perspective && bundles
? bundles.find((bundle) => {
return (
`bundle.${bundle.name}`.toLocaleLowerCase() ===
router.stickyParams.perspective?.toLocaleLowerCase()
)
})
: LATEST

const currentVersion = selectedVersion || LATEST

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {RelativeTime} from 'sanity'
import {useRouter} from 'sanity/router'

import {type BundleDocument} from '../../../store/bundles/types'
import {VersionBadge} from '../../../versions/components/VersionBadge'
import {BundleBadge} from '../../../versions/components/BundleBadge'
import {BundleMenuButton} from '../BundleMenuButton/BundleMenuButton'

type Props = {
Expand All @@ -26,7 +26,7 @@ export function BundleRow({bundle}: Props) {
>
<Flex align="center" gap={2}>
<Box flex="none">
<VersionBadge tone={bundle.tone} icon={bundle.icon} />
<BundleBadge tone={bundle.tone} icon={bundle.icon} />
</Box>
<Stack flex={1} space={2}>
<Flex align="center" gap={2}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {type ComponentType, type FormEvent, useCallback, useState} from 'react'
import {Button} from '../../../../ui-components'
import {LoadingBlock} from '../../../components/loadingBlock/LoadingBlock'
import {AddonDatasetProvider} from '../../../studio/addonDataset/AddonDatasetProvider'
import {BundleForm} from '../../../versions/components/dialog/BundleForm'
import {BundlesProvider, useBundles} from '../BundlesProvider'
import {type BundleDocument} from '../types'
import {useBundleOperations} from '../useBundleOperations'
import {ReleaseForm} from './ReleaseForm'

const WithAddonDatasetProvider = <P extends object>(Component: ComponentType<P>): React.FC<P> => {
const WrappedComponent: React.FC<P> = (props) => (
Expand Down Expand Up @@ -66,7 +66,7 @@ const BundlesStoreStory = () => {
<form onSubmit={handleCreateBundle}>
<Stack space={4}>
<Text weight="medium">Create a new release</Text>
<ReleaseForm onChange={setValue} value={value} />
<BundleForm onChange={setValue} value={value} />
<Flex justify="flex-end">
<Button
text="Create"
Expand Down
133 changes: 0 additions & 133 deletions packages/sanity/src/core/store/bundles/__workshop__/ReleaseForm.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions packages/sanity/src/core/store/bundles/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {type ColorHueKey} from '@sanity/color'
import {type IconSymbol} from '@sanity/icons'
import {type SanityDocument} from '@sanity/types'
import {type ButtonTone} from '@sanity/ui'

export interface BundleDocument extends SanityDocument {
_type: 'bundle'
title: string
name: string
description?: string
tone?: ButtonTone
hue?: ColorHueKey
icon?: IconSymbol
authorId: string
publishedAt?: string
Expand Down
15 changes: 9 additions & 6 deletions packages/sanity/src/core/studio/StudioProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import javascript from 'refractor/lang/javascript.js'
import json from 'refractor/lang/json.js'
import jsx from 'refractor/lang/jsx.js'
import typescript from 'refractor/lang/typescript.js'
import {AddonDatasetProvider} from 'sanity'

import {VersionProvider} from '../../_singletons/core/form/VersionContext'
import {LoadingBlock} from '../components/loadingBlock'
Expand Down Expand Up @@ -70,12 +71,14 @@ export function StudioProvider({
<WorkspaceLoader LoadingComponent={LoadingBlock} ConfigErrorsComponent={ConfigErrorsScreen}>
<StudioTelemetryProvider config={config}>
<LocaleProvider>
<VersionProvider>
<PackageVersionStatusProvider>
<EnableErrorReporting />
<ResourceCacheProvider>{children}</ResourceCacheProvider>
</PackageVersionStatusProvider>
</VersionProvider>
<AddonDatasetProvider>
RitaDias marked this conversation as resolved.
Show resolved Hide resolved
<VersionProvider>
<PackageVersionStatusProvider>
<EnableErrorReporting />
<ResourceCacheProvider>{children}</ResourceCacheProvider>
</PackageVersionStatusProvider>
</VersionProvider>
</AddonDatasetProvider>
</LocaleProvider>
</StudioTelemetryProvider>
</WorkspaceLoader>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import {hues} from '@sanity/color'
import {ChevronDownIcon, Icon} from '@sanity/icons'
import {Box, Flex, Text} from '@sanity/ui'
// eslint-disable-next-line camelcase
import {Box, Flex, rgba, Text, useTheme_v2} from '@sanity/ui'
import {type CSSProperties} from 'react'

import {type SanityVersionIcon} from '../types'
import {type BundleDocument} from '../../store/bundles/types'

export function VersionBadge(
props: Partial<SanityVersionIcon> & {openButton?: boolean; padding?: number; title?: string},
export function BundleBadge(
props: Partial<BundleDocument> & {openButton?: boolean; padding?: number; title?: string},
): JSX.Element {
const {tone, icon, openButton, padding = 3, title} = props
const {hue = 'gray', icon, openButton, padding = 3, title} = props
const {color} = useTheme_v2()

return (
<Flex
gap={padding}
padding={padding}
style={
{
'--card-fg-color': `var(--card-badge-${tone}-fg-color)`,
'--card-icon-color': `var(--card-badge-${tone}-icon-color)`,
'backgroundColor': `var(--card-badge-${tone}-bg-color)`,
'--card-bg-color': rgba(hues[hue][color._dark ? 700 : 300].hex, 0.2),
'--card-fg-color': hues[hue][color._dark ? 400 : 600].hex,
'--card-icon-color': hues[hue][color._dark ? 400 : 600].hex,
'backgroundColor': 'var(--card-bg-color)',
'borderRadius': '9999px',
} as CSSProperties
}
Expand Down
Loading
Loading