fix(frontend): send empty sync is not allowed (#2716)

…d files

The syncFiles function in multiple files has been updated to only sync
connections that have selected files. This change improves the
efficiency of the syncing process and ensures that only relevant
connections are synced.

# Description

Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.

## Checklist before requesting a review

Please delete options that are not relevant.

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged

## Screenshots (if appropriate):
This commit is contained in:
Antoine Dewez 2024-06-24 18:30:42 +02:00 committed by GitHub
parent 76918202fa
commit 18d594493a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 19 deletions

View File

@ -89,7 +89,11 @@ export const BrainRecapStep = (): JSX.Element => {
<div className={styles.cards_wrapper}>
<BrainRecapCard
label="Connection"
number={openedConnections.length}
number={
openedConnections.filter(
(connection) => connection.selectedFiles.files.length
).length
}
/>
<BrainRecapCard
label="URL"

View File

@ -46,9 +46,11 @@ export const useBrainCreationApi = () => {
await Promise.all([...uploadPromises, ...crawlPromises]);
await Promise.all(
openedConnections.map(async (openedConnection) => {
await syncFiles(openedConnection, brainId);
})
openedConnections
.filter((connection) => connection.selectedFiles.files.length)
.map(async (openedConnection) => {
await syncFiles(openedConnection, brainId);
})
);
setKnowledgeToFeed([]);
};

View File

@ -45,21 +45,23 @@ export const useFeedBrainHandler = () => {
const existingConnections = await getActiveSyncsForBrain(brainId);
await Promise.all(
openedConnections.map(async (openedConnection) => {
const existingConnectionIds = existingConnections.map(
(connection) => connection.id
);
if (
!openedConnection.id ||
!existingConnectionIds.includes(openedConnection.id)
) {
await syncFiles(openedConnection, brainId);
} else if (!openedConnection.selectedFiles.files.length) {
await deleteActiveSync(openedConnection.id);
} else {
await updateActiveSync(openedConnection);
}
})
openedConnections
.filter((connection) => connection.selectedFiles.files.length)
.map(async (openedConnection) => {
const existingConnectionIds = existingConnections.map(
(connection) => connection.id
);
if (
!openedConnection.id ||
!existingConnectionIds.includes(openedConnection.id)
) {
await syncFiles(openedConnection, brainId);
} else if (!openedConnection.selectedFiles.files.length) {
await deleteActiveSync(openedConnection.id);
} else {
await updateActiveSync(openedConnection);
}
})
);
await Promise.all([