Skip to content

Commit 11f8a39

Browse files
committed
fix: refernce variant cslp generation fix
1 parent b560395 commit 11f8a39

File tree

2 files changed

+146
-1
lines changed

2 files changed

+146
-1
lines changed

__test__/entry-editable.test.ts

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,151 @@ describe('Entry editable test', () => {
268268

269269
done()
270270
})
271+
272+
it('Reference fields should not inherit parent variants when they have no applied_variants', done => {
273+
const entryWithReferenceAndVariants = {
274+
"title": "home",
275+
"url": "/data/all_test/first",
276+
"single_line": "ssd",
277+
"tags": ["hi"],
278+
"locale": "en-us",
279+
"uid": "blt827e0ad3608248be",
280+
"created_by": "bltf0d59057590e9b09",
281+
"updated_by": "bltf0d59057590e9b09",
282+
"created_at": "2025-08-25T09:43:49.935Z",
283+
"updated_at": "2025-10-09T11:45:19.967Z",
284+
"ACL": [] as any[],
285+
"_version": 40,
286+
"_in_progress": false,
287+
"json_rte": "<p>hisdassf</p>",
288+
"select": "1",
289+
"group": {
290+
"single_line": ""
291+
},
292+
"non_single_line_textbox": "",
293+
"reference": [
294+
{
295+
"title": "base variant",
296+
"single_line": "bases",
297+
"tags": [] as any[],
298+
"locale": "en-us",
299+
"uid": "blt07a6c7258ddba844",
300+
"created_by": "bltf0d59057590e9b09",
301+
"updated_by": "bltf0d59057590e9b09",
302+
"created_at": "2025-10-01T03:10:10.701Z",
303+
"updated_at": "2025-10-09T11:44:44.981Z",
304+
"_content_type_uid": "all_test_3",
305+
"ACL": [] as any[],
306+
"_version": 3,
307+
"_in_progress": false,
308+
"multi_line_reference": "hii\n"
309+
// Note: This reference object has NO _applied_variants
310+
}
311+
],
312+
"taxonomies": [] as any[],
313+
"multi_line": "woek",
314+
"_applied_variants": {
315+
"single_line": "csfff653e89df54e8c",
316+
"tags": "csfff653e89df54e8c",
317+
"multi_line": "csfff653e89df54e8c"
318+
}
319+
}
320+
321+
addTags(entryWithReferenceAndVariants, 'all_test', false)
322+
323+
// Parent entry fields with variants should get v2 prefix
324+
expect((entryWithReferenceAndVariants as any)['$']['single_line']).toEqual('data-cslp=v2:all_test.blt827e0ad3608248be_csfff653e89df54e8c.en-us.single_line')
325+
expect((entryWithReferenceAndVariants as any)['$']['tags']).toEqual('data-cslp=v2:all_test.blt827e0ad3608248be_csfff653e89df54e8c.en-us.tags')
326+
expect((entryWithReferenceAndVariants as any)['$']['multi_line']).toEqual('data-cslp=v2:all_test.blt827e0ad3608248be_csfff653e89df54e8c.en-us.multi_line')
327+
328+
// Reference fields should NOT get v2 prefix since they have no _applied_variants
329+
expect((entryWithReferenceAndVariants as any)['reference'][0]['$']['title']).toEqual('data-cslp=all_test_3.blt07a6c7258ddba844.en-us.title')
330+
expect((entryWithReferenceAndVariants as any)['reference'][0]['$']['single_line']).toEqual('data-cslp=all_test_3.blt07a6c7258ddba844.en-us.single_line')
331+
expect((entryWithReferenceAndVariants as any)['reference'][0]['$']['tags']).toEqual('data-cslp=all_test_3.blt07a6c7258ddba844.en-us.tags')
332+
expect((entryWithReferenceAndVariants as any)['reference'][0]['$']['multi_line_reference']).toEqual('data-cslp=all_test_3.blt07a6c7258ddba844.en-us.multi_line_reference')
333+
334+
done()
335+
})
336+
337+
it('Reference fields with their own applied_variants should use their variants', done => {
338+
const entryWithReferenceHavingVariants = {
339+
"title": "home",
340+
"locale": "en-us",
341+
"uid": "blt827e0ad3608248be",
342+
"ACL": [] as any[],
343+
"_version": 40,
344+
"_in_progress": false,
345+
"single_line": "parent field",
346+
"reference": [
347+
{
348+
"title": "base variant",
349+
"single_line": "reference field",
350+
"locale": "en-us",
351+
"uid": "blt07a6c7258ddba844",
352+
"_content_type_uid": "all_test_3",
353+
"ACL": [] as any[],
354+
"_version": 3,
355+
"_in_progress": false,
356+
"_applied_variants": {
357+
"single_line": "ref_variant_123"
358+
}
359+
}
360+
],
361+
"_applied_variants": {
362+
"single_line": "parent_variant_456"
363+
}
364+
}
365+
366+
addTags(entryWithReferenceHavingVariants, 'all_test', false)
367+
368+
// Parent entry field should get parent variant
369+
expect((entryWithReferenceHavingVariants as any)['$']['single_line']).toEqual('data-cslp=v2:all_test.blt827e0ad3608248be_parent_variant_456.en-us.single_line')
370+
371+
// Reference field should get its own variant, not parent variant
372+
expect((entryWithReferenceHavingVariants as any)['reference'][0]['$']['title']).toEqual('data-cslp=all_test_3.blt07a6c7258ddba844.en-us.title')
373+
expect((entryWithReferenceHavingVariants as any)['reference'][0]['$']['single_line']).toEqual('data-cslp=v2:all_test_3.blt07a6c7258ddba844_ref_variant_123.en-us.single_line')
374+
375+
done()
376+
})
377+
378+
it('Reference fields should work correctly with tagsAsObject=true', done => {
379+
const entryWithReferenceAndVariants = {
380+
"title": "home",
381+
"single_line": "ssd",
382+
"locale": "en-us",
383+
"uid": "blt827e0ad3608248be",
384+
"ACL": [] as any[],
385+
"_version": 40,
386+
"_in_progress": false,
387+
"reference": [
388+
{
389+
"title": "base variant",
390+
"single_line": "bases",
391+
"locale": "en-us",
392+
"uid": "blt07a6c7258ddba844",
393+
"_content_type_uid": "all_test_3",
394+
"ACL": [] as any[],
395+
"_version": 3,
396+
"_in_progress": false
397+
// No _applied_variants
398+
}
399+
],
400+
"_applied_variants": {
401+
"single_line": "csfff653e89df54e8c"
402+
}
403+
}
404+
405+
addTags(entryWithReferenceAndVariants, 'all_test', true)
406+
407+
// Parent entry field with variant should get v2 prefix as object
408+
expect((entryWithReferenceAndVariants as any)['$']['single_line']).toEqual({'data-cslp': 'v2:all_test.blt827e0ad3608248be_csfff653e89df54e8c.en-us.single_line'})
409+
410+
// Reference fields should NOT get v2 prefix as objects
411+
expect((entryWithReferenceAndVariants as any)['reference'][0]['$']['title']).toEqual({'data-cslp': 'all_test_3.blt07a6c7258ddba844.en-us.title'})
412+
expect((entryWithReferenceAndVariants as any)['reference'][0]['$']['single_line']).toEqual({'data-cslp': 'all_test_3.blt07a6c7258ddba844.en-us.single_line'})
413+
414+
done()
415+
})
271416
})
272417

273418
})

src/entry-editable.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function getTag(content: object, prefix: string, tagsAsObject: boolean, locale:
5959
* }]
6060
* }
6161
*/
62-
const newAppliedVariants = obj._applied_variants || obj?.system?.applied_variants || _applied_variants;
62+
const newAppliedVariants = obj._applied_variants || obj?.system?.applied_variants || null //check for _applied_variants in the reference object only return null if not present , do not check in the parent object;
6363
const newShouldApplyVariant = !!newAppliedVariants
6464
value[index].$ = getTag(obj, `${obj._content_type_uid}.${obj.uid}.${obj.locale || locale}`, tagsAsObject, locale, { _applied_variants: newAppliedVariants, shouldApplyVariant: newShouldApplyVariant, metaKey: "" })
6565
} else if (typeof obj === "object") {

0 commit comments

Comments
 (0)