Skip to content

Commit 0503826

Browse files
Merge pull request #1316 from rocket-admin/fixes-saved-filters
Fixes saved filters and widgets
2 parents ed3c075 + 5a6abe9 commit 0503826

4 files changed

Lines changed: 20 additions & 52 deletions

File tree

frontend/src/app/components/dashboard/db-table-view/db-table-widgets/db-table-widgets.component.spec.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ describe('DbTableWidgetsComponent', () => {
158158
},
159159
{
160160
field_name: '',
161-
widget_type: '',
162-
widget_params: '',
161+
widget_type: 'Default',
162+
widget_params: '// No settings required',
163163
name: '',
164164
description: ''
165165
}
@@ -173,44 +173,6 @@ describe('DbTableWidgetsComponent', () => {
173173
expect(component.fields).toEqual(['user_id', 'last_name', 'email']);
174174
});
175175

176-
it('should set empty string in widget_type if widget does not need another appearance', () => {
177-
component.widgets = [
178-
{
179-
field_name: 'user_id',
180-
widget_type: 'textarea',
181-
widget_params: '',
182-
name: '',
183-
description: ''
184-
},
185-
{
186-
field_name: 'user_name',
187-
widget_type: 'Default',
188-
widget_params: '// No settings required',
189-
name: 'name',
190-
description: ''
191-
}
192-
];
193-
194-
component.widgetTypeChange('user_name');
195-
196-
expect(component.widgets).toEqual([
197-
{
198-
field_name: 'user_id',
199-
widget_type: 'textarea',
200-
widget_params: '',
201-
name: '',
202-
description: ''
203-
},
204-
{
205-
field_name: 'user_name',
206-
widget_type: '',
207-
widget_params: '// No settings required',
208-
name: 'name',
209-
description: ''
210-
}
211-
])
212-
});
213-
214176
xit('should open dialog to confirm deletion of widget', () => {
215177
component.fields = ['user_age'];
216178
component.widgets = [

frontend/src/app/components/dashboard/db-table-view/db-table-widgets/db-table-widgets.component.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,8 @@ export class DbTableWidgetsComponent implements OnInit {
306306
addNewWidget() {
307307
this.widgets.push({
308308
field_name: '',
309-
widget_type: '',
310-
widget_params: '',
309+
widget_type: 'Default',
310+
widget_params: '// No settings required',
311311
name: '',
312312
description: ''
313313
});
@@ -319,8 +319,6 @@ export class DbTableWidgetsComponent implements OnInit {
319319

320320
widgetTypeChange(fieldName) {
321321
let currentWidget = this.widgets.find(widget => widget.field_name === fieldName);
322-
323-
if (currentWidget.widget_type === 'Default') currentWidget.widget_type = '';
324322
currentWidget.widget_params = this.defaultParams[currentWidget.widget_type || 'Default'];
325323

326324
this.widgetParamsChange({fieldName: currentWidget.field_name, value: currentWidget.widget_params});
@@ -373,12 +371,20 @@ export class DbTableWidgetsComponent implements OnInit {
373371
.subscribe(res => {
374372
const currentWidgetTypes = res.map((widget: Widget) => widget.field_name);
375373
this.fields = difference(this.fields, currentWidgetTypes);
374+
res.forEach((widget: Widget) => {
375+
if (widget.widget_type === '') widget.widget_type = 'Default';
376+
})
376377
this.widgets = res;
377378
});
378379
}
379380

380381
updateWidgets(afterDeleteAll?: boolean) {
381382
this.submitting = true;
383+
384+
this.widgets.forEach(widget => {
385+
if (widget.widget_type === 'Default') widget.widget_type = '';
386+
});
387+
382388
this._tables.updateTableWidgets(this.connectionID, this.tableName, this.widgets)
383389
.subscribe(() => {
384390
this.submitting = false;

frontend/src/app/components/dashboard/db-table-view/saved-filters-panel/saved-filters-dialog/saved-filters-dialog.component.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<form #tableFiltersForm="ngForm" (ngSubmit)="handleSaveFilters()" class="filters-form">
22
<h1 mat-dialog-title class="filters-header">
3-
<span>New Fast Filter for <strong>{{ data.displayTableName }}</strong></span>
3+
<span>New fast filter for <strong>{{ data.displayTableName }}</strong></span>
44
</h1>
55
<app-content-loader *ngIf="!fields || !tableTypes; else filterControls"></app-content-loader>
66
<ng-template #filterControls>
77
<mat-dialog-content class="filters-content">
88
<!-- Filter Name and Description Fields -->
99
<mat-form-field appearance="outline" class="full-width">
10-
<mat-label>Fast Filter name</mat-label>
10+
<mat-label>Fast filter name</mat-label>
1111
<input matInput required
1212
name="filters_set_name"
1313
[(ngModel)]="data.filtersSet.name">
@@ -16,9 +16,9 @@ <h1 mat-dialog-title class="filters-header">
1616
</mat-error>
1717
</mat-form-field>
1818

19-
<h3 class="section-title">Conditions & Main column</h3>
19+
<h3 class="section-title">Conditions & main column</h3>
2020
<p class="section-description">
21-
Select which conditions to add and choose a Main column. Main columns remain editable, while conditions are set.
21+
Select which conditions to add and choose a main column. Main columns remain editable, while conditions are set.
2222
</p>
2323

2424
<!-- Filter Selection -->
@@ -165,7 +165,7 @@ <h3 class="section-title">Conditions & Main column</h3>
165165
Cancel
166166
</button>
167167
<button mat-flat-button color="primary" type="submit">
168-
Save Filter
168+
Save filter
169169
</button>
170170
</mat-dialog-actions>
171171
</form>

frontend/src/app/components/dashboard/db-table-view/saved-filters-panel/saved-filters-panel.component.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
angularticsAction="Saved filters: first time setup is clicked"
99
(click)="handleOpenSavedFiltersDialog()">
1010
<mat-icon>tune</mat-icon>
11-
Create Fast Filter
11+
Create fast filter
1212
</button>
1313

1414
<button *ngIf="accessLevel === 'edit' && savedFilterData.length !== 0"
1515
mat-icon-button type="button"
16-
matTooltip="Set up, edit, or remove Fast Filters"
16+
matTooltip="Set up, edit, or remove fast filters"
1717
[matMenuTriggerFor]="menu"
1818
angulartics2On="click"
1919
angularticsAction="Saved filters: open menu is clicked">
@@ -22,7 +22,7 @@
2222
<mat-menu #menu="matMenu">
2323
<button mat-menu-item (click)="handleOpenSavedFiltersDialog()">
2424
<mat-icon>add</mat-icon>
25-
New Fast Filter
25+
New fast filter
2626
</button>
2727
<button mat-menu-item
2828
*ngFor="let filter of savedFilterData"

0 commit comments

Comments
 (0)