Skip to content

Commit

Permalink
feat: Allow to pass options to search
Browse files Browse the repository at this point in the history
This is notably useful to pass doctypes to the search, indicating which
doctypes to search and in which order.

See cozy/cozy-libs#2685
  • Loading branch information
paultranvan committed Dec 24, 2024
1 parent 5ded506 commit 649735f
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"comlink": "^4.4.1",
"cozy-app-publish": "^0.34.0",
"cozy-client": "^51.0.0",
"cozy-dataproxy-lib": "^2.1.1",
"cozy-dataproxy-lib": "^2.3.0",
"cozy-device-helper": "^3.7.1",
"cozy-flags": "^4.0.0",
"cozy-logger": "^1.10.4",
Expand Down
7 changes: 6 additions & 1 deletion src/dataproxy/common/DataProxyInterface.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import type { InstanceOptions } from 'cozy-client'
import type { ClientCapabilities } from 'cozy-client/types/types'

// TODO: Should be imported from cozy-dataproxy-lib
export interface SearchOptions {
doctypes: string[]
}

export interface DataProxyWorker {
search: (query: string) => unknown
search: (query: string, options: SearchOptions) => unknown
setup: (clientData: ClientData) => Promise<void>
forceSyncPouch: () => void
}
Expand Down
12 changes: 9 additions & 3 deletions src/dataproxy/parent/ParentWindowProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as Comlink from 'comlink'
import React, { ReactNode } from 'react'

import { DataProxyWorkerContext } from '@/dataproxy/common/DataProxyInterface'
import {
DataProxyWorkerContext,
SearchOptions
} from '@/dataproxy/common/DataProxyInterface'
import { useSharedWorker } from '@/dataproxy/worker/useSharedWorker'

export const ParentWindowContext = React.createContext<
Expand All @@ -17,8 +20,11 @@ export const ParentWindowProvider = React.memo(
const workerContext = useSharedWorker()

const iframeProxy = {
search: async (search: string): Promise<unknown> => {
const result = await workerContext.worker.search(search)
search: async (
search: string,
options: SearchOptions
): Promise<unknown> => {
const result = await workerContext.worker.search(search, options)

return result
}
Expand Down
7 changes: 4 additions & 3 deletions src/dataproxy/worker/shared-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
import {
ClientData,
DataProxyWorker,
DataProxyWorkerPartialState
DataProxyWorkerPartialState,
SearchOptions
} from '@/dataproxy/common/DataProxyInterface'
import { queryIsTrustedDevice } from '@/dataproxy/worker/data'
import { platformWorker } from '@/dataproxy/worker/platformWorker'
Expand Down Expand Up @@ -84,7 +85,7 @@ const dataProxy: DataProxyWorker = {
updateState()
},

search: (query: string) => {
search: (query: string, options: SearchOptions | undefined) => {
if (!client) {
throw new Error(
'Client is required to execute a search, please initialize CozyClient'
Expand All @@ -94,7 +95,7 @@ const dataProxy: DataProxyWorker = {
throw new Error('SearchEngine is not initialized')
}
const startSearchTime = performance.now()
const results = searchEngine.search(query)
const results = searchEngine.search(query, options)
const endSearchTime = performance.now()
log.debug(`Search took ${endSearchTime - startSearchTime} ms`)
return results
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2303,10 +2303,10 @@ cozy-client@^51.0.0:
sift "^6.0.0"
url-search-params-polyfill "^8.0.0"

cozy-dataproxy-lib@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/cozy-dataproxy-lib/-/cozy-dataproxy-lib-2.1.1.tgz#5a1a18fe3ac09cacd451c39ecec7712966a86c60"
integrity sha512-SHURcEf3kPURBueQaes7H0OimL4Zfwuw/lO7ykVU5C4Z7dg2t/Ij5gcofl9Jj0lx9HlKmbffgZvoMCriCzK7Pg==
cozy-dataproxy-lib@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/cozy-dataproxy-lib/-/cozy-dataproxy-lib-2.3.0.tgz#c702c36a674c61edffd31e10d3c9e3665f64c4ef"
integrity sha512-rDYd3yOykArExr8Iz/hoP+2jI57NX0Z/LIDsPmH3W9vifXnb1SVBfekxE4vNXj9vJKLSZ8vfKgl3OuqYbOKVow==
dependencies:
classnames "2.5.1"
comlink "4.4.1"
Expand Down

0 comments on commit 649735f

Please sign in to comment.