-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: External Link (in Action Block) (#234)
# Changes - Adds `ExternalLink` item to `ActionBlock` with required `title` and `url` field (with validation). - Matches the `openInNewTab` property also available in the built-in links in `StructuredText` fields. - Reuses the same `style` field configuration used for the `InternalLink` block. # Associated issue N/A # How to test 1. Open preview link 2. Navigate to the Action Block demo and scroll down to the "Action block with External Links" section. 3. Verify the External Links render as primary and secondary 4. Verify the first action opens the external link in the same tab, and the second action opens a new tab 5. Go the the `external-links` environment and play around with the new External Link option in Action Blocks 6. Verify changes made are reflected in the web page (note: run locally as changes are not updated on deploy preview) # Checklist - [x] I have performed a self-review of my own code - [x] I have made sure that my PR is easy to review (not too big, includes comments) - ~I have made updated relevant documentation files (in project README, docs/, etc)~ - ~I have added a decision log entry if the change affects the architecture or changes a significant technology~ - [x] I have notified a reviewer <!-- Please strike through and check off all items that do not apply (rather than removing them) -->
- Loading branch information
Showing
7 changed files
with
184 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import type { Client } from '@datocms/cli/lib/cma-client-node'; | ||
import { actionStyleField } from './1734363388_actionBlock'; | ||
|
||
export default async function (client: Client) { | ||
console.log('Create new models/block models'); | ||
|
||
console.log( | ||
'Create block model "\uD83D\uDD17 External Link" (`external_link`)' | ||
); | ||
await client.itemTypes.create( | ||
{ | ||
id: 'Yk1ge9eTTf25Iwph1Dx3_g', | ||
name: '\uD83D\uDD17 External Link', | ||
api_key: 'external_link', | ||
modular_block: true, | ||
inverse_relationships_enabled: false, | ||
}, | ||
{ | ||
skip_menu_item_creation: true, | ||
schema_menu_item_id: 'OiBwyNPrR82ZWMawg47csg', | ||
} | ||
); | ||
|
||
console.log('Creating new fields/fieldsets'); | ||
|
||
console.log( | ||
'Create Single-line string field "Title" (`title`) in block model "\uD83D\uDD17 External Link" (`external_link`)' | ||
); | ||
await client.fields.create('Yk1ge9eTTf25Iwph1Dx3_g', { | ||
id: 'Epmmtd7MTfeqpiwLP23D1Q', | ||
label: 'Title', | ||
field_type: 'string', | ||
api_key: 'title', | ||
validators: { required: {} }, | ||
appearance: { | ||
addons: [], | ||
editor: 'single_line', | ||
parameters: { heading: false, placeholder: null }, | ||
}, | ||
default_value: '', | ||
}); | ||
|
||
console.log( | ||
'Create Single-line string field "URL" (`url`) in block model "\uD83D\uDD17 External Link" (`external_link`)' | ||
); | ||
await client.fields.create('Yk1ge9eTTf25Iwph1Dx3_g', { | ||
id: 'bUvYLCENQ3SP_vGhoN07nA', | ||
label: 'URL', | ||
field_type: 'string', | ||
api_key: 'url', | ||
validators: { required: {}, format: { predefined_pattern: 'url' } }, | ||
appearance: { | ||
addons: [], | ||
editor: 'single_line', | ||
parameters: { heading: false, placeholder: null }, | ||
}, | ||
default_value: '', | ||
}); | ||
|
||
console.log( | ||
'Create Boolean field "Open in new tab" (`open_in_new_tab`) in block model "\uD83D\uDD17 External Link" (`external_link`)' | ||
); | ||
await client.fields.create('Yk1ge9eTTf25Iwph1Dx3_g', { | ||
id: 'AlPRQFQdRlixBp4Tgz5qsQ', | ||
label: 'Open in new tab', | ||
field_type: 'boolean', | ||
api_key: 'open_in_new_tab', | ||
appearance: { addons: [], editor: 'boolean', parameters: {} }, | ||
default_value: false, | ||
}); | ||
|
||
console.log( | ||
'Create Single-line string field "Style" (`style`) in block model "\uD83D\uDD17 External Link" (`external_link`)' | ||
); | ||
await client.fields.create('Yk1ge9eTTf25Iwph1Dx3_g', { | ||
id: 'TNl63OntSe6ZLD3wCYxK-g', | ||
...actionStyleField, | ||
}); | ||
|
||
console.log('Update existing fields/fieldsets'); | ||
|
||
console.log( | ||
'Update Modular Content (Multiple blocks) field "Items" (`items`) in block model "\uD83C\uDF9B\uFE0F Action Block" (`action_block`)' | ||
); | ||
await client.fields.update('dAUckF8qR0edf_f7zam6hA', { | ||
validators: { | ||
rich_text_blocks: { | ||
item_types: ['GWnhoQDqQoGJj4-sQTVttw', 'Yk1ge9eTTf25Iwph1Dx3_g'], | ||
}, | ||
size: { min: 1 }, | ||
}, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
fragment ExternalLink on ExternalLinkRecord { | ||
__typename | ||
id | ||
title | ||
url | ||
openInNewTab | ||
style | ||
} |