Skip to content

Commit

Permalink
refactor: consistent caps for acronyms in variable names (#10101)
Browse files Browse the repository at this point in the history
Improves consistency for variable names like `docID`, `insertedID`,
`parentID`
For example: `docId` -> `docID`
  • Loading branch information
r1tsuu authored Dec 20, 2024
1 parent dec87e9 commit a7109ed
Show file tree
Hide file tree
Showing 17 changed files with 80 additions and 80 deletions.
4 changes: 2 additions & 2 deletions packages/db-mongodb/src/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export const create: Create = async function create(
})

try {
const { insertedId } = await Model.collection.insertOne(data, { session })
data._id = insertedId
const { insertedId: insertedID } = await Model.collection.insertOne(data, { session })
data._id = insertedID

transform({
adapter: this,
Expand Down
4 changes: 2 additions & 2 deletions packages/db-mongodb/src/createGlobal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const createGlobal: CreateGlobal = async function createGlobal(

const session = await getSession(this, req)

const { insertedId } = await Model.collection.insertOne(data, { session })
;(data as any)._id = insertedId
const { insertedId: insertedID } = await Model.collection.insertOne(data, { session })
;(data as any)._id = insertedID

transform({
adapter: this,
Expand Down
6 changes: 3 additions & 3 deletions packages/db-mongodb/src/createGlobalVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export const createGlobalVersion: CreateGlobalVersion = async function createGlo
operation: 'create',
})

const { insertedId } = await VersionModel.collection.insertOne(data, { session })
;(data as any)._id = insertedId
const { insertedId: insertedID } = await VersionModel.collection.insertOne(data, { session })
;(data as any)._id = insertedID

await VersionModel.collection.updateMany(
{
$and: [
{
_id: {
$ne: insertedId,
$ne: insertedID,
},
},
{
Expand Down
6 changes: 3 additions & 3 deletions packages/db-mongodb/src/createVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ export const createVersion: CreateVersion = async function createVersion(
operation: 'create',
})

const { insertedId } = await VersionModel.collection.insertOne(data, { session })
data._id = insertedId
const { insertedId: insertedID } = await VersionModel.collection.insertOne(data, { session })
data._id = insertedID

const parentQuery = {
$or: [
Expand All @@ -72,7 +72,7 @@ export const createVersion: CreateVersion = async function createVersion(
$and: [
{
_id: {
$ne: insertedId,
$ne: insertedID,
},
},
parentQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ async function migrateCollectionDocs({
return
}

const remainingDocIds = remainingDocs.map((doc) => doc._versionID)
const remainingDocIDs = remainingDocs.map((doc) => doc._versionID)

await VersionsModel.updateMany(
{
_id: {
$in: remainingDocIds,
$in: remainingDocIDs,
},
},
{
Expand Down
10 changes: 5 additions & 5 deletions packages/next/src/views/LivePreview/index.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const PreviewView: React.FC<Props> = ({
setDocumentIsLocked(true)

if (isLockingEnabled) {
const previousOwnerId =
const previousOwnerID =
typeof documentLockStateRef.current?.user === 'object'
? documentLockStateRef.current?.user?.id
: documentLockStateRef.current?.user
Expand All @@ -225,8 +225,8 @@ const PreviewView: React.FC<Props> = ({
? lockedState.user
: lockedState.user.id

if (!documentLockStateRef.current || lockedUserID !== previousOwnerId) {
if (previousOwnerId === user.id && lockedUserID !== user.id) {
if (!documentLockStateRef.current || lockedUserID !== previousOwnerID) {
if (previousOwnerID === user.id && lockedUserID !== user.id) {
setShowTakeOverModal(true)
documentLockStateRef.current.hasShownLockedModal = true
}
Expand Down Expand Up @@ -270,7 +270,7 @@ const PreviewView: React.FC<Props> = ({

const currentPath = window.location.pathname

const documentId = id || globalSlug
const documentID = id || globalSlug

// Routes where we do NOT want to unlock the document
const stayWithinDocumentPaths = ['preview', 'api', 'versions']
Expand All @@ -280,7 +280,7 @@ const PreviewView: React.FC<Props> = ({
)

// Unlock the document only if we're actually navigating away from the document
if (documentId && documentIsLocked && !isStayingWithinDocument) {
if (documentID && documentIsLocked && !isStayingWithinDocument) {
// Check if this user is still the current editor
if (
typeof documentLockStateRef.current?.user === 'object'
Expand Down
4 changes: 2 additions & 2 deletions packages/next/src/views/Root/getViewFromConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export const getViewFromConfig = ({
// --> /collections/:collectionSlug/:id/api
// --> /collections/:collectionSlug/:id/preview
// --> /collections/:collectionSlug/:id/versions
// --> /collections/:collectionSlug/:id/versions/:versionId
// --> /collections/:collectionSlug/:id/versions/:versionID

ViewToRender = {
Component: DocumentView,
Expand Down Expand Up @@ -311,7 +311,7 @@ export const getViewFromConfig = ({
// Custom Views
// --> /globals/:globalSlug/versions
// --> /globals/:globalSlug/preview
// --> /globals/:globalSlug/versions/:versionId
// --> /globals/:globalSlug/versions/:versionID
// --> /globals/:globalSlug/api

ViewToRender = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function debounce(func, wait, options) {
maxing = false,
maxWait,
result,
timerId,
timerID,
trailing = true

if (typeof func != 'function') {
Expand Down Expand Up @@ -152,7 +152,7 @@ function debounce(func, wait, options) {
// Reset any `maxWait` timer.
lastInvokeTime = time
// Start the timer for the trailing edge.
timerId = setTimeout(timerExpired, wait)
timerID = setTimeout(timerExpired, wait)
// Invoke the leading edge.
return leading ? invokeFunc(time) : result
}
Expand Down Expand Up @@ -186,11 +186,11 @@ function debounce(func, wait, options) {
return trailingEdge(time)
}
// Restart the timer.
timerId = setTimeout(timerExpired, remainingWait(time))
timerID = setTimeout(timerExpired, remainingWait(time))
}

function trailingEdge(time) {
timerId = undefined
timerID = undefined

// Only invoke if we have `lastArgs` which means `func` has been
// debounced at least once.
Expand All @@ -202,15 +202,15 @@ function debounce(func, wait, options) {
}

function cancel() {
if (timerId !== undefined) {
clearTimeout(timerId)
if (timerID !== undefined) {
clearTimeout(timerID)
}
lastInvokeTime = 0
lastArgs = lastCallTime = lastThis = timerId = undefined
lastArgs = lastCallTime = lastThis = timerID = undefined
}

function flush() {
return timerId === undefined ? result : trailingEdge(Date.now())
return timerID === undefined ? result : trailingEdge(Date.now())
}

function debounced() {
Expand All @@ -224,18 +224,18 @@ function debounce(func, wait, options) {
lastCallTime = time

if (isInvoking) {
if (timerId === undefined) {
if (timerID === undefined) {
return leadingEdge(lastCallTime)
}
if (maxing) {
// Handle invocations in a tight loop.
clearTimeout(timerId)
timerId = setTimeout(timerExpired, wait)
clearTimeout(timerID)
timerID = setTimeout(timerExpired, wait)
return invokeFunc(lastCallTime)
}
}
if (timerId === undefined) {
timerId = setTimeout(timerExpired, wait)
if (timerID === undefined) {
timerID = setTimeout(timerExpired, wait)
}
return result
}
Expand Down
8 changes: 4 additions & 4 deletions packages/ui/src/elements/Tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,20 @@ export const Tooltip: React.FC<Props> = (props) => {
)

useEffect(() => {
let timerId: NodeJS.Timeout
let timerID: NodeJS.Timeout

// do not use the delay on transition-out
if (delay && showFromProps) {
timerId = setTimeout(() => {
timerID = setTimeout(() => {
setShow(showFromProps)
}, delay)
} else {
setShow(showFromProps)
}

return () => {
if (timerId) {
clearTimeout(timerId)
if (timerID) {
clearTimeout(timerID)
}
}
}, [showFromProps, delay])
Expand Down
12 changes: 6 additions & 6 deletions packages/ui/src/fields/Relationship/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -447,24 +447,24 @@ const RelationshipFieldComponent: RelationshipFieldClientComponent = (props) =>
})

const currentValue = valueRef.current
const docId = args.doc.id
const docID = args.doc.id

if (hasMany) {
const unchanged = (currentValue as Option[]).some((option) =>
typeof option === 'string' ? option === docId : option.value === docId,
typeof option === 'string' ? option === docID : option.value === docID,
)

const valuesToSet = (currentValue as Option[]).map((option) =>
option.value === docId
? { relationTo: args.collectionConfig.slug, value: docId }
option.value === docID
? { relationTo: args.collectionConfig.slug, value: docID }
: option,
)

setValue(valuesToSet, unchanged)
} else {
const unchanged = currentValue === docId
const unchanged = currentValue === docID

setValue({ relationTo: args.collectionConfig.slug, value: docId }, unchanged)
setValue({ relationTo: args.collectionConfig.slug, value: docID }, unchanged)
}
},
[i18n, config, hasMany, setValue],
Expand Down
16 changes: 8 additions & 8 deletions packages/ui/src/providers/DocumentInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,21 @@ const DocumentInfo: React.FC<
}

const unlockDocument = useCallback(
async (docId: number | string, slug: string) => {
async (docID: number | string, slug: string) => {
try {
const isGlobal = slug === globalSlug

const query = isGlobal
? `where[globalSlug][equals]=${slug}`
: `where[document.value][equals]=${docId}&where[document.relationTo][equals]=${slug}`
: `where[document.value][equals]=${docID}&where[document.relationTo][equals]=${slug}`

const request = await requests.get(`${serverURL}${api}/payload-locked-documents?${query}`)

const { docs } = await request.json()

if (docs.length > 0) {
const lockId = docs[0].id
await requests.delete(`${serverURL}${api}/payload-locked-documents/${lockId}`, {
const lockID = docs[0].id
await requests.delete(`${serverURL}${api}/payload-locked-documents/${lockID}`, {
headers: {
'Content-Type': 'application/json',
},
Expand All @@ -163,29 +163,29 @@ const DocumentInfo: React.FC<
)

const updateDocumentEditor = useCallback(
async (docId: number | string, slug: string, user: ClientUser | number | string) => {
async (docID: number | string, slug: string, user: ClientUser | number | string) => {
try {
const isGlobal = slug === globalSlug

const query = isGlobal
? `where[globalSlug][equals]=${slug}`
: `where[document.value][equals]=${docId}&where[document.relationTo][equals]=${slug}`
: `where[document.value][equals]=${docID}&where[document.relationTo][equals]=${slug}`

// Check if the document is already locked
const request = await requests.get(`${serverURL}${api}/payload-locked-documents?${query}`)

const { docs } = await request.json()

if (docs.length > 0) {
const lockId = docs[0].id
const lockID = docs[0].id

const userData =
typeof user === 'object'
? { relationTo: user.collection, value: user.id }
: { relationTo: 'users', value: user }

// Send a patch request to update the _lastEdited info
await requests.patch(`${serverURL}${api}/payload-locked-documents/${lockId}`, {
await requests.patch(`${serverURL}${api}/payload-locked-documents/${lockID}`, {
body: JSON.stringify({
user: userData,
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/providers/DocumentInfo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ export type DocumentInfoContext = {
setMostRecentVersionIsAutosaved: React.Dispatch<React.SetStateAction<boolean>>
setUnpublishedVersionCount: React.Dispatch<React.SetStateAction<number>>
title: string
unlockDocument: (docId: number | string, slug: string) => Promise<void>
unlockDocument: (docID: number | string, slug: string) => Promise<void>
unpublishedVersionCount: number
updateDocumentEditor: (docId: number | string, slug: string, user: ClientUser) => Promise<void>
updateDocumentEditor: (docID: number | string, slug: string, user: ClientUser) => Promise<void>
updateSavedDocumentData: (data: Data) => void
versionCount: number
} & DocumentInfoProps
4 changes: 2 additions & 2 deletions packages/ui/src/utilities/handleFormStateLocking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ export const handleFormStateLocking = async ({
user: lockedDocument.docs[0]?.user?.value,
}

const lockOwnerId =
const lockOwnerID =
typeof lockedDocument.docs[0]?.user?.value === 'object'
? lockedDocument.docs[0]?.user?.value?.id
: lockedDocument.docs[0]?.user?.value
// Should only update doc if the incoming / current user is also the owner of the locked doc
if (updateLastEdited && req.user && lockOwnerId === req.user.id) {
if (updateLastEdited && req.user && lockOwnerID === req.user.id) {
await req.payload.db.updateOne({
id: lockedDocument.docs[0].id,
collection: 'payload-locked-documents',
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/utilities/handleTakeOver.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const handleTakeOver = (
user: ClientUser | number | string,
isWithinDoc: boolean,
updateDocumentEditor: (
docId: number | string,
docID: number | string,
slug: string,
user: ClientUser | number | string,
) => Promise<void>,
Expand Down
6 changes: 3 additions & 3 deletions packages/ui/src/views/Edit/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export const DefaultEditView: React.FC<ClientSideEditViewProps> = ({
const handleDocumentLocking = useCallback(
(lockedState: LockedState) => {
setDocumentIsLocked(true)
const previousOwnerId =
const previousOwnerID =
typeof documentLockStateRef.current?.user === 'object'
? documentLockStateRef.current?.user?.id
: documentLockStateRef.current?.user
Expand All @@ -218,8 +218,8 @@ export const DefaultEditView: React.FC<ClientSideEditViewProps> = ({
? lockedState.user
: lockedState.user.id

if (!documentLockStateRef.current || lockedUserID !== previousOwnerId) {
if (previousOwnerId === user.id && lockedUserID !== user.id) {
if (!documentLockStateRef.current || lockedUserID !== previousOwnerID) {
if (previousOwnerID === user.id && lockedUserID !== user.id) {
setShowTakeOverModal(true)
documentLockStateRef.current.hasShownLockedModal = true
}
Expand Down
4 changes: 2 additions & 2 deletions test/fields-relationship/PrePopulateFieldUI/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const PrePopulateFieldUI: React.FC<{
)
const json = await res.json()
if (hasMany) {
const docIds = json.docs.map((doc) => {
const docIDs = json.docs.map((doc) => {
if (hasMultipleRelations) {
return {
relationTo: collection1Slug,
Expand All @@ -29,7 +29,7 @@ export const PrePopulateFieldUI: React.FC<{

return doc.id
})
setValue(docIds)
setValue(docIDs)
} else {
// value that does not appear in first 10 docs fetch
setValue(json.docs[6].id)
Expand Down
Loading

0 comments on commit a7109ed

Please sign in to comment.