Skip to content

Commit fa5e9cf

Browse files
authored
Merge pull request #2740 from devvaansh/WEB-368-the-ui-must-not-offer-to-edit-or-delete-the-relationship-column-of-a-custom-data-table
WEB-368 The UI must not offer to edit or delete the relationship column of a (custom) Data Table
2 parents 0fdf1fd + fd53a91 commit fa5e9cf

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

src/app/system/manage-data-tables/edit-data-table/edit-data-table.component.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,48 @@ export class EditDataTableComponent implements OnInit {
154154
) {
155155
this.route.data.subscribe((data: { dataTable: any; columnCodes: any }) => {
156156
this.dataTableData = data.dataTable;
157+
158+
// Get the relationship column name based on application table
159+
const relationshipColumnName = this.getRelationshipColumnName(this.dataTableData.applicationTableName);
160+
157161
this.dataTableData.columnHeaderData.forEach((item: any) => {
162+
// Mark system columns (id, created_at, updated_at) and relationship column as system
158163
item.system = [
159-
'created_at',
160-
'updated_at'
161-
].includes(item.columnName);
164+
'id',
165+
'created_at',
166+
'updated_at'
167+
].includes(item.columnName) || item.columnName === relationshipColumnName;
162168
});
163169
this.columnData = this.dataTableData.columnHeaderData;
164170
this.dataForDialog.columnCodes = data.columnCodes;
165171
});
166172
}
167173

168174
/**
169-
* Creates and sets data table form and columns table.
175+
* Gets the relationship column name.
176+
* @param {string} appTableName Application table name.
177+
* @returns {string} Relationship column name.
178+
*/
179+
getRelationshipColumnName(appTableName: string): string {
180+
// Map application table names to their relationship column names
181+
const tableToColumnMap: { [key: string]: string } = {
182+
m_client: 'client_id',
183+
m_group: 'group_id',
184+
m_center: 'center_id',
185+
m_office: 'office_id',
186+
m_loan: 'loan_id',
187+
m_savings_account: 'savings_account_id',
188+
m_savings_account_transaction: 'savings_transaction_id',
189+
m_product_loan: 'product_loan_id',
190+
m_savings_product: 'savings_product_id',
191+
m_share_product: 'share_product_id'
192+
};
193+
194+
return tableToColumnMap[appTableName] || '';
195+
}
196+
197+
/**
198+
* Create and set data table form and columns table.
170199
*/
171200
ngOnInit() {
172201
this.initData();
@@ -190,7 +219,12 @@ export class EditDataTableComponent implements OnInit {
190219
* Initializes data table changes and column data.
191220
*/
192221
initData() {
193-
this.columnData.shift();
222+
// Remove the 'id' column if it exists (primary key for multi-row datatables)
223+
// but keep the relationship column visible (it's already marked as system)
224+
if (this.columnData.length > 0 && this.columnData[0].columnName === 'id') {
225+
this.columnData.shift();
226+
}
227+
194228
this.dataTableChangesData.apptableName = this.dataTableData.applicationTableName;
195229
this.dataTableChangesData.entitySubType = this.dataTableData.entitySubType;
196230
for (let index = 0; index < this.columnData.length; index++) {

0 commit comments

Comments
 (0)