Skip to content

Commit c1f93f7

Browse files
authored
Adds search landing page (#236)
* restrict controlled-term search to reference-datatype matches * add resource-type and search-definition count endpoints * extract shared search-request/definition helpers * add pending-search store for SearchLanding to SimpleSearch handoff * fix MapFilterPanel to use MapComponent instead of MapWidget * prep SimpleSearch components for reuse * split TermFilter into chip and standalone inputs * add SearchLanding page * nit * fix TS2709 namespace errors on MapComponent type imports * Revert "fix TS2709 namespace errors on MapComponent type imports" This reverts commit 2a7b3f6. * nit * PR feedback
1 parent c4780fe commit c1f93f7

38 files changed

Lines changed: 3237 additions & 548 deletions

‎arches_search/src/arches_search/AdvancedSearch/components/PayloadBuilder/components/GroupBuilder/components/TimeFilter.vue‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const { modelValue, graphSlug } = defineProps<{
3131
}>();
3232
3333
const emit = defineEmits<{
34-
(event: typeof UPDATE_EVENT, clause: LiteralClause): void;
35-
(event: typeof REMOVE_EVENT): void;
34+
(event: "update:modelValue", clause: LiteralClause): void;
35+
(event: "remove"): void;
3636
}>();
3737
3838
const datatypesToAdvancedSearchFacets = inject<

‎arches_search/src/arches_search/SearchApp.vue‎

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,33 @@ import Button from "primevue/button";
66
import Card from "primevue/card";
77
88
import { routeNames } from "@/arches_search/routes.ts";
9+
import { usePendingSearchStore } from "@/arches_search/stores/usePendingSearchStore.ts";
910
1011
const router = useRouter();
1112
const route = useRoute();
1213
14+
router.afterEach((to, _from, failure) => {
15+
if (to.name !== routeNames.simpleSearch || failure) {
16+
usePendingSearchStore().clear();
17+
}
18+
});
19+
20+
const isSearchLanding = computed(() => route.name === routeNames.searchLanding);
1321
const isSimpleSearch = computed(() => route.name === routeNames.simpleSearch);
1422
</script>
1523

1624
<template>
17-
<Card class="search-card">
25+
<Card
26+
:class="{
27+
'search-card': !isSearchLanding,
28+
'search-landing-card': isSearchLanding,
29+
}"
30+
>
1831
<template #header>
19-
<header class="simple-search-header">
32+
<header
33+
v-if="!isSearchLanding"
34+
class="simple-search-header"
35+
>
2036
<h1 class="search-title">
2137
<i class="pi pi-search" />
2238
{{ $gettext("Search the Collection") }}
@@ -26,11 +42,11 @@ const isSimpleSearch = computed(() => route.name === routeNames.simpleSearch);
2642
class="header-nav"
2743
>
2844
<Button
29-
:label="$gettext('Advanced Search')"
3045
icon="pi pi-sliders-h"
3146
icon-pos="left"
32-
:text="true"
3347
class="header-link"
48+
:label="$gettext('Advanced Search')"
49+
:text="true"
3450
@click="
3551
router.push({ name: routeNames.advancedSearch })
3652
"
@@ -41,11 +57,11 @@ const isSimpleSearch = computed(() => route.name === routeNames.simpleSearch);
4157
class="header-nav"
4258
>
4359
<Button
44-
:label="$gettext('Simple Search')"
4560
icon="pi pi-sliders-h"
4661
icon-pos="left"
47-
:text="true"
4862
class="header-link"
63+
:label="$gettext('Simple Search')"
64+
:text="true"
4965
@click="router.push({ name: routeNames.simpleSearch })"
5066
/>
5167
</nav>
@@ -66,9 +82,16 @@ const isSimpleSearch = computed(() => route.name === routeNames.simpleSearch);
6682
border: 0.1rem solid var(--p-content-border-color);
6783
border-radius: 0;
6884
background-color: var(--arches-search-card-bg);
69-
box-shadow:
70-
0 0.1rem 0.3rem rgba(0, 0, 0, 0.06),
71-
0 0.1rem 0.2rem rgba(0, 0, 0, 0.04);
85+
box-shadow: var(--arches-search-card-shadow);
86+
}
87+
88+
.search-landing-card {
89+
display: flex;
90+
flex-direction: column;
91+
block-size: 100%;
92+
overflow-y: auto;
93+
border-radius: 0;
94+
background-color: var(--arches-search-page-bg);
7295
}
7396
7497
.simple-search-header {
@@ -98,18 +121,26 @@ const isSimpleSearch = computed(() => route.name === routeNames.simpleSearch);
98121
color: var(--p-primary-color);
99122
}
100123
101-
:deep(.p-card-body) {
124+
.search-card :deep(.p-card-body),
125+
.search-landing-card :deep(.p-card-body) {
102126
display: flex;
103127
flex-direction: column;
104128
flex: 1;
105-
min-block-size: 0;
106129
padding: 0;
130+
}
131+
132+
.search-card :deep(.p-card-content),
133+
.search-landing-card :deep(.p-card-content) {
134+
flex: 1;
135+
}
136+
137+
.search-card :deep(.p-card-body) {
138+
min-block-size: 0;
107139
overflow-x: hidden;
108140
overflow-y: hidden;
109141
}
110142
111-
:deep(.p-card-content) {
112-
flex: 1;
143+
.search-card :deep(.p-card-content) {
113144
min-block-size: 0;
114145
}
115146
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
<script setup lang="ts">
2+
import { computed, defineAsyncComponent, ref, watchEffect } from "vue";
3+
import { useRouter } from "vue-router";
4+
import { useGettext } from "vue3-gettext";
5+
6+
import SearchLandingHero from "@/arches_search/SearchLanding/components/SearchLandingHero.vue";
7+
import SearchLandingTabs from "@/arches_search/SearchLanding/components/SearchLandingTabs.vue";
8+
import TermSearchInput from "@/arches_search/SimpleSearch/components/TermFilter/TermSearchInput.vue";
9+
import { fetchResourceTypeCounts } from "@/arches_search/SearchLanding/api.ts";
10+
import { useLandingContent } from "@/arches_search/SearchLanding/landing-content.ts";
11+
import { routeNames } from "@/arches_search/routes.ts";
12+
import { usePendingSearchStore } from "@/arches_search/stores/usePendingSearchStore.ts";
13+
14+
import type { Component } from "vue";
15+
import type { TermKind } from "@/arches_search/SimpleSearch/types.ts";
16+
17+
const router = useRouter();
18+
const { interpolate } = useGettext();
19+
20+
const { branding, tabs } = useLandingContent();
21+
const activeTabSlug = ref(tabs[0]?.slug ?? "");
22+
const componentBySlug: Record<string, Component> = Object.fromEntries(
23+
tabs.map((tab) => [
24+
tab.slug,
25+
defineAsyncComponent(() => import(`@/${tab.component}.vue`)),
26+
]),
27+
);
28+
29+
const totalResourceCount = ref<number | null>(null);
30+
31+
const resolvedSubtitle = computed<string | null>(() => {
32+
if (!branding.subtitle) {
33+
return branding.subtitle;
34+
}
35+
if (totalResourceCount.value === null) {
36+
return branding.subtitle;
37+
}
38+
return interpolate(branding.subtitle, {
39+
total: String(totalResourceCount.value),
40+
});
41+
});
42+
43+
const activeTabComponent = computed<Component | null>(
44+
() => componentBySlug[activeTabSlug.value] ?? null,
45+
);
46+
47+
watchEffect(async () => {
48+
try {
49+
const counts = await fetchResourceTypeCounts();
50+
totalResourceCount.value = counts.reduce(
51+
(sum, entry) => sum + entry.count,
52+
0,
53+
);
54+
} catch (error) {
55+
console.error(error);
56+
}
57+
});
58+
59+
function onTabSelect(slug: string): void {
60+
activeTabSlug.value = slug;
61+
}
62+
63+
function onSearchBarSubmit(payload: {
64+
text: string;
65+
termKind?: TermKind;
66+
icon?: string;
67+
}): void {
68+
usePendingSearchStore().set({
69+
term: payload.text,
70+
...(payload.termKind ? { termKind: payload.termKind } : {}),
71+
...(payload.icon ? { termIcon: payload.icon } : {}),
72+
});
73+
router.push({ name: routeNames.simpleSearch });
74+
}
75+
</script>
76+
77+
<template>
78+
<div class="search-landing">
79+
<SearchLandingHero
80+
:eyebrow="branding.eyebrow"
81+
:title="branding.title"
82+
:subtitle="resolvedSubtitle"
83+
>
84+
<TermSearchInput @submit="onSearchBarSubmit" />
85+
</SearchLandingHero>
86+
87+
<div class="search-landing-content">
88+
<SearchLandingTabs
89+
:tabs="tabs"
90+
:model-value="activeTabSlug"
91+
@update:model-value="onTabSelect"
92+
/>
93+
94+
<div class="search-landing-tab-panel">
95+
<KeepAlive>
96+
<component :is="activeTabComponent" />
97+
</KeepAlive>
98+
</div>
99+
100+
<section
101+
v-if="
102+
branding.aboutHeading ||
103+
(branding.aboutBody && branding.aboutBody.length > 0)
104+
"
105+
class="search-landing-about"
106+
>
107+
<div class="search-landing-about-header">
108+
<i
109+
v-if="branding.aboutIcon"
110+
:class="branding.aboutIcon"
111+
/>
112+
<h2
113+
v-if="branding.aboutHeading"
114+
class="search-landing-about-heading"
115+
>
116+
{{ branding.aboutHeading }}
117+
</h2>
118+
</div>
119+
<p
120+
v-for="(paragraph, paragraphIndex) in branding.aboutBody"
121+
:key="paragraphIndex"
122+
class="search-landing-about-body"
123+
>
124+
{{ paragraph }}
125+
</p>
126+
</section>
127+
</div>
128+
</div>
129+
</template>
130+
131+
<style scoped>
132+
.search-landing {
133+
display: flex;
134+
flex-direction: column;
135+
min-block-size: 100%;
136+
}
137+
138+
.search-landing-content {
139+
max-inline-size: 120rem;
140+
margin-inline: auto;
141+
padding-block: 3.2rem 4.8rem;
142+
padding-inline: 2rem;
143+
inline-size: 100%;
144+
}
145+
146+
.search-landing-tab-panel {
147+
min-block-size: 48rem;
148+
padding-block-start: 0.8rem;
149+
}
150+
151+
.search-landing-about {
152+
max-inline-size: 70rem;
153+
margin-block: 4.8rem 0;
154+
margin-inline: auto;
155+
padding-block: 2.2rem;
156+
padding-inline: 2.4rem;
157+
border: 0.1rem solid var(--arches-search-card-border);
158+
border-radius: 1.2rem;
159+
background: var(--arches-search-card-bg);
160+
}
161+
162+
.search-landing-about-header {
163+
display: flex;
164+
align-items: center;
165+
gap: 0.7rem;
166+
margin-block-end: 0.6rem;
167+
}
168+
169+
.search-landing-about-header .pi {
170+
color: var(--p-primary-color);
171+
font-size: 1.4rem;
172+
}
173+
174+
.search-landing-about-heading {
175+
margin: 0;
176+
font-size: 1.6rem;
177+
font-weight: 700;
178+
color: var(--p-text-color);
179+
}
180+
181+
.search-landing-about-body {
182+
margin-block: 0 1.2rem;
183+
margin-inline: 0;
184+
font-size: 1.3rem;
185+
line-height: 1.8;
186+
color: var(--p-text-muted-color);
187+
}
188+
189+
.search-landing-about-body:last-of-type {
190+
margin-block-end: 0;
191+
}
192+
</style>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import Cookies from "js-cookie";
2+
3+
import { generateArchesURL } from "@/arches_vue_components/application";
4+
5+
import type {
6+
ResourceTypeCount,
7+
SearchDefinitionCountRequest,
8+
} from "@/arches_search/SearchLanding/types.ts";
9+
10+
export async function fetchResourceTypeCounts(): Promise<ResourceTypeCount[]> {
11+
const response = await fetch(
12+
generateArchesURL("arches_search:resource_type_counts"),
13+
);
14+
if (!response.ok) {
15+
throw new Error(response.statusText);
16+
}
17+
const data = (await response.json()) as {
18+
resourceTypes: ResourceTypeCount[];
19+
};
20+
return data.resourceTypes;
21+
}
22+
23+
export async function fetchSearchDefinitionCounts(
24+
items: SearchDefinitionCountRequest[],
25+
): Promise<Record<string, number | null>> {
26+
const response = await fetch(
27+
generateArchesURL("arches_search:search_definition_counts"),
28+
{
29+
method: "POST",
30+
headers: {
31+
"Content-Type": "application/json",
32+
"X-CSRFToken": Cookies.get("csrftoken") || "",
33+
},
34+
body: JSON.stringify({ items }),
35+
},
36+
);
37+
if (!response.ok) {
38+
throw new Error(response.statusText);
39+
}
40+
const data = (await response.json()) as {
41+
counts: Record<string, number | null>;
42+
};
43+
return data.counts;
44+
}

0 commit comments

Comments
 (0)