Skip to content

Commit 80a0315

Browse files
authored
Merge pull request #585 from meilisearch/feat/add-side-panel-clean
Add side panel (without unrelated changes)
2 parents 377bb0c + c42a713 commit 80a0315

23 files changed

+747
-230
lines changed

cypress/e2e/cloud-banner.cy.js

Lines changed: 0 additions & 23 deletions
This file was deleted.

cypress/e2e/side-panel.cy.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
describe(`Right side panel`, () => {
2+
beforeEach(() => {
3+
cy.saveApiTokenCookie()
4+
cy.visit('/')
5+
})
6+
7+
it('Should be opened by default', () => {
8+
cy.get('[data-testid="right-panel"]').should('be.visible')
9+
})
10+
11+
it('Should be closed when clicking on the close button', () => {
12+
cy.get('button[aria-label="Close Panel"]').click()
13+
cy.get('[data-testid="right-panel"]').should('not.be.visible')
14+
})
15+
16+
it('Should be opened when clicking on the menu bars button', () => {
17+
cy.get('button[aria-label="Close Panel"]').click()
18+
cy.get('button[aria-label="Open Panel"]').click()
19+
cy.get('[data-testid="right-panel"]').should('be.visible')
20+
})
21+
})

cypress/e2e/test-interface.cy.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,6 @@ describe(`Test interface`, () => {
2323
cy.visit('/')
2424
})
2525

26-
it('Should open the help center on click on the "?" button', () => {
27-
cy.get('button[aria-label="help"]').click()
28-
cy.get('div[aria-label="Help Center"]').within(() => {
29-
cy.contains('Help Center')
30-
cy.contains(
31-
'If you need help with anything, here are a few links that can be useful.'
32-
)
33-
cy.contains('Explore our repositories on Github')
34-
cy.contains('Join our Discord and find the help you need')
35-
cy.contains('Learn how to tune your Meilisearch')
36-
cy.get('a')
37-
.first()
38-
.should('have.attr', 'href', 'https://github.com/meilisearch')
39-
.next()
40-
.should('have.attr', 'href', 'https://discord.meilisearch.com')
41-
.next()
42-
.should(
43-
'have.attr',
44-
'href',
45-
'https://docs.meilisearch.com/?utm_campaign=oss&utm_source=integration&utm_medium=minidashboard'
46-
)
47-
cy.get('button[aria-label="close"]').click()
48-
})
49-
})
50-
5126
it('Should contain a "Show more" button if a document has more than 6 fields', () => {
5227
cy.get('ul')
5328
.children()

cypress/support/commands.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ Cypress.Commands.add('addDocuments', async (uid, documents) => {
4545
console.log({ e })
4646
}
4747
})
48+
49+
Cypress.Commands.add('saveApiTokenCookie', () => {
50+
cy.window().then((win) => {
51+
win.localStorage.setItem('apiKey', JSON.stringify(apiKey))
52+
})
53+
})

jsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"compilerOptions": {
3-
"baseUrl": "src"
3+
"baseUrl": "src",
4+
"jsx": "react"
45
},
56
"include": ["src"]
67
}

src/App.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import { useMeilisearchClientContext } from 'context/MeilisearchClientContext'
1111
import useLocalStorage from 'hooks/useLocalStorage'
1212
import ApiKeyModalContent from 'components/ApiKeyModalContent'
1313
import Body from 'components/Body'
14-
import CloudBanner from 'components/CloudBanner'
1514
import Modal from 'components/Modal'
1615
import NoMeilisearchRunning from 'components/NoMeilisearchRunning'
1716
import ApiKeyAwarenessBanner from 'components/ApiKeyAwarenessBanner'
1817
import getIndexesListWithStats from 'utils/getIndexesListWithStats'
19-
import isCloudBannerEnabled from 'utils/isCloudBannerEnabled'
2018
import shouldDisplayApiKeyModal from 'utils/shouldDisplayApiKeyModal'
2119
import hasAnApiKeySet from 'utils/hasAnApiKeySet'
2220
import clientAgents from './version/client-agents'
@@ -38,7 +36,6 @@ const App = () => {
3836
const [isMeilisearchRunning, setIsMeilisearchRunning] = useState(false)
3937
const [requireApiKeyToWork, setRequireApiKeyToWork] = useState(false)
4038
const [currentIndex, setCurrentIndex] = useLocalStorage('currentIndex')
41-
const [showCloudBanner, setShowCloudBanner] = useState(false)
4239
const [isApiKeyBannerVisible, setIsApiKeyBannerVisible] = useState(false)
4340
const dialog = useDialogState({ animated: true, visible: false })
4441

@@ -78,9 +75,6 @@ const App = () => {
7875
}, [])
7976

8077
useEffect(() => {
81-
if (isCloudBannerEnabled()) {
82-
setShowCloudBanner(true)
83-
}
8478
getApiKeyFromUrl()
8579
}, [])
8680

@@ -114,20 +108,6 @@ const App = () => {
114108
onClientUpdate()
115109
}, [meilisearchJsClient])
116110

