Skip to content

Commit

Permalink
[FIX] pivot: autocomplete dimension after positional
Browse files Browse the repository at this point in the history
Steps to reproduce (in odoo)
- insert the default CRM pivot (grouped by date and stage)
- type in a cell =PIVOT.VALUE(1,"expected_revenue:sum","#create_date:month",1,

=> stage_id and #stage_id should be proposed.

A test is added with a PR in odoo ;)

closes #5107

Task: 4235329
X-original-commit: b50c0f2
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
  • Loading branch information
LucasLefevre committed Oct 21, 2024
1 parent 275a7cf commit b11155e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/registries/auto_completes/pivot_auto_complete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,13 @@ autoCompleteProviders.add("pivot_group_fields", {
const rowFields = rows.map((groupBy) => groupBy.nameWithGranularity);

const proposals: string[] = [];
const previousGroupBy = ["ARG_SEPARATOR", "SPACE"].includes(tokenAtCursor.type)
let previousGroupBy = ["ARG_SEPARATOR", "SPACE"].includes(tokenAtCursor.type)
? argGroupBys.at(-1)
: argGroupBys.at(-2);
const isPositionalSupported = supportedPivotPositionalFormulaRegistry.get(pivot.type);
if (isPositionalSupported && previousGroupBy?.startsWith("#")) {
previousGroupBy = previousGroupBy.slice(1);
}
if (previousGroupBy === undefined) {
proposals.push(colFields[0]);
proposals.push(rowFields[0]);
Expand All @@ -145,7 +149,7 @@ autoCompleteProviders.add("pivot_group_fields", {
})
.concat(
groupBys.map((groupBy) => {
if (!supportedPivotPositionalFormulaRegistry.get(pivot.type)) {
if (!isPositionalSupported) {
return undefined;
}
const fieldName = groupBy.split(":")[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export function createMeasureAutoComplete(
sequence: 0,
autoSelectFirstProposal: true,
getProposals(tokenAtCursor) {
// return []
const measureProposals = pivot.measures
.filter((m) => m !== forComputedMeasure)
.map((measure) => {
Expand Down

0 comments on commit b11155e

Please sign in to comment.