@@ -25,24 +25,24 @@ export const ReloadButton = styled(Button)`
2525const headers = [
2626 {
2727 name : 'Name' ,
28- value : 'name'
28+ value : 'name' ,
2929 } ,
3030 {
3131 name : 'In MeiliSearch' ,
32- value : 'indexed'
32+ value : 'indexed' ,
3333 } ,
3434 {
3535 name : 'Indexing' ,
36- value : 'isIndexing'
36+ value : 'isIndexing' ,
3737 } ,
3838 {
3939 name : 'Documents' ,
40- value : 'numberOfDocuments'
40+ value : 'numberOfDocuments' ,
4141 } ,
4242 {
4343 name : 'Hooks' ,
44- value : 'hooked'
45- }
44+ value : 'hooked' ,
45+ } ,
4646]
4747
4848const Collections = ( { updateCredentials } ) => {
@@ -64,9 +64,12 @@ const Collections = ({ updateCredentials }) => {
6464 const watchUpdates = async ( { collection } ) => {
6565 if ( ! watching . includes ( collection ) ) {
6666 setWatchingCollection ( prev => [ ...prev , collection ] )
67- const response = await request ( `/${ pluginId } /indexes/${ collection } /update/` , {
68- method : 'GET'
69- } )
67+ const response = await request (
68+ `/${ pluginId } /indexes/${ collection } /update/` ,
69+ {
70+ method : 'GET' ,
71+ }
72+ )
7073 if ( response . error ) errorNotifications ( response )
7174
7275 setWatchingCollection ( prev => prev . filter ( col => col !== collection ) )
@@ -76,30 +79,39 @@ const Collections = ({ updateCredentials }) => {
7679
7780 // Add collection to MeiliSearch
7881 const addCollection = async ( { name : collection } ) => {
79- setCollectionsList ( prev => prev . map ( col => {
80- if ( col . name === collection ) return { ...col , indexed : 'Creating..' , _isChecked : true }
81- return col
82- } ) )
82+ setCollectionsList ( prev =>
83+ prev . map ( col => {
84+ if ( col . name === collection )
85+ return { ...col , indexed : 'Creating..' , _isChecked : true }
86+ return col
87+ } )
88+ )
8389 const response = await request ( `/${ pluginId } /collections/${ collection } ` , {
84- method : 'POST'
90+ method : 'POST' ,
8591 } )
8692 if ( response . error ) {
8793 errorNotifications ( response )
8894 } else {
89- successNotification ( { message : `${ collection } is created!` , duration : 4000 } )
95+ successNotification ( {
96+ message : `${ collection } is created!` ,
97+ duration : 4000 ,
98+ } )
9099 watchUpdates ( { collection } ) // start watching
91100 }
92101 setUpdatedCollections ( false ) // Ask for up to date data
93102 }
94103
95104 // Re-indexes all rows from a given collection to MeilISearch
96105 const updateCollections = async ( { collection } ) => {
97- setCollectionsList ( prev => prev . map ( col => {
98- if ( col . name === collection ) return { ...col , indexed : 'Start update...' , _isChecked : true }
99- return col
100- } ) )
106+ setCollectionsList ( prev =>
107+ prev . map ( col => {
108+ if ( col . name === collection )
109+ return { ...col , indexed : 'Start update...' , _isChecked : true }
110+ return col
111+ } )
112+ )
101113 const response = await request ( `/${ pluginId } /collections/${ collection } /` , {
102- method : 'PUT'
114+ method : 'PUT' ,
103115 } )
104116 if ( response . error ) {
105117 errorNotifications ( response )
@@ -113,17 +125,21 @@ const Collections = ({ updateCredentials }) => {
113125 // Remove a collection from MeiliSearch
114126 const removeCollection = async ( { name : collection } ) => {
115127 const res = await request ( `/${ pluginId } /indexes/${ collection } /` , {
116- method : 'DELETE'
128+ method : 'DELETE' ,
117129 } )
118130 if ( res . error ) errorNotifications ( res )
119- else successNotification ( { message : `${ collection } collection is removed from MeiliSearch!` , duration : 4000 } )
131+ else
132+ successNotification ( {
133+ message : `${ collection } collection is removed from MeiliSearch!` ,
134+ duration : 4000 ,
135+ } )
120136 setUpdatedCollections ( false ) // ask for up to date data
121137 }
122138
123139 // Depending on the checkbox states will eather
124140 // - Add the collection to MeiliSearch
125141 // - Remove the collection from MeiliSearch
126- const addOrRemoveCollection = async ( row ) => {
142+ const addOrRemoveCollection = async row => {
127143 if ( row . _isChecked ) await removeCollection ( row )
128144 else addCollection ( row )
129145 }
@@ -140,27 +156,32 @@ const Collections = ({ updateCredentials }) => {
140156 }
141157
142158 // Construct verbose table text
143- const constructColRow = ( col ) => {
159+ const constructColRow = col => {
144160 const { indexed, isIndexing, numberOfDocuments, numberOfRows } = col
145161 return {
146162 ...col ,
147163 indexed : indexed ? 'Yes' : 'No' ,
148164 isIndexing : isIndexing ? 'Yes' : 'No' ,
149165 numberOfDocuments : `${ numberOfDocuments } / ${ numberOfRows } ` ,
150166 hooked : constructReloadStatus ( col . indexed , col . hooked ) ,
151- _isChecked : col . indexed
167+ _isChecked : col . indexed ,
152168 }
153169 }
154170
155171 const fetchCollections = async ( ) => {
156- const { collections, error, ...res } = await request ( `/${ pluginId } /collections/` , {
157- method : 'GET'
158- } )
172+ const { collections, error, ...res } = await request (
173+ `/${ pluginId } /collections/` ,
174+ {
175+ method : 'GET' ,
176+ }
177+ )
159178
160179 if ( error ) errorNotifications ( res )
161180 else {
162181 // Start watching collection that are being indexed
163- collections . map ( col => col . isIndexing && watchUpdates ( { collection : col . name } ) )
182+ collections . map (
183+ col => col . isIndexing && watchUpdates ( { collection : col . name } )
184+ )
164185 // Create verbose text that will be showed in the table
165186 const verboseCols = collections . map ( col => constructColRow ( col ) )
166187 // Find possible collection that needs a reload to activate its hooks
@@ -176,9 +197,13 @@ const Collections = ({ updateCredentials }) => {
176197 const reload = async ( ) => {
177198 try {
178199 strapi . lockApp ( { enabled : true } )
179- const { error, ...res } = await request ( `/${ pluginId } /reload` , {
180- method : 'GET'
181- } , true )
200+ const { error, ...res } = await request (
201+ `/${ pluginId } /reload` ,
202+ {
203+ method : 'GET' ,
204+ } ,
205+ true
206+ )
182207 if ( error ) {
183208 errorNotifications ( res )
184209 strapi . unlockApp ( )
@@ -192,42 +217,44 @@ const Collections = ({ updateCredentials }) => {
192217 }
193218
194219 return (
195- < div className = "col-md-12" >
196- < Wrapper >
197- < Table
198- className = 'collections'
199- headers = { headers }
200- rows = { collectionsList }
201- withBulkAction
202- onSelect = { ( row ) => {
203- addOrRemoveCollection ( row )
204- } }
205- onClickRow = { ( e , data ) => {
206- addOrRemoveCollection ( data )
207- } }
208- rowLinks = { [
209- {
210- icon : < UpdateButton forwardedAs = 'span' > Update</ UpdateButton > ,
211- onClick : data => {
212- updateCollections ( { collection : data . name } )
213- }
214- }
215- ] }
216- />
217- < div style = { { display : 'flex' , justifyContent : 'flex-end' } } >
218- {
219- needReload && < Button
220- color = "delete"
221- className = "reload_button"
222- onClick = { ( ) => { reload ( ) } }
223- style = { { marginTop : '20px' } }
224- >
225- Reload Server
226- </ Button >
227- }
228- </ div >
229- </ Wrapper >
230- </ div >
220+ < div className = "col-md-12" >
221+ < Wrapper >
222+ < Table
223+ className = "collections"
224+ headers = { headers }
225+ rows = { collectionsList }
226+ withBulkAction
227+ onSelect = { row => {
228+ addOrRemoveCollection ( row )
229+ } }
230+ onClickRow = { ( e , data ) => {
231+ addOrRemoveCollection ( data )
232+ } }
233+ rowLinks = { [
234+ {
235+ icon : < UpdateButton forwardedAs = "span" > Update</ UpdateButton > ,
236+ onClick : data => {
237+ updateCollections ( { collection : data . name } )
238+ } ,
239+ } ,
240+ ] }
241+ />
242+ < div style = { { display : 'flex' , justifyContent : 'flex-end' } } >
243+ { needReload && (
244+ < Button
245+ color = "delete"
246+ className = "reload_button"
247+ onClick = { ( ) => {
248+ reload ( )
249+ } }
250+ style = { { marginTop : '20px' } }
251+ >
252+ Reload Server
253+ </ Button >
254+ ) }
255+ </ div >
256+ </ Wrapper >
257+ </ div >
231258 )
232259}
233260
0 commit comments