Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translate filter relationship by crawling to templates #7536

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions app/react/Library/components/FiltersFromProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ import NumberRangeFilter from './NumberRangeFilter';
import SelectFilter from './SelectFilter';
import TextFilter from './TextFilter';

const extractRelationshipLabel = (filteredProperty, label, templates) => {
const relatedTemplate = templates.find(template => template._id === filteredProperty.content);
if (!relatedTemplate?.properties) return label;

const templateProperty = relatedTemplate.properties.find(
property => property._id === filteredProperty?.inherit?.property
);

return templateProperty?.content ? t(templateProperty.content, label, undefined, false) : label;
};

const optionUrl = (value, name, query) => {
const q = rison.encode({
...query,
Expand All @@ -31,18 +42,19 @@ const optionUrl = (value, name, query) => {

return `/library/?q=${q}`;
};
const labelForOption = (filteredProperty, option) => {

const labelForOption = (filteredProperty, option, templates) => {
switch (true) {
case option.id === 'missing':
return t('System', 'No Label', undefined, false);
case filteredProperty.type === 'relationship':
return option.label;
return extractRelationshipLabel(filteredProperty, option.label, templates);
default:
return t(filteredProperty.content, option.label, undefined, false);
}
};

const prepareOptions = (property, location) => {
const prepareOptions = (property, location, templates) => {
const query = searchParamsFromLocationSearch(location, 'q') || {};
const filteredProperty = {
...property,
Expand All @@ -51,7 +63,7 @@ const prepareOptions = (property, location) => {
return filteredProperty.options.map(option => {
const finalTranslatedOption = {
...option,
label: labelForOption(filteredProperty, option),
label: labelForOption(filteredProperty, option, templates),
url: optionUrl(option.value, property.name, query),
};

Expand Down Expand Up @@ -113,7 +125,9 @@ const FiltersFromProperties = ({
onChange,
};

const propertyOptions = property.options ? prepareOptions(property, location) : [];
const propertyOptions = property.options
? prepareOptions(property, location, templates)
: [];

let filter = <TextFilter {...commonProps} />;

Expand Down
Loading