Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ <h2 class="mat-heading-2 settings-fields__heading">General settings</h2>
</mat-slide-toggle>

<h2 class="mat-heading-2 settings-fields__heading">Table view</h2>
<!--<mat-form-field appearance="outline">
<mat-form-field appearance="outline">
<mat-label>Columns visible by default</mat-label>
<mat-select multiple
name="columns_view"
[(ngModel)]="tableSettings.columns_view">
<mat-option *ngFor="let field of fields" [value]="field">{{field}}</mat-option>
</mat-select>
<mat-hint>Choose the columns you want users to see when they first open this table. Changes made to a table's Columns view are saved over the default values.</mat-hint>
</mat-form-field>-->
</mat-form-field>

<!--<div class="order-settings">
<div class="order-settings">
<div class="order-settings__panel">
<span class="order__title">
Columns order
Expand Down Expand Up @@ -103,7 +103,7 @@ <h2 class="mat-heading-2 settings-fields__heading">Table view</h2>
(click)="resetColumnsOrder()">
<mat-icon>restart_alt</mat-icon>
</button>
</div>-->
</div>

<mat-form-field appearance="outline">
<mat-label>Searchable columns</mat-label>
Expand All @@ -115,7 +115,7 @@ <h2 class="mat-heading-2 settings-fields__heading">Table view</h2>
<mat-hint>Choose the columns Rocketadmin scans when using the Search bar.</mat-hint>
</mat-form-field>

<!--<div class="form-group-ordering">
<div class="form-group-ordering">
<mat-form-field appearance="outline" class="form-group-ordering__ordering-by">
<mat-label>Order by</mat-label>
<mat-select name="ordering_field" [(ngModel)]="tableSettings.ordering_field">
Expand All @@ -132,7 +132,7 @@ <h2 class="mat-heading-2 settings-fields__heading">Table view</h2>
<mat-radio-button value="ASC" checked>Ascending</mat-radio-button>
<mat-radio-button value="DESC">Descending</mat-radio-button>
</mat-radio-group>
</div>-->
</div>

