Skip to content

Commit

Permalink
Remove sample & sample areas from add things step UI #1305
Browse files Browse the repository at this point in the history
They will not appear in select2 widget search suggestion,
in result from search API, or in sidebar initial results.

They will still appear in the final report's
"Child Physical Things" section
  • Loading branch information
jacobtylerwalls committed Oct 11, 2023
1 parent dc2ae3d commit 18b3538
Showing 1 changed file with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ define([
params.dirty(dirty);
});

const sampleSubstring = '[Sample'; // for "[Sample of ..." and "[Sample Area of ..."
const regionSubstring = '[Region';
const sampleConceptId = '9db724b9-b3c7-4761-9a50-673d64a15bd8';
const sampleAreaConceptId = '2703e524-b5ea-4548-bea7-7ce354e4e05a';
const regionConceptId = 'a2588fa8-5ae6-4770-a473-dec0c05fb175';

this.value.subscribe(function(a) {
a.forEach(function(action) {
if (action.status === 'added') {
Expand Down Expand Up @@ -116,6 +122,12 @@ define([
.filter(rr =>
rr.graph_id === "9519cb4f-b25b-11e9-8c7b-a4d18cec433a"
)
// Exclude related resources that are samples or sample areas
.filter(rr =>
rr.domains.map(d => d.conceptid).filter(
cid => [sampleConceptId, sampleAreaConceptId, regionConceptId].includes(cid)
).length === 0
)
);

self.startValue().forEach(function(val){
Expand Down Expand Up @@ -237,6 +249,27 @@ define([
params.form.save = self.submit;
params.form.onSaveSuccess = function() {};

const termFilterExcludingSamples = {
type: 'string',
context: '',
context_label: 'Exclude samples',
id: 'sample',
// not localized
text: sampleSubstring,
value: sampleSubstring,
inverted: 'true',
};
const termFilterExcludingRegions = {
type: 'string',
context: '',
context_label: 'Exclude regions',
id: 'region',
// not localized
text: regionSubstring,
value: regionSubstring,
inverted: 'true',
};

this.targetResourceSelectConfig = {
value: self.selectedTerm,
minimumInputLength: 2,
Expand Down Expand Up @@ -269,11 +302,15 @@ define([
text: value,
value: value
});
results.push(termFilterExcludingSamples);
results.push(termFilterExcludingRegions);
self.termOptions = results;

const filteredResults = results.filter(function(result){
return result.context_label.includes("Physical Thing") ||
result.context_label.includes("Search Term");
return (
result.context_label.includes("Physical Thing") ||
result.context_label.includes("Search Term")
) && !result.text.includes(sampleSubstring) && !result.text.includes(regionSubstring);
});
return {
results: filteredResults,
Expand Down Expand Up @@ -313,10 +350,12 @@ define([
}
});

const termFiltersToUse = [termFilterExcludingSamples, termFilterExcludingRegions];
if (termFilter) {
termFilter['inverted'] = false;
filters["term-filter"] = JSON.stringify([termFilter]);
}
termFiltersToUse.unshift(termFilter);
}
filters['term-filter'] = JSON.stringify(termFiltersToUse);

if (pagingFilter) {
filters['paging-filter'] = pagingFilter;
Expand Down

0 comments on commit 18b3538

Please sign in to comment.