Skip to content

Commit

Permalink
Merge pull request #458 from openziti/457-table-resize
Browse files Browse the repository at this point in the history
Resize data table columns when parent container is resized
  • Loading branch information
rgallettonf authored Aug 12, 2024
2 parents 75f161f + 244df9a commit 442e4b8
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 24 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "io.netfoundry.zac",
"version": "3.4.5",
"version": "3.4.6",
"description": "Ziti Administration Console",
"main": "server.js",
"type": "module",
Expand Down
2 changes: 1 addition & 1 deletion projects/ziti-console-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@openziti/ziti-console-lib",
"version": "0.4.5",
"version": "0.4.6",
"repository": {
"type": "git",
"url": "https://github.com/openziti/ziti-console"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ export class ConfigEditorComponent implements OnInit {
jsonDataChanged(event) {
defer(() => {
this.configDataChange.emit(this.configData);
this.updateFormView(this.items, this.configData);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="data-table-container" *ngIf="isLoading || filterApplied || rowData?.length > 0;else nodata">
<div #tableContainer class="data-table-container" *ngIf="showTable;else nodata">
<lib-table-filter-bar
[startCount]="startCount"
[endCount]="endCount"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@
limitations under the License.
*/

import {Component, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild} from '@angular/core';
import {
AfterViewInit,
Component,
ElementRef,
EventEmitter,
Input,
OnChanges,
OnInit,
Output,
ViewChild
} from '@angular/core';

// Import the resized event model
import $ from 'jquery';
Expand Down Expand Up @@ -100,6 +110,7 @@ export class DataTableComponent implements OnChanges, OnInit {
menuLeft;
menuTop;
gridRendered;
resizeHandlerInit = false;
resizeGridColumnsDebounced;
selectedItem: any = {
actionList: [],
Expand Down Expand Up @@ -193,6 +204,7 @@ export class DataTableComponent implements OnChanges, OnInit {

@ViewChild('calendar', { static: false }) calendar: any;
@ViewChild('contextMenu') contextMenu;
@ViewChild('tableContainer') tableContainer: ElementRef;

constructor(public svc: DataTableService, private tableFilterService: DataTableFilterService) {
this.resizeGridColumnsDebounced = _.debounce(this.svc.resizeGridColumns.bind(this.svc), 20, {leading: true});
Expand Down Expand Up @@ -222,6 +234,14 @@ export class DataTableComponent implements OnChanges, OnInit {
});
}

get showTable() {
const _showTable = this.isLoading || this.filterApplied || this.rowData?.length > 0;
if (_showTable && !this.resizeHandlerInit) {
this._initGridResizeHandler();
}
return _showTable;
}

ngOnInit() {
this.frameworkComponents = {
cellSelectComponent: TableCellSelectComponent,
Expand Down Expand Up @@ -471,6 +491,17 @@ export class DataTableComponent implements OnChanges, OnInit {
return this.allowDownload && this._view !== 'process';
}

_initGridResizeHandler() {
if (!this.tableContainer) {
return;
}
const observer = new ResizeObserver(entries => {
this.resizeGridColumnsDebounced();
});
observer.observe(this.tableContainer.nativeElement);
this.resizeHandlerInit = true;
}

_initGridOptions() {
this.gridOptions = {
pagination: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,28 @@ export class DataTableService {
localStorage.setItem(`ziti_${this.tableId}_table_state`, tableStateCookie);
}

onColumnsResized(tableId, gridObj, column) {
this.saveColumnWidths(tableId, gridObj, column);
onColumnsResized(column) {
this.saveColumnWidths(column);
}
private saveColumnWidths(tableId, gridObj, column) {
private saveColumnWidths(column) {
if (!column) {
return;
}
const columnId = column.colId;
const columnWidth = column.actualWidth;
let colWidthsCookie = localStorage.getItem(`ziti_${tableId}_column_widths`);
let colWidthsCookie = localStorage.getItem(`ziti_${this.tableId}_column_widths`);
let colWidths: any = {};
if (!_.isEmpty(colWidthsCookie)) {
colWidths = JSON.parse(colWidthsCookie);
}
colWidths[columnId] = columnWidth;
colWidthsCookie = JSON.stringify(colWidths);
localStorage.setItem(`ziti_${tableId}_column_widths`, colWidthsCookie);
localStorage.setItem(`ziti_${this.tableId}_column_widths`, colWidthsCookie);

let tableStateCookie = localStorage.getItem(`ziti_${tableId}_table_state`);
let tableStateCookie = localStorage.getItem(`ziti_${this.tableId}_table_state`);
let tableState;
if (_.isEmpty(tableStateCookie)) {
tableState = gridObj.columnApi.getColumnState();
tableState = this.gridObj.columnApi.getColumnState();
} else {
tableState = JSON.parse(tableStateCookie);
}
Expand All @@ -70,8 +70,8 @@ export class DataTableService {
}
});
tableStateCookie = JSON.stringify(tableState);
localStorage.setItem(`ziti_${tableId}_table_state`, tableStateCookie);
_.forEach(gridObj.columnApi.columnModel.columnDefs, (colDef) => {
localStorage.setItem(`ziti_${this.tableId}_table_state`, tableStateCookie);
_.forEach(this.gridObj.columnApi.columnModel.columnDefs, (colDef) => {
if (colDef.colId === columnId) {
colDef.suppressSizeToFit = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export class JsonViewComponent implements AfterViewInit, OnChanges {
private schemaDefinitions: any;
oldData: any;
currentData: any;
editorInit = false;

constructor(private growlerService: GrowlerService) {
this.onChangeDebounced = _.debounce(this.onChange.bind(this), 400);
}
Expand All @@ -74,10 +76,13 @@ export class JsonViewComponent implements AfterViewInit, OnChanges {
}

initEditor() {
if (!this.editorDiv || !this.data || this.editorInit) {
return;
}
this.currentData = this.data;
this.content = {
text: undefined,
json: this.data
json: this.data || {}
};
this.editor = new JSONEditor({
target: this.editorDiv.nativeElement,
Expand Down Expand Up @@ -109,6 +114,7 @@ export class JsonViewComponent implements AfterViewInit, OnChanges {
}
}
});
this.editorInit = true;
}

updateEditor() {
Expand All @@ -117,7 +123,7 @@ export class JsonViewComponent implements AfterViewInit, OnChanges {
}
this.oldData = _.cloneDeep(this.data);
this.content = {
json: this.oldData
json: this.oldData || {}
};
this.editor.update(this.content);
}
Expand Down Expand Up @@ -181,6 +187,10 @@ export class JsonViewComponent implements AfterViewInit, OnChanges {
});
}
}
} else if (changes['data']) {
if (!this.editorInit) {
this.initEditor();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ export class ConfigurationFormComponent extends ProjectableForm implements OnIni
this.isLoading = false;
});
if (configId) {
this.closeModal(true, true);
if (this.isModal) {
this.closeModal(true, true);
} else {
this.returnToListPage();
}
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
[label]="'OPTIONAL'"
class="form-field-advanced"
>
<lib-json-view></lib-json-view>
<lib-json-view [(data)]="formData.appData"></lib-json-view>
</lib-form-field-container>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,6 @@
>
<lib-custom-tags [(tags)]="formData.tags"></lib-custom-tags>
</lib-form-field-container>
<lib-form-field-container
[title]="'App Data'"
[label]="'OPTIONAL'"
class="form-field-advanced"
>
<lib-json-view></lib-json-view>
</lib-form-field-container>
</div>
</div>
<div class="form-group-column two-fifths">
Expand Down
11 changes: 11 additions & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# app-ziti-console-v3.4.6
# ziti-console-lib-v0.4.6

## Bug Fixes
* [Issue #450](https://github.com/openziti/ziti-console/issues/450) - Hide the navigation bar when session expires and routing to login page
* [Issue #452](https://github.com/openziti/ziti-console/issues/452) - Correctly show associated entities when using the #all attribute
* [Issue #453](https://github.com/openziti/ziti-console/issues/453) - AppData is not persisting when adding via the JSON editor on edit forms
* [Issue #455](https://github.com/openziti/ziti-console/issues/455) - Prevent overflow of attribute items with long names in tag selector component
* [Issue #457](https://github.com/openziti/ziti-console/issues/457) - Table is not resized when browzer size changes

# app-ziti-console-v3.4.5
## Bug Fixes
* [Issue #444](https://github.com/openziti/ziti-console/issues/444) - BASE_HREF is wrongly quoted


Expand Down

0 comments on commit 442e4b8

Please sign in to comment.