Skip to content

Commit

Permalink
feat: source ip filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Zephyruso committed Dec 1, 2024
1 parent 8b48f45 commit 4a09d25
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
38 changes: 36 additions & 2 deletions src/components/sidebar/ConnectionCtrl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,42 @@
v-model="quickFilterEnabled"
/>
</div>
<div class="join">
<select
v-if="!horizontal"
class="select select-bordered select-sm"
v-model="sourceIPFilter"
>
<option
value=""
label="all"
></option>
<option
v-for="opt in sourceIPs"
:key="opt"
:value="opt"
:label="opt"
/>
</select>
<div class="join flex-1">
<select
v-if="horizontal"
class="join-item select select-bordered select-sm min-w-24"
v-model="sourceIPFilter"
>
<option
value=""
label="all"
></option>
<option
v-for="opt in sourceIPs"
:key="opt"
:value="opt"
:label="opt"
/>
</select>
<input
type="text"
class="input input-sm join-item input-bordered flex-1"
class="input input-sm join-item input-bordered w-24 flex-1"
v-model="connectionFilter"
/>
<button
Expand Down Expand Up @@ -82,6 +114,8 @@ import {
quickFilterEnabled,
quickFilterRegex,
renderConnections,
sourceIPFilter,
sourceIPs,
} from '@/store/connections'
import { PauseIcon, PlayIcon, XMarkIcon } from '@heroicons/vue/24/outline'
import { twMerge } from 'tailwind-merge'
Expand Down
12 changes: 11 additions & 1 deletion src/store/connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CONNECTION_TAB_TYPE, SORT_TYPE } from '@/config'
import type { Connection, ConnectionRawMessage } from '@/types'
import { useStorage } from '@vueuse/core'
import dayjs from 'dayjs'
import { differenceWith } from 'lodash'
import _, { differenceWith } from 'lodash'
import { computed, ref, watch } from 'vue'
import { useConnectionCard } from './config'

Expand Down Expand Up @@ -137,6 +137,10 @@ export const renderConnections = computed(() => {
}
}

if (sourceIPFilter.value && conn.metadata.sourceIP === sourceIPFilter.value) {
return false
}

if (connectionFilter.value) {
return [
conn.metadata.host,
Expand Down Expand Up @@ -166,3 +170,9 @@ export const renderConnections = computed(() => {
return sortResult
})
})

export const sourceIPFilter = ref('')

export const sourceIPs = computed(() => {
return _.uniq(activeConnections.value.map((conn) => conn.metadata.sourceIP))
})

0 comments on commit 4a09d25

Please sign in to comment.