mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
Merge pull request #27895 from overleaf/rh-b2c-js-tsx-canceled
Migrate B2C jsx to tsx: algolia-search and subscriptions GitOrigin-RevId: 917036ce6baf8130d2b10b46efa649f015b84576
This commit is contained in:
8
package-lock.json
generated
8
package-lock.json
generated
@@ -11812,6 +11812,13 @@
|
|||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@types/algoliasearch": {
|
||||||
|
"version": "3.34.11",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/algoliasearch/-/algoliasearch-3.34.11.tgz",
|
||||||
|
"integrity": "sha512-FFMbpmXCHcgbypnOUY98SDEoiLc2bXO51gxgX02ypb8srZZnZCPV/8VKknuEtgr1VkgYLrqLi5BoYzZRVni6Fw==",
|
||||||
|
"dev": true,
|
||||||
|
"license": "MIT"
|
||||||
|
},
|
||||||
"node_modules/@types/aria-query": {
|
"node_modules/@types/aria-query": {
|
||||||
"version": "5.0.4",
|
"version": "5.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz",
|
||||||
@@ -44645,6 +44652,7 @@
|
|||||||
"@testing-library/dom": "^10.4.0",
|
"@testing-library/dom": "^10.4.0",
|
||||||
"@testing-library/react": "^16.3.0",
|
"@testing-library/react": "^16.3.0",
|
||||||
"@testing-library/user-event": "^14.4.3",
|
"@testing-library/user-event": "^14.4.3",
|
||||||
|
"@types/algoliasearch": "^3.34.11",
|
||||||
"@types/bootstrap": "^5.2.10",
|
"@types/bootstrap": "^5.2.10",
|
||||||
"@types/chai": "^4.3.0",
|
"@types/chai": "^4.3.0",
|
||||||
"@types/dateformat": "^5.0.2",
|
"@types/dateformat": "^5.0.2",
|
||||||
|
|||||||
@@ -2,12 +2,44 @@ import _ from 'lodash'
|
|||||||
import AlgoliaSearch from 'algoliasearch'
|
import AlgoliaSearch from 'algoliasearch'
|
||||||
import getMeta from '../../utils/meta'
|
import getMeta from '../../utils/meta'
|
||||||
|
|
||||||
let wikiIdx
|
interface WikiHit {
|
||||||
export async function searchWiki(...args) {
|
pageName: string
|
||||||
|
sectionName?: string
|
||||||
|
kb?: boolean
|
||||||
|
_highlightResult: {
|
||||||
|
pageName: {
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
content: {
|
||||||
|
value: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FormattedWikiHit {
|
||||||
|
url: string
|
||||||
|
pageName: string
|
||||||
|
rawPageName: string
|
||||||
|
sectionName?: string
|
||||||
|
content: string
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AlgoliaSearchResponse {
|
||||||
|
hits: WikiHit[]
|
||||||
|
nbHits: number
|
||||||
|
nbPages: number
|
||||||
|
}
|
||||||
|
|
||||||
|
let wikiIdx: AlgoliaSearch.Index | undefined
|
||||||
|
|
||||||
|
export async function searchWiki(
|
||||||
|
query: string,
|
||||||
|
options?: AlgoliaSearch.QueryParameters
|
||||||
|
): Promise<AlgoliaSearchResponse> {
|
||||||
if (!wikiIdx) {
|
if (!wikiIdx) {
|
||||||
const algoliaConfig = getMeta('ol-algolia')
|
const algoliaConfig = getMeta('ol-algolia')
|
||||||
const wikiIndex = _.get(algoliaConfig, 'indexes.wiki')
|
const wikiIndex = _.get(algoliaConfig, 'indexes.wiki')
|
||||||
if (wikiIndex) {
|
if (wikiIndex && algoliaConfig) {
|
||||||
const client = AlgoliaSearch(algoliaConfig.appId, algoliaConfig.apiKey)
|
const client = AlgoliaSearch(algoliaConfig.appId, algoliaConfig.apiKey)
|
||||||
wikiIdx = client.initIndex(wikiIndex)
|
wikiIdx = client.initIndex(wikiIndex)
|
||||||
}
|
}
|
||||||
@@ -15,10 +47,10 @@ export async function searchWiki(...args) {
|
|||||||
if (!wikiIdx) {
|
if (!wikiIdx) {
|
||||||
return { hits: [], nbHits: 0, nbPages: 0 }
|
return { hits: [], nbHits: 0, nbPages: 0 }
|
||||||
}
|
}
|
||||||
return wikiIdx.search(...args)
|
return wikiIdx.search({ query, ...options }) as Promise<AlgoliaSearchResponse>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatWikiHit(hit) {
|
export function formatWikiHit(hit: WikiHit): FormattedWikiHit {
|
||||||
const pageUnderscored = hit.pageName.replace(/\s/g, '_')
|
const pageUnderscored = hit.pageName.replace(/\s/g, '_')
|
||||||
const pageSlug = encodeURIComponent(pageUnderscored)
|
const pageSlug = encodeURIComponent(pageUnderscored)
|
||||||
const pagePath = hit.kb ? 'how-to' : 'latex'
|
const pagePath = hit.kb ? 'how-to' : 'latex'
|
||||||
@@ -64,6 +64,7 @@ import { ActiveExperiment } from './labs-utils'
|
|||||||
import { Subscription as AdminSubscription } from '../../../types/admin/subscription'
|
import { Subscription as AdminSubscription } from '../../../types/admin/subscription'
|
||||||
import { AdminCapability } from '../../../types/admin-capabilities'
|
import { AdminCapability } from '../../../types/admin-capabilities'
|
||||||
import { GroupAuditLog } from '../../../modules/group-audit-log/frontend/js/components/logs'
|
import { GroupAuditLog } from '../../../modules/group-audit-log/frontend/js/components/logs'
|
||||||
|
import { AlgoliaConfig } from '../../../modules/algolia-search/frontend/js/types'
|
||||||
|
|
||||||
export interface Meta {
|
export interface Meta {
|
||||||
'ol-ExposedSettings': ExposedSettings
|
'ol-ExposedSettings': ExposedSettings
|
||||||
@@ -74,6 +75,7 @@ export interface Meta {
|
|||||||
'ol-adminCapabilities': AdminCapability[]
|
'ol-adminCapabilities': AdminCapability[]
|
||||||
'ol-adminSubscription': AdminSubscription
|
'ol-adminSubscription': AdminSubscription
|
||||||
'ol-aiAssistViaWritefullSource': string
|
'ol-aiAssistViaWritefullSource': string
|
||||||
|
'ol-algolia': AlgoliaConfig | undefined
|
||||||
'ol-allInReconfirmNotificationPeriods': UserEmailData[]
|
'ol-allInReconfirmNotificationPeriods': UserEmailData[]
|
||||||
'ol-allowedExperiments': string[]
|
'ol-allowedExperiments': string[]
|
||||||
'ol-allowedImageNames': AllowedImageName[]
|
'ol-allowedImageNames': AllowedImageName[]
|
||||||
|
|||||||
@@ -232,6 +232,7 @@
|
|||||||
"@testing-library/dom": "^10.4.0",
|
"@testing-library/dom": "^10.4.0",
|
||||||
"@testing-library/react": "^16.3.0",
|
"@testing-library/react": "^16.3.0",
|
||||||
"@testing-library/user-event": "^14.4.3",
|
"@testing-library/user-event": "^14.4.3",
|
||||||
|
"@types/algoliasearch": "^3.34.11",
|
||||||
"@types/bootstrap": "^5.2.10",
|
"@types/bootstrap": "^5.2.10",
|
||||||
"@types/chai": "^4.3.0",
|
"@types/chai": "^4.3.0",
|
||||||
"@types/dateformat": "^5.0.2",
|
"@types/dateformat": "^5.0.2",
|
||||||
|
|||||||
Reference in New Issue
Block a user