Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createModalAction(templateItem) {
// Make sure we're working with serialized definitions
let item = templateItem
if (item && typeof item.serialize === 'function') {
item = item.serialize()
}
// We currently only allow initial value template items in the "new document" dialog
if (item.type !== 'initialValueTemplateItem') {
throw new Error(
'Only initial value template items are currently allowed in the new document structure'
)
}
// Make sure the template actually exists
const tpl = getTemplateById(item.templateId)
if (!tpl) {
throw new Error(`Template "${item.templateId}" not declared`)
}
// Build up an item suited for the "action modal" dialog
const type = schema.get(tpl.schemaType)
const title = item.title || tpl.title
const description = item.description || tpl.description
return {
...tpl,
title,
description,
// Don't show the type name as subtitle if it's the same as the template name
subtitle: type.title === title ? undefined : type.title,
key: item.id,
// Prioritize icon from initial value template item
function resolvePaneOptions(props, templateName, document) {
const {options} = props
const hasDefinedType = options.type && options.type !== '*'
const typeFromOptions = hasDefinedType ? options.type : undefined
let documentType = typeFromOptions || (document && document._type)
if (!documentType && templateName) {
const template = getTemplateById(templateName)
documentType = template && template.schemaType
}
// If we were not passed a schema type, use the resolved value if available
return hasDefinedType ? options : {...options, type: documentType}
}
function getNewRouterState({structure, documentType, params, payload, documentId, paneSegments}) {
const lastChild = structure[structure.length - 1] || {}
const lastGroup = paneSegments[paneSegments.length - 1]
const lastSibling = lastGroup[lastGroup.length - 1]
const terminatesInDocument = lastChild.type === 'document' && lastChild.options.id === documentId
const isTemplateCreate = params.template
const template = isTemplateCreate && getTemplateById(params.template)
const type = (template && template.schemaType) || documentType
const fallbackParameters = {type, template: params.template}
const newDocumentId = documentId === FALLBACK_ID ? UUID() : documentId
return terminatesInDocument
? paneSegments
.slice(0, -1)
.concat([lastGroup.slice(0, -1).concat({...lastSibling, id: newDocumentId})])
: [[{id: `__edit__${newDocumentId}`, params: fallbackParameters, payload}]]
}
maybeHandleOldUrl() {
const {navigate} = this.props.router
const {
action,
legacyEditDocumentId,
type: schemaType,
editDocumentId,
params = {}
} = this.props.router.state
const {template: templateName, ...payloadParams} = params
const template = getTemplateById(templateName)
const type = (template && template.schemaType) || schemaType
const shouldRewrite = (action === 'edit' && legacyEditDocumentId) || (type && editDocumentId)
if (!shouldRewrite) {
return
}
navigate(
getIntentRouteParams({
id: editDocumentId || legacyEditDocumentId,
type,
payloadParams,
templateName
}),
{replace: true}
)
}