Skip to content

Commit

Permalink
Develop MVP design for the version dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathansick committed Jun 24, 2022
1 parent 7cafa97 commit 11229f6
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 18 deletions.
47 changes: 45 additions & 2 deletions keeper/dashboard/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,29 @@ class EditionContext:
git_ref: Optional[str]
"""The git ref that this edition tracks."""

github_url: Optional[str]
"""URL to this git ref on GitHub."""

@classmethod
def from_edition(cls, edition: Edition) -> EditionContext:
def from_edition(
cls, edition: Edition, product: Product
) -> EditionContext:
if edition.tracked_ref and product.doc_repo:
repo_url = product.doc_repo.rstrip("/")
if repo_url[-4:] == ".git":
repo_url = repo_url[:-4]
github_url = f"{repo_url}/tree/{edition.tracked_ref}"
else:
github_url = None

return cls(
title=edition.title,
url=edition.published_url,
date_updated=edition.date_rebuilt,
kind=edition.kind,
slug=edition.slug,
git_ref=edition.tracked_ref,
github_url=github_url,
)


Expand All @@ -73,11 +87,40 @@ def __init__(self, contexts: Sequence[EditionContext]) -> None:

@property
def main_edition(self) -> EditionContext:
"""The main (current) edition."""
for edition in self.data:
if edition.slug == "__main":
return edition
raise ValueError("No __main edition found")

@property
def has_releases(self) -> bool:
return len(self.releases) > 0

@property
def releases(self) -> List[EditionContext]:
"""All edititions tagged as releases."""
release_kinds = (
EditionKind.release,
EditionKind.major,
EditionKind.minor,
)
release_items = [e for e in self.data if e.kind in release_kinds]
sorted_items = sorted(
release_items, key=lambda x: x.slug, reverse=True
)
return sorted_items

@property
def has_drafts(self) -> bool:
return len(self.drafts) > 0

@property
def drafts(self) -> List[EditionContext]:
"""All editions tagged as drafts."""
draft_items = [e for e in self.data if e.kind == EditionKind.draft]
return sorted(draft_items, key=lambda x: x.date_updated, reverse=True)


@dataclass
class BuildContext:
Expand Down Expand Up @@ -129,7 +172,7 @@ def create(cls, product: Product) -> Context:

edition_contexts: EditionContextList = EditionContextList(
[
EditionContext.from_edition(edition)
EditionContext.from_edition(edition=edition, product=product)
for edition in product.editions
]
)
Expand Down
48 changes: 46 additions & 2 deletions keeper/dashboard/static/app.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Resets
/* Resets */
*,
*::before,
*::after {
Expand Down Expand Up @@ -45,8 +45,52 @@ h6 {
overflow-wrap: break-word;
}

// System font stack
/* System font stack */
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
}

main {
/* max-width: 16rem; */
width: 100vw;
margin: 0 auto;
padding: 1rem;
}

@media (min-width: 62rem) {
main {
width: 62rem;
}
}

.main-edition-section {
margin-top: 1rem;
}

.main-edition-section__url {
font-size: 1.2rem;
margin-bottom: 0.5rem;
}

.version-section {
margin-top: 2rem;
}

.version-section__listing {
list-style: none;
padding-left: 0;
}

.version-section__listing > li {
margin-top: 1rem;
}

.dashboard-item-metadata {
list-style: none;
display: flex;
flex-direction: row;
align-items: baseline;
gap: 1.2rem;
padding-left: 0;
}
73 changes: 60 additions & 13 deletions keeper/dashboard/template/edition_dashboard.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,74 @@
{% block page_title %}{{ project.title }} editions{% endblock page_title %}
{% block page_description %}Find documentation editions.{% endblock page_description %}

{% macro edition_article(project, edition) -%}
<article class="dashboard-item">
<header>
<a href="{{ edition.url }}">
<h3>{{ edition.title }}</h3>
</a>
</header>
<ul class="dashboard-item-metadata">
<li>
Updated {{ edition.date_updated | simple_date }}
</li>
{% if edition.git_ref %}
<li>
GitHub: <a href="{{ edition.github_url }}"><code>{{ edition.git_ref }}</code></a>
</li>
{% endif %}
</ul>
</article>
{%- endmacro %}

