@@ -24,82 +24,83 @@ const Collections = ({ updateCredentials }) => {
2424 const [ upToDateCollections , setUpToDateCollection ] = useState ( false ) // Boolean that informs if collections have been updated.
2525 const [ needReload , setNeedReload ] = useState ( false ) // Boolean to inform that reload is requested.
2626 const [ collectionInWaitMode , setCollectionInWaitMode ] = useState ( [ ] ) // Collections that are waiting for their indexation to complete.
27- const [ collectionUpdateIds , setCollectionUpdateIds ] = useState ( { } ) // List of collection's enqueued update ids .
27+ const [ collectionTaskUids , setCollectionTaskUids ] = useState ( { } ) // List of collection's enqueued task uids .
2828
29- // Trigger a updateId fetcher to find enqueued update ids of the indexed collections.
29+ // Trigger a task uids fetcher to find enqueued task of the indexed collections.
3030 useEffect ( ( ) => {
31- findUpdateIds ( )
31+ findTaskUids ( )
3232 } , [ ] )
3333
3434 // Adds a listener that informs if collections have been updated.
3535 useEffect ( ( ) => {
3636 setUpToDateCollection ( false )
3737 } , [ updateCredentials ] )
3838
39- // Adds a listener that updates collections informations when an update occured.
39+ // Adds a listener that updates collections informations on updates
4040 useEffect ( ( ) => {
4141 if ( ! upToDateCollections ) fetchCollections ( )
4242 } , [ upToDateCollections , updateCredentials ] )
4343
44- // Trigger an update watch if a collection has enqueued update id 's.
44+ // Trigger a watch if a collection has enqueued task uid 's.
4545 useEffect ( ( ) => {
46- for ( const collection in collectionUpdateIds ) {
47- if ( collectionUpdateIds [ collection ] . length > 0 ) {
48- watchUpdates ( { collection } )
46+ for ( const collection in collectionTaskUids ) {
47+ if ( collectionTaskUids [ collection ] . length > 0 ) {
48+ watchTasks ( { collection } )
4949 }
5050 }
51- } , [ collectionUpdateIds ] )
51+ } , [ collectionTaskUids ] )
5252
5353 /**
54- * Find all enqueued update id 's of the indexed collections.
54+ * Find all enqueued task uid 's of the indexed collections.
5555 * It is triggered on load.
5656 */
57- const findUpdateIds = async ( ) => {
58- const response = await request ( `/${ pluginId } /collection/update ` , {
57+ const findTaskUids = async ( ) => {
58+ const response = await request ( `/${ pluginId } /collection/tasks ` , {
5959 method : 'GET' ,
6060 } )
6161
6262 if ( response . error ) errorNotifications ( response )
63- setCollectionUpdateIds ( response . updateIds )
63+ setCollectionTaskUids ( response . taskUids )
6464 }
6565
6666 /**
6767 * Watches a collection (if not already)
68- * For a maximum of 5 enqueued updates in MeiliSearch.
68+ * For a maximum of 5 enqueued tasks in MeiliSearch.
6969 *
7070 * @param {string } collection - Collection name.
7171 */
72- const watchUpdates = async ( { collection } ) => {
73- // If collection has pending updates
74- const updateIds = collectionUpdateIds [ collection ]
72+ const watchTasks = async ( { collection } ) => {
73+ // If collection has pending tasks
74+ const taskUids = collectionTaskUids [ collection ]
7575
76- if ( ! collectionInWaitMode . includes ( collection ) && updateIds ?. length > 0 ) {
76+ if ( ! collectionInWaitMode . includes ( collection ) && taskUids ?. length > 0 ) {
7777 addIndexedStatus
7878 setCollectionInWaitMode ( prev => [ ...prev , collection ] )
7979
80- const updateIdsChunk = updateIds . splice ( 0 , 1 )
80+ const taskUidsIdsChunk = taskUids . splice ( 0 , 1 )
8181 const response = await request (
82- `/${ pluginId } /collection/${ collection } /update /batch` ,
82+ `/${ pluginId } /collection/${ collection } /tasks /batch` ,
8383 {
8484 method : 'POST' ,
85- body : { updateIds : updateIdsChunk } ,
85+ body : { taskUids : taskUidsIdsChunk } ,
8686 }
8787 )
88+
8889 if ( response . error ) errorNotifications ( response )
8990
90- const { updateStatus } = response
91+ const { tasksStatus } = response
9192
92- updateStatus . map ( update => {
93- if ( update . status === 'failed' ) {
94- update . error . message = `Some documents could not be added: \n${ update . error . message } `
95- errorNotifications ( update . error )
93+ tasksStatus . map ( task => {
94+ if ( task . status === 'failed' ) {
95+ task . error . message = `Some documents could not be added: \n${ task . error . message } `
96+ errorNotifications ( task . error )
9697 }
9798 } )
9899
99100 setCollectionInWaitMode ( prev => prev . filter ( col => col !== collection ) )
100- setCollectionUpdateIds ( prev => ( {
101+ setCollectionTaskUids ( prev => ( {
101102 ...prev ,
102- [ collection ] : updateIds ,
103+ [ collection ] : taskUids ,
103104 } ) )
104105
105106 setUpToDateCollection ( false ) // Ask for collections to be updated.
@@ -122,9 +123,9 @@ const Collections = ({ updateCredentials }) => {
122123 createResponseNotification ( response , `${ collection } is created!` )
123124
124125 if ( ! response . error ) {
125- setCollectionUpdateIds ( prev => ( {
126+ setCollectionTaskUids ( prev => ( {
126127 ...prev ,
127- [ collection ] : response . updateIds ,
128+ [ collection ] : response . taskUids ,
128129 } ) )
129130 }
130131
@@ -147,9 +148,9 @@ const Collections = ({ updateCredentials }) => {
147148 createResponseNotification ( response , `${ collection } update started!` )
148149
149150 if ( ! response . error ) {
150- setCollectionUpdateIds ( prev => ( {
151+ setCollectionTaskUids ( prev => ( {
151152 ...prev ,
152- [ collection ] : response . updateIds ,
153+ [ collection ] : response . taskUids ,
153154 } ) )
154155 }
155156
@@ -199,10 +200,10 @@ const Collections = ({ updateCredentials }) => {
199200
200201 if ( error ) errorNotifications ( res )
201202 else {
202- // Start watching collections that have pending updates
203+ // Start watching collections that have pending tasks
203204 collections . map ( col => {
204205 if ( col . isIndexing ) {
205- watchUpdates ( { collection : col . collection } )
206+ watchTasks ( { collection : col . collection } )
206207 }
207208 } )
208209
0 commit comments