Skip to content

Commit

Permalink
chore: merge feat/publish-single-locale
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRibbens committed Sep 13, 2024
2 parents 7e6470f + c13899a commit a5d05ad
Show file tree
Hide file tree
Showing 87 changed files with 1,336 additions and 135 deletions.
14 changes: 13 additions & 1 deletion packages/db-mongodb/src/createGlobalVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ import { withSession } from './withSession.js'

export const createGlobalVersion: CreateGlobalVersion = async function createGlobalVersion(
this: MongooseAdapter,
{ autosave, createdAt, globalSlug, parent, req = {} as PayloadRequest, updatedAt, versionData },
{
autosave,
createdAt,
globalSlug,
parent,
publishedLocale,
req = {} as PayloadRequest,
snapshot,
updatedAt,
versionData,
},
) {
const VersionModel = this.versions[globalSlug]
const options = await withSession(this, req)
Expand All @@ -18,6 +28,8 @@ export const createGlobalVersion: CreateGlobalVersion = async function createGlo
createdAt,
latest: true,
parent,
publishedLocale,
snapshot,
updatedAt,
version: versionData,
},
Expand Down
4 changes: 4 additions & 0 deletions packages/db-mongodb/src/createVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export const createVersion: CreateVersion = async function createVersion(
collectionSlug,
createdAt,
parent,
publishedLocale,
req = {} as PayloadRequest,
snapshot,
updatedAt,
versionData,
},
Expand All @@ -26,6 +28,8 @@ export const createVersion: CreateVersion = async function createVersion(
createdAt,
latest: true,
parent,
publishedLocale,
snapshot,
updatedAt,
version: versionData,
},
Expand Down
1 change: 1 addition & 0 deletions packages/db-mongodb/src/findGlobalVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const findGlobalVersions: FindGlobalVersions = async function findGlobalV
) {
const Model = this.versions[global]
const versionFields = buildVersionGlobalFields(
this.payload.config,
this.payload.globals.config.find(({ slug }) => slug === global),
)
const options = {
Expand Down
4 changes: 2 additions & 2 deletions packages/db-mongodb/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const init: Init = function init(this: MongooseAdapter) {
if (collection.versions) {
const versionModelName = getDBName({ config: collection, versions: true })

const versionCollectionFields = buildVersionCollectionFields(collection)
const versionCollectionFields = buildVersionCollectionFields(this.payload.config, collection)

const versionSchema = buildSchema(this.payload.config, versionCollectionFields, {
disableUnique: true,
Expand Down Expand Up @@ -64,7 +64,7 @@ export const init: Init = function init(this: MongooseAdapter) {
if (global.versions) {
const versionModelName = getDBName({ config: global, versions: true })

const versionGlobalFields = buildVersionGlobalFields(global)
const versionGlobalFields = buildVersionGlobalFields(this.payload.config, global)

const versionSchema = buildSchema(this.payload.config, versionGlobalFields, {
disableUnique: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/db-postgres/src/predefinedMigrations/v2-v3/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {
const versionsTableName = adapter.tableNameMap.get(
`_${toSnakeCase(collection.slug)}${adapter.versionsSuffix}`,
)
const versionFields = buildVersionCollectionFields(collection)
const versionFields = buildVersionCollectionFields(payload.config, collection)
const versionPathsToQuery: PathsToQuery = new Set()

traverseFields({
Expand Down Expand Up @@ -191,7 +191,7 @@ export const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {
`_${toSnakeCase(global.slug)}${adapter.versionsSuffix}`,
)

const versionFields = buildVersionGlobalFields(global)
const versionFields = buildVersionGlobalFields(payload.config, global)

const versionPathsToQuery: PathsToQuery = new Set()

Expand Down
17 changes: 15 additions & 2 deletions packages/db-sqlite/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const init: Init = function init(this: SQLiteAdapter) {
})
this.payload.config.collections.forEach((collection: SanitizedCollectionConfig) => {
const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))
const config = this.payload.config

const baseExtraConfig: BaseExtraConfig = {}

Expand All @@ -51,6 +52,17 @@ export const init: Init = function init(this: SQLiteAdapter) {
}
}

if (collection.upload.filenameCompoundIndex) {
const indexName = `${tableName}_filename_compound_idx`

baseExtraConfig.filename_compound_index = (cols) => {
const colsConstraint = collection.upload.filenameCompoundIndex.map((f) => {
return cols[f]
})
return uniqueIndex(indexName).on(colsConstraint[0], ...colsConstraint.slice(1))
}
}

buildTable({
adapter: this,
disableNotNull: !!collection?.versions?.drafts,
Expand All @@ -66,7 +78,7 @@ export const init: Init = function init(this: SQLiteAdapter) {
const versionsTableName = this.tableNameMap.get(
`_${toSnakeCase(collection.slug)}${this.versionsSuffix}`,
)
const versionFields = buildVersionCollectionFields(collection)
const versionFields = buildVersionCollectionFields(config, collection)

buildTable({
adapter: this,
Expand Down Expand Up @@ -105,7 +117,8 @@ export const init: Init = function init(this: SQLiteAdapter) {
versions: true,
versionsCustomName: true,
})
const versionFields = buildVersionGlobalFields(global)
const config = this.payload.config
const versionFields = buildVersionGlobalFields(config, global)

buildTable({
adapter: this,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ export const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {
const versionsTableName = adapter.tableNameMap.get(
`_${toSnakeCase(collection.slug)}${adapter.versionsSuffix}`,
)
const versionFields = buildVersionCollectionFields(collection)

const versionFields = buildVersionCollectionFields(payload.config, collection)
const versionPathsToQuery: PathsToQuery = new Set()

traverseFields({
Expand Down Expand Up @@ -191,7 +192,7 @@ export const migratePostgresV2toV3 = async ({ debug, payload, req }: Args) => {
`_${toSnakeCase(global.slug)}${adapter.versionsSuffix}`,
)

const versionFields = buildVersionGlobalFields(global)
const versionFields = buildVersionGlobalFields(payload.config, global)

const versionPathsToQuery: PathsToQuery = new Set()

Expand Down
13 changes: 11 additions & 2 deletions packages/drizzle/src/createGlobalVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import { upsertRow } from './upsertRow/index.js'

export async function createGlobalVersion<T extends TypeWithID>(
this: DrizzleAdapter,
{ autosave, globalSlug, req = {} as PayloadRequest, versionData }: CreateGlobalVersionArgs,
{
autosave,
globalSlug,
publishedLocale,
req = {} as PayloadRequest,
snapshot,
versionData,
}: CreateGlobalVersionArgs,
) {
const db = this.sessions[await req?.transactionID]?.db || this.drizzle
const global = this.payload.globals.config.find(({ slug }) => slug === globalSlug)
Expand All @@ -22,10 +29,12 @@ export async function createGlobalVersion<T extends TypeWithID>(
data: {
autosave,
latest: true,
publishedLocale,
snapshot,
version: versionData,
},
db,
fields: buildVersionGlobalFields(global),
fields: buildVersionGlobalFields(this.payload.config, global),
operation: 'create',
req,
tableName,
Expand Down
6 changes: 5 additions & 1 deletion packages/drizzle/src/createVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export async function createVersion<T extends TypeWithID>(
autosave,
collectionSlug,
parent,
publishedLocale,
req = {} as PayloadRequest,
snapshot,
versionData,
}: CreateVersionArgs<T>,
) {
Expand All @@ -33,6 +35,8 @@ export async function createVersion<T extends TypeWithID>(
autosave,
latest: true,
parent,
publishedLocale,
snapshot,
version,
}

Expand All @@ -44,7 +48,7 @@ export async function createVersion<T extends TypeWithID>(
adapter: this,
data,
db,
fields: buildVersionCollectionFields(collection),
fields: buildVersionCollectionFields(this.payload.config, collection),
operation: 'create',
req,
tableName,
Expand Down
2 changes: 1 addition & 1 deletion packages/drizzle/src/deleteVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const deleteVersions: DeleteVersions = async function deleteVersion(
`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,
)

const fields = buildVersionCollectionFields(collectionConfig)
const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)

const { docs } = await findMany({
adapter: this,
Expand Down
2 changes: 1 addition & 1 deletion packages/drizzle/src/findGlobalVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const findGlobalVersions: FindGlobalVersions = async function findGlobalV
`_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`,
)

const fields = buildVersionGlobalFields(globalConfig)
const fields = buildVersionGlobalFields(this.payload.config, globalConfig)

return findMany({
adapter: this,
Expand Down
2 changes: 1 addition & 1 deletion packages/drizzle/src/findVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const findVersions: FindVersions = async function findVersions(
`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,
)

const fields = buildVersionCollectionFields(collectionConfig)
const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)

return findMany({
adapter: this,
Expand Down
4 changes: 2 additions & 2 deletions packages/drizzle/src/postgres/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const init: Init = function init(this: BasePostgresAdapter) {
const versionsTableName = this.tableNameMap.get(
`_${toSnakeCase(collection.slug)}${this.versionsSuffix}`,
)
const versionFields = buildVersionCollectionFields(collection)
const versionFields = buildVersionCollectionFields(this.payload.config, collection)

buildTable({
adapter: this,
Expand Down Expand Up @@ -97,7 +97,7 @@ export const init: Init = function init(this: BasePostgresAdapter) {
versions: true,
versionsCustomName: true,
})
const versionFields = buildVersionGlobalFields(global)
const versionFields = buildVersionGlobalFields(this.payload.config, global)

buildTable({
adapter: this,
Expand Down
2 changes: 1 addition & 1 deletion packages/drizzle/src/queryDrafts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const queryDrafts: QueryDrafts = async function queryDrafts(
const tableName = this.tableNameMap.get(
`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,
)
const fields = buildVersionCollectionFields(collectionConfig)
const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)

const combinedWhere = combineQueries({ latest: { equals: true } }, where)

Expand Down
2 changes: 1 addition & 1 deletion packages/drizzle/src/updateGlobalVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function updateGlobalVersion<T extends TypeWithID>(
`_${toSnakeCase(globalConfig.slug)}${this.versionsSuffix}`,
)

const fields = buildVersionGlobalFields(globalConfig)
const fields = buildVersionGlobalFields(this.payload.config, globalConfig)

const { where } = await buildQuery({
adapter: this,
Expand Down
2 changes: 1 addition & 1 deletion packages/drizzle/src/updateVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export async function updateVersion<T extends TypeWithID>(
`_${toSnakeCase(collectionConfig.slug)}${this.versionsSuffix}`,
)

const fields = buildVersionCollectionFields(collectionConfig)
const fields = buildVersionCollectionFields(this.payload.config, collectionConfig)

const { where } = await buildQuery({
adapter: this,
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/schema/initCollections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export function initCollections({ config, graphqlResult }: InitCollectionsGraphQ
if (collectionConfig.versions) {
const versionIDType = config.db.defaultIDType === 'text' ? GraphQLString : GraphQLInt
const versionCollectionFields: Field[] = [
...buildVersionCollectionFields(collectionConfig),
...buildVersionCollectionFields(config, collectionConfig),
{
name: 'id',
type: config.db.defaultIDType as 'text',
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/schema/initGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export function initGlobals({ config, graphqlResult }: InitGlobalsGraphQLArgs):
const idType = config.db.defaultIDType === 'number' ? GraphQLInt : GraphQLString

const versionGlobalFields: Field[] = [
...buildVersionGlobalFields(global),
...buildVersionGlobalFields(config, global),
{
name: 'id',
type: config.db.defaultIDType as 'text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,12 @@ import { baseClass } from '../../Tab/index.js'
export const VersionsPill: React.FC = () => {
const { versions } = useDocumentInfo()

// To prevent CLS (versions are currently loaded client-side), render non-breaking space if there are no versions
// The pill is already conditionally rendered to begin with based on whether the document is version-enabled
// documents that are version enabled _always_ have at least one version
const hasVersions = versions?.totalDocs > 0
// don't count snapshots
const totalVersions = versions?.docs.filter((version) => !version.snapshot).length || 0

if (hasVersions) {
return (
<span
className={[`${baseClass}__count`, hasVersions ? `${baseClass}__count--has-count` : '']
.filter(Boolean)
.join(' ')}
>
{versions.totalDocs.toString()}
</span>
)
if (!versions?.totalDocs) {
return null
}

return <span className={`${baseClass}__count`}>{totalVersions}</span>
}
2 changes: 2 additions & 0 deletions packages/next/src/routes/rest/collections/updateByID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const updateByID: CollectionRouteHandlerWithID = async ({
const depth = searchParams.get('depth')
const autosave = searchParams.get('autosave') === 'true'
const draft = searchParams.get('draft') === 'true'
const publishSpecificLocale = req.query.publishSpecificLocale as string | undefined

const id = sanitizeCollectionID({
id: incomingID,
Expand All @@ -30,6 +31,7 @@ export const updateByID: CollectionRouteHandlerWithID = async ({
data: req.data,
depth: isNumber(depth) ? Number(depth) : undefined,
draft,
publishSpecificLocale,
req,
})

Expand Down
2 changes: 2 additions & 0 deletions packages/next/src/routes/rest/globals/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const update: GlobalRouteHandler = async ({ globalConfig, req }) => {
const depth = searchParams.get('depth')
const draft = searchParams.get('draft') === 'true'
const autosave = searchParams.get('autosave') === 'true'
const publishSpecificLocale = req.query.publishSpecificLocale as string | undefined

const result = await updateOperationGlobal({
slug: globalConfig.slug,
Expand All @@ -19,6 +20,7 @@ export const update: GlobalRouteHandler = async ({ globalConfig, req }) => {
depth: isNumber(depth) ? Number(depth) : undefined,
draft,
globalConfig,
publishSpecificLocale,
req,
})

Expand Down
Loading

0 comments on commit a5d05ad

Please sign in to comment.