Skip to content

Commit

Permalink
Merge branch 'main' of github.com:unepwcmc/wcmc-components into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxycle committed Jun 16, 2022
2 parents db63313 + 66895c1 commit 7bfbfed
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 29 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
### 2.1.1

- Chore: run build and build-lib, update version in package.json

### 2.1.0

- Fix: Use getters in TableHeading and TableFilter components to properly read the state of the store
- Feat: Allow customisable link icons using slots and portals

### 2.0.1

- Fix: Switch order of merged options to ensure options entered via prop take precedence

### 2.0.0

- Fix: fix item.value not displayed due to legend_on not having v-else.
- Breaking change:
- $root.$on.openModal no longer emits tableId
- $root.$on.openModal emits an object with { row, rowIndex, tableId, tableColumns }
- Extract { tableId } in listeners of openModel to fix.

### 1.2.1

- Hotfix: Correct broken import
Expand Down
4 changes: 4 additions & 0 deletions dev/Serve.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
<template #sort-icon>
<span>This element is used as the sorting icon now!</span>
</template>
<template #row-link-icon>
<span>This element is used as the row link icon now!</span>
</template>
-->
</filterable-table>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unep-wcmc/wcmc-components",
"version": "1.2.1",
"version": "2.1.1",
"repository": {
"type": "git",
"url": "git+https://github.com/unepwcmc/wcmc-components.git"
Expand Down
14 changes: 13 additions & 1 deletion src/components/filterable-table/FilterableTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<portal to="sort-icon">
<slot name="sort-icon" />
</portal>

<portal to="row-link-icon">
<slot name="row-link-icon" />
</portal>

<table-filters
:endpoint-download="endpointDownload"
Expand Down Expand Up @@ -241,9 +245,17 @@ export default {
},
importUserOptions () {
const providedOptions = typeof(this.options) == 'object' ? this.options : {}
const defaultOptionsWithoutColumns = JSON.parse(JSON.stringify(DEFAULT_OPTIONS));
delete defaultOptionsWithoutColumns.columns // remove default columns widths which was messing the vertical alignment
const defaultOptionsToMerge = Object.prototype.hasOwnProperty.call(providedOptions, 'columns') ? defaultOptionsWithoutColumns : DEFAULT_OPTIONS
const options = merge(defaultOptionsToMerge, providedOptions)
const obj = {
tableId: this.id,
options: typeof(this.options) == 'object' ? merge({}, DEFAULT_OPTIONS, this.options) : DEFAULT_OPTIONS
options
}
this.updateOptions(obj)
Expand Down
13 changes: 10 additions & 3 deletions src/components/filterable-table/TableFilter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@
</template>

<script>
import TableFilterOption from './TableFilterOption.vue'
import SvgChevron from './svgs/SvgChevron.vue'
import TableFilterOption from './TableFilterOption.vue'
import SvgChevron from './svgs/SvgChevron.vue'
import { createNamespacedHelpers } from 'vuex'
const { mapGetters } = createNamespacedHelpers('filterableTable')
export default {
name: 'TableFilter',
Expand Down Expand Up @@ -96,6 +98,10 @@
},
computed: {
...mapGetters([
'getSelectedSort'
]),
cssVariables () {
return {
'--color-bg' : this.config.trigger.colorBg,
Expand Down Expand Up @@ -240,9 +246,10 @@
name: this.name,
options: this.activeOptions
},
sortObj: this.getSelectedSort(this.tableId),
requestedPage: 1
}
this.$store.dispatch('filterableTable/applyNewFilterOptions', obj)
this.$root.$emit('getNewItems')
Expand Down
44 changes: 22 additions & 22 deletions src/components/filterable-table/TableHeading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
v-text="heading.title"
/>

<table-tooltip v-if="hasTooltip" :text="heading.tooltip" />
<table-tooltip
v-if="hasTooltip"
:text="heading.tooltip"
/>

<div
v-if="tableIsSortable"
Expand All @@ -30,7 +33,7 @@ import { createNamespacedHelpers } from 'vuex'
import TableTooltip from './TableTooltip.vue'
import SvgSortIcon from './svgs/SvgSortIcon.vue'
const { mapState, mapActions } = createNamespacedHelpers('filterableTable')
const { mapGetters, mapState, mapActions } = createNamespacedHelpers('filterableTable')
export default {
name: 'TableHeading',
Expand All @@ -52,14 +55,16 @@ export default {
},
computed: {
...mapGetters([
'getSelectedSort'
]),
...mapState({
tables (state) {
return state.tables
},
}),
columnUnsorted () { return this.currentSort.column !== this.heading.field },
cssVariables () {
const { bgColor, borderColor, borderStyle, borderWidth, fontFamily, fontWeight } = this.headings
Expand All @@ -74,29 +79,12 @@ export default {
}
},
currentSort () { return this.table.selectedSort },
currentSortIsDescending () { return !this.currentSort.ascending },
hasTooltip () { return 'tooltip' in this.heading },
headings () { return this.options.headings },
isNewSortAscending () { return this.columnUnsorted || this.currentSortIsDescending },
options () { return this.table.options },
sortingPayload () {
return {
tableId: this.tableId,
sortObj: {
column: this.heading.field,
ascending: this.isNewSortAscending
}
}
},
table () { return this.tables[this.tableId] },
tableIsSortable () { return this.options.sortable },
Expand All @@ -107,8 +95,20 @@ export default {
'updateSelectedSort'
]),
isNewSortAscending () { return this.columnUnsorted || this.currentSortIsDescending },
sortColumn () {
this.updateSelectedSort(this.sortingPayload)
const currentSort = this.getSelectedSort(this.tableId)
const isNewSortAscending = currentSort.column !== this.heading.field || !currentSort.ascending
const sortingPayload = {
tableId: this.tableId,
sortObj: {
column: this.heading.field,
ascending: isNewSortAscending
}
}
this.updateSelectedSort(sortingPayload)
this.$root.$emit('getNewItems')
},
}
Expand Down
8 changes: 6 additions & 2 deletions src/components/filterable-table/TableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@
class="button"
:href="item.pageUrl"
>
<svg-arrow class="button__svg" />
<portal-target name="row-link-icon">
<svg-arrow class="button__svg" />
</portal-target>
</a>

<button
v-else
class="button"
@click="openModal"
>
<svg-arrow class="button__svg" />
<portal-target name="row-link-icon">
<svg-arrow class="button__svg" />
</portal-target>
</button>
</p>
</div>
Expand Down

0 comments on commit 7bfbfed

Please sign in to comment.