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(core): corel publish 2 action - test #8015

Merged
merged 3 commits into from
Dec 11, 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {getReleaseIdFromReleaseDocumentId, type ReleaseDocument} from '../index'
import {type EditableReleaseDocument} from './types'

export interface ReleaseOperationsStore {
publishRelease: (releaseId: string) => Promise<void>
publishRelease: (releaseId: string, useUnstableAction?: boolean) => Promise<void>
schedule: (releaseId: string, date: Date) => Promise<void>
//todo: reschedule: (releaseId: string, newDate: Date) => Promise<void>
unschedule: (releaseId: string) => Promise<void>
Expand Down Expand Up @@ -60,10 +60,12 @@ export function createReleaseOperationsStore(options: {
})
}

const handlePublishRelease = (releaseId: string) =>
const handlePublishRelease = (releaseId: string, useUnstableAction?: boolean) =>
requestAction(client, [
{
actionType: 'sanity.action.release.publish',
actionType: useUnstableAction
? 'sanity.action.release.publish2'
: 'sanity.action.release.publish',
releaseId: getReleaseIdFromReleaseDocumentId(releaseId),
},
])
Expand Down Expand Up @@ -179,7 +181,7 @@ interface ScheduleApiAction {
}

interface PublishApiAction {
actionType: 'sanity.action.release.publish'
actionType: 'sanity.action.release.publish' | 'sanity.action.release.publish2'
releaseId: string
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {useRouter} from 'sanity/router'
import {Button, Dialog} from '../../../../../ui-components'
import {ToneIcon} from '../../../../../ui-components/toneIcon/ToneIcon'
import {Translate, useTranslation} from '../../../../i18n'
import {supportsLocalStorage} from '../../../../util/supportsLocalStorage'
import {PublishedRelease} from '../../../__telemetry__/releases.telemetry'
import {usePerspective} from '../../../hooks/usePerspective'
import {releasesLocaleNamespace} from '../../../i18n'
Expand All @@ -31,9 +32,16 @@ export const ReleasePublishAllButton = ({
const {t} = useTranslation(releasesLocaleNamespace)
const perspective = usePerspective()
const telemetry = useTelemetry()
const [publishBundleStatus, setPublishBundleStatus] = useState<'idle' | 'confirm' | 'publishing'>(
'idle',
)
const publish2 = useMemo(() => {
if (supportsLocalStorage) {
return localStorage.getItem('publish2') === 'true'
}
return false
}, [])

const [publishBundleStatus, setPublishBundleStatus] = useState<
'idle' | 'confirm' | 'confirm-2' | 'publishing'
>('idle')

const isValidatingDocuments = documents.some(({validation}) => validation.isValidating)
const hasDocumentValidationErrors = documents.some(({validation}) => validation.hasError)
Expand All @@ -44,8 +52,9 @@ export const ReleasePublishAllButton = ({
if (!release) return

try {
const useUnstableAction = publishBundleStatus === 'confirm-2'
setPublishBundleStatus('publishing')
await publishRelease(release._id)
await publishRelease(release._id, useUnstableAction)
telemetry.log(PublishedRelease)
toast.push({
closable: true,
Expand Down Expand Up @@ -85,7 +94,7 @@ export const ReleasePublishAllButton = ({
} finally {
setPublishBundleStatus('idle')
}
}, [release, publishRelease, telemetry, toast, t, router, perspective])
}, [release, publishBundleStatus, publishRelease, telemetry, toast, t, router, perspective])

const confirmPublishDialog = useMemo(() => {
if (publishBundleStatus === 'idle') return null
Expand Down Expand Up @@ -150,6 +159,23 @@ export const ReleasePublishAllButton = ({

return (
<>
{publish2 && (
<Button
tooltipProps={{
disabled: !isPublishButtonDisabled,
content: publishTooltipContent,
placement: 'bottom',
}}
icon={PublishIcon}
disabled={isPublishButtonDisabled || publishBundleStatus === 'publishing'}
// eslint-disable-next-line @sanity/i18n/no-attribute-string-literals
text={'Unstable Publish'}
onClick={() => setPublishBundleStatus('confirm-2')}
loading={publishBundleStatus === 'publishing'}
data-testid="publish-all-button"
tone="suggest"
/>
)}
<Button
tooltipProps={{
disabled: !isPublishButtonDisabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ describe('after releases have loaded', () => {

expect(useReleaseOperationsMockReturn.publishRelease).toHaveBeenCalledWith(
activeASAPRelease._id,
false,
)
})
})
Expand Down
Loading