Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/flattened filters #1218

Merged
merged 12 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions webapp/src/app/core/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export class AuthService {
get redirectUrl(): string {
let redirectUrl = '';

redirectUrl = this.dataStore.getRedirectUrl() || redirectUrl;
redirectUrl = localStorage.getItem("redirectUrl");
return redirectUrl;
}

Expand Down Expand Up @@ -328,13 +328,13 @@ export class AuthService {

this.fetchRolePermissionMapping().subscribe(result => {
this.logger.log('info', '**Successfully set user role capabilities mapping Fetched information**');

observer.next('success');
observer.complete();
},
error => {
this.logger.log('info', '**Error in setting user role capabilities information**');
observer.error(error);
});
observer.next('success');
observer.complete();
} else {
const errorMessage = response.message || 'Error authenticating the id_token';
this.logger.log('error ', errorMessage);
Expand Down
3 changes: 3 additions & 0 deletions webapp/src/app/core/services/permission-guard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export class PermissionGuardService implements CanActivate {
this.router.navigate(['/home']);
return false;
}
const redirectUrl = location.origin + state.url;
if(!redirectUrl.includes("home"))
localStorage.setItem("redirectUrl",redirectUrl);
return true;
}

Expand Down
60 changes: 54 additions & 6 deletions webapp/src/app/core/services/table-state.service.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,76 @@
import { Injectable } from '@angular/core';
import { LoggerService } from 'src/app/shared/services/logger.service';

@Injectable()
export class TableStateService {
state: Object = {};
stateLabel = "allTableStates";

constructor(
private logger: LoggerService
){}

setState(componentKey, obj){
this.state[componentKey] = obj;
try{
const state = this.getStateFromLocalStorage();
state[componentKey] = obj;
localStorage.setItem(this.stateLabel, JSON.stringify(state));
}catch(e){
this.logger.log(componentKey, ": Error in saving state: "+e);
}
}

getState(componentKey){
return this.state?this.state[componentKey]:this.state;
let componentState:any = {};
try{
const state = this.getStateFromLocalStorage();
componentState = state[componentKey];
}catch(e){
this.logger.log(componentKey, ": Error in getting state: "+e);
}
return componentState;
}

getStateFromLocalStorage(){
const state = localStorage.getItem(this.stateLabel);
if(!(state && state!="undefined")){
localStorage.setItem("allTableStates", JSON.stringify({}));
return {};
}
return JSON.parse(state);
}

persistOnly(componentKey){
let componentState = this.getState(componentKey);
this.clearAll();
this.setState(componentState, componentKey);
this.setState(componentKey, componentState);
}

clearState(componentKey){
this.setState(componentKey, {});
try{
const componentState = this.getState(componentKey);
const keys = Object.keys(componentState);
const columnsListKey = keys.find(key => key.includes("whiteList"));
const filterListKey = keys.find(key => key.includes("filter"));
componentState[filterListKey]?.forEach(filter => {
filter.value = undefined;
filter.filterValue = undefined;
})
const newState = {};
newState[columnsListKey] = componentState[columnsListKey];
newState[filterListKey] = componentState[filterListKey];
this.setState(componentKey, newState);
}catch(e){
this.logger.log(componentKey, ": Error in clearing state: "+e);
}
}

clearAll(){
this.state = {};
const state = this.getStateFromLocalStorage();
if(state){
const storedStatesKeys = Object.keys(state);
storedStatesKeys.forEach(state => {
this.clearState(state);
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ <h6>{{pageTitle}}</h6>
[showSearchBar]="true" [showAddRemoveCol]="true" [showFilterBtn]="true" [onScrollDataLoader]="onScrollDataLoader" [totalRows]="totalRows"
[tableScrollTop]="tableScrollTop" [tableDataLoaded]="tableDataLoaded" [columnsSortFunctionMap]="columnsSortFunctionMap"
[rowClickable]="true" [doLocalFilter]="true" [doLocalSearch]="true"
[filterTypeLabels]="filterTypeLabels" [filterTagLabels]="filterTagLabels" [filteredArray]="filters">
[filterTypeLabels]="filterTypeLabels" [filterTagLabels]="filterTagLabels" [filteredArray]="filters"
(whitelistColumnsChanged)="handleWhitelistColumnsChange($event)"
(selectedFilter)="handleFilterSelection()"
(selectedFilterType)="handleFilterTypeSelection()"
(deleteFilters)="deleteFilters($event)"
[selectedRowIndex]="selectedRowIndex">
</app-table>
<div class="data-table-desc">{{dataTableDesc}}</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export class PoliciesComponent implements OnInit, OnDestroy {
pageNumber: number = 0;

searchTxt: String = "";
selectedRowIndex;
tableData: any = [];
tableDataLoaded: boolean = false;
filters: any = [];
Expand Down Expand Up @@ -172,8 +173,9 @@ export class PoliciesComponent implements OnInit, OnDestroy {
);
let state = this.tableStateService.getState("adminPolicies") || {};
if(stateUpdated){
this.clearState();
state = {};
// this.clearState();
state.data = [];
// state = {};
}
if(state){
this.headerColName = state.headerColName || 'Severity';
Expand All @@ -188,6 +190,7 @@ export class PoliciesComponent implements OnInit, OnDestroy {
this.whiteListColumns = state?.whiteListColumns || Object.keys(this.columnWidths);
this.tableScrollTop = state?.tableScrollTop;
this.filters = state?.filters || [];
this.selectedRowIndex = state?.selectedRowIndex;

if(this.filters){
this.getFiltersData(this.tableData);
Expand All @@ -206,12 +209,38 @@ export class PoliciesComponent implements OnInit, OnDestroy {
handleHeaderColNameSelection(event){
this.headerColName = event.headerColName;
this.direction = event.direction;
this.storeState();
}

handleWhitelistColumnsChange(event){
this.whiteListColumns = event;
this.storeState();
}

deleteFilters(event?) {
try {
if (!event) {
this.filters = [];
} else if (event.clearAll) {
this.filters = [];
}
this.storeState();
} catch (error) { }
}

handleFilterSelection(){
this.storeState();
}

handleFilterTypeSelection(){
this.storeState();
}

nextPage(e) {
try {
this.pageNumber++;
this.showLoader = true;
this.storeState();
this.getPolicyDetails(true);
} catch (error) {
this.errorMessage = this.errorHandling.handleJavascriptError(error);
Expand Down Expand Up @@ -254,7 +283,7 @@ export class PoliciesComponent implements OnInit, OnDestroy {
getFiltersData(data){
this.filterTypeLabels = [];
this.filterTagLabels = {};
const filtersList = [...this.whiteListColumns, "Autofix status"];
const filtersList = [...Object.keys(this.columnWidths), "Autofix status"];
filtersList.forEach(column => {
if(column.toLowerCase()=='actions'){
return;
Expand Down Expand Up @@ -387,17 +416,29 @@ export class PoliciesComponent implements OnInit, OnDestroy {
}else{
this.tableDataLoaded = false;
this.bucketNumber = 0;
// this.tableData = [];
this.tableData = [];
this.getPolicyDetails();
}
}

storeState(state){
storeState(data?){
const state = {
totalRows: this.totalRows,
data: data,
headerColName: this.headerColName,
direction: this.direction,
whiteListColumns: this.whiteListColumns,
bucketNumber: this.bucketNumber,
searchTxt: this.searchTxt,
tableScrollTop: this.tableScrollTop,
filters: this.filters,
selectedRowIndex: this.selectedRowIndex
}
this.tableStateService.setState("adminPolicies", state);
}

clearState(){
this.tableStateService.clearState("adminPolicies");
// this.tableStateService.clearState("adminPolicies");
this.isStatePreserved = false;
}

Expand Down Expand Up @@ -610,19 +651,9 @@ export class PoliciesComponent implements OnInit, OnDestroy {
const row = event.rowSelected;
const data = event.data;
const policyId = event.rowSelected["Policy ID"].text;
const state = {
totalRows: this.totalRows,
data: data,
headerColName: this.headerColName,
direction: this.direction,
whiteListColumns: this.whiteListColumns,
bucketNumber: this.bucketNumber,
searchTxt: event.searchTxt,
tableScrollTop: event.tableScrollTop,
filters: event.filters
// filterText: this.filterText
}
this.storeState(state);
this.tableScrollTop = event.tableScrollTop;
this.selectedRowIndex = event.selectedRowIndex;
this.storeState(data);
try {
this.workflowService.addRouterSnapshotToLevel(
this.router.routerState.snapshot.root, 0, this.pageTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ <h6 class="title-text">{{ pageTitle }}</h6>
(selectedFilter)="changeFilterTags($event)"
(selectedFilterType)="changeFilterType($event)"
(whitelistColumnsChanged)="handleWhitelistColumnsChange($event)"
[doLocalSort]="false"
[selectedRowIndex]="selectedRowIndex"
></app-table>
<div class="data-table-desc">{{ dataTableDesc }}</div>
</div>
Expand Down
Loading