Skip to content

Conversation

fdamhaut
Copy link
Contributor

@fdamhaut fdamhaut commented Jul 7, 2025

Description:

description of this task, what is implemented and why it is implemented that way.

Task: TASK_ID

review checklist

  • feature is organized in plugin, or UI components
  • support of duplicate sheet (deep copy)
  • in model/core: ranges are Range object, and can be adapted (adaptRanges)
  • in model/UI: ranges are strings (to show the user)
  • undo-able commands (uses this.history.update)
  • multiuser-able commands (has inverse commands and transformations where needed)
  • new/updated/removed commands are documented
  • exportable in excel
  • translations (_t("qmsdf %s", abc))
  • unit tested
  • clean commented code
  • track breaking changes
  • doc is rebuild (npm run doc)
  • status is correct in Odoo

@robodoo
Copy link
Collaborator

robodoo commented Jul 7, 2025

Pull request status dashboard

Add style and format sheet/col/row default.

This task is groundwork for the infinite viewport.

Task: 4852413
@fdamhaut fdamhaut force-pushed the master-infinite-style-flda branch from 0478283 to 4217257 Compare July 7, 2025 11:29
@@ -58,8 +60,8 @@ export class CellClipboardHandler extends AbstractCellClipboardHandler<
const pivotFormula = createPivotFormula(formulaPivotId, pivotCell);
cell = {
id: cell?.id || "",
style: cell?.style,
format: cell?.format,
style: style,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
style: style,
style,

Same everywhere

Copy link
Collaborator

@LucasLefevre LucasLefevre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is unclear to me while reading what cell.style is supposed be when there are default values.

As a more general comment, I think now it might be a good idea to move all the style management out of the cell core plugin to its own dedicated plugin and remove cell.style. We could use cell ids to set a style on specific cells to avoid all range adaptations etc.)
I didn't check every use of cell.style to see how it would change (there seems be a bit more than 40 uses)
WDYT ?

style: cell?.style,
format: evaluatedCell.format,
style: style,
format: evaluatedCell.format ?? format,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't evaluatedCell.format be the actual format (including the default format)

@@ -47,9 +47,17 @@ import {
import { CorePlugin } from "../core_plugin";
import { PositionMap } from "../ui_core_views/cell_evaluation/position_map";

interface sheetDefault<T> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
interface sheetDefault<T> {
interface SheetDefault<T> {

@@ -449,9 +498,18 @@ export class CellPlugin extends CorePlugin<CoreState> implements CoreState {
}

getCellStyle(position: CellPosition): Style {
return this.getters.getCell(position)?.style || {};
return this.getters.getCell(position)?.style || this.getDefaultCellStyle(position) || {};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return this.getters.getCell(position)?.style || this.getDefaultCellStyle(position) || {};
return this.getters.getCell(position)?.style ?? this.getDefaultCellStyle(position) ?? {};

Comment on lines +600 to +607
this.defaultStyle[sheetId]?.cols?.[col]
);
this.history.update(
"defaultFormat",
sheetId,
"cols",
col,
this.defaultFormat[sheetId]?.cols?.[col]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't it be refColumn 🤔 ? (-> tests are missing)

Suggested change
this.defaultStyle[sheetId]?.cols?.[col]
);
this.history.update(
"defaultFormat",
sheetId,
"cols",
col,
this.defaultFormat[sheetId]?.cols?.[col]
this.defaultStyle[sheetId]?.cols?.[refColumn]
);
this.history.update(
"defaultFormat",
sheetId,
"cols",
col,
this.defaultFormat[sheetId]?.cols?.[refColumn]

Comment on lines +610 to +614
for (const cell of this.getters.getCellFromZone(
sheetId,
this.getters.getColsZone(sheetId, refColumn, refColumn)
)) {
const { row } = this.getters.getCellPosition(cell.id);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (const cell of this.getters.getCellFromZone(
sheetId,
this.getters.getColsZone(sheetId, refColumn, refColumn)
)) {
const { row } = this.getters.getCellPosition(cell.id);
for (let row = 0; row < this.getters.getSheetSize(sheetId).numberOfRows; row++) {

smaller, faster ?
Or maybe it's because sheet won't have a numberOfRows with the infinite viewport ?
In that case:

Suggested change
for (const cell of this.getters.getCellFromZone(
sheetId,
this.getters.getColsZone(sheetId, refColumn, refColumn)
)) {
const { row } = this.getters.getCellPosition(cell.id);
for (let row = 0; row < this.getters.getColsZone(sheetId, refColumn, refColumn).bottom; row++) {

}
}

private updateCellStyleWithDefault(cell: Cell, style: Style | undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand when this method should be called. There's "default" in it's name but there's nothing related to this.defaultStyle in here. Also, I don't understand the deepEquals(cellStyle, style) ? null : cellStyle part where the style is reset. Why should it be reset ?

EDIT:

Also, I don't understand the deepEquals(cellStyle, style) ? null : cellStyle part where the style is reset. Why should it be reset ?

Ah ! is it because style is the same as the default style and it means it can be removed from the cell ? If yes, then I think it doesn't really matter if cell.style is equal to the default style if it simplifies the code and it avoids a deepEquals.
It could also be named more simply to something like addStyle

sheetId,
col,
row,
style: deepEquals(cellStyle, style) ? null : cellStyle,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at this point, we know the cell doesn't exist, so updating the style to null is useless

Comment on lines +59 to +60
defaultStyle: Record<UID, sheetDefault<Style> | undefined>;
defaultFormat: Record<UID, sheetDefault<Format> | undefined>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing import/export from/to json

Comment on lines +202 to +205
const cells = this.getters.getRowCells(sheetId, row);
let maxHeight = 0;
let tallestCell: CellWithSize | undefined = undefined;
for (let i = 0; i < cellIds.length; i++) {
const cell = this.getters.getCellById(cellIds[i]);
if (!cell) {
continue;
}
for (const cell of cells) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -173,3 +173,38 @@ describe("styles", () => {
);
});
});

describe("Default Styles", () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing tests for (at least):

  • copy-paste
  • add/remove col/rows
  • duplicate sheet
  • add default on top of existing style
  • add style on top of existing default

@LucasLefevre
Copy link
Collaborator

LucasLefevre commented Jul 11, 2025

I was thinking more yesterday evening. Why do we make a difference between the global/full rows/full cols and specific cells ? Couldn't we just apply style on ranges everywhere ? (if we remove cell.style/cell.format and move everything in a dedicated plugin managing those ranges)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants