-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: rrahir <rar@odoo.com> Co-authored-by: Pierre Rousseau <pro@odoo.com>
- Loading branch information
Showing
50 changed files
with
3,224 additions
and
156 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 @@ | ||
/** | ||
* The only aim of this file is to make ts-jest happy, as it does not support | ||
* Object.groupBy and Map.groupBy at the current version (29.1.2) | ||
* This is a workaround to make it work. | ||
*/ | ||
|
||
interface ObjectConstructor { | ||
/** | ||
* Groups members of an iterable according to the return value of the passed callback. | ||
* @param items An iterable. | ||
* @param keySelector A callback which will be invoked for each item in items. | ||
*/ | ||
groupBy<K extends PropertyKey, T>( | ||
items: Iterable<T>, | ||
keySelector: (item: T, index: number) => K | ||
): Partial<Record<K, T[]>>; | ||
} | ||
|
||
interface MapConstructor { | ||
/** | ||
* Groups members of an iterable according to the return value of the passed callback. | ||
* @param items An iterable. | ||
* @param keySelector A callback which will be invoked for each item in items. | ||
*/ | ||
groupBy<K, T>(items: Iterable<T>, keySelector: (item: T, index: number) => K): Map<K, T[]>; | ||
} |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
14 changes: 9 additions & 5 deletions
14
src/components/side_panel/pivot/pivot_dimensions/pivot_dimension/pivot_dimension.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
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
30 changes: 30 additions & 0 deletions
30
src/components/side_panel/pivot/pivot_preview/pivot_preview.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,30 @@ | ||
import { Component, useRef } from "@odoo/owl"; | ||
import { getPivotHighlights } from "../../../../helpers/pivot/pivot_highlight"; | ||
import { css } from "../../../helpers"; | ||
import { useHighlightsOnHover } from "../../../helpers/highlight_hook"; | ||
|
||
css/* scss */ ` | ||
.o_pivot_preview { | ||
cursor: pointer; | ||
&:hover { | ||
background-color: #f1f3f4; | ||
} | ||
} | ||
`; | ||
|
||
export class PivotPreview extends Component { | ||
static template = "o-spreadsheet-PivotPreview"; | ||
static props = { pivotId: String }; | ||
setup() { | ||
const previewRef = useRef("pivotPreview"); | ||
useHighlightsOnHover(previewRef, this); | ||
} | ||
|
||
selectPivot() { | ||
this.env.openSidePanel("PivotSidePanel", { pivotId: this.props.pivotId }); | ||
} | ||
|
||
get highlights() { | ||
return getPivotHighlights(this.env.model.getters, this.props.pivotId); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/components/side_panel/pivot/pivot_preview/pivot_preview.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,10 @@ | ||
<templates> | ||
<t t-name="o-spreadsheet-PivotPreview"> | ||
<div | ||
class="o_pivot_preview p-4 border-bottom" | ||
t-ref="pivotPreview" | ||
t-on-click="this.selectPivot"> | ||
<span t-esc="env.model.getters.getPivotDisplayName(props.pivotId)"/> | ||
</div> | ||
</t> | ||
</templates> |
35 changes: 35 additions & 0 deletions
35
src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel.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,35 @@ | ||
import { Component } from "@odoo/owl"; | ||
import { SpreadsheetChildEnv, UID } from "../../../.."; | ||
import { pivotSidePanelRegistry } from "../../../../helpers/pivot/pivot_side_panel_registry"; | ||
import { Section } from "../../components/section/section"; | ||
import { PivotDimensions } from "../pivot_dimensions/pivot_dimensions"; | ||
import { PivotPreview } from "../pivot_preview/pivot_preview"; | ||
|
||
interface Props { | ||
pivotId?: UID; | ||
onCloseSidePanel: () => void; | ||
} | ||
|
||
export class PivotSidePanel extends Component<Props, SpreadsheetChildEnv> { | ||
static template = "o-spreadsheet-PivotSidePanel"; | ||
static props = { | ||
pivotId: { type: String, optional: true }, | ||
onCloseSidePanel: Function, | ||
}; | ||
static components = { | ||
PivotDimensions, | ||
Section, | ||
PivotPreview, | ||
}; | ||
|
||
get sidePanelEditor() { | ||
if (!this.props.pivotId) { | ||
throw new Error("pivotId is required to call this function."); | ||
} | ||
const pivot = this.env.model.getters.getPivotCoreDefinition(this.props.pivotId); | ||
if (!pivot) { | ||
throw new Error("pivotId does not correspond to a pivot."); | ||
} | ||
return pivotSidePanelRegistry.get(pivot.type).editor; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/components/side_panel/pivot/pivot_side_panel/pivot_side_panel.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,10 @@ | ||
<templates> | ||
<t t-name="o-spreadsheet-PivotSidePanel"> | ||
<t t-if="props.pivotId" t-component="sidePanelEditor" t-props="props"/> | ||
<t t-else=""> | ||
<t t-foreach="env.model.getters.getPivotIds()" t-as="pivotId" t-key="pivotId"> | ||
<PivotPreview pivotId="pivotId"/> | ||
</t> | ||
</t> | ||
</t> | ||
</templates> |
106 changes: 106 additions & 0 deletions
106
...panel/pivot/pivot_side_panel/pivot_spreadsheet_side_panel/pivot_spreadsheet_side_panel.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,106 @@ | ||
import { Component, useState } from "@odoo/owl"; | ||
import { SpreadsheetChildEnv } from "../../../../.."; | ||
import { splitReference, toZone } from "../../../../../helpers"; | ||
import { SpreadsheetPivotRuntimeDefinition } from "../../../../../helpers/pivot/spreadsheet_pivot"; | ||
import { Store, useLocalStore } from "../../../../../store_engine"; | ||
import { PivotSidePanelStore } from "../../../../../stores/pivot_side_panel_store"; | ||
import { _t } from "../../../../../translation"; | ||
import { UID } from "../../../../../types"; | ||
import { SpreadsheetPivotCoreDefinition } from "../../../../../types/pivot"; | ||
import { SelectionInput } from "../../../../selection_input/selection_input"; | ||
import { Section } from "../../../components/section/section"; | ||
import { EditableName } from "../../editable_name/editable_name"; | ||
import { PivotDimensions } from "../../pivot_dimensions/pivot_dimensions"; | ||
|
||
interface Props { | ||
pivotId: UID; | ||
onCloseSidePanel: () => void; | ||
} | ||
|
||
export class PivotSpreadsheetSidePanel extends Component<Props, SpreadsheetChildEnv> { | ||
static template = "o-spreadsheet-PivotSpreadsheetSidePanel"; | ||
static props = { | ||
pivotId: String, | ||
onCloseSidePanel: Function, | ||
}; | ||
static components = { | ||
PivotDimensions, | ||
Section, | ||
SelectionInput, | ||
EditableName, | ||
}; | ||
store!: Store<PivotSidePanelStore>; | ||
|
||
state!: { range: string }; | ||
|
||
setup() { | ||
this.store = useLocalStore(PivotSidePanelStore, this.props.pivotId); | ||
this.pivot.loadSync(); //TODOPRO Should be different IMO | ||
this.state = useState({ | ||
range: this.env.model.getters.getRangeString(this.definition.range, "forceSheetReference"), | ||
}); | ||
// this.range = zoneToXc(this.definition.range.zone); | ||
} | ||
get pivot() { | ||
return this.env.model.getters.getPivot(this.props.pivotId); | ||
} | ||
|
||
get name() { | ||
return this.env.model.getters.getPivotName(this.props.pivotId); | ||
} | ||
|
||
get displayName() { | ||
return this.env.model.getters.getPivotDisplayName(this.props.pivotId); | ||
} | ||
|
||
get definition(): SpreadsheetPivotRuntimeDefinition { | ||
return this.pivot.definition as SpreadsheetPivotRuntimeDefinition; | ||
} | ||
|
||
onSelectionChanged(ranges: string[]) { | ||
this.state.range = ranges[0]; | ||
} | ||
|
||
onSelectionConfirmed() { | ||
if (this.state.range) { | ||
const { sheetName, xc } = splitReference(this.state.range); | ||
const sheetId = sheetName | ||
? this.env.model.getters.getSheetIdByName(sheetName) | ||
: this.env.model.getters.getActiveSheetId(); | ||
const zone = toZone(xc); | ||
this.store.update({ sheetId, zone }); | ||
} | ||
} | ||
|
||
duplicatePivot() { | ||
const newPivotId = this.env.model.uuidGenerator.uuidv4(); | ||
const result = this.env.model.dispatch("DUPLICATE_PIVOT", { | ||
pivotId: this.props.pivotId, | ||
newPivotId, | ||
}); | ||
const text = result.isSuccessful | ||
? _t('Pivot duplicated. Use the "Re-insert pivot" menu item to insert it in a sheet.') | ||
: _t("Pivot duplication failed"); | ||
const type = result.isSuccessful ? "success" : "danger"; | ||
this.env.notifyUser({ | ||
text, | ||
sticky: false, | ||
type, | ||
}); | ||
if (result.isSuccessful) { | ||
this.env.openSidePanel("PivotSidePanel", { pivotId: newPivotId }); | ||
} | ||
} | ||
|
||
onNameChanged(name: string) { | ||
this.store.update({ name }); | ||
} | ||
|
||
onDimensionsUpdated(definition: Partial<SpreadsheetPivotCoreDefinition>) { | ||
this.store.update(definition); | ||
} | ||
|
||
back() { | ||
this.env.openSidePanel("PivotSidePanel", {}); | ||
} | ||
} |
Oops, something went wrong.