Skip to content

Commit

Permalink
feat: add filters in list format (#1835)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmendes21 authored Oct 22, 2024
1 parent da648d9 commit 5c485a8
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 16 deletions.
22 changes: 19 additions & 3 deletions src/helpers/real-time-filters-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ const FILTER_BLACK_LIST = [
'naxsiAttackFamilyEq',
'naxsiAttackFamilyNe',
'naxsiAttackFamilyLike',
'naxsiAttackFamilyIlike'
'naxsiAttackFamilyIlike',
'classifiedLike',
'classifiedIlike',
'classifiedIn',
'classifiedNotIn',
'classifiedIsNull',
'actionLike',
'actionIlike',
'actionIn',
'actionNotIn',
'actionIsNull'
]

const SUPPORTED_FILTER_TYPE = ['String', 'Int', 'Float', 'IntRange', 'FloatRange', 'GenericScalar']
Expand Down Expand Up @@ -84,11 +94,17 @@ const FILTER_LIKE_TYPE = {
zoneIdIn: 'ArrayObject',
edgeFunctionIdIn: 'ArrayObject',
botCategoryIn: 'ArrayObject',
challengeSolvedEq: 'Boolean'
challengeSolvedEq: 'Boolean',
classifiedEq: 'StringObject',
classifiedNe: 'StringObject',
actionEq: 'StringObject',
actionNe: 'StringObject',
}

const FILTER_LIKE_ALIAS = {
configurationIdIn: 'Domain'
configurationIdIn: 'Domain',
classifiedEq: 'Classified',
classifiedNe: 'Classified',
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/modules/real-time-metrics/constants/dashboards.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const PAGES_DASHBOARDS = {
},
{
id: 9,
label: 'Bot Manager Advanced',
label: 'Bot Manager',
path: 'bot-manager-advanced',
groupId: 2,
dashboards: [
Expand Down
10 changes: 8 additions & 2 deletions src/modules/real-time-metrics/constants/services-operator-in.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ import {
searchDomainsService,
searchEdgeDnsService,
searchBotCategoryService,
searchClassifiedService
searchChallengeSolvedService,
searchClassifiedService,
searchActionService
} from '@/services/real-time-metrics-services'

const MAP_SERVICE_OPERATION = {
configurationIdIn: searchDomainsService,
zoneIdIn: searchEdgeDnsService,
edgeFunctionIdIn: searchEdgeFunctionsService,
botCategoryIn: searchBotCategoryService,
challengeSolvedEq: searchClassifiedService
challengeSolvedEq: searchChallengeSolvedService,
classifiedEq: searchClassifiedService,
classifiedNe: searchClassifiedService,
actionEq: searchActionService,
actionNe: searchActionService
}

export default MAP_SERVICE_OPERATION
6 changes: 5 additions & 1 deletion src/services/real-time-metrics-services/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import { searchEdgeDnsService } from './search-edge-dns-service'
import { searchEdgeFunctionsService } from './search-edge-functions'
import { loadRealTimeMetricsData } from './load-real-time-metrics-data'
import { searchBotCategoryService } from './search-bot-category-service'
import { searchChallengeSolvedService } from './search-challenge-solved-service'
import { searchClassifiedService } from './search-classified-service'
import { searchActionService } from './search-action-service'

export {
searchDomainsService,
searchEdgeDnsService,
searchEdgeFunctionsService,
loadRealTimeMetricsData,
searchBotCategoryService,
searchClassifiedService
searchChallengeSolvedService,
searchClassifiedService,
searchActionService
}
11 changes: 11 additions & 0 deletions src/services/real-time-metrics-services/search-action-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export const searchActionService = () => {
return [
{ label: 'Allow', value: 'allow' },
{ label: 'Custom HTML', value: 'custom html' },
{ label: 'Deny ', value: 'deny' },
{ label: 'Drop', value: 'drop' },
{ label: 'Hold Connection', value: 'hold connection' },
{ label: 'Random Delay', value: 'random delay' },
{ label: 'Redirect', value: 'redirect' },
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const searchChallengeSolvedService = () => {
return [
{ label: 'Solved', value: true },
{ label: 'Not Solved', value: false }
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export const searchClassifiedService = () => {
return [
{ label: 'Solved', value: true },
{ label: 'Not Solved', value: false }
{ label: 'Legitimate', value: 'legitimate' },
{ label: 'Good Bot', value: 'good bot' },
{ label: 'Bad Bot ', value: 'bad bot' },
{ label: 'Under Evaluation', value: 'under evaluation' },
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
const formattedValue = (filter) => {
let newFilter = { ...filter }
if (filter?.type === 'Boolean')
if (['Boolean', 'StringObject'].includes(filter?.type))
newFilter = { ...filter, value: filter?.value?.label.toLowerCase() }
const isEmptyString = !newFilter?.value && newFilter?.type === 'String'
Expand Down
1 change: 1 addition & 0 deletions src/templates/advanced-filter/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const FIELDS_MAPPING = {
FloatRange: h(floatRangeFilter),
ArrayObject: h(multiselectFilter),
Boolean: h(selectFilter),
StringObject: h(selectFilter),
ArrayString: h(chipsFilter),
GenericScalar: h(textFilter)
}
Expand Down
3 changes: 2 additions & 1 deletion src/templates/advanced-filter/dialog-filter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@
type: operatorSelected.type
}
if (filterSelected.operator[0].value.type === 'Boolean') {
const operatorType = filterSelected.operator[0].value.type
if (['Boolean', 'StringObject'].includes(operatorType)) {
data.value = selectedValue
} else {
data.value = selectedValue ?? { begin, end }
Expand Down
22 changes: 19 additions & 3 deletions src/tests/helpers/realt-time-filter-rules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ describe('RealTimeMetricsModule', () => {
'naxsiAttackFamilyEq',
'naxsiAttackFamilyNe',
'naxsiAttackFamilyLike',
'naxsiAttackFamilyIlike'
'naxsiAttackFamilyIlike',
'classifiedLike',
'classifiedIlike',
'classifiedIn',
'classifiedNotIn',
'classifiedIsNull',
'actionLike',
'actionIlike',
'actionIn',
'actionNotIn',
'actionIsNull'
],
FILTER_WHITELIST: {
SUPPORTED_FILTER_TYPE: [
Expand Down Expand Up @@ -110,10 +120,16 @@ describe('RealTimeMetricsModule', () => {
zoneIdIn: 'ArrayObject',
edgeFunctionIdIn: 'ArrayObject',
botCategoryIn: 'ArrayObject',
challengeSolvedEq: 'Boolean'
challengeSolvedEq: 'Boolean',
classifiedEq: 'StringObject',
classifiedNe: 'StringObject',
actionEq: 'StringObject',
actionNe: 'StringObject',
},
FILTER_LIKE_ALIAS: {
configurationIdIn: 'Domain'
configurationIdIn: 'Domain',
classifiedEq: 'Classified',
classifiedNe: 'Classified',
},
ALIAS_MAPPING: { configurationId: 'domain' }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ describe('RealTimeMetricsModule', () => {
},
{
id: 9,
label: 'Bot Manager Advanced',
label: 'Bot Manager',
path: 'bot-manager-advanced',
groupId: 2,
dashboards: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ describe('RealTimeMetricsModule', () => {
zoneIdIn: services.searchEdgeDnsService,
edgeFunctionIdIn: services.searchEdgeFunctionsService,
botCategoryIn: services.searchBotCategoryService,
challengeSolvedEq: services.searchClassifiedService
challengeSolvedEq: services.searchChallengeSolvedService,
classifiedEq: services.searchClassifiedService,
classifiedNe: services.searchClassifiedService,
actionEq: services.searchActionService,
actionNe: services.searchActionService
}

expect(MAP_SERVICE_OPERATION).toEqual(mapServiceOperation)
Expand Down
12 changes: 12 additions & 0 deletions src/views/RealTimeMetrics/blocks/content-filter-block.vue
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,18 @@
return
}
if (item.type === 'StringObject') {
createAndFilter({
[field]: {
value: item.value.value,
meta: {
inputType: 'String'
}
}
})
return
}
createAndFilter({
[field]: {
value: item.type !== 'Boolean' ? item.value : item.value.value,
Expand Down

0 comments on commit 5c485a8

Please sign in to comment.