Implement filter for searching in rejected translations (#3317)

This commit is contained in:
Harmit Goswami 2024-09-06 10:40:50 -04:00 коммит произвёл GitHub
Родитель 24256cdc9a
Коммит 6df98ce479
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
7 изменённых файлов: 46 добавлений и 10 удалений

Просмотреть файл

@ -299,6 +299,7 @@ class GetEntitiesForm(forms.Form):
extra = forms.CharField(required=False)
search_identifiers = forms.BooleanField(required=False)
search_translations_only = forms.BooleanField(required=False)
search_rejected_translations = forms.BooleanField(required=False)
tag = forms.CharField(required=False)
time = forms.CharField(required=False)
author = forms.CharField(required=False)

Просмотреть файл

@ -733,6 +733,7 @@ class Entity(DirtyFieldsMixin, models.Model):
extra=None,
search_identifiers=None,
search_translations_only=None,
search_rejected_translations=None,
time=None,
author=None,
review_time=None,
@ -841,13 +842,23 @@ class Entity(DirtyFieldsMixin, models.Model):
# only tag needs `distinct` as it traverses m2m fields
entities = entities.distinct()
# TODO: Uncomment the following lines to reactivate the
# feature once all search options are implemented:
# - 857 (rejected translations)
# - 869-870 (context identifiers)
# - 883-884 (translations only)
# Filter by search parameters
if search:
search_list = utils.get_search_phrases(search)
q_rejected = (
Q()
) # if search_rejected_translations else Q(translation__rejected=False)
translation_filters = (
Q(translation__string__icontains_collate=(search, locale.db_collation))
& Q(translation__locale=locale)
& q_rejected
for search in search_list
)
@ -856,9 +867,6 @@ class Entity(DirtyFieldsMixin, models.Model):
)
# if not search_translations_only:
# TODO: remove the comments above and below to reactivate the feature once
# all search options are implemented
q_key = Q(key__icontains=search) # if search_identifiers else Q()
entity_filters = (
Q(string__icontains=search) | Q(string_plural__icontains=search) | q_key

Просмотреть файл

@ -247,6 +247,7 @@ def entities(request):
"extra",
"search_identifiers",
"search_translations_only",
"search_rejected_translations",
"time",
"author",
"review_time",

Просмотреть файл

@ -126,6 +126,7 @@ function buildFetchPayload(
'status',
'search_identifiers',
'search_translations_only',
'search_rejected_translations',
'extra',
'tag',
'author',

Просмотреть файл

@ -22,6 +22,7 @@ export type Location = {
extra: string | null;
search_identifiers: boolean;
search_translations_only: boolean;
search_rejected_translations: boolean;
tag: string | null;
author: string | null;
time: string | null;
@ -37,6 +38,7 @@ const emptyParams = {
extra: null,
search_identifiers: false,
search_translations_only: false,
search_rejected_translations: false,
tag: null,
author: null,
time: null,
@ -98,6 +100,9 @@ function parse(
extra: params.get('extra'),
search_identifiers: params.has('search_identifiers'),
search_translations_only: params.has('search_translations_only'),
search_rejected_translations: params.has(
'search_rejected_translations',
),
tag: params.get('tag'),
author: params.get('author'),
time: params.get('time'),
@ -130,6 +135,7 @@ function stringify(prev: Location, next: string | Partial<Location>) {
'extra',
'search_identifiers',
'search_translations_only',
'search_rejected_translations',
'tag',
'author',
'time',

Просмотреть файл

@ -41,7 +41,10 @@ type InternalProps = Props & {
export type FilterType = 'authors' | 'extras' | 'statuses' | 'tags';
export type SearchType = 'search_identifiers' | 'search_translations_only';
export type SearchType =
| 'search_identifiers'
| 'search_translations_only'
| 'search_rejected_translations';
function getTimeRangeFromURL(timeParameter: string): TimeRangeType {
const [from, to] = timeParameter.split('-');
@ -63,6 +66,7 @@ export type FilterAction = {
export type SearchState = {
search_identifiers: boolean;
search_translations_only: boolean;
search_rejected_translations: boolean;
};
export type SearchAction = {
@ -124,6 +128,7 @@ export function SearchBoxBase({
{
search_identifiers: false,
search_translations_only: false,
search_rejected_translations: false,
},
);
@ -151,13 +156,22 @@ export function SearchBoxBase({
}, [parameters]);
const updateOptionsFromURL = useCallback(() => {
const { search_identifiers, search_translations_only, time } = parameters;
const {
search_identifiers,
search_translations_only,
search_rejected_translations,
time,
} = parameters;
updateSearchOptions([
{ searchOption: 'search_identifiers', value: search_identifiers },
{
searchOption: 'search_translations_only',
value: search_translations_only,
},
{
searchOption: 'search_rejected_translations',
value: search_rejected_translations,
},
]);
setTimeRange(time);
}, [parameters]);
@ -235,12 +249,17 @@ export function SearchBoxBase({
const applyOptions = useCallback(
() =>
checkUnsavedChanges(() => {
const { search_identifiers, search_translations_only } = searchOptions;
const {
search_identifiers,
search_translations_only,
search_rejected_translations,
} = searchOptions;
dispatch(resetEntities());
parameters.push({
...parameters, // Persist all other variables to next state
search_identifiers: search_identifiers,
search_translations_only: search_translations_only,
search_rejected_translations: search_rejected_translations,
entity: 0, // With the new results, the current entity might not be available anymore.
});
}),

Просмотреть файл

@ -68,10 +68,10 @@ export const SEARCH_OPTIONS = [
name: 'Search in translations only',
slug: 'search_translations_only',
},
// {
// name: 'Search in rejected translations',
// slug: 'rejected',
// },
{
name: 'Search in rejected translations',
slug: 'search_rejected_translations',
},
// {
// name: 'Match whole words',
// slug: 'matchWords',