3
0

Fix prompts not opening page in edit mode when used in sucession

This commit is contained in:
Jože Fortun 2024-04-23 12:43:00 +02:00
parent 2fb301536c
commit de90be03a7
4 changed files with 15 additions and 13 deletions

View File

@ -156,16 +156,22 @@ export default {
.then(r => {
record = new compose.Record(this.module, r)
})
.then(() => this.dispatchUiEvent('afterFormSubmit', this.record, { $records: records }))
.then(() => this.dispatchUiEvent('afterFormSubmit', record, { $records: records }))
.then(() => this.updatePrompts())
.then(() => {
if (this.record.valueErrors.set) {
if (record.valueErrors.set) {
this.toastWarning(this.$t('notification:record.validationWarnings'))
} else {
// We do this prop mutation (BAD!!) so that prompts can use the edit prop properly since just redirecting to the /edit route doesn't work (for now)
if (this.edit) {
this.edit = false
}
this.inCreating = false
this.inEditing = false
// reset the record initial state in cases where the record edit page is redirected to the record view page
this.initialRecordState = this.record.clone()
this.initialRecordState = record.clone()
if (this.showRecordModal) {
this.$emit('handle-record-redirect', { recordID: record.recordID, recordPageID: this.page.pageID })

View File

@ -316,23 +316,19 @@ export default {
'page.pageID': {
immediate: true,
handler () {
console.log('1')
if (this.page.pageID === NoID) return
this.layouts = this.getPageLayouts(this.page.pageID)
this.layout = undefined
console.log('1')
},
},
uniqueID: {
immediate: true,
handler () {
console.log('2')
this.record = undefined
this.initialRecordState = undefined
this.refresh()
console.log('2')
},
},

View File

@ -12,8 +12,8 @@ const variants = [
]
const openModeVariants = [
{ value: 'newTab', text: 'Open link in a new tab' },
{ value: 'sameTab', text: 'Open link in the same tab' },
{ value: 'newTab', text: 'Open link in a new tab' },
]
export const prompts = Object.freeze([

View File

@ -108,7 +108,7 @@ const definitions: Record<string, PromptDefinition> = {
const module = pVal(v, 'module')
const namespace = pVal(v, 'namespace')
const record = pVal(v, 'record')
const edit = !!pVal(v, 'edit')
let edit = !!pVal(v, 'edit')
const delay = (pVal(v, 'delay') || 0) as number
const openMode = pVal(v, 'openMode')
@ -185,9 +185,8 @@ const definitions: Record<string, PromptDefinition> = {
// @ts-ignore
if (this.$root.$options.name === 'compose') {
let name = 'page.record'
if (edit || !recordID || recordID === NoID) {
name += recordID && recordID !== NoID ? '.edit' : '.create'
}
edit = edit || !recordID || recordID === NoID
name += edit ? '.edit' : '.create'
// If name and params match, make sure to refresh page instead of push
// @ts-ignore
@ -196,7 +195,7 @@ const definitions: Record<string, PromptDefinition> = {
setTimeout(() => {
console.debug('reroute to %s via prompt in %d sec', name, delay, { namespaceID, slug, moduleID, recordID })
const routeParams = { name, params: { recordID, pageID, slug } }
const routeParams = { name, params: { recordID, pageID, slug, edit } }
if (reloadPage) {
window.location.reload()
} else if (openMode === 'modal') {
@ -204,6 +203,7 @@ const definitions: Record<string, PromptDefinition> = {
this.$root.$emit('show-record-modal', {
recordID: !recordID ? NoID : recordID,
recordPageID: pageID,
edit,
})
} else if (openMode === 'newTab') {
// @ts-ignore