From b11155e7986cf3fe1fb70a2a271c4852731d105a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Lef=C3=A8vre=20=28lul=29?= Date: Mon, 7 Oct 2024 14:31:39 +0000 Subject: [PATCH] [FIX] pivot: autocomplete dimension after positional 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 odoo/o-spreadsheet#5107 Task: 4235329 X-original-commit: b50c0f28610f9c7ee8856d4eb0580aefb0ff2cdd Signed-off-by: Pierre Rousseau (pro) --- src/registries/auto_completes/pivot_auto_complete.ts | 8 ++++++-- .../auto_completes/pivot_dimension_auto_complete.ts | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/registries/auto_completes/pivot_auto_complete.ts b/src/registries/auto_completes/pivot_auto_complete.ts index 970f3aef40..44c671c770 100644 --- a/src/registries/auto_completes/pivot_auto_complete.ts +++ b/src/registries/auto_completes/pivot_auto_complete.ts @@ -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]); @@ -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]; diff --git a/src/registries/auto_completes/pivot_dimension_auto_complete.ts b/src/registries/auto_completes/pivot_dimension_auto_complete.ts index a7bf755ede..2abe97b6b8 100644 --- a/src/registries/auto_completes/pivot_dimension_auto_complete.ts +++ b/src/registries/auto_completes/pivot_dimension_auto_complete.ts @@ -12,7 +12,6 @@ export function createMeasureAutoComplete( sequence: 0, autoSelectFirstProposal: true, getProposals(tokenAtCursor) { - // return [] const measureProposals = pivot.measures .filter((m) => m !== forComputedMeasure) .map((measure) => {