Skip to content

Commit

Permalink
[SDPAP-6808] Data listing i.e custom table (#1276)
Browse files Browse the repository at this point in the history
* feat(@dpc-sdp/ripple-nuxt-tide): add data listing landing page component and mappings, Tide-Api-Search-Index header

* feat(@dpc-sdp/ripple-tide-search-api): add tide-api-search-index to search and getAggregations helper function

* feat: reference site; add data driven component and config

* feat(@dpc-sdp/ripple-nuxt-tide): update nodeModulePath to get data driven component working in monorepo

* feat: updates for new pipeline data, rename to avoid conflict

* feat: add query field boosts

* feat(@dpc-sdp/ripple-nuxt-tide): add support for fuzy matching

* feat(reference): remove data list

* feat(reference): remove myvic nohoist

* feat(reference): revert config-loader update as we no longer need this change

---------

Co-authored-by: David Featherston <david.featherstone@dpc.vic.gov.au>
  • Loading branch information
lambry and David Featherston committed Mar 22, 2023
1 parent 18e536a commit 771a447
Show file tree
Hide file tree
Showing 14 changed files with 874 additions and 141 deletions.
39 changes: 22 additions & 17 deletions packages/ripple-nuxt-tide/lib/core/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,29 @@ export default class TideSearchApi {
this.client = client
}

async search (url, params) {
getConfig (index) {
let headers = {
'TIDE_API_HEADER': 'elastic',
'Content-Type': 'application/json'
}
if (index) {
headers['Tide-Api-Search-Index'] = index
}

return {
baseURL: this.baseUrl,
responseType: 'json',
responseEncoding: 'utf8',
headers
}
}

async search (url, params, index = '') {
try {
const config = {
method: 'get',
baseURL: this.baseUrl,
...this.getConfig(index),
url,
responseType: 'json',
responseEncoding: 'utf8',
headers: {
'TIDE_API_HEADER': 'elastic',
'Content-Type': 'application/json'
},
method: 'get',
paramsSerializer: function (params) {
return qs.stringify(params, { arrayFormat: 'brackets' })
},
Expand All @@ -44,18 +55,12 @@ export default class TideSearchApi {
}
}

async searchByPost (data) {
async searchByPost (data, index = '') {
try {
const config = {
...this.getConfig(index),
method: 'post',
baseURL: this.baseUrl,
url: '/dsl',
responseType: 'json',
responseEncoding: 'utf8',
headers: {
'TIDE_API_HEADER': 'elastic',
'Content-Type': 'application/json'
},
data
}
const response = await this.client(config)
Expand Down
5 changes: 4 additions & 1 deletion packages/ripple-nuxt-tide/lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ const nuxtTide = function (moduleOptions) {
this.addServerMiddleware(require('./server-middleware/basic-auth.js'))
}

if (options.modules?.landingPage?.contentCollection !== false) {
if (
options.modules?.landingPage?.contentCollection !== false &&
options.modules?.landingPage?.dataList !== false
) {
const searchApiOptions = options.searchApi || {}
this.addServerMiddleware(tideSearchApiMiddleware({
templates: options.searchTemplates,
Expand Down
5 changes: 4 additions & 1 deletion packages/ripple-nuxt-tide/lib/templates/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ export default ({ app, req, store , route }, inject) => {
return window.location.origin + apiRoot
}
}
if (options.modules?.landingPage?.contentCollection !== false) {
if (
options.modules?.landingPage?.contentCollection !== false &&
options.modules?.landingPage?.dataList !== false
) {
inject('tideSearchApi', new TideSearchApi({
client: app.$axios,
baseUrl: getBaseUrl()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getQueryParams } from '../lib/data-list'

const data = {
perPage: 10,
currentPage: 1,
sort: 'title',
sortOptions: [{
id: 'title',
name: 'Title',
order: 'asc'
}],
model: {
search: 'Melbourne',
status: ['Pending', 'Complete']
},
searchField: 'search',
queryFields: ['title'],
aggregationFields: ['status']
}

describe('getQueryParams', () => {
const params = getQueryParams(data)

test('should be sorting in ascending order by title', () => {
expect(params.sort).toEqual({ title: 'asc' })
})

test('should return query field value when search field model is set', () => {
expect(params.q).toEqual('Melbourne')
})

test('should return formatted filters with the search field value', () => {
expect(params.filters.status.values).toContain('Pending')
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ describe('Card collection search template', () => {
})
})
})

describe('Data listing search template', () => {
test('should have template', () => {
expect(searchTemplate).toHaveProperty('data-list')
expect(searchTemplate['data-list']).toHaveProperty('requestMapping')
expect(typeof searchTemplate['data-list'].requestMapping).toEqual('function')
})
})

0 comments on commit 771a447

Please sign in to comment.