Skip to content

Commit 2c4613d

Browse files
cdxkerskeptrunedev
authored andcommitted
feature: add openLinksInNewTab as a new parameter for the search component and public page
1 parent 5281e45 commit 2c4613d

File tree

10 files changed

+53
-13
lines changed

10 files changed

+53
-13
lines changed

clients/search-component/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"import": "./dist/vanilla/index.js"
2020
}
2121
},
22-
"version": "0.2.9",
22+
"version": "0.2.10",
2323
"license": "MIT",
2424
"homepage": "https://github.com/devflowinc/trieve/tree/main/clients/search-component",
2525
"scripts": {

clients/search-component/src/TrieveModal/Search/DocsItem.tsx

+9-10
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,11 @@ export const DocsItem = ({ item, requestID, index, className }: Props) => {
6060
descriptionHtml = descriptionHtml.replace(curHeadingText || "", "");
6161
}
6262
descriptionHtml = descriptionHtml.replace(/([.,!?;:])/g, "$1 ");
63-
let title = `${
64-
cleanFirstHeading ||
63+
let title = `${cleanFirstHeading ||
6564
item.chunk.metadata?.title ||
6665
item.chunk.metadata?.page_title ||
6766
item.chunk.metadata?.name
68-
}`.replace("#", "");
67+
}`.replace("#", "");
6968

7069
if (!title.trim() || title == "undefined") {
7170
return null;
@@ -102,8 +101,8 @@ export const DocsItem = ({ item, requestID, index, className }: Props) => {
102101
.map((word) => word.replace(/-/g, " "))
103102
.concat(
104103
item.chunk.metadata?.title ||
105-
item.chunk.metadata.summary ||
106-
urlElements.slice(-1)[0]
104+
item.chunk.metadata.summary ||
105+
urlElements.slice(-1)[0]
107106
)
108107
.map((word) =>
109108
word
@@ -143,6 +142,7 @@ export const DocsItem = ({ item, requestID, index, className }: Props) => {
143142
<li key={item.chunk.id}>
144143
<Component
145144
ref={itemRef}
145+
target={props.openLinksInNewTab ? "_blank" : ""}
146146
id={`trieve-search-item-${index + 1}`}
147147
className={className ?? "item"}
148148
onClick={() =>
@@ -162,12 +162,11 @@ export const DocsItem = ({ item, requestID, index, className }: Props) => {
162162
}}
163163
{...(item.chunk.link
164164
? {
165-
href: `${
166-
item.chunk.link.endsWith("/")
167-
? item.chunk.link.slice(0, -1)
168-
: item.chunk.link
165+
href: `${item.chunk.link.endsWith("/")
166+
? item.chunk.link.slice(0, -1)
167+
: item.chunk.link
169168
}${linkSuffix}`,
170-
}
169+
}
171170
: {})}
172171
>
173172
<div>

clients/search-component/src/utils/hooks/modal-context.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export type ModalProps = {
6666
currencyPosition?: currencyPosition;
6767
responsive?: boolean;
6868
open?: boolean;
69+
openLinksInNewTab?: boolean;
6970
onOpenChange?: (open: boolean) => void;
7071
debounceMs?: number;
7172
};
@@ -93,6 +94,7 @@ const defaultProps = {
9394
useGroupSearch: false,
9495
allowSwitchingModes: true,
9596
defaultCurrency: "$",
97+
openLinksInNewTab: false,
9698
currencyPosition: "before" as currencyPosition,
9799
responsive: false,
98100
debounceMs: 0,

clients/ts-sdk/openapi.json

+4
Original file line numberDiff line numberDiff line change
@@ -12068,6 +12068,10 @@
1206812068
],
1206912069
"nullable": true
1207012070
},
12071+
"openLinksInNewTab": {
12072+
"type": "boolean",
12073+
"nullable": true
12074+
},
1207112075
"placeholder": {
1207212076
"type": "string",
1207312077
"nullable": true

clients/ts-sdk/src/types.gen.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1978,6 +1978,7 @@ export type PublicPageParameters = {
19781978
heroPattern?: ((HeroPattern) | null);
19791979
navLogoImgSrcUrl?: (string) | null;
19801980
openGraphMetadata?: ((OpenGraphMetadata) | null);
1981+
openLinksInNewTab?: (boolean) | null;
19811982
placeholder?: (string) | null;
19821983
problemLink?: (string) | null;
19831984
responsive?: (boolean) | null;

frontends/dashboard/src/pages/dataset/PublicPageSettings.tsx

+27
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,33 @@ const PublicPageControls = () => {
647647
/>
648648
</div>
649649
</div>
650+
<div class="grid grid-cols-2 gap-4">
651+
<div class="flex gap-2">
652+
<div class="flex items-center gap-1">
653+
<label class="block" for="">
654+
Default Open in new tab
655+
</label>
656+
<Tooltip
657+
tooltipText="Enable users to switch between search modes"
658+
body={
659+
<FaRegularCircleQuestion class="h-3 w-3 text-black" />
660+
}
661+
/>
662+
</div>
663+
<input
664+
type="checkbox"
665+
checked={extraParams.openLinksInNewTab || false}
666+
onChange={(e) => {
667+
setExtraParams(
668+
"openLinksInNewTab",
669+
e.currentTarget.checked,
670+
);
671+
}}
672+
class="block w-4 rounded border border-neutral-300 px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
673+
/>
674+
</div>
675+
</div>
676+
650677
</div>
651678
</details>
652679

server/Dockerfile.server

+2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ RUN cargo install cargo-chef
66
WORKDIR /app
77

88
FROM chef AS planner
9+
RUN mkdir /hallucination-detection
910
COPY . .
11+
COPY ../hallucination-detection/ /hallucination-detection
1012
RUN cargo chef prepare --recipe-path recipe.json
1113

1214
FROM chef AS builder

server/src/data/models.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3164,6 +3164,9 @@ impl DatasetConfigurationDTO {
31643164
open_graph_metadata: page_parameters_self
31653165
.open_graph_metadata
31663166
.or(page_parameters_curr.open_graph_metadata),
3167+
open_links_in_new_tab: page_parameters_self
3168+
.open_links_in_new_tab
3169+
.or(page_parameters_curr.open_links_in_new_tab),
31673170
}),
31683171
},
31693172
DISABLE_ANALYTICS: self

server/src/handlers/page_handler.rs

+2
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ pub struct PublicPageParameters {
192192
pub tab_messages: Option<Vec<PublicPageTabMessage>>,
193193
#[serde(skip_serializing_if = "Option::is_none")]
194194
pub open_graph_metadata: Option<OpenGraphMetadata>,
195+
#[serde(skip_serializing_if = "Option::is_none")]
196+
pub open_links_in_new_tab: Option<bool>,
195197
}
196198

197199
#[utoipa::path(

server/src/public/page.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<link rel="stylesheet" href="/static/output.css" />
55
<link
66
rel="stylesheet"
7-
href="https://unpkg.com/[email protected].9/dist/index.css"
7+
href="https://unpkg.com/[email protected].10/dist/index.css"
88
/>
99
<link
1010
rel="apple-touch-icon"
@@ -181,7 +181,7 @@
181181
</style>
182182

183183
<script type="module">
184-
import {renderToDiv} from 'https://unpkg.com/[email protected].9/dist/vanilla/index.js';
184+
import {renderToDiv} from 'https://unpkg.com/[email protected].10/dist/vanilla/index.js';
185185
window.addEventListener('load', () => {
186186
const root = document.getElementById('root');
187187
renderToDiv(root, {

0 commit comments

Comments
 (0)