Skip to content
Open
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
2 changes: 2 additions & 0 deletions packages/db-mongodb/src/createGlobalVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const createGlobalVersion: CreateGlobalVersion = async function createGlo
req,
returning,
snapshot,
unpublishedLocale,
updatedAt,
versionData,
},
Expand All @@ -36,6 +37,7 @@ export const createGlobalVersion: CreateGlobalVersion = async function createGlo
parent,
publishedLocale,
snapshot,
unpublishedLocale,
updatedAt,
version: versionData,
}
Expand Down
2 changes: 2 additions & 0 deletions packages/db-mongodb/src/createVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const createVersion: CreateVersion = async function createVersion(
req,
returning,
snapshot,
unpublishedLocale,
updatedAt,
versionData,
},
Expand All @@ -40,6 +41,7 @@ export const createVersion: CreateVersion = async function createVersion(
parent,
publishedLocale,
snapshot,
unpublishedLocale,
updatedAt,
version: versionData,
}
Expand Down
2 changes: 2 additions & 0 deletions packages/drizzle/src/createGlobalVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function createGlobalVersion<T extends TypeWithID>(
returning,
select,
snapshot,
unpublishedLocale,
updatedAt,
versionData,
}: CreateGlobalVersionArgs,
Expand All @@ -37,6 +38,7 @@ export async function createGlobalVersion<T extends TypeWithID>(
latest: true,
publishedLocale,
snapshot,
unpublishedLocale,
updatedAt,
version: versionData,
},
Expand Down
2 changes: 2 additions & 0 deletions packages/drizzle/src/createVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export async function createVersion<T extends TypeWithID>(
returning,
select,
snapshot,
unpublishedLocale,
updatedAt,
versionData,
}: CreateVersionArgs<T>,
Expand All @@ -43,6 +44,7 @@ export async function createVersion<T extends TypeWithID>(
parent,
publishedLocale,
snapshot,
unpublishedLocale,
updatedAt,
version,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const VersionPillLabel: React.FC<{
[key: string]: unknown
id: number | string
publishedLocale?: string
unpublishedLocale?: string
updatedAt?: string
version: {
[key: string]: unknown
Expand Down Expand Up @@ -85,15 +86,14 @@ export const VersionPillLabel: React.FC<{
? formatDate({ date: doc.updatedAt, i18n, pattern: dateFormat })
: null

const localeCode = Array.isArray(doc.publishedLocale)
? doc.publishedLocale[0]
: doc.publishedLocale
const getLocaleLabel = (input) => {
const code = Array.isArray(input) ? input[0] : input
const loc = localization && localization?.locales?.find((l) => l.code === code)
return loc?.label?.[i18n?.language] || loc?.label || null
}

const locale =
localization && localization?.locales
? localization.locales.find((loc) => loc.code === localeCode)
: null
const localeLabel = locale ? locale?.label?.[i18n?.language] || locale?.label : null
const unpublishedLocaleLabel = getLocaleLabel(doc.unpublishedLocale)
const localeLabel = getLocaleLabel(doc.publishedLocale)

return (
<div className={baseClass}>
Expand All @@ -117,6 +117,11 @@ export const VersionPillLabel: React.FC<{
</React.Fragment>
)}
{localeLabel && <Pill size="small">{localeLabel}</Pill>}
{unpublishedLocaleLabel && (
<Pill size="small">
{unpublishedLocaleLabel} {t('version:unpublished')}
</Pill>
)}
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type AutosaveCellProps = {
autosave?: boolean
id: number | string
publishedLocale?: string
unpublishedLocale?: string
version: {
_status: string
}
Expand Down
2 changes: 2 additions & 0 deletions packages/payload/src/collections/endpoints/updateByID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const updateByIDHandler: PayloadHandler = async (req) => {
const overrideLock = searchParams.get('overrideLock')
const trash = searchParams.get('trash') === 'true'
const publishSpecificLocale = req.query.publishSpecificLocale as string | undefined
const unpublishSpecificLocale = req.query.unpublishSpecificLocale as string | undefined

const doc = await updateByIDOperation({
id,
Expand All @@ -32,6 +33,7 @@ export const updateByIDHandler: PayloadHandler = async (req) => {
req,
select: sanitizeSelectParam(req.query.select),
trash,
unpublishSpecificLocale,
})

let message = req.t('general:updatedSuccessfully')
Expand Down
6 changes: 6 additions & 0 deletions packages/payload/src/collections/operations/local/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export type BaseOptions<TSlug extends CollectionSlug, TSelect extends SelectType
* @default false
*/
trash?: boolean
/**
* Unpublish the document / documents for a specific locale.
*/
unpublishSpecificLocale?: string
/**
* If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.
*/
Expand Down Expand Up @@ -227,6 +231,7 @@ async function updateLocal<
showHiddenFields,
sort,
trash = false,
unpublishSpecificLocale,
where,
} = options

Expand Down Expand Up @@ -261,6 +266,7 @@ async function updateLocal<
showHiddenFields,
sort,
trash,
unpublishSpecificLocale,
where,
}

Expand Down
3 changes: 3 additions & 0 deletions packages/payload/src/collections/operations/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type Arguments<TSlug extends CollectionSlug> = {
*/
sort?: Sort
trash?: boolean
unpublishSpecificLocale?: string
where: Where
}

Expand Down Expand Up @@ -114,6 +115,7 @@ export const updateOperation = async <
showHiddenFields,
sort: incomingSort,
trash = false,
unpublishSpecificLocale,
where,
} = args

Expand Down Expand Up @@ -261,6 +263,7 @@ export const updateOperation = async <
req,
select: select!,
showHiddenFields: showHiddenFields!,
unpublishSpecificLocale,
})

return updatedDoc
Expand Down
7 changes: 7 additions & 0 deletions packages/payload/src/collections/operations/updateByID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export type Arguments<TSlug extends CollectionSlug> = {
select?: SelectType
showHiddenFields?: boolean
trash?: boolean
unpublishSpecificLocale?: string
}

export const updateByIDOperation = async <
Expand Down Expand Up @@ -83,6 +84,10 @@ export const updateByIDOperation = async <
args.req.locale = args.publishSpecificLocale
}

if (args.unpublishSpecificLocale) {
args.req.locale = args.unpublishSpecificLocale
}

const {
id,
autosave = false,
Expand All @@ -105,6 +110,7 @@ export const updateByIDOperation = async <
select: incomingSelect,
showHiddenFields,
trash = false,
unpublishSpecificLocale,
} = args

if (!id) {
Expand Down Expand Up @@ -216,6 +222,7 @@ export const updateByIDOperation = async <
req,
select: select!,
showHiddenFields: showHiddenFields!,
unpublishSpecificLocale,
})

