Skip to content

Commit cf2f2b1

Browse files
committed
Update style and style rules
1 parent 2500f5b commit cf2f2b1

File tree

9 files changed

+207
-161
lines changed

9 files changed

+207
-161
lines changed

admin/src/components/Collections.js

Lines changed: 91 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ const headers = [
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',
@@ -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)
@@ -116,14 +128,18 @@ const Collections = ({ updateCredentials }) => {
116128
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

admin/src/utils/notifications.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
export function errorNotifications ({ message, link }) {
1+
export function errorNotifications({ message, link }) {
22
strapi.notification.toggle({
3-
title,
3+
title: 'Operation on MeiliSearch failed',
44
type: 'warning',
55
message: message,
66
...(link && { link: { url: link, label: 'learn more' } }),
7-
blockTransition: true // The user has to close the error notification manually
7+
blockTransition: true, // The user has to close the error notification manually
88
})
99
}
1010

@@ -13,6 +13,6 @@ export function successNotification({ message, duration = 4000, link }) {
1313
type: 'success',
1414
message: message,
1515
...(link && { link: { url: link, label: 'learn more' } }),
16-
timeout: duration
16+
timeout: duration,
1717
})
1818
}

config/functions/bootstrap.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const meilisearch = {
1818
lifecycles: () => strapi.plugins.meilisearch.services.lifecycles,
1919
}
2020

21-
async function getClient (credentials) {
21+
async function getClient(credentials) {
2222
const client = meilisearch.client(credentials)
2323
return await meilisearch.http(client)
2424
}
@@ -38,18 +38,18 @@ async function getCredentials() {
3838
return { apiKey, host }
3939
}
4040

41-
function addHookedCollectionsToStore ({ store, collections }) {
41+
function addHookedCollectionsToStore({ store, collections }) {
4242
store.set({
4343
key: 'meilisearch_hooked',
44-
value: collections
44+
value: collections,
4545
})
4646
}
4747

48-
async function getHookedCollectionsFromStore ({ store }) {
48+
async function getHookedCollectionsFromStore({ store }) {
4949
return store.get({ key: 'meilisearch_hooked' })
5050
}
5151

52-
function addLifecycles ({ client, collections }) {
52+
function addLifecycles({ client, collections }) {
5353
// Add lifecyles
5454
collections.map(collection => {
5555
const model = strapi.models[collection]
@@ -58,15 +58,15 @@ function addLifecycles ({ client, collections }) {
5858

5959
meilisearchLifecycles.map(lifecycleName => {
6060
const fn = model.lifecycles[lifecycleName] || (() => {})
61-
model.lifecycles[lifecycleName] = (data) => {
61+
model.lifecycles[lifecycleName] = data => {
6262
fn(data)
6363
meilisearch.lifecycles()[lifecycleName](data, collection, client)
6464
}
6565
})
6666
})
6767
}
6868

69-
async function initHooks (store) {
69+
async function initHooks(store) {
7070
try {
7171
const credentials = await getCredentials()
7272
const getHookedCollections = await getHookedCollectionsFromStore({ store })
@@ -81,14 +81,16 @@ async function initHooks (store) {
8181
const models = strapi.models
8282

8383
// get list of Indexes In MeilISearch that are Collections in Strapi
84-
const indexedCollections = Object.keys(models).filter(model => indexes.includes(model))
84+
const indexedCollections = Object.keys(models).filter(model =>
85+
indexes.includes(model)
86+
)
8587
addLifecycles({
8688
collections: indexedCollections,
87-
client
89+
client,
8890
})
8991
addHookedCollectionsToStore({
9092
collections: indexedCollections,
91-
store
93+
store,
9294
})
9395
}
9496

0 commit comments

Comments
 (0)