Skip to content

[PAY-3282] Prevent publishing 0 length playlist #9328

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

Merged
merged 6 commits into from
Jul 31, 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 @@ -62,7 +62,8 @@ export const EditCollectionForm = (props: EditCollectionFormProps) => {
const {
playlist_id,
is_private: initiallyHidden,
is_scheduled_release: isInitiallyScheduled
is_scheduled_release: isInitiallyScheduled,
playlist_contents: initialContents
} = initialValues

const [isDeleteConfirmationOpen, setIsDeleteConfirmationOpen] =
Expand Down Expand Up @@ -157,6 +158,12 @@ export const EditCollectionForm = (props: EditCollectionFormProps) => {
<VisibilityField
entityType={isAlbum ? 'album' : 'playlist'}
isUpload={isUpload}
isPublishable={
isAlbum ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we check isAlbum separately? shouldn't we also check that albums have more than 0 tracks?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember something about removing this check, but tbh I don't remember the logic. I think it has to do with hidden/scheduled tracks being possible now?

(!isAlbum &&
(initialContents?.track_ids?.length ?? 1) > 0 &&
!isUpload)
}
/>
) : (
<ReleaseDateFieldLegacy />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ import { mergeReleaseDateValues } from './mergeReleaseDateValues'

const messages = {
...visibilityMessages,
scheduled: (date: string) => `Scheduled for ${formatCalendarTime(date)}`
scheduled: (date: string) => `Scheduled for ${formatCalendarTime(date)}`,
emptyPlaylistTooltipText: 'You must add at least 1 song.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it have to be a public song?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess based on how we do the checks, no, but maybe we can address that separately? good thought...!

}

type VisibilityType = 'scheduled' | 'public' | 'hidden'

type VisibilityFieldProps = {
entityType: 'track' | 'album' | 'playlist'
isUpload: boolean
isPublishable?: boolean
}

const visibilitySchema = z
Expand Down Expand Up @@ -76,7 +78,7 @@ const visibilitySchema = z
)

export const VisibilityField = (props: VisibilityFieldProps) => {
const { entityType, isUpload } = props
const { entityType, isUpload, isPublishable = true } = props
const useEntityField = entityType === 'track' ? useTrackField : useField
const [
{ value: isHidden },
Expand Down Expand Up @@ -179,6 +181,7 @@ export const VisibilityField = (props: VisibilityFieldProps) => {
<VisibilityMenuFields
entityType={entityType}
initiallyPublic={!initiallyHidden && !isUpload}
isPublishable={isPublishable}
/>
}
/>
Expand All @@ -188,6 +191,7 @@ export const VisibilityField = (props: VisibilityFieldProps) => {
type VisibilityMenuFieldsProps = {
entityType: 'track' | 'album' | 'playlist'
initiallyPublic?: boolean
isPublishable?: boolean
}

const VisibilityMenuFields = (props: VisibilityMenuFieldsProps) => {
Expand All @@ -197,7 +201,7 @@ const VisibilityMenuFields = (props: VisibilityMenuFieldsProps) => {
const { isEnabled: isPaidScheduledEnabled } = useFeatureFlag(
FeatureFlags.PAID_SCHEDULED
)
const { initiallyPublic, entityType } = props
const { initiallyPublic, isPublishable = true, entityType } = props
const [field] = useField<VisibilityType>('visibilityType')

return (
Expand All @@ -206,6 +210,10 @@ const VisibilityMenuFields = (props: VisibilityMenuFieldsProps) => {
value='public'
label={messages.public}
description={messages.publicDescription}
disabled={!isPublishable}
tooltipText={
isPublishable ? undefined : messages.emptyPlaylistTooltipText
}
/>
<ModalRadioItem
value='hidden'
Expand Down