Skip to content

Commit ec29c70

Browse files
committed
feat(dltfilterassistant): show name like dlt-logs
Show the name for a filter like the dlt-logs extension. Don't mark enabled event filters as they are time-sync ones.
1 parent 669126e commit ec29c70

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed

src/webview/src/components/dltFilterAssistant.js

+51-12
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ import { AttributesContext } from './../App';
1919
import { triggerRestQueryDetails, objectShallowEq } from './../util';
2020

2121
/* todos
22+
- add manual trigger button for preview (or find better way to avoid reports constantly popping up)
23+
- cache apply query rests (e.g. only on button press)
24+
- add way for reports to contain multiple filter
25+
- add hover/tooltip for filters showing the full object (e.g. tmpFb...)
2226
- add manual filter entry
2327
- finish support apply mode
24-
- cache apply query rests (e.g. only on button press)
2528
- disallow esc to close?
29+
- add icons for report,... similar to tree-view in dlt-logs
2630
*/
2731

2832
const useStyles = makeStyles(theme => ({
@@ -49,20 +53,55 @@ function intersection(a, b) {
4953
return a.filter((value) => b.indexOf(value) !== -1);
5054
}
5155

52-
function filterFromObj(obj, applyMode) {
56+
export const MSTP_strs = ["log", "app_trace", "nw_trace", "control", "", "", "", ""];
57+
export const MTIN_LOG_strs = ["", "fatal", "error", "warn", "info", "debug", "verbose", "", "", "", "", "", "", "", "", ""];
5358

54-
const typePrefix = (type) => {
55-
switch (type) {
56-
case 0: return '+';
57-
case 1: return '-';
58-
case 2: return '*';
59-
case 3: return '@';
60-
default: return `unknown(${type})`;
61-
}
59+
/**
60+
* return a name similar as in DltFilter.ts from mbehr1/dlt-logs
61+
* @param {Object} filter
62+
*/
63+
function nameForFilterObj(filter) {
64+
65+
let enabled = '';
66+
if (filter.name) {
67+
enabled += filter.name + ' ';
6268
}
69+
let type;
70+
switch (filter.type) {
71+
case 0 /* DltFilterType.POSITIVE*/: type = "+"; break;
72+
case 1 /* DltFilterType.NEGATIVE*/: type = "-"; break;
73+
case 2 /* DltFilterType.MARKER*/: type = "*"; break;
74+
case 3 /* DltFilterType.EVENT*/: type = "@"; break;
75+
default: type = `unknown(${filter.type})`; break;
76+
};
77+
if (filter.negateMatch) {
78+
type += '!';
79+
}
80+
let nameStr = "";
81+
if (filter.mstp !== undefined) {
82+
nameStr += MSTP_strs[filter.mstp];
83+
nameStr += ' ';
84+
}
85+
if (filter.logLevelMin) { // we ignore 0 values here
86+
nameStr += `>=${MTIN_LOG_strs[filter.logLevelMin]} `;
87+
}
88+
if (filter.logLevelMax) { // we ignore 0 value here
89+
nameStr += `<=${MTIN_LOG_strs[filter.logLevelMax]} `;
90+
}
91+
if (filter.ecu) { nameStr += `ECU:${filter.ecu} `; } // we ignore empty strings
92+
if (filter.apid) { nameStr += `APID:${filter.apid} `; }
93+
if (filter.ctid) { nameStr += `CTID:${filter.ctid} `; }
94+
if (filter.payload) { nameStr += `payload contains '${filter.payload}' `; }
95+
if (filter.payloadRegex !== undefined) { nameStr += `payload matches '${filter.payloadRegex}'`; }
96+
if (filter.lifecycles !== undefined) { nameStr += ` in ${filter.lifecycles.length} LCs`; }
97+
98+
return `${enabled}${type}${nameStr}`;
99+
}
100+
101+
function filterFromObj(obj, applyMode) {
63102

64103
return {
65-
name: `${typePrefix(obj.type)}${obj?.name?.length > 0 ? obj.name : JSON.stringify({ ...obj, type: undefined, tmpFb: undefined })}`,
104+
name: nameForFilterObj(obj), // `${typePrefix(obj.type)}${obj?.name?.length > 0 ? obj.name : JSON.stringify({ ...obj, type: undefined, tmpFb: undefined })}`,
66105
value: applyMode ?
67106
(obj.type !== 3 ? `add=${JSON.stringify({ ...obj, tmpFb: 1 })}` : `report=[${JSON.stringify({ ...obj, tmpFb: 1 })}]`) :
68107
JSON.stringify(obj) // todo for report multiple ones should be put into the same report -> same array. refactor logic!
@@ -185,7 +224,7 @@ export default function DLTFilterAssistantDialog(props) {
185224
const attr = filter.attributes;
186225
if (attr.type === 0 || attr.type === 1 || attr.type === 2 || attr.type === 3) { // only pos,neg, marker and event filters
187226
if (!(attr?.atLoadTime)) { // ignore load time ones
188-
const enabled = attr?.enabled ? true : false;
227+
const enabled = attr?.enabled ? (attr.type !== 3 /* event filters should not be enabled */ ? true : false) : false;
189228
const newAttrs = { ...attr, configs: undefined, id: undefined, enabled: undefined }
190229
const newFilter = filterFromObj(newAttrs, props.applyMode);
191230
// does it exist already?

0 commit comments

Comments
 (0)