-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add probe filtering by adoption status for admin users #133
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
cebde3a
feat: add filtering by adoption status for admins
PavelKopecky 4550f3b
refactor: break down probe list filters into smaller components
PavelKopecky 6a801b9
feat: display github username on the probe page
PavelKopecky 775d2e3
fix: remove the u- user prefix from admin probe table
PavelKopecky 2b9d182
refactor: code cleanup
PavelKopecky ce0db98
fix: refresh probe count on adoption
PavelKopecky 8b141c7
fix: pass filter as v-model instead of a prop
PavelKopecky 6ff9e4d
fix
MartinKolarik 144f3a2
refactor
MartinKolarik fa3e5d8
style: change username style on the probe page
PavelKopecky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| <template> | ||
| <div class="flex flex-col gap-2"> | ||
| <span class="flex items-center font-bold">Adoption status:</span> | ||
| <Select | ||
| v-model="usedFilter.adoption" | ||
| :options="ADOPTION_OPTIONS" | ||
| class="min-w-48" | ||
| @change="onChange" | ||
| > | ||
| <template #value="{value}"> | ||
| {{ value[0].toUpperCase() + value.slice(1) }} | ||
| </template> | ||
| <template #option="{option}"> | ||
| {{ option[0].toUpperCase() + option.slice(1) }} | ||
| </template> | ||
| </Select> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { useProbeFilters, ADOPTION_OPTIONS, type Filter } from '~/composables/useProbeFilters'; | ||
|
|
||
| const filter = defineModel('filter', { required: false, type: Object as PropType<Filter> }); | ||
|
|
||
| const { filter: appliedFilter, onParamChange } = useProbeFilters(); | ||
| const usedFilter = computed(() => filter.value ?? appliedFilter.value); | ||
|
|
||
| // only apply changes if the default (shared) filter is used | ||
| const onChange = filter.value ? () => {} : onParamChange; | ||
| </script> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| <template> | ||
| <div class="ml-auto flex h-9 items-stretch gap-x-2 self-end font-normal"> | ||
| <span class="flex items-center font-bold">Status:</span> | ||
| <Select | ||
| v-model="filter.status" | ||
| :options="STATUS_CODES" | ||
| :pt="{ listContainer: { class: '!max-h-64' } }" | ||
| option-label="code" | ||
| class="min-w-64" | ||
| @change="onParamChange" | ||
| > | ||
| <template #option="{option}: {option: StatusCode}"> | ||
| <span class="flex h-full items-center gap-2"> | ||
| <span | ||
| :class="{ | ||
| 'font-bold text-bluegray-900 dark:text-white': option === filter.status, | ||
| 'text-bluegray-400': option !== filter.status | ||
| }"> | ||
| {{ STATUS_MAP[option].name }} | ||
| </span> | ||
| <Tag | ||
| class="-my-0.5" | ||
| :class="{ | ||
| 'bg-primary text-white dark:bg-white dark:text-bluegray-900 ': option === filter.status, | ||
| 'border border-surface-300 bg-surface-0 text-bluegray-900 dark:border-dark-600 dark:bg-dark-800 dark:text-surface-0': option !== filter.status | ||
| }"> | ||
| {{ statusCounts[option] }} | ||
| </Tag> | ||
| </span> | ||
| </template> | ||
|
|
||
| <template #value="{value}: {value: StatusCode}"> | ||
| <span class="flex h-full items-center gap-2"> | ||
| <span class="text-bluegray-400">{{ STATUS_MAP[value].name }}</span> | ||
| <Tag class="-my-1 border ">{{ statusCounts[value] }}</Tag> | ||
| </span> | ||
| </template> | ||
| </Select> | ||
| <InputGroup class="!w-auto"> | ||
| <IconField> | ||
| <InputIcon class="pi pi-search"/> | ||
| <InputText v-model="searchInput" class="m-0 h-full min-w-[280px]" placeholder="Filter by name, location, or tags" @input="onFilterChangeDebounced"/> | ||
| </IconField> | ||
| </InputGroup> | ||
|
|
||
| <div v-if="auth.isAdmin" class="flex size-9 items-stretch justify-between rounded-md border border-surface-300 text-bluegray-700 focus-within:border-primary hover:border-surface-400 dark:border-dark-600 dark:bg-dark-900 dark:text-dark-0 dark:hover:border-dark-400"> | ||
| <Button | ||
| class="relative hover:bg-white focus:ring-primary dark:hover:bg-dark-900 dark:focus:ring-primary" | ||
| severity="secondary" | ||
| size="small" | ||
| text | ||
| @click="adminOptsRef.toggle($event)"> | ||
| <i class="pi pi-sliders-h"/> | ||
| <i v-if="!isDefault('adoption')" class="pi pi-circle-fill absolute right-2 top-2 text-[0.4rem] text-primary"/> | ||
| </Button> | ||
|
|
||
| <Popover ref="adminOptsRef" class="w-fit gap-4 p-4 [&>*]:border-none" role="dialog"> | ||
| <AdminFilterSettings/> | ||
| </Popover> | ||
| </div> | ||
| </div> | ||
| </template> | ||
|
|
||
| <script setup lang="ts"> | ||
| import { aggregate } from '@directus/sdk'; | ||
| import debounce from 'lodash/debounce'; | ||
| import AdminFilterSettings from '~/components/probe/ProbeFilters/AdminFilterSettings.vue'; | ||
| import { useErrorToast } from '~/composables/useErrorToast'; | ||
| import { STATUS_MAP, type StatusCode, useProbeFilters } from '~/composables/useProbeFilters'; | ||
| import { useAuth } from '~/store/auth'; | ||
|
|
||
| const auth = useAuth(); | ||
| const { $directus } = useNuxtApp(); | ||
|
|
||
| const active = ref(true); | ||
| const { filter, onParamChange, onFilterChange, getDirectusFilter, isDefault } = useProbeFilters({ active }); | ||
| const searchInput = ref(filter.value.search); | ||
| const onFilterChangeDebounced = debounce(() => onFilterChange(searchInput.value), 500); | ||
| const filterDeps = computed(() => ({ ...filter.value })); | ||
|
|
||
| const adminOptsRef = ref(); | ||
| const STATUS_CODES = Object.keys(STATUS_MAP) as StatusCode[]; | ||
|
|
||
| const { data: statusCounts, error: statusCountError } = await useLazyAsyncData( | ||
| () => $directus.request<[{ count: number; status: Status; isOutdated: boolean }]>(aggregate('gp_probes', { | ||
| query: { | ||
| filter: getDirectusFilter(filter, [ 'status' ]), | ||
| groupBy: [ 'status', 'isOutdated' ], | ||
| }, | ||
| aggregate: { count: '*' }, | ||
| })), | ||
| { | ||
| watch: [ filterDeps ], | ||
| default: () => Object.fromEntries(STATUS_CODES.map(status => [ status, 0 ])), | ||
| transform: (data) => { | ||
| const counts = Object.fromEntries(STATUS_CODES.map(status => [ status, 0 ])); | ||
|
|
||
| STATUS_CODES.forEach((code) => { | ||
| counts[code] = data.reduce((sum, status) => { | ||
| return STATUS_MAP[code].options.includes(status.status) && (status.isOutdated || !STATUS_MAP[code].outdatedOnly) | ||
| ? sum + status.count | ||
| : sum; | ||
| }, 0); | ||
| }); | ||
|
|
||
| return counts; | ||
| }, | ||
| }, | ||
| ); | ||
|
|
||
| useErrorToast(statusCountError); | ||
|
|
||
| onBeforeUnmount(() => { | ||
| onFilterChangeDebounced.cancel(); | ||
| }); | ||
|
|
||
| onBeforeRouteLeave(() => { | ||
| active.value = false; | ||
| }); | ||
| </script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.