Skip to content

Commit

Permalink
Fix prompts not opening page in edit mode when used in sucession
Browse files Browse the repository at this point in the history
  • Loading branch information
Fajfa committed Apr 24, 2024
1 parent 2fb3015 commit de90be0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
12 changes: 9 additions & 3 deletions client/web/compose/src/mixins/record.js
Expand Up @@ -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 })
Expand Down
4 changes: 0 additions & 4 deletions client/web/compose/src/views/Public/Pages/Records/View.vue
Expand Up @@ -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')
},
},
Expand Down
2 changes: 1 addition & 1 deletion lib/vue/src/components/prompts/definitions.ts
Expand Up @@ -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([
Expand Down
10 changes: 5 additions & 5 deletions lib/vue/src/components/prompts/kinds/index.ts
Expand Up @@ -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')

Expand Down Expand Up @@ -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
Expand All @@ -196,14 +195,15 @@ 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') {
// @ts-ignore
this.$root.$emit('show-record-modal', {
recordID: !recordID ? NoID : recordID,
recordPageID: pageID,
edit,
})
} else if (openMode === 'newTab') {
// @ts-ignore
Expand Down

0 comments on commit de90be0

Please sign in to comment.