await unlinkTempFiles({
Expand Down
12 changes: 11 additions & 1 deletion packages/payload/src/collections/operations/utilities/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type SharedUpdateDocumentArgs<TSlug extends CollectionSlug> = {
req: PayloadRequest
select: SelectType
showHiddenFields: boolean
unpublishSpecificLocale?: string
}

/**
Expand Down Expand Up @@ -94,6 +95,7 @@ export const updateDocument = async <
req,
select,
showHiddenFields,
unpublishSpecificLocale,
}: SharedUpdateDocumentArgs<TSlug>): Promise<TransformCollectionWithSelect<TSlug, TSelect>> => {
const password = data?.password
const shouldSaveDraft =
Expand Down Expand Up @@ -244,7 +246,7 @@ export const updateDocument = async <
Boolean(data?.deletedAt),
}

if (publishSpecificLocale) {
if (publishSpecificLocale || unpublishSpecificLocale) {
versionSnapshotResult = await beforeChange({
...beforeChangeArgs,
docWithLocales,
Expand All @@ -269,9 +271,16 @@ export const updateDocument = async <

let result = await beforeChange({
...beforeChangeArgs,
data: unpublishSpecificLocale ? { id } : { ...data, id },
docWithLocales: publishedDocWithLocales,
})

if (unpublishSpecificLocale && versionSnapshotResult) {
if (Object.keys(result).length <= 1 && result.id) {
result = versionSnapshotResult
}
}

// /////////////////////////////////////
// Handle potential password update
// /////////////////////////////////////
Expand Down Expand Up @@ -322,6 +331,7 @@ export const updateDocument = async <
publishSpecificLocale,
req,
snapshot: versionSnapshotResult,
unpublishSpecificLocale,
})
}

Expand Down
2 changes: 2 additions & 0 deletions packages/payload/src/database/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ export type CreateVersionArgs<T = TypeWithID> = {
returning?: boolean
select?: SelectType
snapshot?: true
unpublishedLocale?: string
updatedAt: string
versionData: T
}
Expand All @@ -426,6 +427,7 @@ export type CreateGlobalVersionArgs<T = TypeWithID> = {
returning?: boolean
select?: SelectType
snapshot?: true
unpublishedLocale?: string
updatedAt: string
versionData: T
}
Expand Down
2 changes: 2 additions & 0 deletions packages/payload/src/globals/endpoints/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const updateHandler: PayloadHandler = async (req) => {
const draft = searchParams.get('draft') === 'true'
const autosave = searchParams.get('autosave') === 'true'
const publishSpecificLocale = req.query.publishSpecificLocale as string | undefined
const unpublishSpecificLocale = req.query.unpublishSpecificLocale as string | undefined

const result = await updateOperation({
slug: globalConfig.slug,
Expand All @@ -28,6 +29,7 @@ export const updateHandler: PayloadHandler = async (req) => {
publishSpecificLocale,
req,
select: sanitizeSelectParam(req.query.select),
unpublishSpecificLocale,
})

let message = req.t('general:updatedSuccessfully')
Expand Down
6 changes: 6 additions & 0 deletions packages/payload/src/globals/operations/local/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export type Options<TSlug extends GlobalSlug, TSelect extends SelectType> = {
* the Global slug to operate against.
*/
slug: TSlug
/**
* Unpublish the document / documents for a specific locale.
*/
unpublishSpecificLocale?: TypedLocale
/**
* If you set `overrideAccess` to `false`, you can pass a user to use against the access control checks.
*/
Expand All @@ -111,6 +115,7 @@ export async function updateGlobalLocal<
publishSpecificLocale,
select,
showHiddenFields,
unpublishSpecificLocale,
} = options

const globalConfig = payload.globals.config.find((config) => config.slug === globalSlug)
Expand All @@ -132,5 +137,6 @@ export async function updateGlobalLocal<
req: await createLocalReq(options as CreateLocalReqOptions, payload),
select,
showHiddenFields,
unpublishSpecificLocale: unpublishSpecificLocale!,
})
}
16 changes: 15 additions & 1 deletion packages/payload/src/globals/operations/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type Args<TSlug extends GlobalSlug> = {
select?: SelectType
showHiddenFields?: boolean
slug: string
unpublishSpecificLocale?: string
}

