Skip to content

Commit

Permalink
refactor(paging): correct logic for filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kinplemelon authored and ysfscream committed Jan 21, 2025
1 parent 2f0961e commit 03eb17e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 14 deletions.
13 changes: 12 additions & 1 deletion src/hooks/Rule/rule/useRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,24 @@ export const useRuleUtils = (): {
}
}

export const SourceServerType = {
MQTTBroker: BridgeType.MQTT,
}

/**
* Unlike RuleInputType, the action here is specific to what type of action it is.
*/
export const RuleSourceType = {
Message: 'message',
Event: 'event',
MQTTBroker: BridgeType.MQTT,
...SourceServerType,
}
export const useRuleInputs = (): {
getBridgeIdFromInput: (input: string) => string
detectInputType: (from: string) => string
isBridgeType: (type: string) => boolean
isNotBridgeSourceTypes: Array<string>
sourceServerOptList: Array<{ value: string; label: string }>
sourceOptList: Array<{ value: string; label: string }>
getRuleSourceIcon: (type: string) => string
} => {
Expand Down Expand Up @@ -272,6 +277,11 @@ export const useRuleInputs = (): {
return ret || specificType
}

const sourceServerOptList = Object.entries(SourceServerType).map(([, value]) => ({
value,
label: getTypeLabel(value),
}))

const sourceOptList = Object.entries(RuleSourceType).map(([, value]) => ({
value,
label: getTypeLabel(value),
Expand Down Expand Up @@ -335,6 +345,7 @@ export const useRuleInputs = (): {
detectInputType,
isBridgeType,
isNotBridgeSourceTypes,
sourceServerOptList,
sourceOptList,
getRuleSourceIcon,
}
Expand Down
16 changes: 12 additions & 4 deletions src/hooks/usePaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interface PageMeta {

export interface FilterItem {
key: string
value: string
value: string | boolean
}

interface SortFrom {
Expand Down Expand Up @@ -46,14 +46,22 @@ export default (): {
chunkList()
}

const checkValue = (filterValue: string | boolean, value: any) => {
if (typeof filterValue === 'string') {
const reg = new RegExp(filterValue, 'i')
return reg.test(value)
}
return filterValue === value
}

const filterList = (filters: Array<FilterItem> = []) => {
latestFiltersString = JSON.stringify(filters)
if (filters.length === 0) {
listAfterFilter.value = totalData.value
} else {
listAfterFilter.value = totalData.value.filter((item) =>
filters.every(({ key, value }) => item[key]?.indexOf && item[key].indexOf(value) > -1),
)
listAfterFilter.value = totalData.value.filter((item) => {
return filters.every(({ key, value: filterValue }) => checkValue(filterValue, item[key]))
})
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/i18n/RuleEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,10 @@ export default {
zh: '关联规则',
en: 'Associated Rules',
},
viewRules: {
zh: '查看规则',
en: 'View Rules',
},
directDispatch: {
zh: '直接派发',
en: 'Direct Dispatch',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import { SEARCH_FORM_RES_PROPS as colProps } from '@/common/constants'
import { titleCase } from '@/common/tools'
import useBridgeTypeValue from '@/hooks/Rule/bridge/useBridgeTypeValue'
import { useRuleInputs } from '@/hooks/Rule/rule/useRule'
import useActionAndSourceStatus from '@/hooks/Rule/useActionAndSourceStatus'
import useI18nTl from '@/hooks/useI18nTl'
import { ConnectionStatus } from '@/types/enum'
Expand Down Expand Up @@ -123,9 +124,10 @@ const showMoreQuery = ref(false)
const filterParams: Ref<ActionAndSourceFilterParams> = ref(createRawFilterParams())
const { egressBridgeTypeList: actionTypeList } = useBridgeTypeValue()
const { sourceServerOptList } = useRuleInputs()
const typeOptList = [
{ value: NOT_SPECIFIC_TYPE, label: t('Base.all') },
...(props.type === 'action' ? actionTypeList : []),
...(props.type === 'source' ? sourceServerOptList : actionTypeList),
]
const { statusOptList } = useActionAndSourceStatus()
Expand Down
33 changes: 25 additions & 8 deletions src/views/RuleEngine/components/ActionAndSourceList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@
<TargetItemStatus type="action" :target="row" />
</template>
</el-table-column>
<el-table-column :label="tl('associatedRules')" :min-width="120">
<template #default="{ row }">
<router-link :to="ruleFilterRoute(row.id)">
{{ row.rules?.length || 0 }}
</router-link>
</template>
</el-table-column>
<el-table-column prop="enable" :label="$t('Base.isEnabled')" :min-width="92" sortable>
<template #default="{ row }">
<OperateWebhookAssociatedPopover
Expand Down Expand Up @@ -64,6 +57,23 @@
{{ dateFormat(row.last_modified_at) }}
</template>
</el-table-column>
<el-table-column :label="tl('associatedRules')" :min-width="120">
<template #default="{ row }">
<router-link
v-for="item in row.rules"
:to="{ name: 'rule-detail', params: { id: item } }"
target="_blank"
:key="item"
>
<el-tag size="small" type="info">{{ item }}</el-tag>
</router-link>
<div class="view-rules-link">
<router-link :to="ruleFilterRoute(row.id)">
{{ `${tl('viewRules')} (${row.rules?.length || 0})` }}
</router-link>
</div>
</template>
</el-table-column>
<el-table-column :label="$t('Base.operation')" :min-width="168">
<template #default="{ row }">
<TableButton
Expand Down Expand Up @@ -113,6 +123,7 @@

<script setup lang="ts">
import { dateFormat } from '@/common/tools'
import CommonPagination from '@/components/commonPagination.vue'
import useActionList from '@/hooks/Rule/action/useActionList'
import useHandleActionItem from '@/hooks/Rule/action/useHandleActionItem'
import useHandleSourceItem from '@/hooks/Rule/action/useHandleSourceItem'
Expand Down Expand Up @@ -300,4 +311,10 @@ const {
const direction = isSource.value ? BridgeDirection.Ingress : BridgeDirection.Egress
</script>

<style lang="scss"></style>
<style lang="scss">
.view-rules-link {
margin-top: 2px;
margin-left: 4px;
font-size: 12px;
}
</style>

0 comments on commit 03eb17e

Please sign in to comment.