Skip to content

Commit

Permalink
fix how translation draft references are created so that they can be …
Browse files Browse the repository at this point in the history
…deleted
  • Loading branch information
SimeonGriggs committed Jul 6, 2022
1 parent bb3570b commit 8b19332
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,16 @@ export const LanguageSelectListItem: React.FC<Props> = ({status, language}) => {
? {
[baseFieldName]: {
_type: 'reference',
_ref: baseDocument._id.replace(`drafts.*`, ``),
_weak: referenceBehavior === 'weak',
_ref: baseDocument._id.replace(`drafts.`, ``),
_weak: true,
_strengthenOnPublish: {
type: currentDocumentType,
weak: referenceBehavior === 'weak',
template: {
id: currentDocumentType,
params: undefined,
},
},
},
}
: {}),
Expand Down
1 change: 1 addition & 0 deletions src/structure/utils/fixBaseDocumentRefs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {createSanityReference, getBaseIdFromId, getConfig, getSanityClient} from
export const fixBaseDocumentRefs = async (schema: string, translatedDocuments: Ti18nDocument[]) => {
const config = getConfig(schema)
const sanityClient = getSanityClient()

if (config.referenceBehavior !== ReferenceBehavior.DISABLED) {
const baseRefFieldName = config.fieldNames.baseReference
const transaction = sanityClient.transaction()
Expand Down
2 changes: 1 addition & 1 deletion src/utils/createSanityReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Ref = Omit<Reference, '_type'> & {_type: 'reference'}
export function createSanityReference(id: string, weak = false): Ref {
return {
_type: 'reference' as const,
_ref: id,
_ref: id.replace(`drafts.`, ``),
...(weak === true ? {_weak: true} : {}),
}
}

0 comments on commit 8b19332

Please sign in to comment.