Skip to content

Commit

Permalink
fix: ensure mandatory fields with defaults are shown as filled
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <patrathewhiz@gmail.com>
  • Loading branch information
enjeck committed Jul 17, 2024
1 parent c79bf0b commit cc065f2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 46 deletions.
23 changes: 3 additions & 20 deletions src/modules/modals/CreateRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { showError, showSuccess } from '@nextcloud/dialogs'
import '@nextcloud/dialogs/dist/index.css'
import ColumnFormComponent from '../main/partials/ColumnFormComponent.vue'
import { translate as t } from '@nextcloud/l10n'
import rowHelper from '../../shared/components/ncTable/mixins/rowHelper.js'
export default {
name: 'CreateRow',
Expand All @@ -49,6 +50,7 @@ export default {
NcNoteCard,
NcButton,
},
mixins: [rowHelper],
props: {
showModal: {
type: Boolean,
Expand Down Expand Up @@ -79,14 +81,7 @@ export default {
return this.columns.filter(col => col.id >= 0)
},
hasEmptyMandatoryRows() {
let mandatoryFieldsEmpty = false
this.columns.forEach(col => {
if (col.mandatory) {
const validValue = this.isValueValidForColumn(this.row[col.id], col)
mandatoryFieldsEmpty = mandatoryFieldsEmpty || !validValue
}
})
return mandatoryFieldsEmpty
return this.checkMandatoryFields(this.row)
},
},
watch: {
Expand All @@ -103,18 +98,6 @@ export default {
this.addNewAfterSave = false
this.$emit('close')
},
isValueValidForColumn(value, column) {
if (column.type === 'selection') {
if (
(value instanceof Array && value.length > 0)
|| (value === parseInt(value))
) {
return true
}
return false
}
return !!value || value === 0
},
async actionConfirm() {
this.localLoading = true
await this.sendNewRowToBE()
Expand Down
29 changes: 3 additions & 26 deletions src/modules/modals/EditRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { translate as t } from '@nextcloud/l10n'
import '@nextcloud/dialogs/dist/index.css'
import ColumnFormComponent from '../main/partials/ColumnFormComponent.vue'
import permissionsMixin from '../../shared/components/ncTable/mixins/permissionsMixin.js'
import rowHelper from '../../shared/components/ncTable/mixins/rowHelper.js'
export default {
name: 'EditRow',
Expand All @@ -61,7 +62,7 @@ export default {
ColumnFormComponent,
NcNoteCard,
},
mixins: [permissionsMixin],
mixins: [permissionsMixin, rowHelper],
props: {
showModal: {
type: Boolean,
Expand Down Expand Up @@ -99,14 +100,7 @@ export default {
return this.columns.filter(col => col.id >= 0)
},
hasEmptyMandatoryRows() {
let mandatoryFieldsEmpty = false
this.columns.forEach(col => {
if (col.mandatory) {
const validValue = this.isValueValidForColumn(this.localRow[col.id], col)
mandatoryFieldsEmpty = mandatoryFieldsEmpty || !validValue
}
})
return mandatoryFieldsEmpty
return this.checkMandatoryFields(this.localRow)
},
},
watch: {
Expand Down Expand Up @@ -140,18 +134,6 @@ export default {
this.reset()
this.$emit('close')
},
isValueValidForColumn(value, column) {
if (column.type === 'selection') {
if (
(value instanceof Array && value.length > 0)
|| (value === parseInt(value))
) {
return true
}
return false
}
return !!value || value === 0
},
async actionConfirm() {
this.localLoading = true
await this.sendRowToBE()
Expand Down Expand Up @@ -254,11 +236,6 @@ export default {
display: inline-block;
}
:where(.fix-col-4) {
display: flex;
justify-content: space-between;
}
:where(.slot.fix-col-4 input, .slot.fix-col-4 .row) {
min-width: 100% !important;
}
Expand Down
36 changes: 36 additions & 0 deletions src/shared/components/ncTable/mixins/rowHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ColumnTypes } from './columnHandler.js'
export default {
methods: {
isValueValidForColumn(value, column) {
const type = column?.type?.split('-')[0]
const columnTypeDefault = type + 'Default'
if (column.type === ColumnTypes.Selection) {
if (
(value instanceof Array && value.length > 0)
|| (value === parseInt(value))
) {
return true
}
const hasDefaultValue = columnTypeDefault in column && !(['', 'null'].includes(column[columnTypeDefault]))
return false || hasDefaultValue
}
let hasDefaultValue = columnTypeDefault in column && !(['', null].includes(column[columnTypeDefault]))
if (column.type === ColumnTypes.SelectionMulti) {
hasDefaultValue = columnTypeDefault in column && column[columnTypeDefault] !== '[]'
return (value instanceof Array && value.length > 0) || hasDefaultValue
}
return (!!value || value === 0) || hasDefaultValue
},

checkMandatoryFields(row) {
let mandatoryFieldsEmpty = false
this.columns.forEach(col => {
if (col.mandatory) {
const validValue = this.isValueValidForColumn(row[col.id], col)
mandatoryFieldsEmpty = mandatoryFieldsEmpty || !validValue
}
})
return mandatoryFieldsEmpty
},
},
}

0 comments on commit cc065f2

Please sign in to comment.