Просмотр исходного кода

Merge pull request #27895 from overleaf/rh-b2c-js-tsx-canceled

Migrate B2C jsx to tsx: algolia-search and subscriptions

GitOrigin-RevId: 917036ce6baf8130d2b10b46efa649f015b84576
roo hutton 11 месяцев назад
Родитель
Сommit
e0ba8a8f1a

+ 8 - 0
package-lock.json

@@ -11812,6 +11812,13 @@
         "@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": {
       "version": "5.0.4",
       "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/react": "^16.3.0",
         "@testing-library/user-event": "^14.4.3",
+        "@types/algoliasearch": "^3.34.11",
         "@types/bootstrap": "^5.2.10",
         "@types/chai": "^4.3.0",
         "@types/dateformat": "^5.0.2",

+ 37 - 5
services/web/frontend/js/features/algolia-search/search-wiki.js → services/web/frontend/js/features/algolia-search/search-wiki.ts

@@ -2,12 +2,44 @@ import _ from 'lodash'
 import AlgoliaSearch from 'algoliasearch'
 import getMeta from '../../utils/meta'
 
-let wikiIdx
-export async function searchWiki(...args) {
+interface WikiHit {
+  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) {
     const algoliaConfig = getMeta('ol-algolia')
     const wikiIndex = _.get(algoliaConfig, 'indexes.wiki')
-    if (wikiIndex) {
+    if (wikiIndex && algoliaConfig) {
       const client = AlgoliaSearch(algoliaConfig.appId, algoliaConfig.apiKey)
       wikiIdx = client.initIndex(wikiIndex)
     }
@@ -15,10 +47,10 @@ export async function searchWiki(...args) {
   if (!wikiIdx) {
     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 pageSlug = encodeURIComponent(pageUnderscored)
   const pagePath = hit.kb ? 'how-to' : 'latex'

+ 0 - 0
services/web/frontend/js/pages/user/subscription/canceled-subscription.jsx → services/web/frontend/js/pages/user/subscription/canceled-subscription.tsx


+ 0 - 0
services/web/frontend/js/pages/user/subscription/dashboard.jsx → services/web/frontend/js/pages/user/subscription/dashboard.tsx


+ 0 - 0
services/web/frontend/js/pages/user/subscription/invite-managed.jsx → services/web/frontend/js/pages/user/subscription/invite-managed.tsx


+ 0 - 0
services/web/frontend/js/pages/user/subscription/successful-subscription.jsx → services/web/frontend/js/pages/user/subscription/successful-subscription.tsx


+ 2 - 0
services/web/frontend/js/utils/meta.ts

@@ -64,6 +64,7 @@ import { ActiveExperiment } from './labs-utils'
 import { Subscription as AdminSubscription } from '../../../types/admin/subscription'
 import { AdminCapability } from '../../../types/admin-capabilities'
 import { GroupAuditLog } from '../../../modules/group-audit-log/frontend/js/components/logs'
+import { AlgoliaConfig } from '../../../modules/algolia-search/frontend/js/types'
 
 export interface Meta {
   'ol-ExposedSettings': ExposedSettings
@@ -74,6 +75,7 @@ export interface Meta {
   'ol-adminCapabilities': AdminCapability[]
   'ol-adminSubscription': AdminSubscription
   'ol-aiAssistViaWritefullSource': string
+  'ol-algolia': AlgoliaConfig | undefined
   'ol-allInReconfirmNotificationPeriods': UserEmailData[]
   'ol-allowedExperiments': string[]
   'ol-allowedImageNames': AllowedImageName[]

+ 1 - 0
services/web/package.json

@@ -232,6 +232,7 @@
     "@testing-library/dom": "^10.4.0",
     "@testing-library/react": "^16.3.0",
     "@testing-library/user-event": "^14.4.3",
+    "@types/algoliasearch": "^3.34.11",
     "@types/bootstrap": "^5.2.10",
     "@types/chai": "^4.3.0",
     "@types/dateformat": "^5.0.2",