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

Page editor: Use single source of truth for URL change #8074

Closed
wants to merge 1 commit into from

Conversation

fregante
Copy link
Contributor

@fregante fregante commented Mar 27, 2024

What does this PR do?

I was reviewing possible improvements for https://github.com/pixiebrix/pixiebrix-source/issues/322 and saw a comment mentioning this incongruence.

We already have a hook that listens to URL changes, we should use it to ensure UI consistency and avoid multiple listeners.

I think part of this can actually be dropped since we don't really do "URL permissions" anymore

Checklist

  • Add tests and/or storybook stories
  • Designate a primary reviewer: @grahamlangford

Copy link

codecov bot commented Mar 27, 2024

Codecov Report

Attention: Patch coverage is 82.60870% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 73.22%. Comparing base (13f40b9) to head (38c2099).

Files Patch % Lines
src/hooks/useGrantedPermissions.ts 81.81% 2 Missing ⚠️
src/pageEditor/PanelContent.tsx 83.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    pixiebrix/pixiebrix-extension#8074      +/-   ##
==========================================
- Coverage   73.22%   73.22%   -0.01%     
==========================================
  Files        1310     1310              
  Lines       40733    40734       +1     
  Branches     7568     7568              
==========================================
  Hits        29826    29826              
- Misses      10907    10908       +1     

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

export function updatePageEditor() {
navigationEvent.emit();
export default function useGrantedPermissions() {
return useAsyncExternalStore(subscribe, getSnapshot);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Gotta love this hook

jest
.mocked(useCurrentInspectedUrl)
.mockReturnValue("https://test.url#updated-url");
rerender(<PanelContent />);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this the right way to mock state changes and listen to useEffect calls? It works but I wonder if there's a better way

cc @fungairino

const dynamicElement = formStateToDynamicElement(activeElement);
updateDynamicElement(allFramesInInspectedTab, dynamicElement);
}
}, [dispatch, activeElement]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: this attempted to connectToContentScript when just the activeElement changed

if (currentUrl && permissions) {
dispatch(tabStateActions.connectToContentScript());
}
}, [dispatch, currentUrl, permissions]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We no longer add/remove URL permissions, so maybe we can drop this?

The only reason to keep it would be if the "permission changed" events are fired via enterprise policy change. I don't know if that's the case though

@fregante fregante marked this pull request as draft March 27, 2024 10:34
@fregante
Copy link
Contributor Author

Disregard, this is actually kinda wrong. The page editor should only connect to the content script when the document reloads, not when the URL changes.

@fregante fregante closed this Mar 27, 2024
@fregante fregante deleted the F/hooks/panel-content-useeffect branch March 27, 2024 11:00
fregante added a commit that referenced this pull request Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants