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(sanity): add release types #7619

Merged
merged 3 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions packages/sanity/src/core/i18n/bundles/studio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,12 @@ export const studioLocaleStrings = defineLocalesResources('studio', {
'release.form.search-icon-tooltip': 'Select release icon',
/** Label for the title form field when creating releases */
'release.form.title': 'Title',
/** Label for the release type 'as soon as possible' */
'release.form.type.asap': 'ASAP',
/** Label for the release type 'at time', meaning it's a release with a scheduled date */
'release.form.type.scheduled': 'At time',
/** Label for the release type 'undecided' */
'release.form.type.undecided': 'Undecided',
/** Tooltip for the dropdown to show all versions of document */
'release.version-list.tooltip': 'See all document versions',

Expand Down
1 change: 1 addition & 0 deletions packages/sanity/src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export * from './i18n'
export * from './presence'
export * from './preview'
export {
DEFAULT_RELEASE_TYPE,
getDocumentIsInPerspective,
LATEST,
ReleaseActions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {ArrowRightIcon} from '@sanity/icons'
import {useTelemetry} from '@sanity/telemetry/react'
import {Box, Flex, useToast} from '@sanity/ui'
import {type FormEvent, useCallback, useState} from 'react'
import {type FormBundleDocument, useTranslation} from 'sanity'
import {DEFAULT_RELEASE_TYPE, type FormBundleDocument, useTranslation} from 'sanity'

import {Button, Dialog} from '../../../../ui-components'
import {type BundleDocument} from '../../../store/bundles/types'
Expand Down Expand Up @@ -40,6 +40,7 @@ export function ReleaseDetailsDialog(props: ReleaseDetailsDialogProps): JSX.Elem
hue: bundle?.hue || 'gray',
icon: bundle?.icon || 'cube',
publishedAt: bundle?.publishedAt,
releaseType: bundle?.releaseType || DEFAULT_RELEASE_TYPE,
} as const
})
const [isSubmitting, setIsSubmitting] = useState(false)
Expand Down
63 changes: 48 additions & 15 deletions packages/sanity/src/core/releases/components/dialog/ReleaseForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import {
useTranslation,
} from 'sanity'

import {Button} from '../../../../ui-components'
import {type CalendarLabels} from '../../../../ui-components/inputs/DateInputs/calendar/types'
import {DateTimeInput} from '../../../../ui-components/inputs/DateInputs/DateTimeInput'
import {getCalendarLabels} from '../../../form/inputs/DateInputs/utils'
import {type BundleDocument} from '../../../store/bundles/types'
import {type BundleDocument, type releaseType} from '../../../store/bundles/types'
import {ReleaseIconEditorPicker, type ReleaseIconEditorPickerValue} from './ReleaseIconEditorPicker'

interface BaseBundleDocument extends Partial<BundleDocument> {
Expand All @@ -33,7 +34,7 @@ export function ReleaseForm(props: {
value: FormBundleDocument
}): JSX.Element {
const {onChange, value} = props
const {title, description, icon, hue, publishedAt} = value
const {title, description, icon, hue, publishedAt, releaseType} = value
// derive the action from whether the initial value prop has a slug
// only editing existing bundles will provide a value.slug
const {t} = useTranslation()
Expand All @@ -44,6 +45,8 @@ export function ReleaseForm(props: {
const [titleErrors, setTitleErrors] = useState<FormNodeValidation[]>([])
const [dateErrors, setDateErrors] = useState<FormNodeValidation[]>([])

const [buttonReleaseType, setButtonReleaseType] = useState<releaseType>(releaseType ?? 'asap')

const {t: coreT} = useTranslation()
const calendarLabels: CalendarLabels = useMemo(() => getCalendarLabels(coreT), [coreT])
const [inputValue, setInputValue] = useState<string | undefined>(
Expand Down Expand Up @@ -95,11 +98,54 @@ export function ReleaseForm(props: {
[onChange, value],
)

const handleButtonReleaseTypeChange = useCallback(
(pickedReleaseType: releaseType) => {
setButtonReleaseType(pickedReleaseType)
onChange({...value, releaseType: pickedReleaseType})
},
[onChange, value],
)

return (
<Stack space={5}>
<Flex>
<ReleaseIconEditorPicker onChange={handleIconValueChange} value={iconValue} />
</Flex>

<Stack space={2} style={{margin: -1}}>
<Flex gap={1}>
<Button
mode="bleed"
onClick={() => handleButtonReleaseTypeChange('asap')}
selected={buttonReleaseType === 'asap'}
text={t('release.form.type.asap')}
/>
<Button
mode="bleed"
onClick={() => handleButtonReleaseTypeChange('scheduled')}
selected={buttonReleaseType === 'scheduled'}
text={t('release.form.type.scheduled')}
/>
<Button
mode="bleed"
onClick={() => handleButtonReleaseTypeChange('undecided')}
selected={buttonReleaseType === 'undecided'}
text={t('release.form.type.undecided')}
/>
</Flex>

{buttonReleaseType === 'scheduled' && (
<DateTimeInput
selectTime
onChange={handleBundlePublishAtChange}
calendarLabels={calendarLabels}
value={value.publishedAt ? new Date(value.publishedAt) : undefined}
inputValue={inputValue || ''}
constrainSize={false}
/>
)}
</Stack>

<Stack space={3}>
<FormFieldHeaderText title={t('release.form.title')} validation={titleErrors} />
<TextInput
Expand All @@ -120,19 +166,6 @@ export function ReleaseForm(props: {
data-testid="release-form-description"
/>
</Stack>

<Stack space={3}>
<FormFieldHeaderText title="Schedule for publishing at" validation={dateErrors} />

<DateTimeInput
selectTime
onChange={handleBundlePublishAtChange}
calendarLabels={calendarLabels}
value={value.publishedAt ? new Date(value.publishedAt) : undefined}
inputValue={inputValue || ''}
constrainSize={false}
/>
</Stack>
</Stack>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ describe('ReleaseDetailsDialog', () => {
icon,
title: 'New title',
description: 'New description',
publishedAt: undefined,
releaseType: 'asap',
})
})

Expand Down
5 changes: 5 additions & 0 deletions packages/sanity/src/core/releases/util/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@ export const LATEST = {
icon: undefined,
hue: 'gray',
} as const

/**
* @internal
*/
export const DEFAULT_RELEASE_TYPE = 'asap'
4 changes: 4 additions & 0 deletions packages/sanity/src/core/store/bundles/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {type PartialExcept} from '../../util'
import {type MetadataWrapper} from './createBundlesMetadataAggregator'
import {type bundlesReducerAction, type bundlesReducerState} from './reducer'

/** @internal */
export type releaseType = 'asap' | 'scheduled' | 'undecided'

/**
* @internal
*/
Expand All @@ -22,6 +25,7 @@ export interface BundleDocument
publishedAt?: string
archivedAt?: string
publishedBy?: string
releaseType: releaseType
}

/**
Expand Down
Loading