Regular filters instead of experimental combobox, sort by timestamp

This commit is contained in:
Erki Aas 2022-10-11 03:20:12 +03:00
parent c9cf7ae603
commit d4052f03a1
1 changed files with 6 additions and 58 deletions

View File

@ -20,20 +20,6 @@ import { AgGridVue } from "ag-grid-vue3";
import "ag-grid-community/styles//ag-grid.css"; import "ag-grid-community/styles//ag-grid.css";
import "ag-grid-community/styles//ag-theme-alpine.css"; import "ag-grid-community/styles//ag-theme-alpine.css";
import ScreenshotCell from "./ScreenshotCell.js"; import ScreenshotCell from "./ScreenshotCell.js";
import ComboboxFilter from './ComboboxFilter.js';
const comboBoxDefinition = () => {
return {
filter: true,
floatingFilter: true,
suppressMenu: true,
floatingFilterComponent: 'ComboboxFilter',
floatingFilterComponentParams: {
suppressFilterButton: true,
options: []
},
}
};
export default { export default {
components: { components: {
@ -62,15 +48,17 @@ export default {
{ {
field: 'kubernetes.namespace', field: 'kubernetes.namespace',
headerName: 'namespace', headerName: 'namespace',
...comboBoxDefinition(), filter: true,
}, },
{ {
field: 'kubernetes.pod.name', field: 'kubernetes.pod.name',
headerName: 'pod', headerName: 'pod',
filter: true,
}, },
{ {
field: 'kubernetes.container.name', field: 'kubernetes.container.name',
headerName: 'container', headerName: 'container',
filter: true,
}, },
{ {
field: 'message', field: 'message',
@ -82,7 +70,8 @@ export default {
}, },
{ {
field: '@timestamp', field: '@timestamp',
width: 70 width: 70,
sortable: true
} }
], ],
} }
@ -90,23 +79,6 @@ export default {
created() { created() {
this.setupStream() this.setupStream()
}, },
watch: {
comboBoxOptions: {
handler(newValue, oldValue) {
const clonedDefs = [ ...this.columnDefs ];
clonedDefs.map((def) => {
if ((def.floatingFilterComponent || null) === 'ComboboxFilter' ) {
def.floatingFilterComponentParams = {
suppressFilterButton: true,
options: Object.values(newValue[def.field])
}
return def
}
})
this.columnDefs = clonedDefs
}
}
},
methods: { methods: {
setupStream() { setupStream() {
let es = new EventSource('/events'); let es = new EventSource('/events');
@ -115,16 +87,11 @@ export default {
onGridReady(params) { onGridReady(params) {
this.gridApi = params.api; this.gridApi = params.api;
this.gridColumnApi = params.columnApi; this.gridColumnApi = params.columnApi;
const timer = setInterval(() => {
this.getComboBoxOptions();
}, 3000);
}, },
handleReceiveMessage (event) { handleReceiveMessage (event) {
const eventData = this.parseEventData(event.data); const eventData = this.parseEventData(event.data);
this.rowData.push(eventData) this.gridApi.updateRowData({add: [eventData]});
this.gridApi.setRowData(this.rowData)
this.gridApi.sizeColumnsToFit() this.gridApi.sizeColumnsToFit()
this.getComboBoxOptions()
}, },
refreshRowData () { refreshRowData () {
const itemsToUpdate = []; const itemsToUpdate = [];
@ -147,25 +114,6 @@ export default {
console.error(e, eventData) console.error(e, eventData)
} }
}, },
getComboBoxOptions () {
const opts = {}
this.columnDefs.map((def) => {
if ((def.floatingFilterComponent || null) === 'ComboboxFilter' ) {
const field = def.field
const unique = {};
this.rowData.map((row) => {
const value = field.split('.').reduce((a, b) => a[b], row);
unique[value] = 1;
})
const uniqueArray = [];
for (const n in unique) uniqueArray.push(n);
opts[field] = uniqueArray
}
})
if (JSON.stringify(this.comboBoxOptions) !== JSON.stringify(opts)) {
this.comboBoxOptions = opts
}
}
} }
} }