Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into stojanovic/fe-95-move…
Browse files Browse the repository at this point in the history
…-form-field-hints-under-input-make-text-more-subtle-less
  • Loading branch information
Ducica committed Oct 19, 2023
2 parents 60ee3a6 + ed7e99e commit dea7e79
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 20 deletions.
13 changes: 13 additions & 0 deletions oarepo_ui/ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,23 @@ def catalog(self):
return self._catalog_config(self._catalog, self.templates.jinja_env)

def _catalog_config(self, catalog, env):

# monkeypatch component - see https://github.com/jpsca/jinjax/issues/32
from markupsafe import Markup
from jinjax.component import Component

def render(self, **kwargs):
assert self.tmpl, f"Component {self.name} has no template"
return Markup(self.tmpl.render(**kwargs).strip())
render.__name__ = 'render_patched_by_oarepo_ui'
Component.render = render
# monkeypatch end

context = {}
env.policies.setdefault("json.dumps_kwargs", {}).setdefault("default", str)
self.app.update_template_context(context)
catalog.jinja_env.loader = env.loader
catalog.jinja_env.autoescape = env.autoescape
context.update(catalog.jinja_env.globals)
context.update(env.globals)
catalog.jinja_env.globals = context
Expand Down
5 changes: 4 additions & 1 deletion oarepo_ui/resources/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def _get_component_path(
f"Unable to find a file named {name}{file_ext} "
f"or one following the pattern {name_dot}*{file_ext}"
)

def _get_from_file(self, *, prefix: str, name: str, url_prefix: str, file_ext: str) -> "Component":
root_path, path = self._get_component_path(prefix, name, file_ext=file_ext)
component = Component(
Expand All @@ -87,7 +88,9 @@ def _get_from_file(self, *, prefix: str, name: str, url_prefix: str, file_ext: s
return component


def get_jinja_template(_catalog, template_def, fields=[]):
def get_jinja_template(_catalog, template_def, fields=None):
if fields is None:
fields = []
jinja_content = None
for component in _catalog.jinja_env.loader.searchpath:
if component["component_file"].endswith(template_def["layout"]):
Expand Down
4 changes: 2 additions & 2 deletions oarepo_ui/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ def search(self):
)

search_config = partial(self.config.search_app_config, **search_options)

search_app_config = search_config(app_id=app_id)
json_data = json.dumps(search_app_config, default=lazy_string_encoder, indent=4)

return _catalog.render(
"search",
__source=source,
search_app_config=json_data,
search_app_config=search_app_config,
ui_config=self.config,
ui_resource=self,
layout=layout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,7 @@ import { i18next } from "@translations/oarepo_ui/i18next";
import { SearchConfigurationContext } from "@js/invenio_search_ui/components";
import { SearchAppSort } from "./SearchAppSort";

const sortTranslation = (sortOptions) => {
const translatedSortOptions = sortOptions.map((sortOption) => {
return {
...sortOption,
text: i18next.t(sortOption.sortBy),
};
});
return translatedSortOptions;
};

export const SearchAppResultOptions = ({ sortOptions, layoutOptions }) => {
sortOptions = sortTranslation(sortOptions);
const { buildUID } = useContext(SearchConfigurationContext);
const multipleLayouts =
Object.values(layoutOptions).filter((i) => i).length > 1;
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-ui
version = 5.0.72
version = 5.0.75
description = UI module for invenio 3.5+
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down
12 changes: 7 additions & 5 deletions tests/test_ui_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ def test_permissions_on_detail(
with client.get(f"/simple-model/{simple_record.id}") as c:
assert c.status_code == 200
assert (
"permissions={'can_edit': False, 'can_new_version': False, 'can_manage': "
"False, 'can_update_draft': False, 'can_read_files': True, 'can_review': "
"False, 'can_view': False, 'can_delete_draft': False, 'can_manage_files': "
"False, 'can_manage_record_access': False}"
'permissions={'can_edit': False, 'can_new_version': False, '
''can_manage': False, 'can_update_draft': False, '
''can_read_files': True, 'can_review': False, '
''can_view': False, 'can_delete_draft': False, '
''can_manage_files': False, 'can_manage_record_access': '
'False}'
) in c.text


Expand All @@ -36,7 +38,7 @@ def test_permissions_on_search(
):
with client.get(f"/simple-model/") as c:
assert c.status_code == 200
assert ("permissions={'can_create': True}") in c.text
assert ("permissions={'can_create': True}") in c.text


def test_filter_on_search(
Expand Down

0 comments on commit dea7e79

Please sign in to comment.