Skip to content

Commit

Permalink
Added report feedback button to WebvizPluginABC (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenthoms authored May 27, 2021
1 parent 32d80cd commit 7c2be2d
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ line argument to allow detailed control of logging output in webviz.
(indirect and direct) are now included in `PLUGIN_PROJECT_METADATA`. This enables
the generated Docker setup, when portable apps are built, to have the same dependency
versions compared to what the user had installed when creating the portable app.
- [#445](https://github.com/equinor/webviz-config/pull/445) - Added report feedback
button to `WebvizPluginABC`.

### Fixed
- [#440](https://github.com/equinor/webviz-config/pull/440) - Fixed setting of global
Expand Down
104 changes: 81 additions & 23 deletions webviz_config/_plugin_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import zipfile
import warnings
import sys
import urllib
from uuid import uuid4
from typing import List, Optional, Type, Union, Dict

Expand All @@ -16,6 +17,8 @@
import bleach
from dash.development.base_component import Component
from dash.dependencies import Input, Output
import jinja2

import webviz_core_components as wcc


Expand All @@ -32,6 +35,25 @@ class EncodedFile(ZipFileMember):
mime_type: str


def _create_feedback_text(
plugin_name: str, dist_name: str, dist_version: str, dependencies: Dict[str, str]
) -> str:
template_environment = jinja2.Environment( # nosec
loader=jinja2.PackageLoader("webviz_config", "templates"),
undefined=jinja2.StrictUndefined,
autoescape=False,
)
template = template_environment.get_template("feedback.md.jinja2")
return template.render(
{
"plugin_name": plugin_name,
"dist_name": dist_name,
"dist_version": dist_version,
"dependencies": dependencies,
}
)


class WebvizPluginABC(abc.ABC):
"""All webviz plugins need to subclass this abstract base class,
e.g.
Expand Down Expand Up @@ -63,6 +85,7 @@ def layout(self):
"expand",
"contact_person",
"guided_tour",
"feedback",
]

# List of plugin specific assets which should be copied
Expand Down Expand Up @@ -150,6 +173,60 @@ def plugin_data_compress(content: List[ZipFileMember]) -> EncodedFile:
)
return WebvizPluginABC.plugin_compressed_data("webviz-data.zip", content)

def _make_extended_deprecation_warnings(
self,
deprecation_warnings: Optional[List[str]] = None,
) -> List[Dict[str, str]]:
# pylint: disable=import-outside-toplevel
from .plugins import PLUGIN_METADATA, PLUGIN_PROJECT_METADATA

extended_deprecation_warnings: List[Dict[str, str]] = []

plugin_name = self.__class__.__name__
dist_name = PLUGIN_METADATA[plugin_name]["dist_name"]
metadata = PLUGIN_PROJECT_METADATA[dist_name]

if deprecation_warnings:
url = (
f"{metadata['documentation_url']}/#/deprecations?id={plugin_name.lower()}"
if metadata["documentation_url"] is not None
else ""
)

for deprecation_warning in deprecation_warnings:
extended_deprecation_warnings.append(
{"message": deprecation_warning, "url": url}
)
return extended_deprecation_warnings

def _make_feedback_url(self) -> str:
# pylint: disable=import-outside-toplevel
from .plugins import PLUGIN_METADATA, PLUGIN_PROJECT_METADATA

plugin_name = self.__class__.__name__
dist_name = PLUGIN_METADATA[plugin_name]["dist_name"]
metadata = PLUGIN_PROJECT_METADATA[dist_name]

feedback_url = ""
if metadata["tracker_url"] is not None:
queries = {
"title": "",
"body": _create_feedback_text(
plugin_name,
dist_name,
metadata["dist_version"],
metadata["dependencies"],
),
}

feedback_url = (
f"{metadata['tracker_url']}/new?{urllib.parse.urlencode(queries)}"
if "github.com" in metadata["tracker_url"]
else metadata["tracker_url"]
)

return feedback_url

def plugin_layout(
self,
contact_person: Optional[dict] = None,
Expand Down Expand Up @@ -179,28 +256,6 @@ def plugin_layout(
if self._add_download_button:
buttons.append("download")

extended_deprecation_warnings: List[Dict[str, str]] = []

if deprecation_warnings:
# pylint: disable=import-outside-toplevel
from .plugins import PLUGIN_METADATA, PLUGIN_PROJECT_METADATA

plugin_name = getattr(getattr(self, "__class__"), "__name__")
dist_name = PLUGIN_METADATA[plugin_name]["dist_name"]
metadata = PLUGIN_PROJECT_METADATA[dist_name]
if metadata and "documentation_url" in metadata:
url = (
f"{metadata['documentation_url']}"
f"/#/deprecations?id={plugin_name.lower()}"
)
else:
url = ""

for deprecation_warning in deprecation_warnings:
extended_deprecation_warnings.append(
{"message": deprecation_warning, "url": url}
)

if buttons or deprecation_warnings:
# pylint: disable=no-member
return wcc.WebvizPluginPlaceholder(
Expand All @@ -214,7 +269,10 @@ def plugin_layout(
)
if "guided_tour" in buttons and hasattr(self, "tour_steps")
else [],
deprecation_warnings=extended_deprecation_warnings,
deprecation_warnings=self._make_extended_deprecation_warnings(
deprecation_warnings
),
feedback_url=self._make_feedback_url(),
)

return self.layout
46 changes: 46 additions & 0 deletions webviz_config/templates/feedback.md.jinja2
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!-- ⚠️ DO NOT INCLUDE DATA/SCREENSHOTS THAT CAN'T BE PUBLICLY AVAILABLE. -->

<!-- You can erase any parts of this template not applicable to your report. -->

### 🐞 Bug report:

<!-- Remove this section if you are filling in a 💡 feature request. -->

**Describe the bug**
A clear and concise description of what the bug is.

**How to reproduce**
Steps to reproduce the behavior.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

---

### 💡 Feature request:

<!-- Remove this section if you are filling in a 🐞 bug report. -->

**Is your feature request related to a problem? Please describe**
A clear and concise description of what the problem is.

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

---

### 🔖 Version information

* **Plugin name:** `{{plugin_name}}`
* **Plugin project version:** `{{dist_name}}=={{dist_version}}`
* **Plugin project dependencies:**
```{% for dependency, version in dependencies.items() %}
{{dependency}}=={{version}}
{%- endfor %}
```

0 comments on commit 7c2be2d

Please sign in to comment.