-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add migrations for contact fields (#142)
* Add migrations for contact fields * Dynamic menuItemType id * Fix error notification contacts field check and update item types to use dynamic menuItemType.id in migrations
- Loading branch information
1 parent
1a74ded
commit 95d6b0f
Showing
1 changed file
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Client } from "@datocms/cli/lib/cma-client-node"; | ||
|
||
export default async function (client: Client) { | ||
const itemTypes = await client.itemTypes.list(); | ||
const menuItemType = itemTypes.find( | ||
(itemType: { api_key: string }) => itemType.api_key === "menu" | ||
) || { id: "" }; | ||
|
||
const fields = await client.fields.list(menuItemType.id); | ||
const findField = (label: string) => | ||
fields.find((field: any) => field.label === label); | ||
|
||
const errorNotificationContactsField = findField( | ||
"Error notification contacts" | ||
); | ||
if (!errorNotificationContactsField) { | ||
console.log( | ||
'Create Multiple links field "Error notification contacts" (`error_notification_contacts`) in model "Menu" (`menu`)' | ||
); | ||
await client.fields.create(menuItemType.id, { | ||
id: "GlLvpmJFTBup26dDM2OMuQ", | ||
label: "Error notification contacts", | ||
field_type: "links", | ||
api_key: "error_notification_contacts", | ||
validators: { | ||
items_item_type: { | ||
on_publish_with_unpublished_references_strategy: "fail", | ||
on_reference_unpublish_strategy: "delete_references", | ||
on_reference_delete_strategy: "delete_references", | ||
item_types: [menuItemType.id], | ||
}, | ||
}, | ||
appearance: { addons: [], editor: "links_select", parameters: {} }, | ||
default_value: null, | ||
}); | ||
} | ||
|
||
const feedbackContactsField = findField("Feedback contacts"); | ||
if (!feedbackContactsField) { | ||
console.log( | ||
'Create Multiple links field "Feedback contacts" (`feedback_contacts`) in model "Menu" (`menu`)' | ||
); | ||
await client.fields.create(menuItemType.id, { | ||
id: "CPxFkf5cRPKm0ORLakLX3Q", | ||
label: "Feedback contacts", | ||
field_type: "links", | ||
api_key: "feedback_contacts", | ||
validators: { | ||
items_item_type: { | ||
on_publish_with_unpublished_references_strategy: "fail", | ||
on_reference_unpublish_strategy: "delete_references", | ||
on_reference_delete_strategy: "delete_references", | ||
item_types: [menuItemType.id], | ||
}, | ||
}, | ||
appearance: { addons: [], editor: "links_select", parameters: {} }, | ||
default_value: null, | ||
}); | ||
} | ||
} |
95d6b0f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://data.openearth.nl as production
🚀 Deployed on https://6752d6181b14702c83c1369d--deltares-viewer.netlify.app
95d6b0f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://nl2120.netlify.app as production
🚀 Deployed on https://6752d62078490f0a9831153d--nl2120.netlify.app
95d6b0f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 Published on https://viewer.openearth.nl as production
🚀 Deployed on https://6752d6226570a5240d3a2a20--rws-viewer.netlify.app