Skip to content

Commit

Permalink
Search across translations (#4208)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Feb 23, 2023
1 parent 0710a4c commit 6bbb7c8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {DEFAULT_SCHEMA, getVocabularySelectionTypes, getMediaTypeKeys, getMediaTypes} from '../constants';
import {IVocabulary, IVocabularyTag} from 'superdesk-api';
import {IVocabulary, IVocabularyItem, IVocabularyTag} from 'superdesk-api';
import {IDirectiveScope} from 'types/Angular/DirectiveScope';
import {remove, reduce} from 'lodash';
import {gettext, downloadFile} from 'core/utils';
Expand All @@ -11,11 +11,13 @@ function getOther() {
}

export interface IScope extends IDirectiveScope<void> {
filterVocabulary(vocabulary: IVocabulary): boolean;
vocabularies: Array<IVocabulary>;
vocabulary: any;
tags: IVocabulary['tags'];
loading: boolean;
mediaTypes: object;
searchString: string;
openVocabulary(vocabulary: IVocabulary): void;
downloadVocabulary(vocabulary: IVocabulary): void;
uploadConfig(): void;
Expand Down Expand Up @@ -140,6 +142,22 @@ export function VocabularyConfigController($scope: IScope, $route, $routeParams,
$scope.existsVocabulariesForTag = (currentTag: IVocabularyTag, tab: string) =>
($scope.vocabularies || []).some((vocabulary) => checkTag(vocabulary, currentTag, tab));

/**
* Checks if a vocabulary's display_name matches the search
* query or if it matches a translation of that vocabulary.
*/
$scope.filterVocabulary = function(vocabulary: IVocabulary): boolean {
const translationMach = Object.values(vocabulary?.translations?.display_name ?? {})
.find((translation: string) => translation.toLowerCase().indexOf($scope.searchString) !== -1);
const displayNameMatch = vocabulary.display_name.toLowerCase().indexOf($scope.searchString) !== -1;

if (($scope.searchString?.length ?? 0) > 0 || displayNameMatch || translationMach != null) {
return true;
} else {
return false;
}
};

/**
* Don't show OTHER tag if it is the only tag available for current tab
*/
Expand Down
6 changes: 3 additions & 3 deletions scripts/apps/vocabularies/views/vocabulary-config.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="sd-page__flex-helper">
<div class="sd-page__header">
<sd-search-handler ng-model="query.display_name" data-debounce="200"></sd-search-handler>
<sd-search-handler ng-model="searchString" data-debounce="200"></sd-search-handler>
<span class="sd-page__element-grow"></span>
<button class="btn btn--primary"
ng-click="createCustomField('text')" ng-if="tab === 'text-fields'">
Expand All @@ -19,7 +19,7 @@
<i class="icon-plus-sign icon--white"></i>
<span translate>Add New</span>
</button>

<button class="btn btn--primary"
ng-click="createVocabulary()" ng-if="tab === 'vocabularies'">
<i class="icon-plus-sign icon--white"></i>
Expand Down Expand Up @@ -56,7 +56,7 @@
<div class="sd-list-item-group sd-list-item-group--space-between-items" style="max-width: 1000px;">
<div
class="sd-list-item sd-shadow--z1"
ng-repeat="vocabulary in getVocabulariesForTag(tag, tab) | orderBy:'display_name|translate' | filter: query track by vocabulary._id"
ng-repeat="vocabulary in getVocabulariesForTag(tag, tab) | orderBy:'display_name|translate' | filter: filterVocabulary track by vocabulary._id"
data-test-id="vocabulary-item"
>
<div class="sd-list-item__column sd-list-item__column--grow sd-list-item__column--no-border">
Expand Down
5 changes: 5 additions & 0 deletions scripts/core/superdesk-api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,11 @@ declare module 'superdesk-api' {
service: {};
priority?: number;
unique_field: string;
translations?: {
display_name: {
[key: string]: string;
};
};
schema: {};
field_type:
| 'text'
Expand Down

0 comments on commit 6bbb7c8

Please sign in to comment.