-
-
Couldn't load subscription status.
- Fork 350
feat: implement tab close functionality with i18n support #2049
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
base: main
Are you sure you want to change the base?
Changes from all commits
bb9d7f0
ff2e881
08faa61
233d918
27dd17f
3926d29
ea59dcd
dc01bea
f5367f7
f801c7e
c0f2df5
aa0ce39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import {LinkOutlined} from '@ant-design/icons'; | ||
| import {Badge, Button, Spin, Tabs} from 'antd'; | ||
| import {Badge, Button, Dropdown, Spin, Tabs} from 'antd'; | ||
| import _ from 'lodash'; | ||
| import {useEffect} from 'react'; | ||
| import {useEffect, useState} from 'react'; | ||
| import {useNavigate} from 'react-router'; | ||
|
|
||
| import {BUTTON} from '../../constants/antd-types'; | ||
|
|
@@ -24,11 +24,12 @@ import SessionStyles from './Session.module.css'; | |
|
|
||
| const Session = (props) => { | ||
| const { | ||
| tabKey, | ||
| switchTabs, | ||
| serverType, | ||
| setServerType, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No such function exists. You probably wanted to use |
||
| server, | ||
| visibleProviders = [], | ||
| removeVisibleProvider, | ||
| caps, | ||
| capsUUID, | ||
| capsName, | ||
|
|
@@ -44,8 +45,9 @@ const Session = (props) => { | |
| } = props; | ||
|
|
||
| const navigate = useNavigate(); | ||
| const [activeTab, setActiveTab] = useState(SESSION_BUILDER_TABS.CAPS_BUILDER); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't quite see the reason in adding this, along with |
||
|
|
||
| const isAttaching = tabKey === 'attach'; | ||
| const isAttaching = serverType === 'attach'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure why this was changed. |
||
|
|
||
| const handleSelectServerTab = async (tab) => { | ||
| const {changeServerType, addCloudProvider} = props; | ||
|
|
@@ -56,20 +58,54 @@ const Session = (props) => { | |
| await changeServerType(tab); | ||
| }; | ||
|
|
||
| const handleTabChange = (tab) => { | ||
| setActiveTab(tab); | ||
| switchTabs(tab); | ||
| }; | ||
|
|
||
| const handleSwitchTabs = (tab) => { | ||
| switchTabs(tab); | ||
| setActiveTab(tab); | ||
| }; | ||
|
|
||
| const loadNewSession = async (caps, attachSessId = null) => { | ||
| if (await newSession(_.cloneDeep(caps), attachSessId)) { | ||
| navigate('/inspector', {replace: true}); | ||
| } | ||
| }; | ||
|
|
||
| const getContextMenu = (tabKey) => ({ | ||
| items: [ | ||
| { | ||
| key: 'closeTab', | ||
| label: t('Close tab'), | ||
| onClick: () => handleCloseTab(tabKey), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately this action will also trigger |
||
| disabled: tabKey === SERVER_TYPES.REMOTE, | ||
| }, | ||
| ], | ||
| }); | ||
|
|
||
| const handleContextMenu = (e) => { | ||
| e.preventDefault(); | ||
| e.stopPropagation(); | ||
| }; | ||
|
|
||
| const handleCloseTab = (tabKey) => { | ||
| if (tabKey !== SERVER_TYPES.REMOTE) { | ||
| removeVisibleProvider(tabKey); | ||
| if (serverType === tabKey) { | ||
| setServerType(SERVER_TYPES.REMOTE); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| const { | ||
| setLocalServerParams, | ||
| getSavedSessions, | ||
| setSavedServerParams, | ||
| initFromSessionFile, | ||
| setStateFromSessionFile, | ||
| setVisibleProviders, | ||
| bindWindowClose, | ||
| initFromQueryString, | ||
| saveSessionAsFile, | ||
|
|
@@ -79,7 +115,6 @@ const Session = (props) => { | |
| bindWindowClose(); | ||
| switchTabs(SESSION_BUILDER_TABS.CAPS_BUILDER); | ||
| await getSavedSessions(); | ||
| await setVisibleProviders(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason why this was removed? |
||
| await setSavedServerParams(); | ||
| await setLocalServerParams(); | ||
| initFromQueryString(loadNewSession); | ||
|
|
@@ -108,13 +143,17 @@ const Session = (props) => { | |
| key: SERVER_TYPES.REMOTE, | ||
| children: <ServerTabCustom {...props} />, | ||
| }, | ||
| ..._(visibleProviders).map((providerName) => { | ||
| ..._.map(visibleProviders, (providerName) => { | ||
| const provider = CloudProviders[providerName]; | ||
| if (!provider) { | ||
| return true; | ||
| } | ||
| return { | ||
| label: <div>{provider.tabhead()}</div>, | ||
| label: ( | ||
| <Dropdown menu={getContextMenu(providerName)} trigger={['contextMenu']}> | ||
| <div onContextMenu={(e) => handleContextMenu(e)}>{provider.tabhead()}</div> | ||
| </Dropdown> | ||
| ), | ||
| key: providerName, | ||
| children: provider.tab(props), | ||
| }; | ||
|
|
@@ -129,8 +168,8 @@ const Session = (props) => { | |
| </div> | ||
|
|
||
| <Tabs | ||
| activeKey={tabKey} | ||
| onChange={switchTabs} | ||
| activeKey={activeTab} | ||
| onChange={handleTabChange} | ||
| className={SessionStyles.scrollingTabCont} | ||
| items={[ | ||
| { | ||
|
|
@@ -149,7 +188,7 @@ const Session = (props) => { | |
| key: SESSION_BUILDER_TABS.SAVED_CAPS, | ||
| className: SessionStyles.scrollingTab, | ||
| disabled: savedSessions.length === 0, | ||
| children: <SavedSessions {...props} />, | ||
| children: <SavedSessions {...props} handleSwitchTabs={handleSwitchTabs} />, | ||
| }, | ||
| { | ||
| label: t('Attach to Session'), | ||
|
|
||
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.
It is enough to only add English resources. localized resources are synchronized automatically to crowdin as soon as the PR is merged and should not be changed manually.
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 only kept English resources