constructor()

in src/panel/indexStore.ts [15:57]


    constructor(state: Record<string, Record<string, Record<string, Visibility>>>, defaultSelection?: boolean) {
        this.filtersRow = state.filtersRow;
        this.filtersColumn = state.filtersColumn;
        const setState = () => {
            const {filtersRow, filtersColumn} = this;
            const state = { filtersRow: toJS(filtersRow), filtersColumn: toJS(filtersColumn) };
            vscode.postMessage({ command: 'setState', state: JSON.stringify(state, null, '    ') });
            // PostMessage object key order unstable. Stringify is stable.
        };
        // Sadly unable to observe at the root.
        observe(this.filtersRow.Level, setState);
        observe(this.filtersRow.Baseline, setState);
        observe(this.filtersRow.Suppression, setState);
        observe(this.filtersColumn.Columns, setState);

        // `change` should be `IArrayWillSplice<Log>` but `intercept()` is not being inferred properly.
        // eslint-disable-next-line @typescript-eslint/no-explicit-any
        intercept(this.logs, (change: any) => {
            if (change.type !== 'splice') throw new Error(`Unexpected change type. ${change.type}`);
            change.added.forEach((log: Log) => augmentLog(log, this.driverlessRules));
            return change;
        });

        observe(this.logs, () => {
            if (this.logs.length) return;
            this.selection.set(undefined);
        });

        if (defaultSelection) {
            const store = this.resultTableStoreByLocation;
            when(() => !!store.rows.length, () => {
                const item = store.rows.find(row => row instanceof RowItem) as RowItem<Result>;
                this.selection.set(item);
            });
        }

        autorun(() => {
            const selectedRow = this.selection.get();
            const result = selectedRow instanceof RowItem && selectedRow.item;
            if (!result?._uri) return; // Bail on no result or location-less result.
            postSelectArtifact(result, result.locations?.[0]?.physicalLocation);
        });
    }