Skip to content

Commit ac1036d

Browse files
committed
Refactor: Extract table cell component for better reusability (get value)
Signed-off-by: Kostiantyn Miakshyn <molodchick@gmail.com>
1 parent ee620a4 commit ac1036d

3 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/modules/main/partials/ColumnFormComponent.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,7 @@ export default {
7575
},
7676
methods: {
7777
getValueForColumn() {
78-
if (this.column.type === 'relation_lookup' && this.column.customSettings?.relationColumnId) {
79-
return this.value?.[this.column.customSettings.relationColumnId] ?? null
80-
}
81-
return this.value
78+
return this.column.getValueForForm(this.value)
8279
},
8380
snakeToCamel(str) {
8481
str = str.toLowerCase().replace(/([-_][a-z])/g, group =>

src/shared/components/ncTable/mixins/columnClass.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ export class AbstractColumn {
9191
return this.id
9292
}
9393

94+
/**
95+
* Get the value for form input.
96+
* Default implementation returns the value as-is.
97+
*
98+
* @param {*} value The raw value
99+
* @return {*} The value for form input
100+
*/
101+
getValueForForm(value) {
102+
return value
103+
}
104+
94105
}
95106

96107
export class AbstractUsergroupColumn extends AbstractColumn {

src/shared/components/ncTable/mixins/columnsTypes/relationLookup.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ export default class RelationLookupColumn extends AbstractColumn {
4545
return this.customSettings.relationColumnId
4646
}
4747

48+
/**
49+
* Get the value for form input.
50+
* For relation lookup, extracts the value from the relation column id.
51+
*
52+
* @param {*} value The raw value
53+
* @return {*} The value for form input
54+
*/
55+
getValueForForm(value) {
56+
if (this.customSettings?.relationColumnId) {
57+
return value?.[this.customSettings.relationColumnId] ?? null
58+
}
59+
return value
60+
}
61+
4862
getValueString(valueObject) {
4963
valueObject = valueObject || this.value || null
5064
if (!valueObject || valueObject.value === null || valueObject.value === undefined) {

0 commit comments

Comments
 (0)