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

feat(workspaces): change tab behavior to prevent modified tabs from being closed by accident COMPASS-5022 #5952

Merged
merged 12 commits into from
Jun 26, 2024

Conversation

gribnoysup
Copy link
Collaborator

@gribnoysup gribnoysup commented Jun 20, 2024

This is a POC that introduces a new system that allows tabs to control the flow of the closing behavior and additionally changes the tab opening / closing logic to align it more with what VSCode is doing.

New tab flow control interrface allows tabs to register handlers that can return a value telling the workspaces plugin whether or not the tab can be closed or replaced by another tab. In case of workspace communicating that it can't be replaced, new workspace will be opened in the new tab. In case of workspace communicating that it can't be closed, a confirmation modal will pop up on the screen asking to approve the close action.

Using this new interface, this patch also changes the tab opening behavior to the one that is closer to the VSCode behavior with some suggestions from @mcasimir.

  • When opening a new workspace
    • If similar workspace (as determined by isWorkspaceEqual method) already exists, move focus to the existing workspace
    • If workspace doesn't exist yet, try to open it over the current active tab
      • If the current active tab was interacted with (any click or keypress event inside the tab), open new workspace in the new tab next to the current active one
      • If the current tab wasn't touched yet, open workspace over the active tab
  • When closing a workspace
    • Only for "Aggregations": if pipeline was modified, ask for user confirmation before closing the tab
    • Otherwise just close the tab, even if the tab was interacted with (as described above)

I recorded some examples of the new behavior, but it's probably better to just pull the branch (or use the build when it's ready) and try it out locally.

Opening new tab over existing one:

Kapture 2024-06-20 at 11 45 46

Closing Aggregations tab with / without pipeline:

Kapture 2024-06-20 at 11 46 55

To be very clear: this is not a final behavior we already decided on, we're just trying out things more or less aligned with what design team is currently discussing, any suggestions are welcome and we definitely should define it in text somewhere and ask for confirmation from everyone involved in this discussion.

…ab closing flow; apply initial logic for preventing tabs from closing by accident
@gribnoysup gribnoysup added feat poc no release notes Fix or feature not for release notes labels Jun 20, 2024
@@ -164,6 +164,21 @@ export function activateWorkspacePlugin(
}
});

// TODO(COMPASS-8033): activate this code and account for it in e2e tests and
Copy link
Collaborator Author

@gribnoysup gribnoysup Jun 25, 2024

Choose a reason for hiding this comment

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

Splitting this out to a separate ticket. It works just fine in the browser, but it requires some extra research into how this will affect our e2e tests and generally electron environment where the browser warning is not shown (it just silently doesn't refresh the page)

@gribnoysup gribnoysup added release notes and removed poc no release notes Fix or feature not for release notes labels Jun 25, 2024
@gribnoysup gribnoysup changed the title feat(workspaces): provide an interface to allow tabs to control closing / replacing behavior feat(workspaces): change tab behavior to prevent modified tabs from being closed by accident COMPASS-5022 Jun 25, 2024
@gribnoysup gribnoysup marked this pull request as ready for review June 25, 2024 17:23
@@ -82,8 +132,7 @@ type CompassWorkspacesProps = {
onCreateTab(defaultTab?: OpenWorkspaceOptions | null): void;
onCloseTab(at: number): void;
onNamespaceNotFound(
tab: WorkspaceTab,
connectionId: string,
Copy link
Collaborator Author

@gribnoysup gribnoysup Jun 26, 2024

Choose a reason for hiding this comment

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

Drive-by: no point in having connectionId explicitly in the interface where it's already passed with the tab

packages/compass-workspaces/src/provider.tsx Outdated Show resolved Hide resolved
packages/compass-workspaces/src/provider.tsx Outdated Show resolved Hide resolved
@@ -53,6 +59,7 @@ export const cleanupLocalAppRegistries = () => {

export enum WorkspacesActions {
OpenWorkspace = 'compass-workspaces/OpenWorkspace',
OpenFallbackWorkspace = 'compass-workspace/OpenFallbackWorkspace',
Copy link
Collaborator Author

@gribnoysup gribnoysup Jun 26, 2024

Choose a reason for hiding this comment

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

Drive-by change: this should've always been a separate action, I was a bit lazy when adding this logic initially

packages/compass-workspaces/src/stores/workspaces.ts Outdated Show resolved Hide resolved
activeTabId: newActiveTabId,
tabs: newTabs,
};
return _bulkTabsClose({
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Drive-by: at some point this logic was factored out to a separate method, but this place that was the original place for this logic wasn't updated to use it, fixed

OpenWorkspaceAction | FetchCollectionInfoAction
> => {
return (
const fetchCollectionInfo = (
Copy link
Collaborator Author

@gribnoysup gribnoysup Jun 26, 2024

Choose a reason for hiding this comment

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

Just extracted to a separate thunk action from openWorkspace with no changes

@gribnoysup gribnoysup merged commit 514d005 into main Jun 26, 2024
30 checks passed
@gribnoysup gribnoysup deleted the poc-prevent-agg-tab-from-closing branch June 26, 2024 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants