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

feat: add onBeforePasteCell event to excel copy buffer #1298

Merged
merged 6 commits into from
Jan 4, 2024
Merged

feat: add onBeforePasteCell event to excel copy buffer #1298

merged 6 commits into from
Jan 4, 2024

Conversation

zewa666
Copy link
Contributor

@zewa666 zewa666 commented Dec 30, 2023

This adds the ability to define on a per cell basis whether a paste should be denied or allowed.

It can be configured with the new excelCopyBufferOption:

excelCopyBufferOptions: {
  onBeforePasteCell: (e, args) => {
    // only disable for first cell of a row
    return args.cell > 0;
  }
},

This is going to be a pre-requisite for the Row Based Edit Plugin

@zewa666
Copy link
Contributor Author

zewa666 commented Dec 30, 2023

I wasn't sure where to document this since there doesn't seem to be any kind of docs around for the CellExcelCopyManager. If you could point me to the proper place I'll update the docs as well.

Furthermore, I'm again not sure in which example to add this so that I can write a couple of Cypress tests.

Copy link

codecov bot commented Dec 30, 2023

Codecov Report

Attention: 14 lines in your changes are missing coverage. Please review.

Comparison is base (3bf3822) 93.7% compared to head (0fc96f1) 95.5%.
Report is 10 commits behind head on master.

Files Patch % Lines
packages/common/src/core/slickGrid.ts 50.0% 14 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1298     +/-   ##
========================================
+ Coverage    93.7%   95.5%   +1.9%     
========================================
  Files         198     198             
  Lines       21317   21336     +19     
  Branches     7089    7093      +4     
========================================
+ Hits        19956   20366    +410     
+ Misses       1361     970    -391     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -345,6 +371,12 @@ export class SlickCellExternalCopyManager {
}
}

protected trigger<ArgType = any>(evt: SlickEvent, args?: ArgType, e?: Event | SlickEventData) {
Copy link
Owner

Choose a reason for hiding this comment

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

so this looks like a full copy of the trigger method from SlickGrid, so perhaps we could just make the SlickGrid method as a public method and call it from here (and probably better to rename it as something like triggerEvent, or any other name, to be a little more specific)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was hesitant to ask for that but yep this would be my prefered solution as well

@ghiscoding
Copy link
Owner

ghiscoding commented Dec 30, 2023

I wasn't sure where to document this since there doesn't seem to be any kind of docs around for the CellExcelCopyManager. If you could point me to the proper place I'll update the docs as well.

Furthermore, I'm again not sure in which example to add this so that I can write a couple of Cypress tests.

I do have a excel-copy-buffer.md in the Angular-Slickgrid project, I might have forgot to copy it here (there's so much stuff to keep in sync with so many SlickGrid repos lol), you could copy it in the same grid functionalities folder and remove/update what's necessary

@zewa666
Copy link
Contributor Author

zewa666 commented Dec 31, 2023

alright your mentioned feedback should be addressed wit hthe last commit.

The last part would be to define which example to take. I thought I'd go with example19 and deny pasting on a couple of cells and a complete row to show off how it works.

@zewa666
Copy link
Contributor Author

zewa666 commented Dec 31, 2023

image

@ghiscoding
Copy link
Owner

ghiscoding commented Dec 31, 2023

looking good, did you wanted me to merge it now or did you wanted to add the Example 19 changes in this PR?

ohh I just noticed that slickCellExternalCopyManager.ts test coverage decreased by 3 lines it says, can that be addressed too? It seems to be your new onBeforePasteCell

@zewa666
Copy link
Contributor Author

zewa666 commented Dec 31, 2023

just wanted to make sure no 19 is the right one. yep I'll address the unit tests along with the cypress tests. but thats gonna happen next year. wish you a great new year 🥳

@zewa666
Copy link
Contributor Author

zewa666 commented Jan 1, 2024

hmmm cant figure out how to properly simulate copy & paste witb cypress. I've prepped the sample, although with a little linter issue. maybe you could take a look at how to achieve those e2e tests?

@ghiscoding
Copy link
Owner

There's a small build error preventing the Cypress to run, just changing e to _e should resolve the problem.

image

As for the Copy+Paste, I found this article Handling Copy and Paste in Cypress on eggheade.io, he's using .invoke which is required for pasting into an input value cy.get("[type='email']").invoke('val', textToPaste). I'm not exactly sure what you're trying to do, worst we can simply test it by hand and skip Cypress tests for now

@zewa666
Copy link
Contributor Author

zewa666 commented Jan 2, 2024

yep I've tried that but its not exactly doing whats expected since it works around the original browser paste behavior. I tried copying 3 consecutive cells and pasting them so that 2 cells are written but the 3rd overlaps with a blocked region. no matter what I tried I couldnt get it to perform the original browser behavior. so yeah I agree on skipping these. I'll later push the linter fix.

@ghiscoding
Copy link
Owner

note that I often have to use the force: true in Cypress to overcome some problems with it. Anyway skipping it is ok too, let me know when you want the PR to be merged, looking good so far

@zewa666
Copy link
Contributor Author

zewa666 commented Jan 4, 2024

@ghiscoding sry I've been sick the last two days and slowly recovering. I've fixed the linter issue and yeah I think we can go ahead and merge this, so that I can continue on my other branch

@zewa666
Copy link
Contributor Author

zewa666 commented Jan 4, 2024

hmm there is still an issue with coverage as it seems. need too check that. havent been able to notice which part is yet to be covered

@zewa666
Copy link
Contributor Author

zewa666 commented Jan 4, 2024

ok so it complains because I touched slickGrid.ts but it hasn't enough coverage I guess right? not sure that's something related to this PR, so from my side all fine and rdy for merge

@ghiscoding
Copy link
Owner

ghiscoding commented Jan 4, 2024

ok so it complains because I touched slickGrid.ts but it hasn't enough coverage I guess right? not sure that's something related to this PR, so from my side all fine and rdy for merge

no problem there, I've completed full coverage of SlickDataView yesterday but SlickGrid coverage will take a while longer, so it's fine don't worry about it, Codecov is a bit weird when coverage is missing, it will display that coverage is missing for x lines if you did touch these lines even if coverage didn't actually change.

Alright I'll go ahead and merge then, hopefully you recover soon, it's not a good year start but probably expected with all Christmas reunions 😅

@ghiscoding ghiscoding changed the title feat: add onBeforePasteCell event feat: add onBeforePasteCell event to excel copy buffer Jan 4, 2024
@ghiscoding ghiscoding merged commit 22037ca into ghiscoding:master Jan 4, 2024
4 of 5 checks passed
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.

2 participants