Skip to content

Commit

Permalink
feat(@dpc-sdp/ripple-tide-search): add siteSearchContentTypes feature…
Browse files Browse the repository at this point in the history
…Flag
  • Loading branch information
David Featherston committed Jul 23, 2024
1 parent 560ddc1 commit 1d2ab6f
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 8 deletions.
17 changes: 14 additions & 3 deletions examples/nuxt-app/test/features/site/search.feature
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
Feature: Site search

Background:
Given the site endpoint returns fixture "/site/reference" with status 200

@mockserver
Example: Display and manage site search results
Given the site endpoint returns fixture "/site/reference" with status 200
Given the "/api/tide/search/**" network request is delayed by 500 milliseconds and stubbed with fixture "/site/search-response", status 200 and alias "siteSearchReq"
When I visit the page "/search?q=demo"
Then the search listing skeleton should display 10 items with the class "tide-search-result-skeleton"
Expand Down Expand Up @@ -35,8 +33,21 @@ Feature: Site search
Then the filters toggle should show 0 applied filters
And the search input should have the value ""

@mockserver
Example: Overrides site search content types with feature flag
Given the "/api/tide/search/**" network request is stubbed with fixture "/site/search-response" and status 200 as alias "siteSearchReq"
Then I load the site fixture with "/site/reference"
And the feature flag "siteSearchContentTypes" is set to "landing_page, event, news, publication"
And the site endpoint returns the loaded fixture

When I visit the page "/search?q=demo"
Then I toggle the search listing filters section
And I clear the search filters
Then the network request "siteSearchReq" should be called with the "/site/search-request-content-types" fixture

@mockserver
Example: Search bar max input length
Given the site endpoint returns fixture "/site/reference" with status 200
Given the "/api/tide/search/**" network request is stubbed with fixture "/site/search-response" and status 200 as alias "siteSearchReq"
When I visit the page "/search"
Then the search input should be have a max length of 128
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"query": "",
"filters": {
"all": [
{
"any": [
{
"field_node_site": "TEST_SITE"
}
]
},
{
"any": [
{
"type": [
"landing_page",
"event",
"news",
"publication"
]
}
]
}
]
},
"search_fields": {
"title": {
"weight": 10
},
"body": {},
"field_paragraph_body": {},
"field_landing_page_summary": {},
"summary_processed": {},
"field_paragraph_summary": {},
"field_event_details_event_locality": {}
},
"result_fields": {
"title": {
"raw": {
"size": 150
}
},
"field_landing_page_summary": {
"snippet": {
"size": 150,
"fallback": true
}
},
"summary_processed": {
"snippet": {
"size": 150,
"fallback": true
}
},
"changed": {
"raw": {}
},
"url": {
"raw": {}
},
"type": {
"raw": {}
}
},
"page": {
"size": 10,
"current": 1
}
}
4 changes: 4 additions & 0 deletions packages/ripple-tide-api/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,10 @@ export interface IRplFeatureFlags {
* @description Sets the number of toggle-able levels
*/
sectionNavToggleLevels?: number
/**
* @description Allow overriding the site search content types
*/
siteSearchContentTypes?: string
/**
* @description Custom flags
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/ripple-tide-search/components/TideSearchPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { ref, watch } from 'vue'
import {
getActiveFilterURL,
scrollToElementTopWithOffset,
useRuntimeConfig,
useTideSite
useRuntimeConfig
} from '#imports'
import useSearchUI from './../composables/useSearchUI'
import {
Expand All @@ -15,9 +14,11 @@ import { FormKit } from '@formkit/vue'
import { SearchDriverOptions } from '@elastic/search-ui'
import { useRippleEvent } from '@dpc-sdp/ripple-ui-core'
import type { rplEventPayload } from '@dpc-sdp/ripple-ui-core'
import type { TideSiteData } from '@dpc-sdp/ripple-tide-api/types'
interface Props {
id: string
site: TideSiteData
pageTitle: string
filtersConfig: AppSearchFilterConfigItem[]
searchDriverOptions: Omit<SearchDriverOptions, 'apiConnector'>
Expand Down Expand Up @@ -81,7 +82,6 @@ const emit = defineEmits<{
const { emitRplEvent } = useRippleEvent('tide-search', emit)
const { public: config } = useRuntimeConfig()
const site = await useTideSite()
const apiConnectorOptions = {
// Omit the search key, we'll add it on the server
Expand Down
15 changes: 13 additions & 2 deletions packages/ripple-tide-search/pages/search.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<script setup lang="ts">
import { AppSearchFilterConfigItem, MappedSearchResult } from '../types'
import { formatDate, useRuntimeConfig, useAppConfig } from '#imports'
import {
formatDate,
useRuntimeConfig,
useAppConfig,
useTideSite
} from '#imports'
const appConfig = useAppConfig()
const runtimeConfig = useRuntimeConfig()
const site = await useTideSite()
const filtersConfig: AppSearchFilterConfigItem[] = [
{
Expand All @@ -25,7 +31,11 @@ const searchDriverOptions = {
},
{
field: 'type',
values: appConfig.ripple?.search?.contentTypes
values: site?.featureFlags?.siteSearchContentTypes
? site?.featureFlags?.siteSearchContentTypes
.split(',')
.map((type) => type.trim())
: appConfig.ripple?.search?.contentTypes
}
],
search_fields: {
Expand Down Expand Up @@ -101,6 +111,7 @@ const searchResultsMappingFn = (item): MappedSearchResult<any> => {
<template>
<TideSearchPage
pageTitle="Search"
:site="site"
:searchDriverOptions="searchDriverOptions"
:filtersConfig="filtersConfig"
:searchResultsMappingFn="searchResultsMappingFn"
Expand Down

0 comments on commit 1d2ab6f

Please sign in to comment.