Skip to content

Commit

Permalink
Improve explore button logic (#43)
Browse files Browse the repository at this point in the history
* feat: improve explore button logic

Don't show explore button on top of dataset page if there is no main resource explorable
  • Loading branch information
nicolaskempf57 authored Jul 15, 2024
1 parent 20a9ddb commit 25ee53d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Current (in progress)

- Remove useless max size setting [#41](https://github.com/opendatateam/udata-tabular-preview/pull/41)
- Improve explore button logic [#43](https://github.com/opendatateam/udata-tabular-preview/pull/43)

## 4.0.0 (2024-05-06)

Expand All @@ -11,7 +12,7 @@
- Don't show preview if parsing has failed [#36](https://github.com/opendatateam/udata-tabular-preview/pull/36)
- Display the latest date of the preview [#37](https://github.com/opendatateam/udata-tabular-preview/pull/37)
- Set long description content type to markdown in dist [#39](https://github.com/opendatateam/udata-tabular-preview/pull/39)
- Publish .dev version on pypi [#40](https://github.com/opendatateam/udata-tabular-preview/pull/40)
- Publish .dev version on pypi [#40](https://github.com/opendatateam/udata-tabular-preview/pull/40)

## 4.0.0 (2024-03-22)

Expand Down
10 changes: 9 additions & 1 deletion udata_tabular_preview/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def can_explore_dataset(ctx):
return dataset and any(can_explore(resource) for resource in dataset.resources)


def can_explore_any_main_resource(ctx):
dataset = ctx.get('dataset', None)
return dataset and any(
can_explore(resource)
and resource.type == "main"
for resource in dataset.resources)


@template_hook('header.snippets', when=can_explore_dataset)
def load_explore_metadata(ctx):
dataset = ctx.get('dataset', None)
Expand All @@ -42,7 +50,7 @@ def load_explore_style(ctx):
return render_template('styles.html')


@template_hook('dataset.display.explore-button', when=can_explore_dataset)
@template_hook('dataset.display.explore-button', when=can_explore_any_main_resource)
def load_explore_button(ctx):
dataset = ctx.get('dataset', None)
explore_url = current_app.config.get('TABULAR_EXPLORE_URL')
Expand Down

0 comments on commit 25ee53d

Please sign in to comment.