{% block body %}
<main>
{% set main_edition = editions.main_edition %}

<header>
<h1>{{ project.title }}</h1>
<a href="{{main_edition.url}}"><h1>{{ project.title }}</h1></a>
</header>

<section>
<section class="main-edition-section">
<p class="main-edition-section__url"><a href="{{main_edition.url}}">{{main_edition.url}}</a></p>
<p>
Default edition last updated {{ main_edition.date_updated | simple_date }}.
{% if main_edition.git_ref %}
Based on the <a href="{{ main_edition.github_url }}"><code>{{ main_edition.git_ref }}</code></a>
branch/tag at <a href="{{ project.source_repo_url }}">{{ project.source_repo_url }}</a>.
{% endif %}
</p>
</section>

{% if editions.has_releases %}
<section class="version-section">
<header>
<h2>Releases</h2>
</header>
<ul class="version-section__listing">
{% for edition in editions.releases %}
<li>
{{ edition_article(project, edition) }}
</li>
{% endfor %}
</ul>
</section>
{% endif %}

{% if editions.has_drafts %}
<section class="version-section">
<header>
<h2>Current edition</h2>
<h2>Drafts</h2>
</header>
<article class="dashboard-item">
{% set mainedition = editions.main_edition %}
<p class="current-edition__url"><a href=""></a></p>
<ul class="dashboard-item-metadata">
<li>Updated {{ mainedition.date_updated | simple_date }}</li>
{% if mainedition.git_ref %}
<li>Git ref <code>{{ mainedition.git_ref}}</code></li>
{% endif %}
</ul>
</article>
<ul class="version-section__listing">
{% for edition in editions.drafts %}
<li>
{{ edition_article(project, edition) }}
</li>
{% endfor %}
</ul>
</section>
{% endif %}

</main>
{% endblock body %}
48 changes: 47 additions & 1 deletion tests/test_dashboard_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,56 @@ def test_templates() -> None:
EditionContext(
title="Current",
url="https://example.com/ltd-test/",
date_updated=datetime(2022, 6, 21, tzinfo=timezone.utc),
date_updated=datetime(2022, 6, 24, tzinfo=timezone.utc),
kind=EditionKind.main,
slug="__main",
git_ref="main",
github_url="https://example.com/ltd-test/tree/main",
)
)

editions.append(
EditionContext(
title="1.0.0",
url="https://example.com/ltd-test/v/1.0.0",
date_updated=datetime(2022, 6, 21, tzinfo=timezone.utc),
kind=EditionKind.release,
slug="1.0.0",
git_ref="1.0.0",
github_url="https://example.com/ltd-test/tree/1.0.0",
)
)
editions.append(
EditionContext(
title="1.1.0",
url="https://example.com/ltd-test/v/1.1.0",
date_updated=datetime(2022, 6, 22, tzinfo=timezone.utc),
kind=EditionKind.release,
slug="1.1.0",
git_ref="1.1.0",
github_url="https://example.com/ltd-test/tree/1.1.0",
)
)
editions.append(
EditionContext(
title="2.0.0",
url="https://example.com/ltd-test/v/2.0.0",
date_updated=datetime(2022, 6, 24, tzinfo=timezone.utc),
kind=EditionKind.release,
slug="2.0.0",
git_ref="2.0.0",
github_url="https://example.com/ltd-test/tree/2.0.0",
)
)
editions.append(
EditionContext(
title="my-branch",
url="https://example.com/ltd-test/v/my-branch",
date_updated=datetime(2022, 6, 24, tzinfo=timezone.utc),
kind=EditionKind.draft,
slug="my-branch",
git_ref="my-branch",
github_url="https://example.com/ltd-test/tree/my-branch",
)
)

Expand Down

0 comments on commit 11229f6

Please sign in to comment.