export const updateOperation = async <
Expand All @@ -57,6 +58,10 @@ export const updateOperation = async <
args.req.locale = args.publishSpecificLocale
}

if (args.unpublishSpecificLocale) {
args.req.locale = args.unpublishSpecificLocale
}

const {
slug,
autosave,
Expand All @@ -72,6 +77,7 @@ export const updateOperation = async <
req,
select: incomingSelect,
showHiddenFields,
unpublishSpecificLocale,
} = args

try {
Expand Down Expand Up @@ -234,7 +240,7 @@ export const updateOperation = async <
shouldSaveDraft && globalConfig.versions.drafts && !globalConfig.versions.drafts.validate,
}

if (publishSpecificLocale) {
if (publishSpecificLocale || unpublishSpecificLocale) {
const latestVersion = await getLatestGlobalVersion({
slug,
config: globalConfig,
Expand All @@ -254,9 +260,16 @@ export const updateOperation = async <

let result = await beforeChange({
...beforeChangeArgs,
data: unpublishSpecificLocale ? {} : data,
docWithLocales: publishedDocWithLocales,
})

if (unpublishSpecificLocale && versionSnapshotResult) {
if (Object.keys(result).length === 0) {
result = versionSnapshotResult
}
}

// /////////////////////////////////////
// Update
// /////////////////////////////////////
Expand Down Expand Up @@ -308,6 +321,7 @@ export const updateOperation = async <
req,
select,
snapshot: versionSnapshotResult,
unpublishSpecificLocale,
})

result = {
Expand Down
Loading
Loading