Skip to content

Commit

Permalink
feat(utilities): offer ability to exclude localized fields (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
thompsonsj authored Jun 19, 2023
1 parent 30c38f2 commit 7d4e4e4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/utilities/getLocalizedFields.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,31 @@ describe("fn: getLocalizedFields", () => {
expect(getLocalizedFields({ fields })).toEqual(fields)
})

it("excludes a localized text field based on the admin description", () => {
const fields: Field[] = [
{
name: 'textLocalizedField',
type: 'text',
localized: true,
},
{
name: 'textLocalizedFieldWithExcludeDescription',
type: 'text',
localized: true,
admin: {
description: "Not sent to CrowdIn. Localize in the CMS.",
}
},
]
expect(getLocalizedFields({ fields })).toEqual([
{
name: 'textLocalizedField',
type: 'text',
localized: true,
},
])
})

it("includes a richText field", () => {
const fields: Field[] = [
{
Expand Down
10 changes: 9 additions & 1 deletion src/utilities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,15 @@ export const getFieldSlugs = (fields: FieldWithName[]): string[] => fields.filte

const hasLocalizedProp = (field: Field) => "localized" in field && field.localized

export const isLocalizedField = (field: Field, addLocalizedProp: boolean = false) => (hasLocalizedProp(field) || addLocalizedProp) && localizedFieldTypes.includes(field.type)
export const isLocalizedField = (field: Field, addLocalizedProp: boolean = false) => (hasLocalizedProp(field) || addLocalizedProp) && localizedFieldTypes.includes(field.type) && !excludeBasedOnDescription(field)

const excludeBasedOnDescription = (field: Field) => {
const description = get(field, 'admin.description', '')
if (description.includes("Not sent to CrowdIn. Localize in the CMS.")) {
return true
}
return false
}

export const containsLocalizedFields = ({
fields,
Expand Down

0 comments on commit 7d4e4e4

Please sign in to comment.