Skip to content

Commit e9bfa8c

Browse files
committed
refactor(version): show version in a snackbar
1 parent 8a2bc0e commit e9bfa8c

2 files changed

Lines changed: 13 additions & 29 deletions

File tree

src/views/search/Search.js

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { CloseOutline } from '@kyper/icon/CloseOutline'
1818
import { Search as SearchIcon } from '@kyper/icon/Search'
1919
import InputAdornment from '@mui/material/InputAdornment'
2020
import { TextField } from 'src/privacy/input'
21-
import { IconButton } from '@mui/material'
21+
import { IconButton, Snackbar } from '@mui/material'
2222

2323
import { __ } from 'src/utilities/Intl'
2424
import * as connectActions from 'src/redux/actions/Connect'
@@ -62,20 +62,6 @@ export const initialState = {
6262

6363
const MAX_SUGGESTED_LIST_SIZE = 25
6464

65-
const getVersionLabel = (version) => {
66-
// Check for SHA pattern
67-
if (typeof version === 'string' && /^[0-9a-f]{7,40}$/i.test(version)) {
68-
return `v.${version.slice(0, 7)}`
69-
}
70-
71-
// Trim a string that isn't a SHA pattern
72-
if (typeof version === 'string' && version.trim() !== '') {
73-
return `v.${version.trim()}`
74-
}
75-
76-
return ''
77-
}
78-
7965
const reducer = (state, action) => {
8066
switch (action.type) {
8167
case SEARCH_ACTIONS.LOAD_SUCCESS:
@@ -172,7 +158,6 @@ export const Search = React.forwardRef((_, navigationRef) => {
172158

173159
const MINIMUM_SEARCH_LENGTH = 2
174160
const isFirstTimeUser = connectedMembers.length === 0
175-
const versionLabel = getVersionLabel(widgetVersion)
176161

177162
useImperativeHandle(navigationRef, () => {
178163
return {
@@ -358,11 +343,12 @@ export const Search = React.forwardRef((_, navigationRef) => {
358343
{__('Select your institution')}
359344
</Text>
360345
{/* This version is a hidden feature unless a user is told how to find it */}
361-
{headerClicks >= 5 && versionLabel && (
362-
<Text data-test="search-version-label" style={inlineStyles.version}>
363-
{versionLabel}
364-
</Text>
365-
)}
346+
<Snackbar
347+
autoHideDuration={6000}
348+
message={widgetVersion}
349+
onClose={() => setHeaderClicks(0)}
350+
open={headerClicks >= 5 && Boolean(widgetVersion)}
351+
/>
366352
<TextField
367353
InputProps={{
368354
startAdornment: (

src/views/search/__tests__/Search-test.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,32 +93,30 @@ describe('Search View', () => {
9393
render(<Search {...defaultProps} ref={ref} />, { store })
9494

9595
const header = await screen.findByText('Select your institution')
96-
expect(screen.queryByText('v.abcdef1')).not.toBeInTheDocument()
96+
expect(screen.queryByRole('alert')).not.toBeInTheDocument()
9797

9898
for (let i = 0; i < 5; i++) {
9999
fireEvent.click(header)
100100
}
101101

102-
expect(await screen.findByText('v.abcdef1')).toBeInTheDocument()
102+
expect(await screen.findByRole('alert')).toHaveTextContent('abcdef1234567')
103103
})
104104

105-
it('does not show version after five clicks when version is not provided', async () => {
105+
it('does not show version snackbar after five clicks when version is not provided', async () => {
106106
const ref = React.createRef()
107107
const store = createTestReduxStore()
108108

109-
const { container } = render(<Search {...defaultProps} ref={ref} />, { store })
109+
render(<Search {...defaultProps} ref={ref} />, { store })
110110

111111
const header = await screen.findByText('Select your institution')
112-
expect(container.querySelector('[data-test="search-version-label"]')).not.toBeInTheDocument()
112+
expect(screen.queryByRole('alert')).not.toBeInTheDocument()
113113

114114
for (let i = 0; i < 5; i++) {
115115
fireEvent.click(header)
116116
}
117117

118118
await waitFor(() => {
119-
expect(
120-
container.querySelector('[data-test="search-version-label"]'),
121-
).not.toBeInTheDocument()
119+
expect(screen.queryByRole('alert')).not.toBeInTheDocument()
122120
})
123121
})
124122
})

0 commit comments

Comments
 (0)