Skip to content

Commit

Permalink
Support single_block
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoverna committed Jan 23, 2024
1 parent 91c2d9e commit c0bc8b4
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/hooks/sourceNodes/createTypes/item/fields/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ module.exports = ({
}) => {
const parentItemTypeName = gqlItemTypeName(parentItemType);

const itemTypeIds = field.validators.itemItemType.itemTypes;
const itemTypeIds =
field.validators[
field.fieldType === 'single_block' ? 'singleBlockBlocks' : 'itemItemType'
].itemTypes;

if (itemTypeIds.length === 0) {
return { type: 'String' };
Expand Down
1 change: 1 addition & 0 deletions src/hooks/sourceNodes/createTypes/item/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = ({
json: simpleField('JSON'),
lat_lon: simpleField('DatoCmsLatLonField'),
link: require('./fields/link'),
single_block: require('./fields/link'),
links: require('./fields/richText'),
rich_text: require('./fields/richText'),
structured_text: require('./fields/structuredText'),
Expand Down
70 changes: 65 additions & 5 deletions test/__snapshots__/graphql.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,10 @@ Object {
},
"datoCmsAsset": Object {
"fixed": Object {
"base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABUAAAAQCAYAAAD52jQlAAAAAXNSR0IArs4c6QAAA/lJREFUOE99lF1MHFUUx/937szOfgy7QJdv6UqBTYFaLWqghQf0odbqg9GwPpj62WiaaC0F0pIYM22NLzVprTHVplGTouCuYqopWpuw29ImtMDSrXxIWxbRZQWWAlt2YT9m5voAVUKJv7d77zm/e5KTcwhWIUPmZMhat75ug16j21QjP6AkYhP+hfEpB1zq6vi14FZflGKAAICnyCDF1unP8DHFyygdLjauH7tqaTgNAAyMMDCyOvce90kdcKluyHxj/4c3ulKVI5pJAJJJIUU05o2so8uiQ4SAsB68KciQ73OsyVIlSx86C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8InNABQoAijm6hfk4hF5hIxWZdmzvx8PPFf7f+NfwDPEMf2dzjr3wAAAABJRU5ErkJggg==",
},
"forceBlurhashFixed": Object {
"base64": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAATCAMAAAC9bj0JAAAAtFBMVEXAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHAKoHNKC3VAAAAPHRSTlMAAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8xMjM0NTY3ODk6OzzSxYW5AAAAw0lEQVR42mWRyXIDMQhEBWiZ8f//aE62JJa0EmcWp4sDVa+aFiintySTq6dD+WgKOY34B1rL7Fm6fQCprVCYcJ93UCBKRtC4O5iJU4hLNruHQ3HpTxDhyZfiCtYkogBd/AJqLUUwyp2Z/QTbvjcAN4LHxgG2x2PHfmQuTBg236BBtWY4dDnCQ38AJVqF9MQssurXER29UAi5mdrSX8ZTVWcVDtfZe38dIM2vsSEdITp6v23+HK3gVqbDPk5iL8NT7fzDbw3EbHnrenJcAAAAAElFTkSuQmCC",
Expand Down Expand Up @@ -1665,6 +1665,40 @@ https://www.datocms-assets.com/34723/1620629638-plant.jpeg?auto=format&dpr=0.6&f
},
},
],
"_allSingleBlockLocales": Array [
Object {
"locale": "en",
"value": Object {
"innerModularContent": Array [],
"multipleLinks": Array [
Object {
"singleLineString": "Single line string",
},
],
"originalId": "Ks-Ts9b3QP6JjP9_gjMKHQ",
"singleLink": Object {
"singleLineString": "Single line string",
},
"title": "Single 1",
},
},
Object {
"locale": "it",
"value": Object {
"innerModularContent": Array [],
"multipleLinks": Array [
Object {
"singleLineString": "Stringa semplice",
},
],
"originalId": "B7qCt24dTmaEJEljW0vn_g",
"singleLink": Object {
"singleLineString": "Stringa semplice",
},
"title": "Blocco singolo 1",
},
},
],
"_allSingleLineStringLocales": Array [
Object {
"locale": "en",
Expand Down Expand Up @@ -2382,9 +2416,9 @@ https://www.datocms-assets.com/34723/1620629638-plant.jpeg?auto=format&dpr=0.6&f
"__typename": "DatoCmsMetaField",
"createdAt": "2020-09-22T15:46:24.300+01:00",
"isValid": true,
"publishedAt": "2023-02-08T12:10:05.407+00:00",
"publishedAt": "2024-01-23T15:50:24.486+00:00",
"status": "published",
"updatedAt": "2023-02-08T12:10:05.316+00:00",
"updatedAt": "2024-01-23T15:50:24.365+00:00",
},
"model": Object {
"allLocalesRequired": false,
Expand Down Expand Up @@ -2672,6 +2706,19 @@ https://www.datocms-assets.com/34723/1620629638-plant.jpeg?auto=format&dpr=0.6&f
"label": "Modular content",
"originalId": "1400207",
},
Object {
"appeareance": Object {
"addons": Array [],
"editor": "framed_single_block",
"parameters": Object {
"startCollapsed": false,
},
},
"fieldType": "single_block",
"id": "DatoCmsField-ZO6yKrCFSlmHJz0OZWRiSA",
"label": "Single block",
"originalId": "ZO6yKrCFSlmHJz0OZWRiSA",
},
Object {
"appeareance": Object {
"addons": Array [],
Expand Down Expand Up @@ -2863,7 +2910,7 @@ Foo
},
Object {
"attributes": Object {
"content": "2023-02-08T12:10:05Z",
"content": "2024-01-23T15:50:24Z",
"property": "article:modified_time",
},
"tagName": "meta",
Expand Down Expand Up @@ -3158,6 +3205,19 @@ https://www.datocms-assets.com/34723/1620629638-plant.jpeg?auto=format&dpr=0.6&f
"video": null,
"width": 100,
},
"singleBlock": Object {
"innerModularContent": Array [],
"multipleLinks": Array [
Object {
"singleLineString": "Single line string",
},
],
"originalId": "Ks-Ts9b3QP6JjP9_gjMKHQ",
"singleLink": Object {
"singleLineString": "Single line string",
},
"title": "Single 1",
},
"singleLineString": "Single line string",
"singleLink": Object {
"id": "DatoCmsArticle-7364346",
Expand Down
43 changes: 43 additions & 0 deletions test/graphql.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,49 @@ test('items', async () => {
}
}
}
singleBlock {
title
originalId
singleLink {
singleLineString
}
multipleLinks {
singleLineString
}
innerModularContent {
title
originalId
singleLink {
singleLineString
}
multipleLinks {
singleLineString
}
}
}
_allSingleBlockLocales {
locale
value {
title
originalId
singleLink {
singleLineString
}
multipleLinks {
singleLineString
}
innerModularContent {
title
originalId
singleLink {
singleLineString
}
multipleLinks {
singleLineString
}
}
}
}
structuredText {
value
blocks {
Expand Down

0 comments on commit c0bc8b4

Please sign in to comment.