117-
const handleCloudBannerClose = () => {
118-
setShowCloudBanner(false)
119-
localStorage.setItem('bannerVisibility', JSON.stringify(false))
120-
}
121-
122-
// Retrieve the banner visibility state from local storage on component mount
123-
React.useEffect(() => {
124-
const storedVisibility = localStorage.getItem('bannerVisibility')
125-
if (storedVisibility) {
126-
setShowCloudBanner(JSON.parse(storedVisibility))
127-
}
128-
return () => {}
129-
}, [])
130-
131111
return (
132112
<ApiKeyContext.Provider value={{ apiKey, setApiKey }}>
133113
<Wrapper>
@@ -136,12 +116,6 @@ const App = () => {
136116
onClose={() => setIsApiKeyBannerVisible(false)}
137117
/>
138118
)}
139-
{showCloudBanner && (
140-
<CloudBanner
141-
handleBannerClose={handleCloudBannerClose}
142-
isBannerVisible={showCloudBanner}
143-
/>
144-
)}
145119
{isMeilisearchRunning ? (
146120
<Body
147121
currentIndex={currentIndex}
@@ -150,7 +124,6 @@ const App = () => {
150124
requireApiKeyToWork={requireApiKeyToWork}
151125
getIndexesList={getIndexesList}
152126
isApiKeyBannerVisible={isApiKeyBannerVisible}
153-
isCloudBannerVisible={showCloudBanner}
154127
/>
155128
) : (
156129
<NoMeilisearchRunning />

src/components/Body.js

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import React from 'react'
22
import { InstantSearch } from 'react-instantsearch-dom'
3+
import styled from 'styled-components'
34

45
import { useMeilisearchClientContext } from 'context/MeilisearchClientContext'
56
import Box from 'components/Box'
67
import Header from 'components/Header/index'
8+
import RightPanel from 'components/RightPanel'
79
import BodyWrapper from 'components/BodyWrapper'
810
import EmptyView from 'components/EmptyView'
911
import OnBoarding from 'components/OnBoarding'
1012
import Results from 'components/Results'
1113
import Typography from 'components/Typography'
1214

15+
const ContentWrapper = styled.div`
16+
width: ${({ isRightPanelOpen, theme }) =>
17+
isRightPanelOpen ? `calc(100% - ${theme.sizes.rightPanel})` : '100%'};
18+
transition: width 0.3s ease-in-out;
19+
`
20+
1321
const IndexContent = ({ currentIndex }) => {
1422
if (!currentIndex) return <OnBoarding />
1523
if (currentIndex?.stats?.numberOfDocuments > 0) return <Results />
@@ -34,38 +42,50 @@ const Body = ({
3442
setCurrentIndex,
3543
requireApiKeyToWork,
3644
isApiKeyBannerVisible,
37-
isCloudBannerVisible,
3845
}) => {
3946
const { meilisearchJsClient, instantMeilisearchClient } =
4047
useMeilisearchClientContext()
4148

49+
// Right-side panel
50+
const [isRightPanelOpen, setIsRightPanelOpen] = React.useState(true)
51+
const handleTogglePanel = React.useCallback(() => {
52+
setIsRightPanelOpen((isOpen) => !isOpen)
53+
}, [])
54+
4255
return (
4356
<InstantSearch
4457
indexName={currentIndex ? currentIndex.uid : ''}
4558
searchClient={instantMeilisearchClient}
4659
>
47-
<Header
48-
indexes={indexes}
49-
currentIndex={currentIndex}
50-
setCurrentIndex={setCurrentIndex}
51-
requireApiKeyToWork={requireApiKeyToWork}
52-
client={meilisearchJsClient}
53-
refreshIndexes={getIndexesList}
54-
isApiKeyBannerVisible={isApiKeyBannerVisible}
55-
isCloudBannerVisible={isCloudBannerVisible}
60+
<ContentWrapper isRightPanelOpen={isRightPanelOpen}>
61+
<Header
62+
indexes={indexes}
63+
currentIndex={currentIndex}
64+
setCurrentIndex={setCurrentIndex}
65+
requireApiKeyToWork={requireApiKeyToWork}
66+
client={meilisearchJsClient}
67+
refreshIndexes={getIndexesList}
68+
isApiKeyBannerVisible={isApiKeyBannerVisible}
69+
showPanelButton={!isRightPanelOpen}
70+
onPanelToggle={handleTogglePanel}
71+
/>
72+
<BodyWrapper>
73+
{/* <Sidebar /> */}
74+
<Box
75+
width={928}
76+
m="0 auto"
77+
py={4}
78+
display="flex"
79+
flexDirection="column"
80+
>
81+
<IndexContent currentIndex={currentIndex} />
82+
</Box>
83+
</BodyWrapper>
84+
</ContentWrapper>
85+
<RightPanel
86+
isOpen={isRightPanelOpen}
87+
onClose={() => setIsRightPanelOpen(false)}
5688
/>
57-
<BodyWrapper>
58-
{/* <Sidebar /> */}
59-
<Box
60-
width={928}
61-
m="0 auto"
62-
py={4}
63-
display="flex"
64-
flexDirection="column"
65-
>
66-
<IndexContent currentIndex={currentIndex} />
67-
</Box>
68-
</BodyWrapper>
6989
</InstantSearch>
7090
)
7191
}

src/components/CloudBanner.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)