Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] clipboard: paste conditional format, data validation & merge content when original content is deleted #4170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Rachico
Copy link

@Rachico Rachico commented May 6, 2024

[IMP] clipboard: paste conditional format, data validation & merge content when original content is deleted

Problem

Before this commit, when copy/pasting cells with CF/DV/merge, if we delete the CF/DV/merge before pasting the cells, the paste content will not contain the previously copied content.

Solution

This commit solves the issue by adding new attributes cfRules, merges, dataValidationRules in the clipboard content and using the content saved in this key to re-create the features.

Task: 3870289

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 May 6, 2024

@Rachico Rachico force-pushed the master-keep-cf-and-merge-at-paste-mera branch 2 times, most recently from 852969d to 115f8e8 Compare May 10, 2024 12:24
@Rachico Rachico marked this pull request as ready for review May 10, 2024 12:26
@Rachico Rachico force-pushed the master-keep-cf-and-merge-at-paste-mera branch 5 times, most recently from 625d9a5 to e279183 Compare May 13, 2024 13:23
@rrahir
Copy link
Collaborator

rrahir commented May 15, 2024

-> change the title as a [FIX] : the rationale is the following - we currently lose information when copy/pasting and the current result is different from the intended one.

@Rachico Rachico force-pushed the master-keep-cf-and-merge-at-paste-mera branch from e279183 to 40ba85f Compare May 16, 2024 11:45
Copy link
Collaborator

@rrahir rrahir left a comment

Choose a reason for hiding this comment

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

Nice work, the tests seem good :)
As discussed, there are some issues with the current state of the clipboard (regarding the development of this feature) which should be generally addressed before implementing your solution.

See the related task

target: Zone[],
content: T1[][],
options?: ClipboardOptions,
clipboardContent?: T
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you sure you need to add a second key clipboardContent?
Wouldn't it be possible to just add more information in the content key just like you did in the merge clipboard?

Copy link
Collaborator

Choose a reason for hiding this comment

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

After discussing with Anthony:

  • the typing of T1 was set to be the minimal required information to manage the pasting
  • We can change it to whatever we want. -> content: T is an acceptable change

paste(target: ClipboardPasteTarget, clippedContent: T, options: ClipboardOptions | undefined) {}
paste(
target: ClipboardPasteTarget,
clippedContent: T | MinimalClipboardData,
Copy link
Collaborator

@rrahir rrahir May 16, 2024

Choose a reason for hiding this comment

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

T is a generic (https://www.typescriptlang.org/docs/handbook/2/generics.html), so it could be a MinimalClipboardData.

If you are certain this should be a minimalClipboardData (or undefined, as it can currently be the case), then it might be a plan to update it like you did for the isPastAllowed below.
However, I would discuss with @anhe-odoo first to see if he had a reason to use a generic here.

Copy link
Collaborator

Choose a reason for hiding this comment

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

After discussing with Anthony:
clippedContent was set as a generic such that every handler could define their own type and only deal with the data they wanted/cared about. It is a good approach and should stay that way.
On the other hand, nothing prevents us from having the type of the handler extending an interface representing the global keys found in the clipboard (more something like ClipboardCellData rahter that minimalClipboardData if possible).

@Rachico Rachico force-pushed the master-keep-cf-and-merge-at-paste-mera branch 8 times, most recently from ecb018d to e129216 Compare May 23, 2024 11:39
@Rachico Rachico changed the title [IMP] clipboard: keep CF and merge content when pasting a deleted CF or merge [IMP] clipboard: paste conditional format, data validation & merge content when original content is deleted May 23, 2024
@Rachico Rachico force-pushed the master-keep-cf-and-merge-at-paste-mera branch from e129216 to ce7d734 Compare May 23, 2024 12:42
Copy link
Contributor

@hokolomopo hokolomopo left a comment

Choose a reason for hiding this comment

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

👋

Soudns fine, with some minor details to fix. You should always avoid casting types, unless you really have no other choice. 🙂

this.pasteFromCopy(
sheetId,
zones,
clippedContent.cfRules as ClipboardConditionalFormat[][],
Copy link
Contributor

Choose a reason for hiding this comment

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

this cast looks wrong no ? clippedContent.cfRules can definetly have undefined values

Copy link
Author

Choose a reason for hiding this comment

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

@hokolomopo good point 👍

this.pasteFromCopy(
sheetId,
zones,
clippedContent.dataValidationRules as ClipboardDataValidationRule[][]
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment than for CFs

return;
}
const sheetId = this.getters.getActiveSheetId();
this.pasteFromCopy(sheetId, target.zones, content.cells, options);
this.pasteFromCopy(sheetId, target.zones, content.merges as Merge[][], options);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment. As a rule of thumb, if you have to cast something 90% of the times there's something wrong somewhere.

Comment on lines 42 to 46
if (!content.cells) {
return CommandResult.Success;
}
const clipboardHeight = content.cells.length;
const clipboardWidth = content.cells[0].length;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can replace content.cells by content.merges now no ? That way we don't reference cells, chich is introduced by another clipboard

@@ -1547,6 +1606,137 @@ describe("clipboard", () => {
expect(getStyle(model, "C2")).toEqual({});
});

test("copy cells with CF => remove origin CF => paste => it should paste with original CF", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, we should aim to make tests short and readable, rather than try to test absolutely everything. I don't think you need to test that every single command is successfully dispatched, nor do you need to test both than the cell content is pasted AND the CF is pasted AND that the Cf succefully is applied. That's a lot of bloating, making the test hard to understand at first glance IMO.

The test could be 15 lines instead of 60, only adding a CF => copy it => Remove the CF => paste => check the CF is pasted. We don't need to also test that we can paste cell values, nor that CF are correctly applied to the cells. It's tested somewhere else.

2 small general details:

  • try to prettify thing on single lines when you can. expect(getStyle(model, "A1")).toEqual({fillColor: "#00FF00" }); is short enough to be on a single line, no need to take 3 lines
  • if you want to test that a command behaved correctly, avoid testing toBeSuccessfullyDispatched but rather the state of the model after the command. For example here REMOVE_CONDITIONAL_FORMATwould have been dispatched, but not actually removed the CF. But again, you don't need to test that every single command is successful, I'd say to only test it if it helps the readability of the test.

Copy link
Contributor

Choose a reason for hiding this comment

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

(same comment for the next test)

@Rachico Rachico force-pushed the master-keep-cf-and-merge-at-paste-mera branch 3 times, most recently from 0c64a7e to b271631 Compare May 29, 2024 07:58
@Rachico Rachico requested review from hokolomopo and rrahir May 29, 2024 07:59
@Rachico Rachico force-pushed the master-keep-cf-and-merge-at-paste-mera branch 2 times, most recently from b86f3e1 to 6575968 Compare May 29, 2024 08:30
…ntent when original content is deleted

Currently, when copy/pasting cells with CF/DV/merge, if we delete the CF/DV/merge before pasting the cells, the paste content will not contain the previously copied content.

This commit solves the issue by adding new attributes cfRules, merges & dataValidationRules in the clipboard content and using the content saved in these keys to re-create the features.

Task: 3597039
@Rachico Rachico force-pushed the master-keep-cf-and-merge-at-paste-mera branch from 6575968 to 50c3d9d Compare May 29, 2024 13:14
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.

None yet

4 participants