@yext/visual-editor 2.0.0-beta.11 → 2.0.0-beta.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{SectionLibraryVisualEditorProvider-DJMXab-H.js → SectionLibraryVisualEditorProvider-DJezMczO.js} +4106 -4029
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.test.tsx +1 -1
- package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.tsx +44 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorRadius.test.ts +418 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorResultCard.tsx +25 -0
- package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorWrapper.tsx +58 -25
- package/dist/cli/assets/directory-locator-source/sectionLibrarySupport.ts +4 -0
- package/dist/cli/yextve.js +3 -3
- package/dist/{createYextFieldTransforms-B7vqqb3m.d.ts → createYextFieldTransforms-B3f0jVg6.d.ts} +22 -15
- package/dist/index.d.ts +19 -10
- package/dist/locales/platform/cs/visual-editor.json +4 -0
- package/dist/locales/platform/da/visual-editor.json +4 -0
- package/dist/locales/platform/de/visual-editor.json +4 -0
- package/dist/locales/platform/en/visual-editor.json +4 -0
- package/dist/locales/platform/en-GB/visual-editor.json +4 -0
- package/dist/locales/platform/es/visual-editor.json +4 -0
- package/dist/locales/platform/et/visual-editor.json +4 -0
- package/dist/locales/platform/fi/visual-editor.json +4 -0
- package/dist/locales/platform/fr/visual-editor.json +4 -0
- package/dist/locales/platform/hr/visual-editor.json +4 -0
- package/dist/locales/platform/hu/visual-editor.json +4 -0
- package/dist/locales/platform/it/visual-editor.json +4 -0
- package/dist/locales/platform/ja/visual-editor.json +4 -0
- package/dist/locales/platform/lt/visual-editor.json +4 -0
- package/dist/locales/platform/lv/visual-editor.json +4 -0
- package/dist/locales/platform/nb/visual-editor.json +4 -0
- package/dist/locales/platform/nl/visual-editor.json +4 -0
- package/dist/locales/platform/pl/visual-editor.json +4 -0
- package/dist/locales/platform/pt/visual-editor.json +4 -0
- package/dist/locales/platform/ro/visual-editor.json +4 -0
- package/dist/locales/platform/sk/visual-editor.json +4 -0
- package/dist/locales/platform/sv/visual-editor.json +4 -0
- package/dist/locales/platform/tr/visual-editor.json +4 -0
- package/dist/locales/platform/zh/visual-editor.json +4 -0
- package/dist/locales/platform/zh-TW/visual-editor.json +4 -0
- package/dist/plugin/plugin.js +2 -1
- package/dist/plugin/vite-plugin/layout-generation/modelProxy.d.ts +1 -1
- package/dist/section-library-support.js +52 -52
- package/dist/sectionLibrarySupport.d.ts +2 -2
- package/dist/{visual-editor-Bs3wAslG.js → visual-editor-89bNoCOk.js} +4 -0
- package/dist/{visual-editor-sOPDMkOR.js → visual-editor-8Okvw03s.js} +25 -21
- package/dist/{visual-editor-vomNdlNO.js → visual-editor-B-9-8VqT.js} +40 -36
- package/dist/{visual-editor-DjTEbi-1.js → visual-editor-BEiQqs_Z.js} +4 -0
- package/dist/{visual-editor-D7VeTRK_.js → visual-editor-BPOG2TRh.js} +4 -0
- package/dist/{visual-editor-DkHhrFsX.js → visual-editor-BWDv00Sj.js} +19 -15
- package/dist/{visual-editor-zKhC7_0C.js → visual-editor-BfzO6vuG.js} +25 -21
- package/dist/{visual-editor-Duishbsa.js → visual-editor-BmfXE4Nt.js} +19 -15
- package/dist/{visual-editor-QpGupjY5.js → visual-editor-C5aegP-t.js} +73 -69
- package/dist/{visual-editor-CHWtMtlu.js → visual-editor-C7Ne5NW6.js} +39 -35
- package/dist/{visual-editor-DtL-Zuv_.js → visual-editor-CJMynoK2.js} +40 -36
- package/dist/{visual-editor-CtQwadxQ.js → visual-editor-C_SC4gLo.js} +4 -0
- package/dist/{visual-editor-ClC6hoz3.js → visual-editor-CiE_sZgp.js} +37 -33
- package/dist/{visual-editor-C9TLeAzP.js → visual-editor-Crc50YSl.js} +24 -20
- package/dist/{visual-editor-BK6fTU7k.js → visual-editor-DSYNp8sQ.js} +4 -0
- package/dist/{visual-editor-CcfUKpnd.js → visual-editor-DVI-AF67.js} +26 -22
- package/dist/{visual-editor-qJW0uCiQ.js → visual-editor-D_Xqs07E.js} +57 -53
- package/dist/{visual-editor-tPb7n5l8.js → visual-editor-DcNe0Txh.js} +25 -21
- package/dist/{visual-editor-LXMNWXry.js → visual-editor-DuH1uy-p.js} +57 -53
- package/dist/{visual-editor-DTE5kxrA.js → visual-editor-DuxrpEsM.js} +20 -16
- package/dist/{visual-editor-_TatCCAS.js → visual-editor-TsYZAz_J.js} +4 -0
- package/dist/{visual-editor-6mKs9VUe.js → visual-editor-bjHpuHcP.js} +20 -16
- package/dist/{visual-editor-gjpr-NAN.js → visual-editor-d-SdfYpR.js} +25 -21
- package/dist/{visual-editor-gEaWoNRu.js → visual-editor-dWLAQOr6.js} +4 -0
- package/dist/{visual-editor-BruRrJYN.js → visual-editor-yqgcCbY4.js} +4 -0
- package/dist/visual-editor.css +1 -1
- package/dist/visual-editor.js +4370 -4315
- package/package.json +3 -3
package/dist/cli/assets/directory-locator-source/components/sections/locator/Locator.test.tsx
CHANGED
|
@@ -1471,7 +1471,7 @@ describe("Locator", async () => {
|
|
|
1471
1471
|
String(input).includes("/search/filtersearch")
|
|
1472
1472
|
)
|
|
1473
1473
|
).toBe(false);
|
|
1474
|
-
expect(screen.
|
|
1474
|
+
expect(await screen.findByText(/Custom Search Area/)).toBeInTheDocument();
|
|
1475
1475
|
} finally {
|
|
1476
1476
|
window.history.replaceState(window.history.state, "", originalUrl);
|
|
1477
1477
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getPreferredDistanceUnit } from "../../../utils/i18n/distance.ts";
|
|
1
2
|
import { FieldLabel, setDeep } from "@puckeditor/core";
|
|
2
3
|
import { type MultiSelectorValue } from "../../../fields/MultiSelectorField.tsx";
|
|
3
4
|
import { YextAutoField } from "../../../fields/YextAutoField.tsx";
|
|
@@ -34,6 +35,7 @@ import {
|
|
|
34
35
|
DEFAULT_LOCATION_STYLE,
|
|
35
36
|
DEFAULT_MAKI_ICON_NAME,
|
|
36
37
|
DEFAULT_PIN_ICON_WIDTH,
|
|
38
|
+
DEFAULT_RADIUS,
|
|
37
39
|
LOCATOR_PIN_ICON_FIELD,
|
|
38
40
|
MAX_PIN_ICON_WIDTH,
|
|
39
41
|
makiIconOptions,
|
|
@@ -98,6 +100,17 @@ export interface LocatorProps {
|
|
|
98
100
|
keywordsDisplayName?: TranslatableString;
|
|
99
101
|
};
|
|
100
102
|
|
|
103
|
+
/**
|
|
104
|
+
* The default radius for nearby-location searches. Leave unset to use Search's
|
|
105
|
+
* suggested radius, or 25 in the locale's preferred unit for coordinate searches.
|
|
106
|
+
* Visitor-selected distances and explicit map/URL search areas take precedence.
|
|
107
|
+
* Geographic boundary filters are unaffected.
|
|
108
|
+
*/
|
|
109
|
+
defaultSearchRadius?: {
|
|
110
|
+
value?: number;
|
|
111
|
+
unit: "mile" | "kilometer";
|
|
112
|
+
};
|
|
113
|
+
|
|
101
114
|
/**
|
|
102
115
|
* The starting location for the map.
|
|
103
116
|
*/
|
|
@@ -336,6 +349,37 @@ const locatorFields: YextFields<LocatorProps> = {
|
|
|
336
349
|
},
|
|
337
350
|
},
|
|
338
351
|
},
|
|
352
|
+
defaultSearchRadius: {
|
|
353
|
+
type: "optional",
|
|
354
|
+
label: msg("fields.defaultSearchRadius", "Default Search Radius"),
|
|
355
|
+
defaultCustomValue: ({ locale }) => ({
|
|
356
|
+
value: DEFAULT_RADIUS,
|
|
357
|
+
unit: getPreferredDistanceUnit(locale),
|
|
358
|
+
}),
|
|
359
|
+
field: {
|
|
360
|
+
type: "object",
|
|
361
|
+
objectFields: {
|
|
362
|
+
value: {
|
|
363
|
+
type: "number",
|
|
364
|
+
label: msg("fields.radius", "Radius"),
|
|
365
|
+
min: 0,
|
|
366
|
+
step: 1,
|
|
367
|
+
},
|
|
368
|
+
unit: {
|
|
369
|
+
type: "basicSelector",
|
|
370
|
+
generation: { required: true },
|
|
371
|
+
label: msg("fields.distanceUnit", "Distance Unit"),
|
|
372
|
+
options: [
|
|
373
|
+
{ label: msg("mile", "mile", { count: 2 }), value: "mile" },
|
|
374
|
+
{
|
|
375
|
+
label: msg("kilometer", "kilometer", { count: 2 }),
|
|
376
|
+
value: "kilometer",
|
|
377
|
+
},
|
|
378
|
+
],
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
},
|
|
382
|
+
},
|
|
339
383
|
mapStartingLocation: {
|
|
340
384
|
type: "object",
|
|
341
385
|
label: msg("fields.options.mapStartingLocation", "Map Starting Location"),
|
package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorRadius.test.ts
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { act, cleanup, render, screen, waitFor } from "@testing-library/react";
|
|
3
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
4
|
+
import {
|
|
5
|
+
Matcher,
|
|
6
|
+
type NearFilterValue,
|
|
7
|
+
type SelectableStaticFilter,
|
|
8
|
+
} from "@yext/search-headless-react";
|
|
9
|
+
import { getUserLocation, type FilterSearch } from "@yext/search-ui-react";
|
|
10
|
+
import type { FilterModal } from "./Filters.tsx";
|
|
11
|
+
import type { LocatorMap } from "./Map.tsx";
|
|
12
|
+
import type { LocatorProps } from "./Locator.tsx";
|
|
13
|
+
import { LocatorWrapper } from "./LocatorWrapper.tsx";
|
|
14
|
+
|
|
15
|
+
const mocks = vi.hoisted(() => ({
|
|
16
|
+
locale: "en",
|
|
17
|
+
state: {
|
|
18
|
+
vertical: { results: [], resultsCount: 0, offset: 0 },
|
|
19
|
+
filters: { static: [] as SelectableStaticFilter[], facets: [] },
|
|
20
|
+
searchStatus: { isLoading: false },
|
|
21
|
+
},
|
|
22
|
+
filterSearch: {} as React.ComponentProps<typeof FilterSearch>,
|
|
23
|
+
filterModal: {} as React.ComponentProps<typeof FilterModal>,
|
|
24
|
+
map: {} as React.ComponentProps<typeof LocatorMap>,
|
|
25
|
+
actions: {
|
|
26
|
+
setSessionTrackingEnabled: vi.fn(),
|
|
27
|
+
setFacetAllowList: vi.fn(),
|
|
28
|
+
setOffset: vi.fn(),
|
|
29
|
+
setVerticalLimit: vi.fn(),
|
|
30
|
+
setStaticFilters: vi.fn(),
|
|
31
|
+
setFilterOption: vi.fn(),
|
|
32
|
+
executeVerticalQuery: vi.fn(),
|
|
33
|
+
executeFilterSearch: vi.fn(),
|
|
34
|
+
resetFacets: vi.fn(),
|
|
35
|
+
},
|
|
36
|
+
}));
|
|
37
|
+
|
|
38
|
+
vi.mock("@yext/search-headless-react", async (importOriginal) => ({
|
|
39
|
+
...(await importOriginal<typeof import("@yext/search-headless-react")>()),
|
|
40
|
+
provideHeadless: () => mocks.actions,
|
|
41
|
+
SearchHeadlessProvider: ({ children }: React.PropsWithChildren) => children,
|
|
42
|
+
useSearchActions: () => mocks.actions,
|
|
43
|
+
useSearchState: (selector: (state: typeof mocks.state) => unknown) =>
|
|
44
|
+
selector(mocks.state),
|
|
45
|
+
}));
|
|
46
|
+
vi.mock("@yext/search-ui-react", () => ({
|
|
47
|
+
AnalyticsProvider: ({ children }: React.PropsWithChildren) => children,
|
|
48
|
+
SearchI18nextProvider: ({ children }: React.PropsWithChildren) => children,
|
|
49
|
+
useAnalytics: () => undefined,
|
|
50
|
+
AppliedFilters: () => null,
|
|
51
|
+
Pagination: () => null,
|
|
52
|
+
VerticalResults: () => null,
|
|
53
|
+
FilterSearch: (props: typeof mocks.filterSearch) => {
|
|
54
|
+
mocks.filterSearch = props;
|
|
55
|
+
return null;
|
|
56
|
+
},
|
|
57
|
+
getUserLocation: vi
|
|
58
|
+
.fn()
|
|
59
|
+
.mockRejectedValue(new Error("Geolocation unavailable")),
|
|
60
|
+
executeSearch: () => mocks.actions.executeVerticalQuery(),
|
|
61
|
+
}));
|
|
62
|
+
vi.mock("@yext/pages-components", () => ({ useAnalytics: () => undefined }));
|
|
63
|
+
vi.mock("react-i18next", async (importOriginal) => ({
|
|
64
|
+
...(await importOriginal<typeof import("react-i18next")>()),
|
|
65
|
+
useTranslation: () => ({
|
|
66
|
+
t: (_key: string, fallback: string) => fallback,
|
|
67
|
+
i18n: { language: mocks.locale },
|
|
68
|
+
}),
|
|
69
|
+
}));
|
|
70
|
+
vi.mock("../../../hooks/useDocument.tsx", () => ({
|
|
71
|
+
useDocument: () => ({ id: "locator", locale: mocks.locale }),
|
|
72
|
+
}));
|
|
73
|
+
vi.mock("../../../hooks/useViewport.ts", () => ({
|
|
74
|
+
getViewport: () => ({ isMobile: false }),
|
|
75
|
+
useWindowWidth: () => 1024,
|
|
76
|
+
}));
|
|
77
|
+
vi.mock("../../../utils/searchHeadlessConfig.ts", () => ({
|
|
78
|
+
createSearchHeadlessConfig: () => ({}),
|
|
79
|
+
createSearchAnalyticsConfig: () => ({}),
|
|
80
|
+
}));
|
|
81
|
+
vi.mock("./Map.tsx", async (importOriginal) => ({
|
|
82
|
+
...(await importOriginal<typeof import("./Map.tsx")>()),
|
|
83
|
+
LocatorMap: (props: typeof mocks.map) => {
|
|
84
|
+
mocks.map = props;
|
|
85
|
+
return null;
|
|
86
|
+
},
|
|
87
|
+
LoadingMapPlaceholder: () => null,
|
|
88
|
+
}));
|
|
89
|
+
vi.mock("./Filters.tsx", async (importOriginal) => ({
|
|
90
|
+
...(await importOriginal<typeof import("./Filters.tsx")>()),
|
|
91
|
+
FilterModal: (props: typeof mocks.filterModal) => {
|
|
92
|
+
mocks.filterModal = props;
|
|
93
|
+
return null;
|
|
94
|
+
},
|
|
95
|
+
}));
|
|
96
|
+
vi.mock("./Results.tsx", () => ({
|
|
97
|
+
RESULTS_LIMIT: 20,
|
|
98
|
+
MobileLocatorResultsSection: () => null,
|
|
99
|
+
ResultsCountSummary: () => null,
|
|
100
|
+
}));
|
|
101
|
+
vi.mock("./LocatorResultCard.tsx", () => ({
|
|
102
|
+
DEFAULT_LOCATOR_RESULT_CARD_PROPS: {},
|
|
103
|
+
LocatorResultCard: () => null,
|
|
104
|
+
}));
|
|
105
|
+
|
|
106
|
+
const suggestedValue = { lat: 38.9, lng: -77.1, radius: 12000 };
|
|
107
|
+
const getLocationFilter = () =>
|
|
108
|
+
mocks.state.filters.static.find(
|
|
109
|
+
({ filter }) =>
|
|
110
|
+
filter.kind === "fieldValue" && filter.fieldId === "builtin.location"
|
|
111
|
+
)?.filter;
|
|
112
|
+
const getRadius = () =>
|
|
113
|
+
(getLocationFilter() as { value: NearFilterValue } | undefined)?.value.radius;
|
|
114
|
+
const renderLocator = (radius?: LocatorProps["defaultSearchRadius"]) =>
|
|
115
|
+
render(
|
|
116
|
+
React.createElement(LocatorWrapper, {
|
|
117
|
+
locationStyles: [],
|
|
118
|
+
resultCard: [],
|
|
119
|
+
filters: { openNowButton: false, showDistanceOptions: true },
|
|
120
|
+
defaultSearchRadius: radius,
|
|
121
|
+
puck: {
|
|
122
|
+
metadata: {},
|
|
123
|
+
isEditing: false,
|
|
124
|
+
dragRef: null,
|
|
125
|
+
renderDropZone: () => null,
|
|
126
|
+
},
|
|
127
|
+
})
|
|
128
|
+
);
|
|
129
|
+
const selectSuggestion = async () =>
|
|
130
|
+
act(async () => {
|
|
131
|
+
mocks.filterSearch.onSelect?.({
|
|
132
|
+
currentFilter: undefined,
|
|
133
|
+
setCurrentFilter: vi.fn(),
|
|
134
|
+
executeFilterSearch: mocks.actions.executeFilterSearch,
|
|
135
|
+
newFilter: {
|
|
136
|
+
kind: "fieldValue",
|
|
137
|
+
fieldId: "builtin.location",
|
|
138
|
+
matcher: Matcher.Near,
|
|
139
|
+
value: suggestedValue,
|
|
140
|
+
},
|
|
141
|
+
newDisplayName: "Arlington",
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
beforeEach(() => {
|
|
146
|
+
vi.clearAllMocks();
|
|
147
|
+
vi.mocked(getUserLocation).mockRejectedValue(
|
|
148
|
+
new Error("Geolocation unavailable")
|
|
149
|
+
);
|
|
150
|
+
mocks.locale = "en";
|
|
151
|
+
mocks.state.filters = { static: [], facets: [] };
|
|
152
|
+
window.history.replaceState(null, "", "/");
|
|
153
|
+
mocks.actions.setStaticFilters.mockImplementation(
|
|
154
|
+
(filters: SelectableStaticFilter[]) => {
|
|
155
|
+
mocks.state.filters = { ...mocks.state.filters, static: filters };
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
mocks.actions.executeFilterSearch.mockResolvedValue({
|
|
159
|
+
sections: [
|
|
160
|
+
{
|
|
161
|
+
results: [
|
|
162
|
+
{
|
|
163
|
+
value: "Arlington",
|
|
164
|
+
filter: {
|
|
165
|
+
kind: "fieldValue",
|
|
166
|
+
fieldId: "builtin.location",
|
|
167
|
+
matcher: Matcher.Near,
|
|
168
|
+
value: suggestedValue,
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
],
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
afterEach(() => {
|
|
177
|
+
cleanup();
|
|
178
|
+
window.history.replaceState(null, "", "/");
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
describe("Locator default search radius", () => {
|
|
182
|
+
it.each<{
|
|
183
|
+
name: string;
|
|
184
|
+
query: string;
|
|
185
|
+
radius?: LocatorProps["defaultSearchRadius"];
|
|
186
|
+
locale?: string;
|
|
187
|
+
expected: number;
|
|
188
|
+
}>([
|
|
189
|
+
{
|
|
190
|
+
name: "uses Search's suggested radius when automatic",
|
|
191
|
+
query: "?q=Arlington",
|
|
192
|
+
expected: 12000,
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: "overrides named searches in miles",
|
|
196
|
+
query: "?q=Arlington",
|
|
197
|
+
radius: { value: 50, unit: "mile" },
|
|
198
|
+
expected: 80467.2,
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
name: "overrides legacy initialLocation searches in kilometers",
|
|
202
|
+
query: "?initialLocation=Arlington",
|
|
203
|
+
radius: { value: 60, unit: "kilometer" },
|
|
204
|
+
expected: 60000,
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: "uses the configured radius for initial coordinates",
|
|
208
|
+
query: "",
|
|
209
|
+
radius: { value: 50, unit: "kilometer" },
|
|
210
|
+
expected: 50000,
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
name: "uses 25 miles for automatic English coordinates",
|
|
214
|
+
query: "",
|
|
215
|
+
expected: 40233.6,
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
name: "uses 25 kilometers for automatic French coordinates",
|
|
219
|
+
query: "",
|
|
220
|
+
locale: "fr",
|
|
221
|
+
expected: 25000,
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
name: "converts configured miles independently of locale",
|
|
225
|
+
query: "?q=Arlington",
|
|
226
|
+
locale: "fr",
|
|
227
|
+
radius: { value: 50, unit: "mile" },
|
|
228
|
+
expected: 80467.2,
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
name: "preserves explicit URL areas",
|
|
232
|
+
query: "?q=38.9,-77.1,9000",
|
|
233
|
+
radius: { value: 50, unit: "mile" },
|
|
234
|
+
expected: 9000,
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
name: "treats cleared values as automatic",
|
|
238
|
+
query: "?q=Arlington",
|
|
239
|
+
radius: { unit: "mile" },
|
|
240
|
+
expected: 12000,
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
name: "treats zero as automatic",
|
|
244
|
+
query: "?q=Arlington",
|
|
245
|
+
radius: { value: 0, unit: "mile" },
|
|
246
|
+
expected: 12000,
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: "uses the locale fallback for zero coordinate radius",
|
|
250
|
+
query: "",
|
|
251
|
+
radius: { value: 0, unit: "kilometer" },
|
|
252
|
+
expected: 40233.6,
|
|
253
|
+
},
|
|
254
|
+
])("$name", async ({ query, radius, locale = "en", expected }) => {
|
|
255
|
+
mocks.locale = locale;
|
|
256
|
+
window.history.replaceState(null, "", `/${query}`);
|
|
257
|
+
renderLocator(radius);
|
|
258
|
+
await waitFor(() => expect(getRadius()).toBeCloseTo(expected));
|
|
259
|
+
expect(mocks.filterSearch.geolocationProps?.radius).toBeCloseTo(
|
|
260
|
+
radius?.value
|
|
261
|
+
? radius.value * (radius.unit === "mile" ? 1 : 1 / 1.609344)
|
|
262
|
+
: locale === "en"
|
|
263
|
+
? 25
|
|
264
|
+
: 25 / 1.609344
|
|
265
|
+
);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("uses the configured radius for suggestions and restores it after distance overrides", async () => {
|
|
269
|
+
renderLocator({ value: 50, unit: "mile" });
|
|
270
|
+
await waitFor(() => expect(getRadius()).toBeCloseTo(80467.2));
|
|
271
|
+
await selectSuggestion();
|
|
272
|
+
expect(getRadius()).toBeCloseTo(80467.2);
|
|
273
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
274
|
+
expect(getRadius()).toBeCloseTo(8046.72);
|
|
275
|
+
await selectSuggestion();
|
|
276
|
+
expect(getRadius()).toBeCloseTo(8046.72);
|
|
277
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
278
|
+
expect(getRadius()).toBeCloseTo(80467.2);
|
|
279
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
280
|
+
await act(async () => mocks.filterModal.handleClearFiltersClick());
|
|
281
|
+
expect(getRadius()).toBeCloseTo(80467.2);
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it.each(["builtin.region", "address.countryCode"])(
|
|
285
|
+
"preserves %s boundary filters",
|
|
286
|
+
async (fieldId) => {
|
|
287
|
+
const filter = {
|
|
288
|
+
kind: "fieldValue" as const,
|
|
289
|
+
fieldId,
|
|
290
|
+
matcher: Matcher.Equals,
|
|
291
|
+
value: "VA",
|
|
292
|
+
};
|
|
293
|
+
mocks.actions.executeFilterSearch.mockResolvedValue({
|
|
294
|
+
sections: [{ results: [{ value: "Virginia", filter }] }],
|
|
295
|
+
});
|
|
296
|
+
window.history.replaceState(null, "", "/?q=Virginia");
|
|
297
|
+
renderLocator({ value: 50, unit: "mile" });
|
|
298
|
+
await waitFor(() =>
|
|
299
|
+
expect(mocks.actions.executeVerticalQuery).toHaveBeenCalled()
|
|
300
|
+
);
|
|
301
|
+
expect(mocks.state.filters.static[0].filter).toEqual(filter);
|
|
302
|
+
await act(async () =>
|
|
303
|
+
mocks.filterSearch.onSelect?.({
|
|
304
|
+
currentFilter: undefined,
|
|
305
|
+
setCurrentFilter: vi.fn(),
|
|
306
|
+
executeFilterSearch: mocks.actions.executeFilterSearch,
|
|
307
|
+
newFilter: filter,
|
|
308
|
+
newDisplayName: "Virginia",
|
|
309
|
+
})
|
|
310
|
+
);
|
|
311
|
+
expect(mocks.state.filters.static[0].filter).toEqual(filter);
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
it.each<{
|
|
316
|
+
radius?: LocatorProps["defaultSearchRadius"];
|
|
317
|
+
locale: string;
|
|
318
|
+
accuracy: number;
|
|
319
|
+
expected: number;
|
|
320
|
+
}>([
|
|
321
|
+
{
|
|
322
|
+
radius: { value: 50, unit: "kilometer" },
|
|
323
|
+
locale: "en",
|
|
324
|
+
accuracy: 10,
|
|
325
|
+
expected: 50000,
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
radius: { value: 50, unit: "kilometer" },
|
|
329
|
+
locale: "en",
|
|
330
|
+
accuracy: 100000,
|
|
331
|
+
expected: 100000,
|
|
332
|
+
},
|
|
333
|
+
{
|
|
334
|
+
radius: { value: 50, unit: "mile" },
|
|
335
|
+
locale: "en",
|
|
336
|
+
accuracy: 100000,
|
|
337
|
+
expected: 100000,
|
|
338
|
+
},
|
|
339
|
+
{ locale: "en", accuracy: 100000, expected: 100000 },
|
|
340
|
+
{ locale: "fr", accuracy: 10, expected: 25000 },
|
|
341
|
+
{ locale: "fr", accuracy: 100000, expected: 100000 },
|
|
342
|
+
])(
|
|
343
|
+
"respects initial geolocation accuracy $accuracy with radius $radius in $locale",
|
|
344
|
+
async ({ radius, locale, accuracy, expected }) => {
|
|
345
|
+
mocks.locale = locale;
|
|
346
|
+
vi.mocked(getUserLocation).mockResolvedValue({
|
|
347
|
+
coords: { latitude: 38.9, longitude: -77.1, accuracy },
|
|
348
|
+
} as GeolocationPosition);
|
|
349
|
+
renderLocator(radius);
|
|
350
|
+
await waitFor(() => expect(getRadius()).toBeCloseTo(expected));
|
|
351
|
+
await act(async () =>
|
|
352
|
+
mocks.filterModal.handleDistanceClick(
|
|
353
|
+
5,
|
|
354
|
+
locale === "en" ? "mile" : "kilometer"
|
|
355
|
+
)
|
|
356
|
+
);
|
|
357
|
+
await act(async () => mocks.filterModal.handleClearFiltersClick());
|
|
358
|
+
expect(getRadius()).toBeCloseTo(expected);
|
|
359
|
+
}
|
|
360
|
+
);
|
|
361
|
+
|
|
362
|
+
it.each([10, 10000])(
|
|
363
|
+
"preserves the selected distance and configured base with initial accuracy %s",
|
|
364
|
+
async (accuracy) => {
|
|
365
|
+
renderLocator({ value: 50, unit: "kilometer" });
|
|
366
|
+
await waitFor(() => expect(getRadius()).toBe(50000));
|
|
367
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
368
|
+
vi.mocked(getUserLocation).mockResolvedValue({
|
|
369
|
+
coords: { latitude: 38.9, longitude: -77.1, accuracy },
|
|
370
|
+
} as GeolocationPosition);
|
|
371
|
+
await act(async () =>
|
|
372
|
+
window.dispatchEvent(new PopStateEvent("popstate"))
|
|
373
|
+
);
|
|
374
|
+
await waitFor(() =>
|
|
375
|
+
expect(getRadius()).toBeCloseTo(Math.max(accuracy, 8046.72))
|
|
376
|
+
);
|
|
377
|
+
await act(async () => mocks.filterModal.handleClearFiltersClick());
|
|
378
|
+
expect(getRadius()).toBe(50000);
|
|
379
|
+
}
|
|
380
|
+
);
|
|
381
|
+
|
|
382
|
+
it.each([10, 100000])(
|
|
383
|
+
"respects current-location accuracy of %s meters and restores the base radius",
|
|
384
|
+
async (accuracy) => {
|
|
385
|
+
renderLocator({ value: 50, unit: "kilometer" });
|
|
386
|
+
await waitFor(() => expect(getRadius()).toBe(50000));
|
|
387
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
388
|
+
await act(async () =>
|
|
389
|
+
mocks.filterSearch.geolocationProps?.handleClick?.({
|
|
390
|
+
coords: { latitude: 38.9, longitude: -77.1, accuracy },
|
|
391
|
+
} as GeolocationPosition)
|
|
392
|
+
);
|
|
393
|
+
expect(getRadius()).toBeCloseTo(Math.max(accuracy, 8046.72));
|
|
394
|
+
await act(async () => mocks.filterModal.handleClearFiltersClick());
|
|
395
|
+
expect(getRadius()).toBe(Math.max(accuracy, 50000));
|
|
396
|
+
}
|
|
397
|
+
);
|
|
398
|
+
|
|
399
|
+
it("preserves a map search area and clears the previous distance selection", async () => {
|
|
400
|
+
renderLocator({ value: 50, unit: "mile" });
|
|
401
|
+
await waitFor(() => expect(getRadius()).toBeCloseTo(80467.2));
|
|
402
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
403
|
+
await act(async () =>
|
|
404
|
+
mocks.map.onDragHandler?.(
|
|
405
|
+
{ latitude: 38.9, longitude: -77.1, distanceTo: () => 9000 } as any,
|
|
406
|
+
{ getNorthEast: () => ({}) } as any
|
|
407
|
+
)
|
|
408
|
+
);
|
|
409
|
+
await act(async () =>
|
|
410
|
+
screen.getByRole("button", { name: "Search This Area" }).click()
|
|
411
|
+
);
|
|
412
|
+
expect(getRadius()).toBe(9000);
|
|
413
|
+
expect(mocks.filterModal.selectedDistanceOption).toBeNull();
|
|
414
|
+
await act(async () => mocks.filterModal.handleDistanceClick(5, "mile"));
|
|
415
|
+
await act(async () => mocks.filterModal.handleClearFiltersClick());
|
|
416
|
+
expect(getRadius()).toBe(9000);
|
|
417
|
+
});
|
|
418
|
+
});
|
package/dist/cli/assets/directory-locator-source/components/sections/locator/LocatorResultCard.tsx
CHANGED
|
@@ -176,6 +176,12 @@ export interface LocatorResultCardProps {
|
|
|
176
176
|
/** Whether to show the "Get Directions" link */
|
|
177
177
|
showGetDirectionsLink: boolean;
|
|
178
178
|
|
|
179
|
+
/**
|
|
180
|
+
* Whether to open the Get Directions link in a new tab.
|
|
181
|
+
* @defaultValue false
|
|
182
|
+
*/
|
|
183
|
+
openInNewTab?: boolean;
|
|
184
|
+
|
|
179
185
|
/** Whether the address block is visible in live mode */
|
|
180
186
|
liveVisibility: boolean;
|
|
181
187
|
};
|
|
@@ -299,6 +305,7 @@ export const DEFAULT_LOCATOR_RESULT_CARD_PROPS: LocatorResultCardProps = {
|
|
|
299
305
|
showRegion: true,
|
|
300
306
|
showCountry: false,
|
|
301
307
|
showGetDirectionsLink: true,
|
|
308
|
+
openInNewTab: false,
|
|
302
309
|
liveVisibility: true,
|
|
303
310
|
},
|
|
304
311
|
phone: {
|
|
@@ -613,6 +620,14 @@ export const LocatorResultCardFields: YextObjectField<LocatorResultCardProps> =
|
|
|
613
620
|
{ label: msg("fields.options.no", "No"), value: false },
|
|
614
621
|
],
|
|
615
622
|
},
|
|
623
|
+
openInNewTab: {
|
|
624
|
+
label: msg("fields.openInNewTab", "Open in new tab"),
|
|
625
|
+
type: "radio",
|
|
626
|
+
options: [
|
|
627
|
+
{ label: msg("fields.options.yes", "Yes"), value: true },
|
|
628
|
+
{ label: msg("fields.options.no", "No"), value: false },
|
|
629
|
+
],
|
|
630
|
+
},
|
|
616
631
|
liveVisibility: {
|
|
617
632
|
label: msg("fields.visibleOnLivePage", "Visible on Live Page"),
|
|
618
633
|
type: "radio",
|
|
@@ -1029,6 +1044,16 @@ export const LocatorResultCard = React.memo(
|
|
|
1029
1044
|
props.address.showGetDirectionsLink && (
|
|
1030
1045
|
<a
|
|
1031
1046
|
href={getDirectionsLink}
|
|
1047
|
+
target={
|
|
1048
|
+
props.address.openInNewTab
|
|
1049
|
+
? "_blank"
|
|
1050
|
+
: undefined
|
|
1051
|
+
}
|
|
1052
|
+
rel={
|
|
1053
|
+
props.address.openInNewTab
|
|
1054
|
+
? "noopener noreferrer"
|
|
1055
|
+
: undefined
|
|
1056
|
+
}
|
|
1032
1057
|
onClick={handleGetDirectionsClick}
|
|
1033
1058
|
aria-label={t("getDirectionsForLocation", {
|
|
1034
1059
|
address: location.address.line1,
|