<mat-form-field appearance="outline">
<mat-label>Sortable columns</mat-label>
Expand Down Expand Up @@ -189,7 +189,7 @@ <h2 class="mat-heading-2" style="margin-bottom: -4px; margin-top: 12px">"Edit ro
<button mat-flat-button color="primary"
type="submit"
class="settings-form__save-button"
[disabled]="(submitting || tableSettingsForm.form.invalid || tableSettingsForm.form.pristine) && !iconChanged">
[disabled]="(submitting || tableSettingsForm.form.invalid || tableSettingsForm.form.pristine) && !orderChanged && !iconChanged">
Save
</button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ describe('DbTableSettingsComponent', () => {
icon: '',
search_fields: [],
excluded_fields: [],
list_fields: [],
ordering: TableOrdering.Ascending,
ordering_field: "",
columns_view: [],
// identification_fields: [],
// list_per_page: null,
identity_column: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Component, OnInit } from '@angular/core';
import { TableField, TableSettings } from 'src/app/models/table';
import { TableField, TableOrdering, TableSettings } from 'src/app/models/table';

import { AlertComponent } from '../../../ui-components/alert/alert.component';
import { Angulartics2 } from 'angulartics2';
import { BreadcrumbsComponent } from '../../../ui-components/breadcrumbs/breadcrumbs.component';
import { CommonModule } from '@angular/common';
import { CompanyService } from 'src/app/services/company.service';
import { ConnectionsService } from 'src/app/services/connections.service';
import { DragDropModule } from '@angular/cdk/drag-drop';
import { CdkDragDrop, DragDropModule, moveItemInArray } from '@angular/cdk/drag-drop';
import { FormsModule } from '@angular/forms';
import { IconPickerComponent } from '../../../ui-components/icon-picker/icon-picker.component';
import { Location } from '@angular/common';
Expand Down Expand Up @@ -60,14 +60,20 @@ export class DbTableSettingsComponent implements OnInit {
public loading: boolean = true;
public fields: string[];
public fields_to_exclude: string[];
public orderChanged: boolean = false;
public iconChanged: boolean = false;
public listFieldsOrder: string[];
public tableSettingsInitial: TableSettings = {
connection_id: '',
table_name: '',
icon: '',
display_name: '',
autocomplete_columns: [],
identity_column: '',
ordering: TableOrdering.Ascending,
ordering_field: '',
list_fields: [],
columns_view: [],
search_fields: [],
excluded_fields: [],
readonly_fields: [],
Expand Down Expand Up @@ -137,9 +143,13 @@ export class DbTableSettingsComponent implements OnInit {
if (Object.keys(res).length !== 0) {
this.isSettingsExist = true
this.tableSettings = res;
this.listFieldsOrder = [...res.list_fields];
} else {
this.tableSettings = this.tableSettingsInitial;
};
if (Object.keys(res).length === 0 || (res && res.list_fields && !res.list_fields.length)) {
Comment on lines +146 to +150

Copilot AI Jan 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initialization of listFieldsOrder at line 146 will fail when res.list_fields is undefined or null, as spreading undefined/null will throw a runtime error. The check at line 150 only handles empty arrays, not the case where list_fields doesn't exist on the response object. This can occur when table settings exist but don't have list_fields populated, which would cause a crash when trying to spread the undefined value.

Suggested change
this.listFieldsOrder = [...res.list_fields];
} else {
this.tableSettings = this.tableSettingsInitial;
};
if (Object.keys(res).length === 0 || (res && res.list_fields && !res.list_fields.length)) {
this.listFieldsOrder = Array.isArray(res.list_fields) ? [...res.list_fields] : [];
} else {
this.tableSettings = this.tableSettingsInitial;
};
if (Object.keys(res).length === 0 || !res.list_fields || !res.list_fields.length) {

Copilot uses AI. Check for mistakes.
this.listFieldsOrder = [...this.fields];
};
this.title.setTitle(`${res.display_name || this.displayTableName} - Table settings | ${this._company.companyTabTitle || 'Rocketadmin'}`);
}
);
Expand All @@ -150,6 +160,18 @@ export class DbTableSettingsComponent implements OnInit {
this.iconChanged = true;
}

drop(event: CdkDragDrop<string[]>) {
moveItemInArray(this.listFieldsOrder, event.previousIndex, event.currentIndex);
this.tableSettings.list_fields = [...this.listFieldsOrder];
this.orderChanged = true;
}

resetColumnsOrder() {
this.tableSettings.list_fields = [];
this.listFieldsOrder = [...this.fields];
this.orderChanged = true;
}

updateSettings() {
this.submitting = true;
this.tableSettings.connection_id = this.connectionID;
Expand All @@ -160,7 +182,11 @@ export class DbTableSettingsComponent implements OnInit {
for (const [key, value] of Object.entries(this.tableSettings)) {
if (key !== 'connection_id' && key !== 'table_name' && key !== 'ordering') {
if (Array.isArray(value)) {
updatedSettings[key] = value.length > 0
if (key === 'list_fields') {
updatedSettings[key] = this.orderChanged;
} else {
updatedSettings[key] = value.length > 0;
}
Comment on lines +185 to +189

Copilot AI Jan 21, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The analytics tracking for list_fields is inconsistent with other array fields. While other array fields like search_fields and excluded_fields track whether they have values (value.length > 0), list_fields tracks the orderChanged flag. This inconsistency means that for analytics purposes, if list_fields has values but wasn't changed in this session, it would be tracked as false, while an empty search_fields array would also be tracked as false. This makes it difficult to interpret the analytics data consistently.

Copilot uses AI. Check for mistakes.
} else {
updatedSettings[key] = Boolean(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ export class TablesDataSource implements DataSource<Object> {
normalizedTitle: this.widgets[item.column_name]?.name || normalizeFieldName(item.column_name),
selected: res.table_settings.columns_view.includes(item.column_name)
}
} else if (res.columns_view && res.columns_view.length !== 0) {
return {
title: item.column_name,
normalizedTitle: this.widgets[item.column_name]?.name || normalizeFieldName(item.column_name),
selected: res.columns_view.includes(item.column_name)
}
} else {
if (index < 6) {
return {
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/models/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export interface TableSettings {
display_name: string,
autocomplete_columns: string[],
identity_column: string,
ordering: TableOrdering,
ordering_field: string,
list_fields: string[],
columns_view: string[],
search_fields: string[],
excluded_fields: string[],
readonly_fields: string[],
Expand Down
Loading