-
Notifications
You must be signed in to change notification settings - Fork 556
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: convert variable panel tabs to carbon (#4687)
* style: convert variable panel tabs to carbon * test: add panel header test back * refactor: add undefined check for first tab * refactor: use default layer color
- Loading branch information
Showing
6 changed files
with
262 additions
and
1 deletion.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
client/src/App/Carbon/ProcessInstance/BottomPanel/VariablePanel/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. Licensed under a proprietary license. | ||
* See the License.txt file for more information. You may not use this file | ||
* except in compliance with the proprietary license. | ||
*/ | ||
|
||
import {observer} from 'mobx-react'; | ||
import {when} from 'mobx'; | ||
|
||
import {flowNodeSelectionStore} from 'modules/stores/flowNodeSelection'; | ||
import {useEffect} from 'react'; | ||
import {variablesStore} from 'modules/stores/variables'; | ||
import {TabView} from 'modules/components/Carbon/TabView'; | ||
|
||
const VariablePanel = observer(function VariablePanel() { | ||
useEffect(() => { | ||
const variablesLoadedCheckDisposer = when( | ||
() => ['fetched', 'error'].includes(variablesStore.state.status), | ||
() => { | ||
variablesStore.setAreVariablesLoadedOnce(true); | ||
} | ||
); | ||
|
||
return () => { | ||
variablesStore.setAreVariablesLoadedOnce(false); | ||
variablesLoadedCheckDisposer(); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<TabView | ||
tabs={[ | ||
{ | ||
id: 'variables', | ||
label: 'Variables', | ||
content: <div>variables</div>, | ||
}, | ||
...(flowNodeSelectionStore.isRootNodeSelected | ||
? [] | ||
: [ | ||
{ | ||
id: 'input-mappings', | ||
label: 'Input Mappings', | ||
content: <div>input mappings</div>, | ||
}, | ||
{ | ||
id: 'output-mappings', | ||
label: 'Output Mappings', | ||
content: <div>output mappings</div>, | ||
}, | ||
]), | ||
]} | ||
/> | ||
); | ||
}); | ||
|
||
export {VariablePanel}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
client/src/modules/components/Carbon/TabView/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. Licensed under a proprietary license. | ||
* See the License.txt file for more information. You may not use this file | ||
* except in compliance with the proprietary license. | ||
*/ | ||
|
||
import {render, screen} from 'modules/testing-library'; | ||
import {ThemeProvider} from 'modules/theme/ThemeProvider'; | ||
import {TabView} from './index'; | ||
|
||
describe('TabView', () => { | ||
it('should render panel header if there is only one tab', () => { | ||
render( | ||
<TabView | ||
tabs={[ | ||
{ | ||
id: 'tab-1', | ||
label: 'First Tab', | ||
content: <div>Content of the first tab</div>, | ||
}, | ||
]} | ||
/>, | ||
{wrapper: ThemeProvider} | ||
); | ||
|
||
expect( | ||
screen.getByRole('heading', {name: 'First Tab'}) | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.queryByRole('tab', {name: 'First Tab'}) | ||
).not.toBeInTheDocument(); | ||
expect(screen.getByText('Content of the first tab')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render first tab by default', () => { | ||
render( | ||
<TabView | ||
tabs={[ | ||
{ | ||
id: 'tab-1', | ||
label: 'First Tab', | ||
content: <div>Content of the first tab</div>, | ||
}, | ||
{ | ||
id: 'tab-2', | ||
label: 'Second Tab', | ||
content: <div>Content of the second tab</div>, | ||
}, | ||
]} | ||
/>, | ||
{wrapper: ThemeProvider} | ||
); | ||
|
||
expect(screen.getByRole('tab', {name: 'First Tab'})).toBeInTheDocument(); | ||
expect(screen.getByRole('tab', {name: 'Second Tab'})).toBeInTheDocument(); | ||
|
||
expect(screen.getByText('Content of the first tab')).toBeVisible(); | ||
}); | ||
|
||
it('should switch between tabs', async () => { | ||
const {user} = render( | ||
<TabView | ||
tabs={[ | ||
{ | ||
id: 'tab-1', | ||
label: 'First Tab', | ||
content: <div>Content of the first tab</div>, | ||
}, | ||
{ | ||
id: 'tab-2', | ||
label: 'Second Tab', | ||
content: <div>Content of the second tab</div>, | ||
}, | ||
]} | ||
/>, | ||
{wrapper: ThemeProvider} | ||
); | ||
|
||
expect(screen.getByText('Content of the first tab')).toBeVisible(); | ||
|
||
await user.click(screen.getByRole('tab', {name: 'Second Tab'})); | ||
expect(screen.queryByText('Content of the first tab')).not.toBeVisible(); | ||
expect(screen.getByText('Content of the second tab')).toBeVisible(); | ||
|
||
await user.click(screen.getByRole('tab', {name: 'First Tab'})); | ||
expect(screen.getByText('Content of the first tab')).toBeVisible(); | ||
expect(screen.queryByText('Content of the second tab')).not.toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. Licensed under a proprietary license. | ||
* See the License.txt file for more information. You may not use this file | ||
* except in compliance with the proprietary license. | ||
*/ | ||
|
||
import {PanelHeader} from 'modules/components/Carbon/PanelHeader'; | ||
import {Container, Tab, Content} from './styled'; | ||
import {tracking} from 'modules/tracking'; | ||
import {Tabs, TabList, TabPanels, TabPanel} from '@carbon/react'; | ||
|
||
type TabType = { | ||
id: string; | ||
label: string; | ||
content: React.ReactNode; | ||
}; | ||
|
||
type Props = { | ||
tabs: TabType[]; | ||
eventName?: 'variables-panel-used'; | ||
dataTestId?: string; | ||
}; | ||
|
||
const TabView: React.FC<Props> = ({tabs = [], eventName, dataTestId}) => { | ||
return ( | ||
<Container data-testid={dataTestId}> | ||
{tabs.length === 1 && tabs[0] !== undefined ? ( | ||
<> | ||
<PanelHeader title={tabs[0].label} size="sm"></PanelHeader> | ||
<Content>{tabs[0].content}</Content> | ||
</> | ||
) : ( | ||
<Tabs> | ||
<TabList aria-label="Variable Panel Tabs"> | ||
{tabs.map(({id, label}) => ( | ||
<Tab | ||
key={id} | ||
onClick={() => { | ||
if (eventName !== undefined) { | ||
tracking.track({ | ||
eventName, | ||
toTab: id, | ||
}); | ||
} | ||
}} | ||
> | ||
{label} | ||
</Tab> | ||
))} | ||
</TabList> | ||
<TabPanels> | ||
{tabs.map(({id, content}) => ( | ||
<TabPanel key={id}>{content}</TabPanel> | ||
))} | ||
</TabPanels> | ||
</Tabs> | ||
)} | ||
</Container> | ||
); | ||
}; | ||
|
||
export {TabView}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH | ||
* under one or more contributor license agreements. Licensed under a proprietary license. | ||
* See the License.txt file for more information. You may not use this file | ||
* except in compliance with the proprietary license. | ||
*/ | ||
|
||
import styled from 'styled-components'; | ||
import {Tab as BaseTab} from '@carbon/react'; | ||
|
||
const Container = styled.div` | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
background-color: var(--cds-layer); | ||
`; | ||
|
||
const Content = styled.section` | ||
padding: var(--cds-spacing-05); | ||
`; | ||
|
||
const Tab = styled(BaseTab)` | ||
padding: 10px var(--cds-spacing-05) 8px !important; | ||
`; | ||
|
||
export {Container, Content, Tab}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters