-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Grouping] improvements #27581
[Grouping] improvements #27581
Conversation
Pinging @elastic/kibana-canvas |
dba0e52
to
023c2dd
Compare
c40abaf
to
9afa0a1
Compare
💚 Build Succeeded |
9afa0a1
to
d9afefc
Compare
💚 Build Succeeded |
💚 Build Succeeded |
workpadState, | ||
['pages', pageIndex, getLocation(element.position.type)], | ||
trimElement(element) | ||
return elements.reduce( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: while I appreciate this bit, building an object and using assign might be easier to comprehend.
@@ -10,6 +10,7 @@ import { get } from 'lodash'; | |||
import * as actions from '../actions/elements'; | |||
|
|||
const getLocation = type => (type === 'group' ? 'groups' : 'elements'); | |||
const firstOccurrence = (element, index, array) => array.indexOf(element) === index; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a neat little de-duping helper, so rare to see that third arg used. 👍
nit: Since this is only used in 1 place, keeping it near where it's used is probably better for comprehension.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @w33ble! IIRC there are a few other places in the layout engine that use such a function except they're inlined; if that's the case, I'd move it to functional.js
and link to it from wherever else it's repeated now, otherwise move it near where it's used. Good you mentioned this rule of thumb, because otherwise I tended to put small, generic functions atop of files even if they were used only once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, your call if you want to address either of my nits or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 Thanks for fixing the duplicate page issue on old workpads. I just had one nitpick, but it's not a blocker.
({ dispatch, type }, element, pageId) => { | ||
const newElement = { ...getDefaultElement(), ...getBareElement(element) }; | ||
// move the element so users can see that it was added | ||
export const insertNodes = createThunk('insertNodes', ({ dispatch, type }, elements, pageId) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This function looks awfully similar to the addElement
function. Can we just delete addElement
and maybe rename this addElements
since it handles adding multiple elements?
The only difference is this function adds an offset to the position of the new element, but I feel like the offset could be added elsewhere. It'd be a nice refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* chore: remove asynchronous element selection * chore: remove duplication between duplicateElement and rawDuplicateElement * chore: renamed rawDuplicateElement to insertNodes (pure rename, not yet set based) * perf: bulk node insertion * chore: removed unnecessary element id duplications * fix: supply empty array if preexisting workbook had none
* chore: remove asynchronous element selection * chore: remove duplication between duplicateElement and rawDuplicateElement * chore: renamed rawDuplicateElement to insertNodes (pure rename, not yet set based) * perf: bulk node insertion * chore: removed unnecessary element id duplications * fix: supply empty array if preexisting workbook had none
* chore: remove asynchronous element selection * chore: remove duplication between duplicateElement and rawDuplicateElement * chore: renamed rawDuplicateElement to insertNodes (pure rename, not yet set based) * perf: bulk node insertion * chore: removed unnecessary element id duplications * fix: supply empty array if preexisting workbook had none
* chore: remove asynchronous element selection * chore: remove duplication between duplicateElement and rawDuplicateElement * chore: renamed rawDuplicateElement to insertNodes (pure rename, not yet set based) * perf: bulk node insertion * chore: removed unnecessary element id duplications * fix: supply empty array if preexisting workbook had none
Improvement to grouping:
setTimeout
insertNodes
actually insert multiple nodes, satisfying how I repurposed [Canvas] Perf: Turn duplicateElement and rawDuplicateElement actions into a single duplicateSubtree action #27447