Skip to content

Commit cde73f7

Browse files
author
Piotr
committed
sorting facet values
1 parent 857cd08 commit cde73f7

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/App.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,9 +625,15 @@ const updateSampleLine = () => {
625625
<button class="btn-sm" style="margin-top:4px" @click="store.resetCorrelationFilter()">Reset correlation
626626
filter</button>
627627
</div>
628+
<br />
629+
<span class="sort-label">Sort facets </span>
630+
<button class="btn-sm" @click="store.facetSort = 'label'"
631+
:disabled="store.facetSort === 'label'">Label</button>
632+
<button class="btn-sm" @click="store.facetSort = 'count'"
633+
:disabled="store.facetSort === 'count'">Count</button>
628634
</div>
629635
<Filter />
630-
<FacetComponent :facets="store.facets" />
636+
<FacetComponent :facets="store.facets" :sort="store.facetSort" />
631637
</template>
632638
</div>
633639
</div>

src/app.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@
135135
.counter {
136136
text-align: center;
137137
padding-bottom: 10px;
138+
139+
.sort-label{
140+
font-size: 12px;
141+
}
138142
}
139143

140144
}

src/components/Facet.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script lang="ts" setup>
2-
import { computed } from 'vue';
3-
import { FacetCollection, FacetValues } from '../types';
2+
import { computed, ref } from 'vue';
3+
import { FacetCollection, FacetItem, FacetValues } from '../types';
44
55
const props = defineProps<{
6-
facets: FacetValues
6+
facets: FacetValues,
7+
sort: SortPropName
78
}>()
89
910
const toggleAll = (f: FacetCollection) => {
@@ -21,6 +22,12 @@ const facetsSorted = computed(() => {
2122
})
2223
})
2324
25+
export type SortPropName = 'count' | 'label'
26+
const facetItemsSorted = (items: FacetItem[], sortBy: SortPropName) => {
27+
let dir = sortBy === 'count' ? -1 : 1
28+
return items.sort((a, b) => a[sortBy] > b[sortBy] ? 1 * dir : -1 * dir)
29+
}
30+
2431
const formatNumber = (num: number): string => {
2532
return Intl.NumberFormat('en-US', {
2633
notation: "compact",
@@ -40,7 +47,7 @@ const formatNumber = (num: number): string => {
4047
<span class="facet-toggle" @click="toggleAll(f)">All</span>
4148
</div>
4249
<div v-if="f.toggled" class="facet-items">
43-
<div v-for="l in f.items" class="facet-item" @click="l.selected = !l.selected"
50+
<div v-for="l in facetItemsSorted(f.items, props.sort)" class="facet-item" @click="l.selected = !l.selected"
4451
:class="{ 'facet-selected': l.selected }">
4552
<div class="facet-label" :title="l.label">{{ l.label }}</div>
4653
<div class="facet-val" :title="l.count.toString()">{{ formatNumber(l.count) }}</div>

src/store.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { Layout } from "./config";
66
import { useFilterStore } from "./stores/filter";
77
import { client } from "./api";
88
import { formatThousands, getUrlParam } from "./utils";
9+
import { SortPropName } from "./components/Facet.vue";
910

1011
export interface Notification {
1112
id?: string;
@@ -58,6 +59,7 @@ export const useMainStore = defineStore("main", () => {
5859
const settingsDrawer = ref<boolean>(false)
5960
const correlationFilter = ref<string>("")
6061
const tracesRows = ref<Record<string, TraceRow>>({})
62+
const facetSort = ref<SortPropName>("label")
6163

6264
const initSettings = ref<InitSettings>()
6365

@@ -385,6 +387,7 @@ export const useMainStore = defineStore("main", () => {
385387
searchbarValid,
386388
searchClear,
387389

388-
toggleRowMark
390+
toggleRowMark,
391+
facetSort
389392
};
390393
});

0 commit comments

Comments
 (0)