-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: Asset Search Provider Service & Component (#683)
* New: Added assets search provider and display component * Update: Gold bar * Update: Private display component name * Update: Add comments to tests * Update: Refactored tests * Update: Addressing comments * Update packages/core/addon/mirage/utils/rsql-utils.js Co-Authored-By: Kevin Hinterlong <kevinhinterlong@users.noreply.github.com> * Update packages/core/addon/mirage/utils/rsql-utils.js Co-Authored-By: Kevin Hinterlong <kevinhinterlong@users.noreply.github.com> * Update packages/core/app/mirage/routes/dashboard.js Co-Authored-By: Kevin Hinterlong <kevinhinterlong@users.noreply.github.com> * Update packages/core/app/mirage/routes/report.js Co-Authored-By: Kevin Hinterlong <kevinhinterlong@users.noreply.github.com> * Update packages/search/addon/components/navi-search-result/asset.hbs Co-Authored-By: Kevin Hinterlong <kevinhinterlong@users.noreply.github.com> * Update packages/search/addon/services/navi-search/navi-asset-search-provider.js Co-Authored-By: Kevin Hinterlong <kevinhinterlong@users.noreply.github.com> * Update: Addressing comments * Update: Addressing comments * Update: Addressing comments * Update: Typo * Update: Addressing comments * Update: Add package lock * Update: Parse route in component * Update: Added comments * Update: Addressing comments * Update bard.js * Update bard-dimensions.js * Update: Addressed comments * Update: Addressed comments * Update: Addressing comments Co-authored-by: Kevin Hinterlong <kevinhinterlong@users.noreply.github.com>
- Loading branch information
1 parent
99ffd4a
commit 3744eed
Showing
18 changed files
with
44,395 additions
and
729 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/** | ||
* Copyright 2020, Yahoo Holdings Inc. | ||
* Licensed under the terms of the MIT license. See accompanying LICENSE.md file for terms. | ||
* | ||
* Utilities for parsing RSQL. | ||
*/ | ||
|
||
import Response from 'ember-cli-mirage/response'; | ||
|
||
/** | ||
* @method getFilterParams – Parse filter parameters in the form of "(title==*H*,request==*Revenue*)";author==*ramvish* | ||
* to a list of all the OR parameters, ie., [H, Revenue] | ||
* @param {String} queryFilter | ||
* @returns {Array} Filter parameters | ||
*/ | ||
export function getFilterParams(queryFilter) { | ||
if (queryFilter && queryFilter.includes('author') && queryFilter.includes(';')) { | ||
queryFilter = queryFilter.split(';')[0]; | ||
return queryFilter | ||
.replace(/[()*]/g, '') | ||
.split(',') | ||
.map(el => el.split('==')); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @method getQueryAuthor – Parse filter parameters in the form of "(title==*H*,request==*Revenue*)";author==*ramvish* | ||
* to get the author, ie., ramvish | ||
* @param {String} queryFilter | ||
* @returns Author | ||
*/ | ||
export function getQueryAuthor(queryFilter) { | ||
if (queryFilter && queryFilter.includes('author')) { | ||
if (queryFilter.includes('(')) { | ||
queryFilter = queryFilter.split(';')[1]; | ||
} | ||
return queryFilter.split('==')[1]; | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @method filterModel – Filter a model's entries (report, dashboard) based on a query filter | ||
* @param {Object} model | ||
* @param {String} queryFilter | ||
* @returns {Object} modelObject | ||
*/ | ||
export function filterModel(model, queryFilter) { | ||
let modelObject; | ||
try { | ||
let filterParameters = getFilterParams(queryFilter); | ||
let author = getQueryAuthor(queryFilter); | ||
if (filterParameters == null && author == null) { | ||
throw new Error('No search parameters'); | ||
} | ||
modelObject = model.where(report => { | ||
// Author can be optional, ie., not included in the query, but filterparameters are always included. | ||
const matchesFilterParameterIfExists = filterParameters | ||
? filterParameters.some(filterParameter => | ||
JSON.stringify(report[filterParameter[0]]).match(new RegExp(filterParameter[1], 'i')) | ||
) | ||
: false; | ||
const matchesAuthorIfExists = author ? report.authorId.match(new RegExp(author, 'i')) : true; | ||
return matchesFilterParameterIfExists && matchesAuthorIfExists; | ||
}); | ||
} catch (error) { | ||
modelObject = new Response( | ||
400, | ||
{ data: {} }, | ||
{ | ||
errors: ['InvalidPredicateException: Invalid filter format'] | ||
} | ||
); | ||
} | ||
return modelObject; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/search/addon/components/navi-search-result/asset.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{{! Copyright 2020, Yahoo Holdings Inc. Licensed under the terms of the MIT license. See accompanying LICENSE.md file for terms. }} | ||
<ul class='navi-search-results' ...attributes> | ||
{{#each this.results as |result|}} | ||
<li class='navi-search-result__asset'> | ||
<LinkTo @route={{result.route}} @model={{result.modelId}}> | ||
{{result.title}} | ||
</LinkTo> | ||
</li> | ||
{{/each}} | ||
</ul> |
33 changes: 33 additions & 0 deletions
33
packages/search/addon/components/navi-search-result/asset.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright 2020, Yahoo Holdings Inc. | ||
* Licensed under the terms of the MIT license. See accompanying LICENSE.md file for terms. | ||
* | ||
* A component that displays results for reports and dashboards | ||
*/ | ||
|
||
import Component from '@glimmer/component'; | ||
import { pluralize } from 'ember-inflector'; | ||
|
||
export default class NaviAssetSearchResultComponent extends Component { | ||
/** | ||
* @property {Array} results | ||
*/ | ||
get results() { | ||
return this.args?.data?.map(value => { | ||
value.route = this._getRouteFor(value); | ||
return value; | ||
}); | ||
} | ||
|
||
/** | ||
* @method _extractRoute – Extracts the route name of a given asset (report or dashboard) | ||
* @private | ||
* @param {Object} asset | ||
* @returns {String} Route | ||
*/ | ||
_getRouteFor(asset) { | ||
const type = asset?.constructor?.modelName, | ||
pluralType = pluralize(type); | ||
return `${pluralType}.${type}`; | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
packages/search/addon/services/navi-search/navi-asset-search-provider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/** | ||
* Copyright 2020, Yahoo Holdings Inc. | ||
* Licensed under the terms of the MIT license. See accompanying LICENSE.md file for terms. | ||
* | ||
* This service is used to search for reports and dashboards stored in the persistence layer. | ||
*/ | ||
|
||
import { inject as service } from '@ember/service'; | ||
import NaviBaseSearchProviderService from '../navi-base-search-provider'; | ||
import { keepLatestTask } from 'ember-concurrency-decorators'; | ||
import { pluralize } from 'ember-inflector'; | ||
|
||
export default class NaviAssetSearchProviderService extends NaviBaseSearchProviderService { | ||
/** | ||
* @property {Ember.Service} store | ||
*/ | ||
@service store; | ||
|
||
/** | ||
* @property {Ember.Service} user | ||
*/ | ||
@service user; | ||
|
||
/** | ||
* @property {String} _displayComponentName | ||
* @private | ||
*/ | ||
_displayComponentName = 'navi-search-result/asset'; | ||
|
||
/** | ||
* @method _parseParamsFilterString – Parses string query to search parameters | ||
* @private | ||
* @param {String} query | ||
* @param {String} type | ||
* @returns {Object} query object | ||
*/ | ||
_parseParamsFilterString(query, type) { | ||
let paramsFilterString = ''; | ||
if (typeof query == 'string' && query) { | ||
if (type === 'report') { | ||
paramsFilterString = `(title==*${query}*,request==*${query}*)`; | ||
} else if (type === 'dashboard') { | ||
paramsFilterString = `(title==*${query}*)`; | ||
} | ||
} | ||
return paramsFilterString; | ||
} | ||
|
||
/** | ||
* @method _constructSearchQuery – Constructs the query filter parameters adhering to the RSQL standard | ||
* The query is built to return results from the specified author. The user's query is matched against multiple fields, | ||
* therefore an 'or' is used between the different parameters and finally there's an 'and' with the author. | ||
* @private | ||
* @param {String} userQuery | ||
* @param {String} type | ||
* @returns {Object} search query object | ||
*/ | ||
_constructSearchQuery(userQuery, type) { | ||
const author = this.user.getUser().id; | ||
const pluralType = pluralize(type); | ||
let query = { filter: { [pluralType]: '' } }; | ||
|
||
const paramsFilterString = this._parseParamsFilterString(userQuery, type); | ||
const authorFilterString = author ? (paramsFilterString ? `;author==${author}` : `author==${author}`) : ''; | ||
|
||
query.filter[pluralType] = `${paramsFilterString}${authorFilterString}`; | ||
|
||
return query; | ||
} | ||
|
||
/** | ||
* @method search – Searches for reports and dashboards in the persistence layer | ||
* @override | ||
* @param {String} query | ||
* @yields {Promise} promise with search query results | ||
* @returns {Object} Object containing component, title, and data to be displayed | ||
*/ | ||
@keepLatestTask | ||
*search(query) { | ||
const types = ['report', 'dashboard']; | ||
const promises = []; | ||
|
||
types.forEach(type => { | ||
promises.push(this.store.query(type, this._constructSearchQuery(query, type))); | ||
}); | ||
|
||
const data = yield Promise.all(promises).then(function(values) { | ||
return values.flatMap(value => value.toArray()); | ||
}); | ||
return { | ||
component: this._displayComponentName, | ||
title: 'Reports & Dashboards', | ||
data | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'navi-search/components/navi-search-result/asset'; |
1 change: 1 addition & 0 deletions
1
packages/search/app/services/navi-search/navi-asset-search-provider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from 'navi-search/services/navi-search/navi-asset-search-provider'; |
Oops, something went wrong.