Skip to content

Commit

Permalink
feat: add filter footer sort
Browse files Browse the repository at this point in the history
  • Loading branch information
pirhoo committed Jul 11, 2024
1 parent 05589f8 commit 999cdff
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 14 deletions.
3 changes: 2 additions & 1 deletion components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ declare module 'vue' {
ColumnFilterBadge: typeof import('./src/components/ColumnFilterBadge.vue')['default']
ColumnFilterDropdown: typeof import('./src/components/ColumnFilterDropdown.vue')['default']
ContentTypeBadge: typeof import('./src/components/ContentTypeBadge.vue')['default']
copy: typeof import('./src/components/FiltersPanelSectionFilter copy.vue')['default']
copy: typeof import('./src/components/FiltersPanelSectionFilterFooter copy.vue')['default']
DismissableAlert: typeof import('./src/components/DismissableAlert.vue')['default']
DocumentActions: typeof import('./src/components/DocumentActions.vue')['default']
DocumentAttachments: typeof import('./src/components/DocumentAttachments.vue')['default']
Expand Down Expand Up @@ -120,6 +120,7 @@ declare module 'vue' {
FiltersPanelSectionFilter: typeof import('./src/components/FiltersPanelSectionFilter.vue')['default']
FiltersPanelSectionFilterEntry: typeof import('./src/components/FiltersPanelSectionFilterEntry.vue')['default']
FiltersPanelSectionFilterFooter: typeof import('./src/components/FiltersPanelSectionFilterFooter.vue')['default']
FiltersPanelSectionFilterFooterSort: typeof import('./src/components/FiltersPanelSectionFilterFooterSort.vue')['default']
FiltersPanelSectionFilterTitle: typeof import('./src/components/FiltersPanelSectionFilterTitle.vue')['default']
FiltersPanelSectionFilterToggler: typeof import('./src/components/FiltersPanelSectionFilterToggler.vue')['default']
FiltersPanelSectionTitle: typeof import('./src/components/FiltersPanelSectionTitle.vue')['default']
Expand Down
9 changes: 7 additions & 2 deletions src/components/FiltersPanelSectionFilterFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { computed } from 'vue'
import IconButton from '@/components/IconButton'
import FiltersPanelSectionFilterFooterSort from '@/components/FiltersPanelSectionFilterFooterSort'
const props = defineProps({
hideContextualize: {
Expand All @@ -16,6 +17,9 @@ const props = defineProps({
hideSort: {
type: Boolean
},
sort: {
type: Object
},
contextualize: {
type: Boolean
},
Expand All @@ -24,7 +28,7 @@ const props = defineProps({
}
})
const emit = defineEmits(['update:contextualize', 'update:exclude', 'expand', 'sort'])
const emit = defineEmits(['update:contextualize', 'update:exclude', 'update:sort', 'expand'])
const isEmpty = computed(() => {
return props.hideContextualize && props.hideExclude && props.hideExpand && props.hideSort
Expand All @@ -48,7 +52,7 @@ const classList = computed(() => {
<icon-button icon-left="arrows-out-simple" label="Expand" @click="emit('expand')" />
</div>
<div v-if="!hideSort" class="col d-flex justify-content-end">
<icon-button icon-left="caret-up-down" label="Sort" />
<filters-panel-section-filter-footer-sort @update:modelValue="emit('update:sort', $event)" />
</div>
</div>
<div class="row g-0">
Expand Down Expand Up @@ -76,6 +80,7 @@ const classList = computed(() => {
}
&:deep(.icon-button),
&:deep(.dropdown-toggle),
&:deep(.form-check) {
padding: $spacer-xxs 0;
border: 0;
Expand Down
70 changes: 70 additions & 0 deletions src/components/FiltersPanelSectionFilterFooterSort.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<script setup>
import { ref, computed } from 'vue'
import { PhosphorIcon } from '@icij/murmur-next'
import settings from '@/utils/settings'
const props = defineProps({
modelValue: {
type: Object,
default: () => ({ sortBy: '_count', sortByOrder: 'desc' })
},
sortByOptions: {
type: Array,
default: () => settings.filter.sortByOptions
}
})
const emit = defineEmits(['update:modelValue'])
const showDropdown = ref(false)
const sortByOptionsWithLabels = computed(() => {
return props.sortByOptions.map(({ sortBy, sortByOrder }) => {
const label = `filter.sortByDropdown.options.${sortBy}.${sortByOrder}`
return { label, sortBy, sortByOrder }
})
})
const applySort = ({ sortBy, sortByOrder }) => {
if (sortBy !== props.modelValue.sortBy || sortByOrder !== props.modelValue.sortByOrder) {
emit('update:modelValue', { sortBy, sortByOrder })
}
}
const isOptionActive = ({ sortBy, sortByOrder }) => {
return props.modelValue.sortBy === sortBy && props.modelValue.sortByOrder === sortByOrder
}
</script>

<template>
<b-dropdown
v-model="showDropdown"
class="filters-panel-section-filter-footer-sort"
variant="link"
end
dropup
teleport-to="body"
no-caret
>
<template #button-content>
<phosphor-icon name="caret-up-down" />
Sort
</template>
<b-dropdown-item
v-for="(option, i) in sortByOptionsWithLabels"
:key="i"
:active="isOptionActive(option)"
@click="applySort(option)"
>
{{ $t(option.label) }}
</b-dropdown-item>
</b-dropdown>
</template>

<style lang="scss" scoped>
.filters-panel-section-filter-footer-sort {
&:deep(.dropdown-toggle) {
color: inherit;
}
}
</style>
20 changes: 9 additions & 11 deletions src/stories/components/FiltersPanelSection.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ export default {
},
argTypes: {},
args: {
title: 'Documents info',
collapse: false
title: 'Documents info'
},
render: (args) => ({
components: {
Expand All @@ -23,15 +22,14 @@ export default {
template: `
<div class="p-5" style="background-color: var(--bs-light-bg-subtle);">
<filters-panel-section :title="args.title">
<filters-panel-section-filter title="Tags" icon="tag" :collapse="args.collapse" @toggle="args.collapse = $event">
<filters-panel-section-filter-entry label="russia" model-value :count="1233" />
<filters-panel-section-filter-entry label="france" model-value :count="437" />
<filters-panel-section-filter-entry label="china" model-value :count="211" />
<filters-panel-section-filter-entry label="usa" :count="210" />
<filters-panel-section-filter-entry label="germany" :count="148" />
<filters-panel-section-filter-entry label="sudan" :count="135" />
<filters-panel-section-filter-entry label="australia" :count="36" />
</filters-panel-section-filter>
<filters-panel-section-filter title="Project" icon="circles-three-plus" collapse />
<filters-panel-section-filter title="Path" icon="tree-structure" collapse />
<filters-panel-section-filter title="File type" icon="file-text" collapse />
<filters-panel-section-filter title="Creation date" icon="calendar-blank" collapse />
<filters-panel-section-filter title="Language" icon="globe-hemisphere-west" collapse />
<filters-panel-section-filter title="Indexing date" icon="calendar-plus" collapse />
<filters-panel-section-filter title="Extraction lebel" icon="paperclip" collapse />
<filters-panel-section-filter title="Has attachments" icon="paperclip" collapse />
</filter-panel-section>
</div>
`
Expand Down

0 comments on commit 999cdff

Please sign in to comment.