Skip to content

Commit

Permalink
Fix redirect on save as copy and resolve wrong titles on all records
Browse files Browse the repository at this point in the history
  • Loading branch information
Fajfa committed Aug 16, 2023
1 parent c96e4be commit 308fd7a
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 89 deletions.
3 changes: 1 addition & 2 deletions client/web/compose/src/components/Common/RecordToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
@click.prevent="$emit('back')"
>
<font-awesome-icon

:icon="['fas', showRecordModal && !inEditing ? 'times' : 'chevron-left']"
:icon="['fas', showRecordModal ? 'times' : 'chevron-left']"
class="back-icon"
/>
{{ backLabel }}
Expand Down
14 changes: 6 additions & 8 deletions client/web/compose/src/components/PageBlocks/RecordListBase.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
v-bind="$props"
:scrollable-body="false"
v-on="$listeners"
@refreshBlock="refresh(false, false)"
@refreshBlock="refresh(true, false)"
>
<template
v-if="isFederated"
Expand Down Expand Up @@ -1535,13 +1535,12 @@ export default {
}
},
refresh (resetPagination = false, checkSelected = false) {
async refresh (resetPagination = false, checkSelected = false) {
// Prevent refresh if records are selected or inline editing
if (checkSelected && (this.selected.length || this.inlineEdit.recordIDs.length)) return
this.$nextTick(() => {
return this.pullRecords(resetPagination)
})
await this.$nextTick()
return this.pullRecords(resetPagination)
},
/**
Expand All @@ -1566,9 +1565,6 @@ export default {
const query = queryToFilter(this.query, this.drillDownFilter || this.prefilter, this.fields.map(({ moduleField }) => moduleField), this.recordListFilter)
const { moduleID, namespaceID } = this.recordListModule
if (this.filter.pageCursor) {
this.filter.sort = ''
}
let paginationOptions = {}
if (resetPagination) {
Expand All @@ -1578,6 +1574,8 @@ export default {
incPageNavigation: fullPageNavigation,
incTotal: showTotalCount,
}
} else if (this.filter.pageCursor) {
this.filter.sort = ''
}
// Filter's out deleted records when filter.deleted is 2, and undeleted records when filter.deleted is 0
Expand Down
5 changes: 4 additions & 1 deletion client/web/compose/src/components/Public/Record/Modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
:page="page"
:module="module"
:record-i-d="recordID"
:values="values"
show-record-modal
@handle-record-redirect="loadRecord"
/>
Expand Down Expand Up @@ -69,6 +70,7 @@ export default {
recordID: undefined,
module: undefined,
page: undefined,
values: undefined,
}
},
Expand Down Expand Up @@ -116,7 +118,8 @@ export default {
clearRecordIDs: 'ui/clearRecordIDs',
}),
loadRecord ({ recordID, recordPageID }) {
loadRecord ({ recordID, recordPageID, values }) {
this.values = values
this.loadModal({ recordID, recordPageID })
setTimeout(() => {
Expand Down
33 changes: 27 additions & 6 deletions client/web/compose/src/mixins/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default {
this.processingSubmit = true
this.processing = true

let record
const isNew = this.record.recordID === NoID
const queue = []

Expand Down Expand Up @@ -142,17 +143,29 @@ export default {

throw err
})
.then(record => {
this.record = new compose.Record(this.module, record)
.then(r => {
record = new compose.Record(this.module, r)
})
.then(() => this.dispatchUiEvent('afterFormSubmit', this.record, { $records: records }))
.then(() => this.updatePrompts())
.then(() => {
if (this.record.valueErrors.set) {
this.toastWarning(this.$t('notification:record.validationWarnings'))
} else {
this.inCreating = false
if (isNew) {
this.inCreating = false
this.inEditing = false
} else {
this.record = record
}

if (this.showRecordModal) {
this.$emit('handle-record-redirect', { recordID: record.recordID, recordPageID: this.page.pageID })
} else {
this.$router.push({ name: route, params: { ...this.$route.params, recordID: record.recordID } })
}
}

this.toastSuccess(this.$t(`notification:record.${isNew ? 'create' : 'update'}Success`))
})
.catch(this.toastErrorHandler(this.$t(`notification:record.${isNew ? 'create' : 'update'}Failed`)))
Expand All @@ -170,6 +183,7 @@ export default {
this.processingSubmit = true
this.processing = true

let record
const isNew = this.record.recordID === NoID

return this
Expand All @@ -192,15 +206,22 @@ export default {

throw err
})
.then(record => {
this.record = new compose.Record(this.module, record)
.then(r => {
record = new compose.Record(this.module, r)
})
.then(() => this.dispatchUiEvent('beforeFormSubmit', this.record))
.then(() => this.dispatchUiEvent('afterFormSubmit', record))
.then(() => this.updatePrompts())
.then(() => {
if (this.record.valueErrors.set) {
this.toastWarning(this.$t('notification:record.validationWarnings'))
} else {
if (isNew) {
this.inCreating = false
this.inEditing = false
} else {
this.record = record
}

this.$router.push({ name: route, params: { ...this.$route.params, recordID: this.record.recordID } })
}
})
Expand Down
22 changes: 1 addition & 21 deletions client/web/compose/src/views/Admin/Modules/Records/Create.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script>
import ViewRecord from './View'
import { compose } from '@cortezaproject/corteza-js'
export default {
i18nOptions: {
Expand All @@ -11,30 +10,11 @@ export default {
extends: ViewRecord,
props: {
// If component was called (via router) with some pre-seed values
values: {
type: Object,
required: false,
default: () => ({}),
},
},
data () {
return {
inEditing: true,
inCreating: true,
}
},
computed: {
title () {
const { name, handle } = this.module
return this.$t('allRecords.create.title', { name: name || handle, interpolation: { escapeValue: false } })
},
},
created () {
this.record = new compose.Record(this.module, { values: this.values })
},
}
</script>
14 changes: 1 addition & 13 deletions client/web/compose/src/views/Admin/Modules/Records/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,8 @@ export default {
data () {
return {
inEditing: true,
inCreating: false,
}
},
computed: {
title () {
const { name, handle } = this.module
return this.$t('allRecords.edit.title', { name: name || handle, interpolation: { escapeValue: false } })
},
},
methods: {
handleBack () {
this.$router.push({ name: 'admin.modules.record.view' })
},
},
}
</script>
17 changes: 14 additions & 3 deletions client/web/compose/src/views/Admin/Modules/Records/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@
<script>
import { mapGetters } from 'vuex'
import RecordToolbar from 'corteza-webapp-compose/src/components/Common/RecordToolbar'
import users from 'corteza-webapp-compose/src/mixins/users'
import record from 'corteza-webapp-compose/src/mixins/record'
import { compose } from '@cortezaproject/corteza-js'
import RecordBase from 'corteza-webapp-compose/src/components/PageBlocks/RecordBase'
Expand All @@ -124,12 +123,21 @@ export default {
mixins: [
// The record mixin contains all of the logic for creating/editing/deleting the record
record,
users,
],
props: {
// If component was called (via router) with some pre-seed values
values: {
type: Object,
required: false,
default: () => ({}),
},
},
data () {
return {
inEditing: false,
inCreating: false,
blocks: [],
Expand All @@ -148,7 +156,9 @@ export default {
title () {
const { name, handle } = this.module
return this.$t('allRecords.view.title', { name: name || handle, interpolation: { escapeValue: false } })
const titlePrefix = this.inCreating ? 'create' : this.inEditing ? 'edit' : 'view'
return this.$t(`allRecords.${titlePrefix}.title`, { name: name || handle, interpolation: { escapeValue: false } })
},
module () {
Expand Down Expand Up @@ -219,6 +229,7 @@ export default {
created () {
this.createBlocks()
this.record = new compose.Record(this.module, { values: this.values })
},
methods: {
Expand Down
31 changes: 0 additions & 31 deletions client/web/compose/src/views/Public/Pages/Records/Create.vue
Original file line number Diff line number Diff line change
@@ -1,46 +1,15 @@
<script>
import ViewRecord from './View'
import { compose } from '@cortezaproject/corteza-js'
export default {
name: 'CreateRecord',
extends: ViewRecord,
props: {
// When creating from related record blocks
refRecord: {
type: compose.Record,
required: false,
default: () => ({}),
},
// If component was called (via router) with some pre-seed values
values: {
type: Object,
required: false,
default: () => ({}),
},
},
data () {
return {
inEditing: true,
inCreating: true,
}
},
created () {
this.record = new compose.Record(this.module, { values: this.values })
if (this.refRecord) {
// Record create form called from a related records block,
// we'll try to find an appropriate field and cross-link this new record to ref
const recRefField = this.module.fields.find(f => f.kind === 'Record' && f.options.moduleID === this.refRecord.moduleID)
if (recRefField) {
this.record.values[recRefField.name] = this.refRecord.recordID
}
}
},
}
</script>
35 changes: 31 additions & 4 deletions client/web/compose/src/views/Public/Pages/Records/View.vue
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ export default {
default: '',
},
// When creating from related record blocks
refRecord: {
type: compose.Record,
required: false,
default: () => ({}),
},
// If component was called (via router) with some pre-seed values
values: {
type: Object,
required: false,
default: () => ({}),
},
// Open record in a modal
showRecordModal: {
type: Boolean,
Expand Down Expand Up @@ -343,7 +357,16 @@ export default {
this.handleBack()
})
} else {
this.record = new compose.Record(module, {})
this.record = new compose.Record(module, { values: this.values })
}
if (this.refRecord) {
// Record create form called from a related records block,
// we'll try to find an appropriate field and cross-link this new record to ref
const recRefField = this.module.fields.find(f => f.kind === 'Record' && f.options.moduleID === this.refRecord.moduleID)
if (recRefField) {
this.record.values[recRefField.name] = this.refRecord.recordID
}
}
}
},
Expand All @@ -352,7 +375,12 @@ export default {
/**
* Not the best way since we can not always know where we
* came from (and "where" is back).
*/
*/
if (this.showRecordModal) {
this.$bvModal.hide('record-modal')
return
}
const previousPage = await this.popPreviousPages()
const extraPop = !this.inCreating
this.$router.push(previousPage || { name: 'pages', params: { slug: this.namespace.slug || this.namespace.namespaceID } })
Expand Down Expand Up @@ -382,8 +410,7 @@ export default {
this.inEditing = true
this.inCreating = true
this.record = new compose.Record(this.module, { values: this.record.values })
this.$emit('handle-record-redirect', { recordID: NoID, recordPageID: this.page.pageID })
this.$emit('handle-record-redirect', { recordID: NoID, recordPageID: this.page.pageID, values: this.record.values })
},
handleEdit () {
Expand Down

0 comments on commit 308fd7a

Please sign in to comment.