Skip to content

Commit 3a36efe

Browse files
bors[bot]bidoubiwa
andauthored
Merge #87
87: Update linter r=bidoubiwa a=bidoubiwa fixes: #59 Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 0f89ec1 + cf2f2b1 commit 3a36efe

File tree

23 files changed

+403
-285
lines changed

23 files changed

+403
-285
lines changed

.editorconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ indent_size = 2
1010
charset = utf-8
1111
trim_trailing_whitespace = true
1212
max_line_length = 80
13+
quote_type = single
1314

1415
[*.{js,ts}]
1516
quote_type = single

.eslintrc.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,44 @@ module.exports = {
33
browser: true,
44
commonjs: true,
55
es2020: true,
6-
node: true
6+
node: true,
77
},
88
globals: {
9-
strapi: true
9+
strapi: true,
1010
},
1111
extends: [
12+
'eslint:recommended',
1213
'plugin:react/recommended',
13-
'standard',
14-
'plugin:cypress/recommended'
14+
'plugin:cypress/recommended',
15+
'plugin:prettier/recommended',
1516
],
1617
parserOptions: {
1718
ecmaFeatures: {
18-
jsx: true
19+
jsx: true,
1920
},
20-
ecmaVersion: 11
21+
ecmaVersion: 11,
2122
},
22-
ignorePatterns: ['playground/plugins'],
23-
plugins: [
24-
'react'
25-
],
23+
ignorePatterns: ['playground'],
24+
plugins: ['react', 'prettier'],
2625
settings: {
2726
react: {
28-
version: 'detect'
29-
}
27+
version: 'detect',
28+
},
3029
},
3130
rules: {
32-
'react/jsx-indent': 'error',
33-
'react/jsx-indent-props': [2, 2],
3431
'cypress/no-unnecessary-waiting': 'off',
3532
'react/prop-types': 'off',
3633
'react/jsx-closing-bracket-location': [2, 'tag-aligned'],
3734
'no-unused-vars': ['error', { varsIgnorePattern: '^omit.*$' }],
38-
'array-callback-return': 'off'
39-
}
35+
'array-callback-return': 'off',
36+
'arrow-parens': ['error', 'as-needed'],
37+
'prettier/prettier': [
38+
'error',
39+
{
40+
quoteProps: 'consistent',
41+
semi: false,
42+
arrowParens: 'avoid',
43+
},
44+
],
45+
},
4046
}

admin/src/components/Collections.js

Lines changed: 95 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ export const ReloadButton = styled(Button)`
2525
const 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

4848
const 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

Comments
 (0)