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

Plugin: add-rows-on-paste #599

Merged
merged 3 commits into from
Oct 16, 2024
Merged

Plugin: add-rows-on-paste #599

merged 3 commits into from
Oct 16, 2024

Conversation

richardliebmann
Copy link

This plugin adds new rows to the data if the number of entries is greater than the current data count.

Closes #338

Copy link
Contributor

@Techn1x Techn1x left a comment

Choose a reason for hiding this comment

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

looks great to me, thanks for writing this up

Comment on lines 29 to 33
const newRows = [];

for(let i = 0; i < count; i++) {
newRows.push({ index: rowLength + i, data: {} });
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be a handy shortcut

const newRows = Array.from({ length: count }, (_, i) => ({ index: rowLength + i, data: {} }))

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe loop works better and more efficient

Comment on lines 41 to 46
const items = this.providers.data.stores.rgRow.store.get('source');

items.push(...event.detail.newRows.map(j => j.data))


this.providers.data.setData(items);
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that we'e doing a items.push() (mutates the items array) and then also calling setData(items), are we mutating the data source twice here?

Wondering if this might be better, or maybe it doesn't matter;

const items = [
  ...this.providers.data.stores.rgRow.store.get('source'),
  ...event.detail.newRows.map(j => j.data)
]
this.providers.data.setData(items);

@richardliebmann
Copy link
Author

@Techn1x How would you recommend adding columns as well? This might be more difficult because of the mapping from column to object property?

@Techn1x
Copy link
Contributor

Techn1x commented Oct 11, 2024

This might be more difficult because of the mapping from column to object property?

Yeah you're totally right, didn't think of that. I think it's a fair assumption that columns are statically defined by the developr and won't change based on user pasting in data input

Copy link
Contributor

@Techn1x Techn1x left a comment

Choose a reason for hiding this comment

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

LGTM, though I am not a maintainer (and am actually fairly new to the library) so my review probably holds no weight :)

src/plugins/index.ts Outdated Show resolved Hide resolved
src/plugins/add-rows-on-past.plugin.ts Outdated Show resolved Hide resolved
src/plugins/add-rows-on-past.plugin.ts Outdated Show resolved Hide resolved
src/plugins/add-rows-on-past.plugin.ts Outdated Show resolved Hide resolved
@m2a2x
Copy link
Collaborator

m2a2x commented Oct 15, 2024

LGTM, though I am not a maintainer (and am actually fairly new to the library) so my review probably holds no weight :)

I believe that's the point of open source so everyone reviews holds wait :-)

Copy link

@richardliebmann richardliebmann requested a review from m2a2x October 16, 2024 12:27
@m2a2x m2a2x merged commit b703d75 into revolist:main Oct 16, 2024
1 check passed
@m2a2x
Copy link
Collaborator

m2a2x commented Oct 16, 2024

Thank you @richardliebmann, all merged, probably we'll add some more updates on it in the future if you don't mind.

@revolist revolist changed the title add plugin add-rows-on-past Plugin: add-rows-on-past Oct 18, 2024
@revolist revolist changed the title Plugin: add-rows-on-past Plugin: add-rows-on-paste Oct 18, 2024
@Techn1x
Copy link
Contributor

Techn1x commented Dec 16, 2024

Silly question but what path do I import this plugin from? There's docs on creating plugins but I am having trouble using 😄

import { AutoAddRowsPlugin } from '@revogrid/revolist/........'?

EDIT: nevermind, it's simply from the main path. Just had to read the source code and see how it was all being exported
import { AutoAddRowsPlugin } from '@revogrid/revolist'

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.

Copy paste should create new rows and columns
3 participants