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
Allow GraphiQL apps control over closing tabs #3563
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 5b37ed0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3563 +/- ##
==========================================
- Coverage 55.33% 55.33% -0.01%
==========================================
Files 115 115
Lines 5349 5355 +6
Branches 1450 1452 +2
==========================================
+ Hits 2960 2963 +3
- Misses 1963 1964 +1
- Partials 426 428 +2
|
if (editorContext.activeTabIndex === index) { | ||
executionContext.stop(); | ||
onClick={async () => { | ||
if ( |
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 think we should move all of this into closeTab
itself, even what was directly in the handler here before, making it async. i see no reason to let this be an implementation detail for sdk users, as if the context they are using has this logic they would expect this as as an internal detail of the method if it's exposed to the user yeah?
const closeTab = useCallback<EditorContextType['closeTab']>(
async index => {
if (await closeTabConfirmation(index)) {
// this could be a breaking change for users who are already stopping
// execution manually like graphiql does, however stopping execution twice should not
// cause any errors?
if (index === tabState.activeTabIndex) {
stop();
}
setTabState(current => {
const updated = {
tabs: current.tabs.filter((_tab, i) => index !== i),
activeTabIndex: Math.max(current.activeTabIndex - 1, 0),
};
storeTabs(updated);
setEditorValues(updated.tabs[updated.activeTabIndex]);
onTabChange?.(updated);
return updated;
});
}
},
[
onTabChange,
setEditorValues,
storeTabs,
closeTabConfirmation,
tabState.activeTabIndex,
],
);
and then here in graphiql:
<Tab.Close
onClick={async () => editorContext.closeTab(index)}
/>
so then sdk users have this in const { openTab, closeTab } = useEditorContext()
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.
this is awesome, and makes a lot of sense! i'm glad you're able to achieve this with your app. just the one change,,I hope that's ok!
Absolutely, I don't mind a little boy scouting, looks much cleaner now overall. I think this looks good to go now. PS:
Yea, it totally works - but... Since the plugin is handling its own state management and its own data fetching, it is a bit tricky, since I need the top level component that mounts
|
@acao Are we good to go? |
fbb81ad
to
5b37ed0
Compare
Allow GraphiQL apps control over closing tabs
This feature is about closing tabs.
Current functionality:
Requested functionality
In our case, we are working on a Collection plugin that you can click to read saved queries / variables / headers from a DB, and this opens it in a new tab. So we need to sync tabState with the list of Collection items. And if a user starts to change a Collection item, we want to warn the user that changes will be lost.
It is the same as if the user selected a file in a code editor, started to change it, and then tries to close the tab.
Mock screenshots