-
-
Notifications
You must be signed in to change notification settings - Fork 18
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
WIP: Feature: Add setting to ignore components #136
base: master
Are you sure you want to change the base?
Conversation
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.
Just some spelling errors
Thanks. I think you can suggest the change directly in the review then I can just "accept it" Had to change a filename though anyway. |
I thought this was the case but trying to do this on the other PR and it doesn't seem to work as it did before. hmm edit: Ah you press the "Add suggestion" icon |
packages/simulator/utils.js
Outdated
@@ -15,7 +15,7 @@ export async function injectPanel(containerNode) { | |||
// this contains all sorts of CSS tags etc | |||
containerNode.innerHTML = rawPanelHtml | |||
// keep only the Alpine components in the panel | |||
const panelAppHtml = Array.from(containerNode.querySelectorAll('[x-data]')) | |||
const panelAppHtml = Array.from(containerNode.querySelectorAll('#devtools-container > [x-data]')) |
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.
Thinking this will only work on the simulator. Will see what i can do. It's otherwise duplicating the settings page.
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.
How about adding data-testid
s to the panel "root" components, data-testid="panel-root"
maybe?
Would have to be added to both
<div x-data x-show="false" class="preload">Devtools loading...</div> |
and
<div id="app" class="h-full" x-cloak x-data="devtools()" x-init="init()" x-spread="devtoolsRootDirectives()"> |
Should keep the selectors simpler and it matches our use-case (we're selecting using the testid's for dev/testing purposes only)
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.
Updated now if you want to check it
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.
Looks good to me
@@ -12,7 +12,7 @@ | |||
</style> | |||
</head> | |||
|
|||
<body class="antialiased"> | |||
<body id="devtools-container" class="antialiased"> |
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.
@HugoDF It doesn't seem like this is hurting anything, but is there something I'm maybe missing?
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.
there isn't but it might work out better to use testid's on the "root panel components" we want to inject in the simulator (see #136 (comment))
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.
Just realized the map is only run in the simulator anyway, so it's not necessary here regardless.
Accessing storage seems quite involved so probably worth chatting about it. Not entirely sure how to set up the communication from background.js to the devtools without some big refactoring or just adding a separate channel I think it needs to be separate from the existing proxy that is set up, right? Essentially, I think we want to do this: // background.js
chrome.storage.sync.get(['alpine-devtools-settings'], (result) => {
// Load alpine in here so the initial settings can be passed in
})
chrome.storage.onChanged.addListener((changes, namespace) => {
// not sure how this works yet, but it should push an update to devtools when a setting is changed elsewhere
})
function updateSettings(settings) {
chrome.storage.sync.set({'alpine-devtools-settings': settings}, () => {
// report back OK or not
})
}) // devtools.js
// Should have a listener for the sync update and a function to talk back to background.js edit: Looks like you added something like I was thinking about on the warnings PR, right? Should we maybe create a generic API with a handler function? |
@KevinBatdorf how about using Does that have access to storage? Since it's creating the panel I'm thinking it might be able to send it some data |
Otherwise in https://www.github.com/alpine-collective/alpinejs-devtools/tree/master/packages%2Fshell-chrome%2Fsrc%2Fbackground.js You've got access to all the "tabs" (using |
@HugoDF I looked into this finally and it's actually an issue with the simulator. The sync settings work fine using the actual devtools. So what that means is we can't test anything and it's slightly more annoying to develop. I'm thinking maybe we just hold off on having a settings page for now and focus on other improvements? |
That kind of makes sense, I think it's fine to have the settings page untested (unless there's an easy way to fake it) |
Yeah we can stub out some defaults for basic testing and show an error message. The error message we're getting is "Error: Cannot read property 'sync' of undefined" from |
Yeah let's do that to get existing tests passing. You said it's all working just not in the simulator? That's fine |
Another blocker is that you can't dispatch events like you do in the browser. I haven't wrapped my head around how the communication works from front -> back -> front, etc either. Not sure the best way to communicate between components otherwise, so now the settings component will just re-try until the data is available. It's probably ok. I'll try to work on it some more tomorrow. |
Status update. So the sync works and settings are saving properly. The issue I'm facing now is that we need to be able to access the settings from the backend.js before the front devtools renders, and I'm not entirely clear on how the back and front communicate to each other. It needs to happen right before this line: That way we can filter out what gets sent to the devtools. @HugoDF You probably know best how to post a message to the front, get the settings, and send them to the back? |
🤔 so the way to do that is either to add it to the If that's too early/we dont have the data from storage at that point, we can send a fresh message when we do have the data, that'll trigger the component discovery & has the preferences (I haven't pulled this down and given it a go, when I do I can be more specific 🙂 or even PR something into this one) |
I'll try that out and see. But feel free to take over this PR and work on it if you have an idea. Just send me a DM if you will so we're not both working on changes. |
This also includes wiring up settings management in general, using the ignore setting as the example case.
TODO:
document.querySelectorAll()
with a default ofx-devtools-ignore
onChange
event to auto update devtools on change.https://developer.chrome.com/docs/extensions/reference/storage/
I'll share thoughts on the UI a bit more after I add an option and description, so we can discuss things early on.
But currently I tweaked things a bit to look like this: