Skip to content

Commit e7066a1

Browse files
author
David Kim
authored
fix: fix context menu styling and scroll bar issue (#3206)
* fix: fix context menu styling and scroll bar issue * fix: lint fix and test fix * fix: fix unit tests
1 parent 1ca0e91 commit e7066a1

File tree

4 files changed

+59
-38
lines changed

4 files changed

+59
-38
lines changed

src/authorizations/components/redesigned/ResourceAccordion.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ class ResourceAccordion extends Component<OwnProps> {
4949
<DapperScrollbars
5050
autoHide={true}
5151
autoSize={true}
52-
style={{width: '100%', maxHeight: '300px'}}
52+
// this width is max-width of modal - padding left and right
53+
style={{width: '100%', maxWidth: '752px', maxHeight: '300px'}}
5354
>
5455
<AllAccordionBody
5556
resourceName={resourceName}
@@ -70,7 +71,8 @@ class ResourceAccordion extends Component<OwnProps> {
7071
<DapperScrollbars
7172
autoHide={true}
7273
autoSize={true}
73-
style={{width: '100%', maxHeight: '300px'}}
74+
// this width is max-width of modal - padding left and right
75+
style={{width: '100%', maxWidth: '752px', maxHeight: '300px'}}
7476
>
7577
<AllAccordionBody
7678
resourceName="Other Resources"

src/authorizations/components/redesigned/TokenRow.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ describe('TokenRowResourceCard', () => {
3333
it('displays delete button', () => {
3434
const {getByTestId} = setup()
3535

36-
expect(getByTestId('delete-token')).toBeVisible()
36+
expect(getByTestId('context-delete-menu--button')).toBeVisible()
3737
})
3838
})

src/authorizations/components/redesigned/TokenRow.tsx

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import React, {PureComponent} from 'react'
2+
import React, {createRef, PureComponent, RefObject} from 'react'
33
import {connect, ConnectedProps} from 'react-redux'
44
import {createDateTimeFormatter} from 'src/utils/datetime/formatters'
55
import {withRouter, RouteComponentProps} from 'react-router-dom'
@@ -21,14 +21,16 @@ import {
2121
FlexDirection,
2222
JustifyContent,
2323
ComponentColor,
24-
Button,
2524
ResourceCard,
2625
IconFont,
2726
ButtonShape,
27+
Appearance,
28+
ConfirmationButton,
29+
List,
30+
Popover,
31+
SquareButton,
2832
} from '@influxdata/clockface'
2933

30-
import {Context} from 'src/clockface'
31-
3234
// Types
3335
import {Authorization, AppState} from 'src/types'
3436
import {
@@ -86,33 +88,46 @@ class TokensRow extends PureComponent<Props> {
8688
}
8789

8890
private get contextMenu(): JSX.Element {
89-
return (
90-
<Context>
91-
<FlexBox margin={ComponentSize.Medium}>
92-
<Button
93-
icon={IconFont.Duplicate}
94-
color={ComponentColor.Secondary}
95-
text="Clone"
96-
onClick={this.handleClone}
97-
testID="clone-token"
98-
size={ComponentSize.ExtraSmall}
99-
/>
91+
const settingsRef: RefObject<HTMLButtonElement> = createRef()
10092

101-
<Context.Menu
102-
icon={IconFont.Trash_New}
103-
color={ComponentColor.Danger}
104-
text="Delete"
105-
shape={ButtonShape.StretchToFit}
106-
size={ComponentSize.ExtraSmall}
107-
>
108-
<Context.Item
109-
label="Confirm"
110-
action={this.handleDelete}
111-
testID="delete-token"
112-
/>
113-
</Context.Menu>
114-
</FlexBox>
115-
</Context>
93+
return (
94+
<FlexBox margin={ComponentSize.ExtraSmall}>
95+
<ConfirmationButton
96+
color={ComponentColor.Colorless}
97+
icon={IconFont.Trash_New}
98+
shape={ButtonShape.Square}
99+
size={ComponentSize.ExtraSmall}
100+
confirmationLabel="Yes, delete this dashboard"
101+
onConfirm={this.handleDelete}
102+
confirmationButtonText="Confirm"
103+
testID="context-delete-menu"
104+
/>
105+
<SquareButton
106+
ref={settingsRef}
107+
size={ComponentSize.ExtraSmall}
108+
icon={IconFont.CogSolid_New}
109+
color={ComponentColor.Colorless}
110+
testID="context-menu-token"
111+
/>
112+
<Popover
113+
appearance={Appearance.Outline}
114+
enableDefaultStyles={false}
115+
style={{minWidth: '112px'}}
116+
contents={() => (
117+
<List>
118+
<List.Item
119+
onClick={this.handleClone}
120+
size={ComponentSize.Small}
121+
style={{fontWeight: 500}}
122+
testID="context-clone-token"
123+
>
124+
Clone
125+
</List.Item>
126+
</List>
127+
)}
128+
triggerRef={settingsRef}
129+
/>
130+
</FlexBox>
116131
)
117132
}
118133

src/authorizations/components/redesigned/TokensTab.test.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,17 @@ describe('TokensTab', () => {
123123
).toHaveTextContent('My token')
124124

125125
const deleteButton = tokenCard.querySelector(
126-
"[data-testid='delete-token']"
126+
"[data-testid='context-delete-menu--button']"
127127
)
128128

129+
fireEvent.click(deleteButton)
130+
129131
const tokenID = '03c03a8a64728000'
130132

131133
expect(ui.store.getState().resources.tokens.byID[tokenID]).toBeTruthy()
132134
expect(ui.store.getState().resources.tokens.allIDs).toContain(tokenID)
133135

134-
fireEvent.click(deleteButton)
136+
fireEvent.click(screen.getByText('Confirm'))
135137

136138
await waitFor(() => expect(deleteAuthorization).toBeCalled())
137139
expect(mocked(deleteAuthorization).mock.calls[0][0]['authID']).toEqual(
@@ -148,10 +150,12 @@ describe('TokensTab', () => {
148150
)
149151

150152
const tokenCard = (await screen.findAllByTestId('token-card My token'))[0]
153+
const menuButton = tokenCard.querySelector(
154+
"[data-testid='context-menu-token']"
155+
)
156+
fireEvent.click(menuButton)
151157

152-
const cloneButton = tokenCard.querySelector('[data-testid=clone-token]')
153-
154-
fireEvent.click(cloneButton)
158+
fireEvent.click(screen.getByText('Clone'))
155159

156160
await waitFor(() => expect(createAuthorization).toBeCalled())
157161
})

0 commit comments

Comments
 (0)