Skip to content

Commit

Permalink
fix(ui): scheduled publish not showing related events in postgres (#1…
Browse files Browse the repository at this point in the history
…0481)

Since postgres uses number IDs by default, when we were storing the
relationship field value with postgres we weren't able to query it

This fixes that problem by casting the ID to always a string making it
safe for querying inside the JSON field
  • Loading branch information
paulpopus authored Jan 13, 2025
1 parent 69fac59 commit c9584a9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/payload/src/versions/schedule/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { CollectionSlug, GlobalSlug } from '../../index.js'
export type SchedulePublishTaskInput = {
doc?: {
relationTo: CollectionSlug
value: number | string
value: string
}
global?: GlobalSlug
locale?: string
Expand Down
23 changes: 15 additions & 8 deletions packages/ui/src/elements/PublishButton/ScheduleDrawer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { Where } from 'payload'

import { useModal } from '@faceless-ui/modal'
import { getTranslation } from '@payloadcms/translations'
import * as qs from 'qs-esm'
import React from 'react'
import { toast } from 'sonner'

Expand Down Expand Up @@ -78,7 +79,7 @@ export const ScheduleDrawer: React.FC<Props> = ({ slug }) => {
}, [localization, i18n])

const fetchUpcoming = React.useCallback(async () => {
const params: { sort: string; where: Where } = {
const query: { sort: string; where: Where } = {
sort: 'waitUntil',
where: {
and: [
Expand All @@ -97,29 +98,35 @@ export const ScheduleDrawer: React.FC<Props> = ({ slug }) => {
}

if (collectionSlug) {
params.where.and.push({
query.where.and.push({
'input.doc.value': {
equals: id,
equals: String(id),
},
})

params.where.and.push({
query.where.and.push({
'input.doc.relationTo': {
equals: collectionSlug,
},
})
}

if (globalSlug) {
params.where.and.push({
query.where.and.push({
'input.global': {
equals: globalSlug,
},
})
}

const { docs } = await requests
.get(`${serverURL}${api}/payload-jobs`, { params })
.post(`${serverURL}${api}/payload-jobs`, {
body: qs.stringify(query),
headers: {
'Accept-Language': i18n.language,
'Content-Type': 'application/x-www-form-urlencoded',
'X-HTTP-Method-Override': 'GET',
},
})
.then((res) => res.json())

setUpcomingColumns(buildUpcomingColumns({ dateFormat, docs, i18n, localization, t }))
Expand All @@ -146,7 +153,7 @@ export const ScheduleDrawer: React.FC<Props> = ({ slug }) => {
doc: collectionSlug
? {
relationTo: collectionSlug,
value: id,
value: String(id),
}
: undefined,
global: globalSlug || undefined,
Expand Down

0 comments on commit c9584a9

Please sign in to comment.