From e0ba8a8f1a02efe6826b73c5887095a0193e2a12 Mon Sep 17 00:00:00 2001 From: roo hutton Date: Wed, 20 Aug 2025 11:01:38 +0100 Subject: [PATCH] Merge pull request #27895 from overleaf/rh-b2c-js-tsx-canceled Migrate B2C jsx to tsx: algolia-search and subscriptions GitOrigin-RevId: 917036ce6baf8130d2b10b46efa649f015b84576 --- package-lock.json | 8 ++++ .../{search-wiki.js => search-wiki.ts} | 42 ++++++++++++++++--- ...cription.jsx => canceled-subscription.tsx} | 0 .../{dashboard.jsx => dashboard.tsx} | 0 ...{invite-managed.jsx => invite-managed.tsx} | 0 ...iption.jsx => successful-subscription.tsx} | 0 services/web/frontend/js/utils/meta.ts | 2 + services/web/package.json | 1 + 8 files changed, 48 insertions(+), 5 deletions(-) rename services/web/frontend/js/features/algolia-search/{search-wiki.js => search-wiki.ts} (60%) rename services/web/frontend/js/pages/user/subscription/{canceled-subscription.jsx => canceled-subscription.tsx} (100%) rename services/web/frontend/js/pages/user/subscription/{dashboard.jsx => dashboard.tsx} (100%) rename services/web/frontend/js/pages/user/subscription/{invite-managed.jsx => invite-managed.tsx} (100%) rename services/web/frontend/js/pages/user/subscription/{successful-subscription.jsx => successful-subscription.tsx} (100%) diff --git a/package-lock.json b/package-lock.json index 9b21f9326d..32d1efc9db 100644 --- a/package-lock.json +++ b/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", diff --git a/services/web/frontend/js/features/algolia-search/search-wiki.js b/services/web/frontend/js/features/algolia-search/search-wiki.ts similarity index 60% rename from services/web/frontend/js/features/algolia-search/search-wiki.js rename to services/web/frontend/js/features/algolia-search/search-wiki.ts index 9e2a50a42d..6e085cab66 100644 --- a/services/web/frontend/js/features/algolia-search/search-wiki.js +++ b/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 { 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 } -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' diff --git a/services/web/frontend/js/pages/user/subscription/canceled-subscription.jsx b/services/web/frontend/js/pages/user/subscription/canceled-subscription.tsx similarity index 100% rename from services/web/frontend/js/pages/user/subscription/canceled-subscription.jsx rename to services/web/frontend/js/pages/user/subscription/canceled-subscription.tsx diff --git a/services/web/frontend/js/pages/user/subscription/dashboard.jsx b/services/web/frontend/js/pages/user/subscription/dashboard.tsx similarity index 100% rename from services/web/frontend/js/pages/user/subscription/dashboard.jsx rename to services/web/frontend/js/pages/user/subscription/dashboard.tsx diff --git a/services/web/frontend/js/pages/user/subscription/invite-managed.jsx b/services/web/frontend/js/pages/user/subscription/invite-managed.tsx similarity index 100% rename from services/web/frontend/js/pages/user/subscription/invite-managed.jsx rename to services/web/frontend/js/pages/user/subscription/invite-managed.tsx diff --git a/services/web/frontend/js/pages/user/subscription/successful-subscription.jsx b/services/web/frontend/js/pages/user/subscription/successful-subscription.tsx similarity index 100% rename from services/web/frontend/js/pages/user/subscription/successful-subscription.jsx rename to services/web/frontend/js/pages/user/subscription/successful-subscription.tsx diff --git a/services/web/frontend/js/utils/meta.ts b/services/web/frontend/js/utils/meta.ts index 162ed749f1..4e56245b50 100644 --- a/services/web/frontend/js/utils/meta.ts +++ b/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[] diff --git a/services/web/package.json b/services/web/package.json index 45a564781d..2c674ac6a8 100644 --- a/services/web/package.json +++ b/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",