-
Notifications
You must be signed in to change notification settings - Fork 22
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
Upgrade DOM bricks to be root aware #4910
Conversation
Codecov Report
@@ Coverage Diff @@
## main #4910 +/- ##
==========================================
+ Coverage 57.97% 58.75% +0.77%
==========================================
Files 960 962 +2
Lines 28752 28899 +147
Branches 5521 5545 +24
==========================================
+ Hits 16670 16980 +310
+ Misses 12082 11919 -163
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
@@ -43,17 +43,17 @@ class CustomEventEffect extends Effect { | |||
required: ["eventName"], | |||
}; | |||
|
|||
override async isRootAware(): Promise<boolean> { |
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.
It wasn't declaring itself as root aware even though it was using the root
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -0,0 +1,91 @@ | |||
/* | |||
* Copyright (C) 2022 PixieBrix, Inc. |
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.
Please update the year
src/blocks/rootModeHelpers.ts
Outdated
if (!isRootAware && isEmpty(selector)) { | ||
throw new PropError( | ||
"Selector is required", | ||
blockId, | ||
selectorProp, | ||
selector | ||
); | ||
} | ||
|
||
if (isRootAware) { | ||
if (isEmpty(selector)) { | ||
return $(root); | ||
} | ||
|
||
return $safeFind(selector, root); | ||
} | ||
|
||
return $safeFind(selector, document); |
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: making it based on the isRootAware
, check it once and have 2 branches for isRootAware == true
and isRootAware == false
:
if (!isRootAware && isEmpty(selector)) { | |
throw new PropError( | |
"Selector is required", | |
blockId, | |
selectorProp, | |
selector | |
); | |
} | |
if (isRootAware) { | |
if (isEmpty(selector)) { | |
return $(root); | |
} | |
return $safeFind(selector, root); | |
} | |
return $safeFind(selector, document); | |
if (isRootAware) { | |
if (isEmpty(selector)) { | |
return $(root); | |
} | |
return $safeFind(selector, root); | |
} | |
if (isEmpty(selector)) { | |
throw new PropError( | |
"Selector is required", | |
blockId, | |
selectorProp, | |
selector | |
); | |
} | |
return $safeFind(selector, document); |
src/blocks/rootModeHelpers.ts
Outdated
* Special prop used to upgrade DOM bricks to be root-aware | ||
* @since 1.7.16 | ||
*/ | ||
export const IS_ROOT_AWARE_BRICK_PROPS = { |
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.
We could freeze the object, just to make sure it's never mutated.
Alternatively we can change the API , exporting a method which injects the isRootAware
property into a properties object:
inputSchema: Schema = propertiesToSchema(
addRootAwareProperty(
{
selector: {
@@ -45,34 +51,50 @@ export class AttachAutocomplete extends Effect {
type: "string",
},
},
}),
["options"]
);
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.
👍 I'll go ahead an freeze the object
|
||
const inputs = $elements | ||
.toArray() | ||
.filter((x) => !(x instanceof Document) && x.tagName === "INPUT"); |
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: Is !(x instanceof Document)
added just to fix a type error?
Looks unnecessary and a little bit confusing.
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.
$elements is a Document or HTMLElement. There's really no way of avoiding putting the check somewhere, and Typescript needs enough confidence that all of the array elements are HTMLElements
document.body.innerHTML = ` | ||
<html> | ||
<body> | ||
<div> |
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: there's one extra space in the indent.
@@ -130,7 +142,7 @@ export class TourEffect extends Effect { | |||
} | |||
|
|||
const [firstStep] = steps as Step[]; | |||
if ($safeFind(firstStep.element).length === 0) { | |||
if ($safeFind(firstStep.element, $root).length === 0) { |
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.
Can we use $safeFindElementsWithRootMode
to be consistent?
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.
We can't because the $safeFindElementsWithRootMode
assumes in its error message that the selector is a top level prop.
Tours will generally have multiple tour stops, so it's expected that the user is providing a selector for each tour stop
In the future, the user would use the Display Temporary Information brick with location: popover
to show a popover on a single element
{ selector, orientation = "infer" }: BlockArg, | ||
{ root }: BlockOptions | ||
): Promise<unknown> { | ||
const table = selector ? requireSingleElement(selector, root) : root; |
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.
Using root
implies that the Reader is root aware, doesn't it? If yes, it should provide the isRootAware
property.
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.
The brick was already rootAware with isRootAware() returning true. This PR makes the selector optional. So we don't need to add an isRootAware prop to the brick inputs
|
||
// The DOM brick is running in legacy mode. | ||
return ( | ||
<ConnectedFieldTemplate |
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 can be replaced by FieldTemplate
, it will skip unnecessary re-renders triggered by the Formik updates.
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.
I'd have to replicate the touched/error, etc. logic for it then. I think it's cleaner to use the connected component. We'll see if it has any impact on performance
src/components/form/widgets/switchButton/SwitchButtonWidget.tsx
Outdated
Show resolved
Hide resolved
11acf32
to
5e1dd2d
Compare
What does this PR do?
Reviewer Tips
isRootAware()
method overridenDemo
Future Work
Checklist