Skip to content

Commit

Permalink
Add tooltips for labels (#665)
Browse files Browse the repository at this point in the history
We already have a list of label definitions but don't display them. I
think showing the definitions could clear up a bit of ambiguity (does
"hardware" mean "runs on hardware", or "for designing hardware"?)

This PR uses the carbon tooltip component to display these on the
website.

![Screenshot 2024-02-01 at 11 22
19](https://github.com/Qiskit/ecosystem/assets/36071638/ea1e0fdd-def8-4660-a279-586ba6f09b3a)

---------

Co-authored-by: Eric Arellano <[email protected]>
  • Loading branch information
frankharkins and Eric-Arellano authored Feb 1, 2024
1 parent 384c626 commit 7bb16e1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
18 changes: 16 additions & 2 deletions ecosystem/cli/website.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""CliWebsite class for controlling all CLI functions."""
import os
import json
from pathlib import Path
from typing import Optional

from jinja2 import Environment, FileSystemLoader
Expand All @@ -22,9 +24,14 @@ def __init__(self, root_path: Optional[str] = None):
self.current_dir = root_path or os.path.abspath(os.getcwd())
self.resources_dir = "{}/ecosystem/resources".format(self.current_dir)
self.dao = DAO(path=self.resources_dir)
self.label_descriptions = {
item["name"]: item["description"]
for item in json.loads(Path(self.resources_dir, "labels.json").read_text())
}

def build_website(self):
"""Generates the ecosystem web page reading the TOML files."""
# pylint: disable=too-many-locals
environment = Environment(loader=FileSystemLoader("ecosystem/html_templates/"))
projects = self.dao.storage.read()
projects_sorted = sorted(
Expand Down Expand Up @@ -53,8 +60,15 @@ def build_website(self):
for _, repo in projects_sorted:
# Card tags
tags = ""
for label in repo.labels:
tags += templates["tag"].render(color="purple", title=label, text=label)
for index, label in enumerate(repo.labels):
tags += templates["tag"].render(
color="purple",
text=label,
tooltip=self.label_descriptions[label],
# Sometimes tooltips are clipped by the browser window.
# While not perfect, the following line solves 95% of cases
alignment="bottom" if (index % 3) == 2 else "bottom-left",
)

# Card links
links = ""
Expand Down
9 changes: 8 additions & 1 deletion ecosystem/html_templates/tag.html.jinja
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
<cds-tag type="{{color}}" title="{{title}}" size="md">{{text}}</cds-tag>
<cds-tooltip align="{{ alignment }}">
<div class="sb-tooltip-trigger" aria-labelledby="content">
<cds-tag type="{{color}}" title="" size="md">{{text}}</cds-tag>
</div>
<cds-tooltip-content id="content">
{{ tooltip }}
</cds-tooltip-content>
</cds-tooltip>
4 changes: 4 additions & 0 deletions ecosystem/html_templates/webpage.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
type="module"
src="https://1.www.s81c.com/common/carbon/web-components/tag/v2/latest/tag.min.js"
></script>
<script
type="module"
src="https://1.www.s81c.com/common/carbon/web-components/tag/v2/latest/tooltip.min.js"
></script>
<link
rel="stylesheet"
href="https://1.www.s81c.com/common/carbon-for-ibm-dotcom/tag/v1/latest/plex.css"
Expand Down
8 changes: 8 additions & 0 deletions ecosystem/resources/labels.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@
"name": "Error mitigation",
"description": "Includes tools for mitigating errors"
},
{
"name": "Education",
"description": "For learning or teaching about quantum computing"
},
{
"name": "Finance",
"description": "Applies quantum computing to finance"
Expand Down Expand Up @@ -91,6 +95,10 @@
"name": "Quantum information",
"description": "Tool for quantum information experiments"
},
{
"name": "Rust",
"description": "Written in the Rust programming language"
},
{
"name": "Software development kit",
"description": "Helps develop Qiskit code"
Expand Down
7 changes: 1 addition & 6 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from contextlib import redirect_stdout
from pathlib import Path

from ecosystem.cli import CliCI, CliWebsite, CliMembers
from ecosystem.cli import CliCI, CliMembers
from ecosystem.daos import DAO
from ecosystem.models.repository import Repository

Expand Down Expand Up @@ -46,11 +46,6 @@ def setUp(self) -> None:
def tearDown(self) -> None:
shutil.rmtree(self.path)

def test_build_website(self):
"""Test the website builder function."""
cli_website = CliWebsite(root_path=f"{os.path.abspath(os.getcwd())}/../")
self.assertIsInstance(cli_website.build_website(), str)

def test_parser_issue(self):
"""Tests issue parsing function.
Function: Cli
Expand Down

0 comments on commit 7bb16e1

Please sign in to comment.