Skip to content

Commit b4013fb

Browse files
committed
Enhancement: Add column width setting (code review changes)
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent ca6f4da commit b4013fb

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

src/modules/modals/CreateColumn.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
:title.sync="column.title"
1616
:custom-settings.sync="column.customSettings"
1717
:selected-views.sync="column.selectedViews"
18-
:title-missing-error="titleMissingError" />
18+
:title-missing-error="titleMissingError"
19+
:width-invalid-error="widthInvalidError" />
1920
</div>
2021
<div class="fix-col-2" style="display: block">
2122
<div class="row no-padding-on-mobile space-L">
@@ -115,6 +116,7 @@ import UsergroupForm from '../../shared/components/ncTable/partials/columnTypePa
115116
import { useTablesStore } from '../../store/store.js'
116117
import { useDataStore } from '../../store/data.js'
117118
import { mapActions } from 'pinia'
119+
import { COLUMN_WIDTH_MAX, COLUMN_WIDTH_MIN } from '../../shared/constants.js'
118120
119121
export default {
120122
name: 'CreateColumn',
@@ -193,6 +195,7 @@ export default {
193195
textAppAvailable: !!window.OCA?.Text?.createEditor,
194196
addNewAfterSave: false,
195197
typeMissingError: false,
198+
widthInvalidError: false,
196199
titleMissingError: false,
197200
typeOptions: [
198201
{ id: 'text', label: t('tables', 'Text') },
@@ -290,10 +293,10 @@ export default {
290293
showInfo(t('tables', 'Please insert a title for the new column.'))
291294
this.titleMissingError = true
292295
} else if (this.column.customSettings?.width
293-
&& (this.column.customSettings?.width < 20 || this.column.customSettings?.width > 1000)) {
296+
&& (this.column.customSettings?.width < COLUMN_WIDTH_MIN || this.column.customSettings?.width > COLUMN_WIDTH_MAX)) {
294297
this.titleMissingError = false
295-
showError(t('tables', 'Cannot save column. Column width must be between {min} and {max}.', { min: 20, max: 1000 }))
296-
this.typeMissingError = true
298+
showError(t('tables', 'Cannot save column. Column width must be between {min} and {max}.', { min: COLUMN_WIDTH_MIN, max: COLUMN_WIDTH_MAX }))
299+
this.widthInvalidError = true
297300
} else if (this.column.type === null) {
298301
this.titleMissingError = false
299302
showInfo(t('tables', 'You need to select a type for the new column.'))
@@ -328,9 +331,8 @@ export default {
328331
mandatory: this.column.mandatory,
329332
viewId: this.isView ? this.element.id : null,
330333
tableId: !this.isView ? this.element.id : null,
331-
customSettings: this.column.customSettings,
334+
customSettings: { width: this.column.customSettings.width },
332335
}
333-
data.customSettings = { width: data.customSettings.width }
334336
335337
if (this.combinedType === ColumnTypes.TextLine) {
336338
data.textUnique = this.column.textUnique
@@ -435,6 +437,7 @@ export default {
435437
this.column.selectedViews = []
436438
}
437439
this.titleMissingError = false
440+
this.widthInvalidError = false
438441
this.typeMissingError = false
439442
},
440443
},

src/modules/modals/EditColumn.vue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
:title.sync="editColumn.title"
1616
:custom-settings.sync="editColumn.customSettings"
1717
:edit-column="true"
18-
:title-missing-error="editErrorTitle" />
18+
:title-missing-error="editErrorTitle"
19+
:width-invalid-error="widthInvalidError" />
1920
</div>
2021
<div class="col-2 space-LR space-T">
2122
<component :is="getColumnForm" :column="editColumn" :can-save.sync="canSave" />
@@ -69,6 +70,7 @@ import { ColumnTypes } from '../../shared/components/ncTable/mixins/columnHandle
6970
import moment from '@nextcloud/moment'
7071
import { mapActions } from 'pinia'
7172
import { useDataStore } from '../../store/data.js'
73+
import { COLUMN_WIDTH_MAX, COLUMN_WIDTH_MIN } from '../../shared/constants.js'
7274
7375
export default {
7476
name: 'EditColumn',
@@ -120,9 +122,10 @@ export default {
120122
data() {
121123
return {
122124
loading: false,
123-
editColumn: Object.assign({}, this.column),
125+
editColumn: JSON.parse(JSON.stringify(this.column)),
124126
deleteId: null,
125127
editErrorTitle: false,
128+
widthInvalidError: false,
126129
canSave: true, // used to avoid saving an incorrect config
127130
}
128131
},
@@ -169,13 +172,12 @@ export default {
169172
}
170173
171174
if (this.editColumn.customSettings?.width
172-
&& (this.editColumn.customSettings?.width < 20 || this.editColumn.customSettings?.width > 1000)) {
173-
showError(t('tables', 'Cannot save column. Column width must be between {min} and {max}.', { min: 20, max: 1000 }))
174-
this.editErrorTitle = true
175+
&& (this.editColumn.customSettings?.width < COLUMN_WIDTH_MIN || this.editColumn.customSettings?.width > COLUMN_WIDTH_MAX)) {
176+
showError(t('tables', 'Cannot save column. Column width must be between {min} and {max}.', { min: COLUMN_WIDTH_MIN, max: COLUMN_WIDTH_MAX }))
177+
this.widthInvalidError = true
175178
return
176179
}
177180
178-
this.editErrorTitle = false
179181
await this.updateLocalColumn()
180182
this.reset()
181183
this.$emit('close')
@@ -185,6 +187,7 @@ export default {
185187
this.editColumn = null
186188
this.deleteId = null
187189
this.editErrorTitle = false
190+
this.widthInvalidError = false
188191
},
189192
async updateLocalColumn() {
190193
const data = Object.assign({}, this.editColumn)

src/shared/components/ncTable/partials/columnTypePartials/forms/MainForm.vue

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
</div>
3030

3131
<!-- column width -->
32-
<div class="fix-col-4 mandatory title space-T">
32+
<div class="fix-col-4 mandatory title space-T" :class="{error: widthInvalidError}">
3333
{{ t('tables', 'Column width') }}
3434
</div>
35-
<div class="fix-col-4">
35+
<div class="fix-col-4" :class="{error: widthInvalidError}">
3636
<input
3737
v-model.number="localColumnWidth"
3838
type="number"
3939
pattern="\d+"
4040
min="20"
4141
max="1000"
42-
:placeholder="t('tables', 'Enter a column width')">
42+
:placeholder="t('tables', 'Enter a column width between {min} and {max}', { min: COLUMN_WIDTH_MIN, max: COLUMN_WIDTH_MAX })">
4343
</div>
4444

4545
<!-- add to views -->
@@ -77,6 +77,7 @@ import { NcCheckboxRadioSwitch, NcSelect } from '@nextcloud/vue'
7777
import { mapState } from 'pinia'
7878
import { translate as t } from '@nextcloud/l10n'
7979
import { useTablesStore } from '../../../../../../store/store.js'
80+
import { COLUMN_WIDTH_MAX, COLUMN_WIDTH_MIN } from '../../../../../constants.js'
8081
8182
export default {
8283
name: 'MainForm',
@@ -105,6 +106,10 @@ export default {
105106
type: Boolean,
106107
default: false,
107108
},
109+
widthInvalidError: {
110+
type: Boolean,
111+
default: false,
112+
},
108113
editColumn: {
109114
type: Boolean,
110115
default: false,
@@ -116,6 +121,12 @@ export default {
116121
},
117122
},
118123
},
124+
data() {
125+
return {
126+
COLUMN_WIDTH_MIN,
127+
COLUMN_WIDTH_MAX,
128+
}
129+
},
119130
computed: {
120131
...mapState(useTablesStore, ['views', 'activeElement', 'isView']),
121132
localTitle: {
@@ -163,3 +174,13 @@ export default {
163174
},
164175
}
165176
</script>
177+
178+
<style lang="scss" scoped>
179+
.error {
180+
color: var(--color-error);
181+
}
182+
183+
.error input {
184+
border-color: var(--color-error);
185+
}
186+
</style>

src/shared/constants.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,6 @@ export const USERGROUP_TYPE = {
4848
GROUP: 1,
4949
CIRCLE: 2,
5050
}
51+
52+
export const COLUMN_WIDTH_MIN = 50
53+
export const COLUMN_WIDTH_MAX = 1000

0 commit comments

Comments
 (0)