aiidalab / ipyoptimade

Import structures in jupyter notebook using OPTIMADE
MIT License
2 stars 1 forks source link

WIP: drowpdown widget extended #17

Closed unkcpz closed 2 months ago

codecov[bot] commented 6 months ago

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (2eb0593) 33.76% compared to head (04dc7c1) 33.76%. Report is 9 commits behind head on main.

:exclamation: Current head 04dc7c1 differs from pull request most recent head 5feda9d. Consider uploading reports for the commit 5feda9d to get more accurate results

Files Patch % Lines
...yoptimade/subwidgets/extended_dropdown/__init__.py 0.00% 6 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #17 +/- ## ========================================== - Coverage 33.76% 33.76% -0.01% ========================================== Files 20 21 +1 Lines 2375 2387 +12 ========================================== + Hits 802 806 +4 - Misses 1573 1581 +8 ``` | [Flag](https://app.codecov.io/gh/aiidalab/ipyoptimade/pull/17/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidalab) | Coverage Δ | | |---|---|---| | [ipyoptimade-py-3.11](https://app.codecov.io/gh/aiidalab/ipyoptimade/pull/17/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidalab) | `33.76% <0.00%> (-0.01%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=aiidalab#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

unkcpz commented 6 months ago

Just for the record, I asked the anywidget developers in Discords, and got the suggestion for such case it is better to implement from scratch.

import anywidget
import traitlets

class Dropdown(anywidget.AnyWidget):
    _esm = """
    function render({ model, el }) {
      let options = model.get("options");
      let value = model.get("value");
      let select = document.createElement("select");
      for (let [value, text] of options) {
        let option = document.createElement("option");
        option.value = value;
        option.text = text;
        select.appendChild(option);
      }
      if (value) {
        select.value = value;
      }
      select.addEventListener("change", () => {
        model.set("value", select.value);
        model.save_changes();
      })
      model.on("change:value", () => {
        select.value = model.get("value");
      });
      el.appendChild(select);
    }
    export default { render };
    """

    value = traitlets.Unicode().tag(sync=True)
    options = traitlets.List().tag(sync=True)