-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] pivot: allow to sort the pivot on any column
This commit allows the user to right click on a pivot cell to sort the pivot on that column. closes #4998 Task: 3989395 Signed-off-by: Lucas Lefèvre (lul) <[email protected]>
- Loading branch information
1 parent
e858997
commit 4133585
Showing
22 changed files
with
1,070 additions
and
109 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
|
@@ -84,5 +84,6 @@ | |
</div> | ||
</t> | ||
</div> | ||
<PivotSortSection definition="props.definition" pivotId="props.pivotId"/> | ||
</t> | ||
</templates> |
86 changes: 86 additions & 0 deletions
86
...nents/side_panel/pivot/pivot_layout_configurator/pivot_sort_section/pivot_sort_section.ts
This file contains 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,86 @@ | ||
import { Component } from "@odoo/owl"; | ||
import { SpreadsheetChildEnv } from "../../../../.."; | ||
import { GRAY_100, GRAY_300, PRIMARY_BUTTON_BG } from "../../../../../constants"; | ||
import { formatValue } from "../../../../../helpers"; | ||
import { | ||
getFieldDisplayName, | ||
isSortedColumnValid, | ||
} from "../../../../../helpers/pivot/pivot_helpers"; | ||
import { PivotRuntimeDefinition } from "../../../../../helpers/pivot/pivot_runtime_definition"; | ||
import { _t } from "../../../../../translation"; | ||
import { PivotDomain, UID } from "../../../../../types"; | ||
import { css } from "../../../../helpers"; | ||
import { Section } from "../../../components/section/section"; | ||
|
||
interface Props { | ||
definition: PivotRuntimeDefinition; | ||
pivotId: UID; | ||
} | ||
|
||
css/* scss */ ` | ||
.o-pivot-sort { | ||
.o-sort-card { | ||
width: fit-content; | ||
background-color: ${GRAY_100}; | ||
border: 1px solid ${GRAY_300}; | ||
.o-sort-value { | ||
color: ${PRIMARY_BUTTON_BG}; | ||
} | ||
} | ||
} | ||
`; | ||
|
||
export class PivotSortSection extends Component<Props, SpreadsheetChildEnv> { | ||
static template = "o-spreadsheet-PivotSortSection"; | ||
static components = { | ||
Section, | ||
}; | ||
static props = { | ||
definition: Object, | ||
pivotId: String, | ||
}; | ||
|
||
get hasValidSort() { | ||
const pivot = this.env.model.getters.getPivot(this.props.pivotId); | ||
return ( | ||
!!this.props.definition.sortedColumn && | ||
isSortedColumnValid(this.props.definition.sortedColumn, pivot) | ||
); | ||
} | ||
|
||
get sortDescription() { | ||
const sortOrder = | ||
this.props.definition.sortedColumn?.order === "asc" ? _t("ascending") : _t("descending"); | ||
return _t("Sorted on column (%(ascOrDesc)s):", { | ||
ascOrDesc: sortOrder, | ||
}); | ||
} | ||
|
||
get sortValuesAndFields() { | ||
const sortedColumn = this.props.definition.sortedColumn; | ||
if (!sortedColumn) { | ||
return []; | ||
} | ||
const pivot = this.env.model.getters.getPivot(this.props.pivotId); | ||
const locale = this.env.model.getters.getLocale(); | ||
|
||
const currentDomain: PivotDomain = []; | ||
const sortValues: { field?: string; value: string }[] = []; | ||
for (const domainItem of sortedColumn.domain) { | ||
currentDomain.push(domainItem); | ||
const { value, format } = pivot.getPivotHeaderValueAndFormat(currentDomain); | ||
const label = formatValue(value, { format, locale }); | ||
const field = pivot.definition.getDimension(domainItem.field); | ||
sortValues.push({ field: getFieldDisplayName(field), value: label }); | ||
} | ||
|
||
if (sortedColumn.domain.length === 0) { | ||
sortValues.push({ value: _t("Total") }); | ||
} | ||
const measureLabel = pivot.getMeasure(sortedColumn.measure).displayName; | ||
sortValues.push({ value: measureLabel, field: _t("Measure") }); | ||
|
||
return sortValues; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...ents/side_panel/pivot/pivot_layout_configurator/pivot_sort_section/pivot_sort_section.xml
This file contains 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,19 @@ | ||
<templates> | ||
<t t-name="o-spreadsheet-PivotSortSection"> | ||
<Section t-if="hasValidSort" class="'o-pivot-sort'"> | ||
<t t-set-slot="title">Sorting</t> | ||
<div t-esc="sortDescription" class="pb-2"/> | ||
<div class="d-flex flex-column gap-2"> | ||
<t t-foreach="sortValuesAndFields" t-as="valueAndField" t-key="valueAndField_index"> | ||
<div class="o-sort-card d-flex gap-1 px-2"> | ||
<t t-if="valueAndField.field"> | ||
<span class="fw-bolder" t-esc="valueAndField.field"/> | ||
= | ||
</t> | ||
<span class="fw-bolder o-sort-value" t-esc="valueAndField.value"/> | ||
</div> | ||
</t> | ||
</div> | ||
</Section> | ||
</t> | ||
</templates> |
This file contains 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 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 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 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 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.