-
Notifications
You must be signed in to change notification settings - Fork 14k
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
refactor: Boostrap to AntD - Tabs #14048
Changes from all commits
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import Tabs, { TabsProps } from '.'; | ||
|
||
const { TabPane } = Tabs; | ||
|
||
export default { | ||
title: 'Tabs', | ||
component: Tabs, | ||
}; | ||
|
||
export const InteractiveTabs = (args: TabsProps) => ( | ||
<Tabs {...args}> | ||
<TabPane tab="Tab 1" key="1"> | ||
Content of Tab Pane 1 | ||
</TabPane> | ||
<TabPane tab="Tab 2" key="2"> | ||
Content of Tab Pane 2 | ||
</TabPane> | ||
<TabPane tab="Tab 3" key="3"> | ||
Content of Tab Pane 3 | ||
</TabPane> | ||
</Tabs> | ||
); | ||
|
||
InteractiveTabs.args = { | ||
defaultActiveKey: '1', | ||
animated: true, | ||
centered: false, | ||
fullWidth: false, | ||
allowOverflow: false, | ||
}; | ||
|
||
InteractiveTabs.argTypes = { | ||
onChange: { action: 'onChange' }, | ||
type: { | ||
defaultValue: 'line', | ||
control: { | ||
type: 'inline-radio', | ||
options: ['line', 'card', 'editable-card'], | ||
}, | ||
}, | ||
}; | ||
|
||
InteractiveTabs.story = { | ||
parameters: { | ||
knobs: { | ||
disable: true, | ||
}, | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,8 @@ | |
// ParentSize uses resize observer so the dashboard will update size | ||
// when its container size changes, due to e.g., builder side panel opening | ||
import { ParentSize } from '@vx/responsive'; | ||
import { TabContainer, TabContent, TabPane } from 'react-bootstrap'; | ||
import React, { FC, SyntheticEvent, useEffect, useState } from 'react'; | ||
import Tabs from 'src/components/Tabs'; | ||
import React, { FC, useEffect, useState } from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import DashboardGrid from 'src/dashboard/containers/DashboardGrid'; | ||
import getLeafComponentIdFromPath from 'src/dashboard/util/getLeafComponentIdFromPath'; | ||
|
@@ -33,13 +33,9 @@ import { getRootLevelTabIndex } from './utils'; | |
|
||
type DashboardContainerProps = { | ||
topLevelTabs?: LayoutItem; | ||
handleChangeTab: (event: SyntheticEvent<TabContainer, Event>) => void; | ||
}; | ||
|
||
const DashboardContainer: FC<DashboardContainerProps> = ({ | ||
topLevelTabs, | ||
handleChangeTab, | ||
}) => { | ||
const DashboardContainer: FC<DashboardContainerProps> = ({ topLevelTabs }) => { | ||
const dashboardLayout = useSelector<RootState, DashboardLayout>( | ||
state => state.dashboardLayout.present, | ||
); | ||
|
@@ -58,6 +54,9 @@ const DashboardContainer: FC<DashboardContainerProps> = ({ | |
? topLevelTabs.children | ||
: [DASHBOARD_GRID_ID]; | ||
|
||
const min = Math.min(tabIndex, childIds.length - 1); | ||
const activeKey = min === 0 ? DASHBOARD_GRID_ID : min.toString(); | ||
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. Ensures that the key of the first element is always |
||
|
||
return ( | ||
<div className="grid-container" data-test="grid-container"> | ||
<ParentSize> | ||
|
@@ -68,35 +67,29 @@ const DashboardContainer: FC<DashboardContainerProps> = ({ | |
the entire dashboard upon adding/removing top-level tabs, which would otherwise | ||
happen because of React's diffing algorithm | ||
*/ | ||
<TabContainer | ||
<Tabs | ||
id={DASHBOARD_GRID_ID} | ||
activeKey={Math.min(tabIndex, childIds.length - 1)} | ||
onSelect={handleChangeTab} | ||
// @ts-ignore | ||
animation | ||
mountOnEnter | ||
unmountOnExit={false} | ||
activeKey={activeKey} | ||
renderTabBar={() => <></>} | ||
rusackas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
fullWidth={false} | ||
> | ||
<TabContent> | ||
{childIds.map((id, index) => ( | ||
// Matching the key of the first TabPane irrespective of topLevelTabs | ||
// lets us keep the same React component tree when !!topLevelTabs changes. | ||
// This avoids expensive mounts/unmounts of the entire dashboard. | ||
<TabPane | ||
key={index === 0 ? DASHBOARD_GRID_ID : id} | ||
eventKey={index} | ||
> | ||
<DashboardGrid | ||
gridComponent={dashboardLayout[id]} | ||
// see isValidChild for why tabs do not increment the depth of their children | ||
depth={DASHBOARD_ROOT_DEPTH + 1} // (topLevelTabs ? 0 : 1)} | ||
width={width} | ||
isComponentVisible={index === tabIndex} | ||
/> | ||
</TabPane> | ||
))} | ||
</TabContent> | ||
</TabContainer> | ||
{childIds.map((id, index) => ( | ||
// Matching the key of the first TabPane irrespective of topLevelTabs | ||
// lets us keep the same React component tree when !!topLevelTabs changes. | ||
// This avoids expensive mounts/unmounts of the entire dashboard. | ||
<Tabs.TabPane | ||
key={index === 0 ? DASHBOARD_GRID_ID : index.toString()} | ||
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.
|
||
> | ||
<DashboardGrid | ||
gridComponent={dashboardLayout[id]} | ||
// see isValidChild for why tabs do not increment the depth of their children | ||
depth={DASHBOARD_ROOT_DEPTH + 1} // (topLevelTabs ? 0 : 1)} | ||
width={width} | ||
isComponentVisible={index === tabIndex} | ||
/> | ||
</Tabs.TabPane> | ||
))} | ||
</Tabs> | ||
)} | ||
</ParentSize> | ||
</div> | ||
|
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.
handleChangeTab
was never called during runtime and the function interfaces were not compatible:TabContainer.onSelect
does not providepathToTabIndex
to(event: SyntheticEvent<TabContainer, Event>) => void