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

Adds sidepanel open and close actions, and gives the user the option to disable click-outside closure of sidepanel #13488

Merged
merged 12 commits into from
Apr 26, 2024

Conversation

mike12345567
Copy link
Collaborator

Re-introduces #13463

PR opened for @aptkingston to comment on, original creator @mikesealey

…user the option to disable click-outside closure of sidepanel""
Copy link

linear bot commented Apr 15, 2024

Copy link
Member

@aptkingston aptkingston left a comment

Choose a reason for hiding this comment

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

Well done on your first contribution @mikesealey! I've tried to be reasonably verbose here to help explain the changes I've suggested.

Feel free to ask away with any questions if anything isn't clear :)

@@ -26,6 +29,10 @@
}
}

$: {
sidePanelStore.actions.setSidepanelState(clickOutsideToClose)
Copy link
Member

Choose a reason for hiding this comment

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

We can't use this store to store a single boolean here, because each side panel has its own setting for whether it can be clicked outside to close or not. By using a single store, multiple side panels will override each other and the last to render will "win" in case where we have multiple side panels (which we do have - like the table autoscreen).

One solution would be only setting this value when a certain side panel actually opens - because all we care about is handling the correct behaviour for the side panel that is currently open, and only one can be open at any given time.

The way you could do this is move this line to be inside the

if (open) {
...
}

statement down below.

This way the store is updated to reflect the desired behaviour whenever any side panel is opened.

"type": "boolean",
"key": "clickOutsideToClose",
"label": "Click outside to close",
"defaultValue": true
Copy link
Member

Choose a reason for hiding this comment

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

We can't default this to true, because all existing apps won't have this value set. For backwards compatibility we need to assume that the default value of any new settings are falsey, and invert the logic.

In this case, this new setting would have to something like "Ignore clicks outside" with a default value of false. This means all old apps will continue to work as normal and the new behaviour is opt in.

{
"type": "event",
"key": "onSidePanelClose",
"label": "On side panel close"
Copy link
Member

Choose a reason for hiding this comment

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

NAB: We should rename this to just "On close" to keep it in one line.

@@ -32,11 +33,19 @@ export const createSidePanelStore = () => {
}, 50)
}

const setSidepanelState = bool => {
Copy link
Member

Choose a reason for hiding this comment

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

We should use a more descriptive name here - setSidepanelState is very generic and doesn't describe what it's actually doing. I'd recommend something like setIgnoreClicksOutside (if you follow my suggestion for how to rename the setting, otherwise adapt appropriately).

@@ -32,11 +33,19 @@ export const createSidePanelStore = () => {
}, 50)
}

const setSidepanelState = bool => {
clearTimeout(timeout)
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to clear the timeout here - that's specifically for improving the opening/closing behaviour.

@@ -6723,7 +6723,21 @@
"illegalChildren": ["section", "sidepanel"],
"showEmptyState": false,
"draggable": false,
"info": "Side panels are hidden by default. They will only be revealed when triggered by the 'Open Side Panel' action."
"info": "Side panels are hidden by default. They will only be revealed when triggered by the 'Open Side Panel' action.",
"sendEvents": true,
Copy link
Member

Choose a reason for hiding this comment

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

Just confirming this is intentional. sendEvents will mean that we will send posthost events whenever this setting is changed by any user. We typically use it to track usage of certain things to improve our default behaviour. Just letting you know that in case this wasn't intentional.

},
{
"type": "event",
"key": "onSidePanelClose",
Copy link
Member

Choose a reason for hiding this comment

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

NAB: This can just be called onClose. This is already in the context of the side panel, so we don't need to repeat the name "side panel" inside the setting.

@@ -51,6 +64,7 @@
} else {
if (target.contains(node)) {
target.removeChild(node)
handleSidePanelClose()
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what the default svelte behaviour is here, but I would just double check that this won't invoke the close callback immediately on first render, when the side panel is closed by default.

@mikesealey
Copy link
Collaborator

Link to screen recording demonstration

Copy link
Member

@aptkingston aptkingston left a comment

Choose a reason for hiding this comment

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

LGTM (looks good to me)! Nice work @mikesealey. 🚀

@mikesealey mikesealey merged commit 93eb489 into master Apr 26, 2024
10 checks passed
@mikesealey mikesealey deleted the revert-13487-revert-13463-BUDI-8157 branch April 26, 2024 15:35
@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants