Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use assistant (search and AI) from cozy-dataproxy-lib #3266

Merged
merged 8 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 27 additions & 55 deletions .bundlemonrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,108 +2,82 @@
"baseDir": "./build",
"files": [
{
"path": "app/drive.<hash>.js",
"maxSize": "300 KB"
"path": "app/drive.<hash>.js"
},
{
"path": "app/drive.<hash>.min.css",
"maxSize": "55 KB"
"path": "app/drive.<hash>.min.css"
},
{
"path": "img/app-icon.<hash>.svg",
"maxSize": "1 KB"
"path": "img/app-icon.<hash>.svg"
},
{
"path": "intents/drive.<hash>.js",
"maxSize": "190 KB"
"path": "intents/drive.<hash>.js"
},
{
"path": "intents/drive.<hash>.min.css",
"maxSize": "37 KB"
"path": "intents/drive.<hash>.min.css"
},
{
"path": "intents/index.html",
"maxSize": "1 KB"
"path": "intents/index.html"
},
{
"path": "onlyOffice/slide.pptx",
"maxSize": "25 KB"
"path": "onlyOffice/slide.pptx"
},
{
"path": "onlyOffice/spreadsheet.xlsx",
"maxSize": "6 KB"
"path": "onlyOffice/spreadsheet.xlsx"
},
{
"path": "onlyOffice/text.docx",
"maxSize": "6 KB"
"path": "onlyOffice/text.docx"
},
{
"path": "public/cozy-bar.css",
"maxSize": "24 KB"
"path": "public/cozy-bar.css"
},
{
"path": "public/cozy-bar.js",
"maxSize": "854 KB"
"path": "public/cozy-bar.js"
},
{
"path": "public/cozy-client-js.js",
"maxSize": "160 KB"
"path": "public/cozy-client-js.js"
},
{
"path": "public/drive.<hash>.js",
"maxSize": "1.70 MB"
"path": "public/drive.<hash>.js"
},
{
"path": "public/drive.<hash>.min.css",
"maxSize": "100 KB"
"path": "public/drive.<hash>.min.css"
},
{
"path": "public/pdf.worker.entry.<hash>.worker.js",
"maxSize": "350 KB"
"path": "public/pdf.worker.entry.<hash>.worker.js"
},
{
"path": "services/dacc/drive.js",
"maxSize": "500 KB"
"path": "services/dacc/drive.js"
},
{
"path": "services/qualificationMigration/drive.js",
"maxSize": "500 KB"
"path": "services/qualificationMigration/drive.js"
},
{
"path": "vendors/drive.<hash>.<hash>.min.css",
"maxSize": "35 KB"
"path": "vendors/drive.<hash>.<hash>.min.css"
},
{
"path": "vendors/drive.<hash>.js",
"maxSize": "2.0 MB"
"path": "vendors/drive.<hash>.js"
},
{
"path": "app-drive.<hash>.min.css",
"maxSize": "56 KB"
"path": "app-drive.<hash>.min.css"
},
{
"path": "index.html",
"maxSize": "1 KB"
"path": "index.html"
},
{
"path": "intents-drive.<hash>.min.css",
"maxSize": "40 KB"
"path": "intents-drive.<hash>.min.css"
},
{
"path": "manifest.json",
"maxSize": "1 KB"
"path": "manifest.json"
},
{
"path": "manifest.webapp",
"maxSize": "2 KB"
"path": "manifest.webapp"
},
{
"path": "public-drive.<hash>.min.css",
"maxSize": "100 KB"
"path": "public-drive.<hash>.min.css"
},
{
"path": "vendors-drive.<hash>.min.css",
"maxSize": "1 B"
"path": "vendors-drive.<hash>.min.css"
}
],
"groups": [
Expand All @@ -129,7 +103,5 @@
"path": "vendors/**"
}
],
"reportOutput": [
"github"
]
"reportOutput": ["github"]
}
7 changes: 7 additions & 0 deletions jestHelpers/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@ jest.mock('cozy-intent', () => ({
useWebviewIntent: jest.fn()
}))

jest.mock('cozy-dataproxy-lib', () => ({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pourquoi fait-on ça ? Un commentaire serait bienvenu je pense. Est-ce qu'on devrait généraliser l'approche à toutes les libs ?

Copy link
Contributor Author

@zatteo zatteo Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deux raisons :

  • les tests échouent avec l'import de cozy-dataproxy-lib avec des sombres histoires de babel pas à jour (et je n'ai pas trop envie d'investiguer ça maintenant)
  • il n'y a aucune raison de tester ces composants dans les apps qui sont autonomes

Pas sûr que ce soit généralisable.

DataProxyProvider: ({ children }) => children,
SearchDialog: () => <div>SearchDialog</div>,
AssistantDialog: () => <div>AssistantDialog</div>,
AssistantDesktop: () => <div>AssistantDesktop</div>
}))

