Skip to content

Commit

Permalink
feat(dltfilterassistant): show name like dlt-logs
Browse files Browse the repository at this point in the history
Show the name for a filter like the dlt-logs extension.
Don't mark enabled event filters as they are time-sync ones.
  • Loading branch information
mbehr1 committed Jan 1, 2021
1 parent 669126e commit ec29c70
Showing 1 changed file with 51 additions and 12 deletions.
63 changes: 51 additions & 12 deletions src/webview/src/components/dltFilterAssistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ import { AttributesContext } from './../App';
import { triggerRestQueryDetails, objectShallowEq } from './../util';

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

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

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

const typePrefix = (type) => {
switch (type) {
case 0: return '+';
case 1: return '-';
case 2: return '*';
case 3: return '@';
default: return `unknown(${type})`;
}
/**
* return a name similar as in DltFilter.ts from mbehr1/dlt-logs
* @param {Object} filter
*/
function nameForFilterObj(filter) {

let enabled = '';
if (filter.name) {
enabled += filter.name + ' ';
}
let type;
switch (filter.type) {
case 0 /* DltFilterType.POSITIVE*/: type = "+"; break;
case 1 /* DltFilterType.NEGATIVE*/: type = "-"; break;
case 2 /* DltFilterType.MARKER*/: type = "*"; break;
case 3 /* DltFilterType.EVENT*/: type = "@"; break;
default: type = `unknown(${filter.type})`; break;
};
if (filter.negateMatch) {
type += '!';
}
let nameStr = "";
if (filter.mstp !== undefined) {
nameStr += MSTP_strs[filter.mstp];
nameStr += ' ';
}
if (filter.logLevelMin) { // we ignore 0 values here
nameStr += `>=${MTIN_LOG_strs[filter.logLevelMin]} `;
}
if (filter.logLevelMax) { // we ignore 0 value here
nameStr += `<=${MTIN_LOG_strs[filter.logLevelMax]} `;
}
if (filter.ecu) { nameStr += `ECU:${filter.ecu} `; } // we ignore empty strings
if (filter.apid) { nameStr += `APID:${filter.apid} `; }
if (filter.ctid) { nameStr += `CTID:${filter.ctid} `; }
if (filter.payload) { nameStr += `payload contains '${filter.payload}' `; }
if (filter.payloadRegex !== undefined) { nameStr += `payload matches '${filter.payloadRegex}'`; }
if (filter.lifecycles !== undefined) { nameStr += ` in ${filter.lifecycles.length} LCs`; }

return `${enabled}${type}${nameStr}`;
}

function filterFromObj(obj, applyMode) {

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

0 comments on commit ec29c70

Please sign in to comment.