Skip to content

Commit

Permalink
sorting facet values
Browse files Browse the repository at this point in the history
  • Loading branch information
Piotr committed Nov 28, 2024
1 parent 857cd08 commit cde73f7
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
8 changes: 7 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -625,9 +625,15 @@ const updateSampleLine = () => {
<button class="btn-sm" style="margin-top:4px" @click="store.resetCorrelationFilter()">Reset correlation
filter</button>
</div>
<br />
<span class="sort-label">Sort facets </span>
<button class="btn-sm" @click="store.facetSort = 'label'"
:disabled="store.facetSort === 'label'">Label</button>
<button class="btn-sm" @click="store.facetSort = 'count'"
:disabled="store.facetSort === 'count'">Count</button>
</div>
<Filter />
<FacetComponent :facets="store.facets" />
<FacetComponent :facets="store.facets" :sort="store.facetSort" />
</template>
</div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions src/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@
.counter {
text-align: center;
padding-bottom: 10px;

.sort-label{
font-size: 12px;
}
}

}
Expand Down
15 changes: 11 additions & 4 deletions src/components/Facet.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts" setup>
import { computed } from 'vue';
import { FacetCollection, FacetValues } from '../types';
import { computed, ref } from 'vue';

Check failure on line 2 in src/components/Facet.vue

View workflow job for this annotation

GitHub Actions / Publish to Cloudflare Pages

'ref' is declared but its value is never read.
import { FacetCollection, FacetItem, FacetValues } from '../types';
const props = defineProps<{
facets: FacetValues
facets: FacetValues,
sort: SortPropName
}>()
const toggleAll = (f: FacetCollection) => {
Expand All @@ -21,6 +22,12 @@ const facetsSorted = computed(() => {
})
})
export type SortPropName = 'count' | 'label'
const facetItemsSorted = (items: FacetItem[], sortBy: SortPropName) => {
let dir = sortBy === 'count' ? -1 : 1
return items.sort((a, b) => a[sortBy] > b[sortBy] ? 1 * dir : -1 * dir)
}
const formatNumber = (num: number): string => {
return Intl.NumberFormat('en-US', {
notation: "compact",
Expand All @@ -40,7 +47,7 @@ const formatNumber = (num: number): string => {
<span class="facet-toggle" @click="toggleAll(f)">All</span>
</div>
<div v-if="f.toggled" class="facet-items">
<div v-for="l in f.items" class="facet-item" @click="l.selected = !l.selected"
<div v-for="l in facetItemsSorted(f.items, props.sort)" class="facet-item" @click="l.selected = !l.selected"
:class="{ 'facet-selected': l.selected }">
<div class="facet-label" :title="l.label">{{ l.label }}</div>
<div class="facet-val" :title="l.count.toString()">{{ formatNumber(l.count) }}</div>
Expand Down
5 changes: 4 additions & 1 deletion src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Layout } from "./config";
import { useFilterStore } from "./stores/filter";
import { client } from "./api";
import { formatThousands, getUrlParam } from "./utils";
import { SortPropName } from "./components/Facet.vue";

export interface Notification {
id?: string;
Expand Down Expand Up @@ -58,6 +59,7 @@ export const useMainStore = defineStore("main", () => {
const settingsDrawer = ref<boolean>(false)
const correlationFilter = ref<string>("")
const tracesRows = ref<Record<string, TraceRow>>({})
const facetSort = ref<SortPropName>("label")

const initSettings = ref<InitSettings>()

Expand Down Expand Up @@ -385,6 +387,7 @@ export const useMainStore = defineStore("main", () => {
searchbarValid,
searchClear,

toggleRowMark
toggleRowMark,
facetSort
};
});

0 comments on commit cde73f7

Please sign in to comment.