// see https://github.com/jsdom/jsdom/issues/1695
window.HTMLElement.prototype.scroll = function () {}
10 changes: 10 additions & 0 deletions manifest.webapp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,16 @@
"type": "eu.mycozy.dacc_v2",
"verbs": ["POST"],
"description": "Remote-doctype required to send anonymized measures to the DACC shared among mycozy.eu's Cozy."
},
"chatConversations": {
"description": "Required by the cozy Assistant",
"type": "io.cozy.ai.chat.conversations",
"verbs": ["GET", "POST"]
},
"chatEvents": {
"description": "Required by the cozy Assistant",
"type": "io.cozy.ai.chat.events",
"verbs": ["GET"]
}
},
"accept_from_flagship": true,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"cozy-ci": "0.5.2",
"cozy-client": "^51.6.1",
"cozy-client-js": "0.20.0",
"cozy-dataproxy-lib": "^1.9.0",
"cozy-device-helper": "^2.7.0",
"cozy-devtools": "^1.2.1",
"cozy-doctypes": "1.85.4",
Expand All @@ -94,7 +95,7 @@
"cozy-logger": "1.9.1",
"cozy-minilog": "3.3.1",
"cozy-realtime": "4.6.0",
"cozy-scripts": "^8.3.0",
"cozy-scripts": "^8.4.0",
"cozy-sharing": "^16.17.0",
"cozy-stack-client": "^51.6.0",
"cozy-ui": "^114.0.1",
Expand Down
6 changes: 0 additions & 6 deletions src/assets/icons/icon-search-empty.svg

This file was deleted.

9 changes: 8 additions & 1 deletion src/components/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'react'
import { Provider } from 'react-redux'

import { BarProvider } from 'cozy-bar'
import { DataProxyProvider } from 'cozy-dataproxy-lib'
import { WebviewIntentProvider } from 'cozy-intent'

import PushBannerProvider from 'components/PushBanner/PushBannerProvider'
Expand All @@ -28,7 +29,13 @@ const App = ({ isPublic, store, client, lang, polyglot, children }) => {
<PushBannerProvider>
<AcceptingSharingProvider>
<ThumbnailSizeContextProvider>
<ModalContextProvider>{children}</ModalContextProvider>
<ModalContextProvider>
{isPublic ? (
children
) : (
<DataProxyProvider>{children}</DataProxyProvider>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

je crois qu'on gère les providers public autrement 🤔
DriveProvider est partagé entre les différentes targets, mais ensuite chaque target a ses propres provider, il me semble

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je suis pas hyper fan de cette solution mais j'ai pas trouvé de meilleur endroit. En regardant le code la seule différence que j'ai vu entre public et non public c'est la prop isPublic pour la target public <App isPublic ...></App>

)}
</ModalContextProvider>
</ThumbnailSizeContextProvider>
</AcceptingSharingProvider>
</PushBannerProvider>
Expand Down
14 changes: 12 additions & 2 deletions src/modules/navigation/AppRoute.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react'
import { Route, useParams, Navigate } from 'react-router-dom'

import { RealTimeQueries } from 'cozy-client'
import { SearchDialog, AssistantDialog } from 'cozy-dataproxy-lib'
import flag from 'cozy-flags'

import ExternalRedirect from './ExternalRedirect'
Expand All @@ -12,7 +14,6 @@ import OnlyOfficeCreateView from '../views/OnlyOffice/Create'
import OnlyOfficePaywallView from '../views/OnlyOffice/OnlyOfficePaywallView'
import RecentView from '../views/Recent'
import FilesViewerRecent from '../views/Recent/FilesViewerRecent'
import SearchView from '../views/Search/SearchView'
import SharingsView from '../views/Sharings'
import SharingsFilesViewer from '../views/Sharings/FilesViewerSharings'
import SharingsFolderView from '../views/Sharings/SharingsFolderView'
Expand Down Expand Up @@ -152,7 +153,16 @@ const AppRoute = () => (
/>

<Route path="file/:fileId" element={<FileOpenerExternal />} />
<Route path="search" element={<SearchView />} />
<Route path="search" element={<SearchDialog />} />
<Route
path="assistant/:conversationId"
element={
<>
<RealTimeQueries doctype="io.cozy.ai.chat.conversations" />
<AssistantDialog />
</>
}
/>

<Route path="favorites" element={<FavoritesView />}>
<Route path="file/:fileId/revision" element={<FileHistory />} />
Expand Down
15 changes: 10 additions & 5 deletions src/modules/search/components/AppBarSearch.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import React from 'react'

import { BarSearch } from 'cozy-bar'
import { AssistantDesktop } from 'cozy-dataproxy-lib'
import useBreakpoints from 'cozy-ui/transpiled/react/providers/Breakpoints'
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'

import BarSearchAutosuggest from 'modules/search/components/BarSearchAutosuggest'

const AppBarSearch = () => {
const { t } = useI18n()
const { isMobile } = useBreakpoints()

return <BarSearch>{!isMobile && <BarSearchAutosuggest t={t} />}</BarSearch>
return (
<BarSearch>
{!isMobile && (
<AssistantDesktop
componentsProps={{ SearchBarDesktop: { size: 'small' } }}
/>
)}
</BarSearch>
)
}

export default AppBarSearch
17 changes: 0 additions & 17 deletions src/modules/search/components/AppBarSearch.spec.jsx

This file was deleted.

Loading
Loading