-
Notifications
You must be signed in to change notification settings - Fork 4
feat(#178): Responsiveness & interactivity for PI Dashboard #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jimmysway
wants to merge
5
commits into
nerc-project:main
Choose a base branch
from
jimmysway:issue-178-responsive-interactive
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8f89ba0
feat(#178): Responsiveness & interactivity for PI Dashboard
jimmysway c6787c2
Added unit tests along with Visual tests using Vitest and Playwright.
jimmysway c7f57fc
Enhance Dockerfile and static assets for NERC chart integration
jimmysway bd75b44
Reduced charting complexity
jimmysway b4b6cda
fixed import path
jimmysway File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| name: Frontend Tests | ||
|
|
||
| on: | ||
| push: | ||
| branches: [ main ] | ||
| paths: | ||
| - "src/static/**" | ||
| - "package.json" | ||
| - "vitest.config.js" | ||
| - "playwright.config.js" | ||
| - ".github/workflows/frontend-tests.yaml" | ||
| pull_request: | ||
| branches: [ main ] | ||
| paths: | ||
| - "src/static/**" | ||
| - "package.json" | ||
| - "vitest.config.js" | ||
| - "playwright.config.js" | ||
| - ".github/workflows/frontend-tests.yaml" | ||
|
|
||
| jobs: | ||
| unit-tests: | ||
| name: Unit Tests (Vitest) | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: src/static/package-lock.json | ||
|
|
||
| - run: npm ci | ||
| working-directory: src/static | ||
|
|
||
| - run: npm run test:unit | ||
| working-directory: src/static | ||
|
|
||
| visual-tests: | ||
| name: Visual Tests (Playwright) | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
| cache-dependency-path: src/static/package-lock.json | ||
|
|
||
| - run: npm ci | ||
| working-directory: src/static | ||
|
|
||
| - name: Install Playwright browsers | ||
| run: npx playwright install --with-deps chromium | ||
| working-directory: src/static | ||
|
|
||
| - name: Run visual tests | ||
| run: npm run test:visual | ||
| working-directory: src/static | ||
|
|
||
| - name: Upload screenshots on failure | ||
| if: failure() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: playwright-screenshots | ||
| path: src/static/tests/visual/test-results/ | ||
| retention-days: 7 | ||
|
|
||
| - name: Upload snapshot updates | ||
| if: always() | ||
| uses: actions/upload-artifact@v4 | ||
| with: | ||
| name: playwright-snapshots | ||
| path: src/static/tests/visual/snapshots/ | ||
| retention-days: 30 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| diff --git a/coldfront/core/allocation/templates/allocation/allocation_detail.html b/coldfront/core/allocation/templates/allocation/allocation_detail.html | ||
| index 369cf81..cfea375 100644 | ||
| --- a/coldfront/core/allocation/templates/allocation/allocation_detail.html | ||
| +++ b/coldfront/core/allocation/templates/allocation/allocation_detail.html | ||
| @@ -173,6 +173,61 @@ Allocation Detail | ||
| </div> | ||
| </div> | ||
|
|
||
| +<!-- NERC Usage Chart --> | ||
| +<div class="card mb-3"> | ||
| + <div class="card-header"> | ||
| + <h3 class="d-inline"><i class="fas fa-chart-bar" aria-hidden="true"></i> SU Costs</h3> | ||
| + </div> | ||
| + <div class="card-body"> | ||
| + <!-- Chart info header section --> | ||
| + <div class="d-flex justify-content-between align-items-start mb-3 chart-info-header"> | ||
| + <div> | ||
| + <h5 class="mb-1 font-weight-bold chart-title" id="chart-title">SU Cost - Cumulative</h5> | ||
| + <p class="mb-0 text-muted small" id="chart-subtitle">Showing the cumulative cost for the last month</p> | ||
| + </div> | ||
| + </div> | ||
| + <!-- Toolbar section --> | ||
| + <div class="mb-3 d-flex justify-content-between align-items-center pb-3 chart-toolbar"> | ||
| + <div class="d-flex align-items-center"> | ||
| + <div class="btn-group toggle-btn-group-view" role="group" aria-label="Toggle view"> | ||
| + <button type="button" class="btn toggle-btn active" id="show-graph-btn"> | ||
| + <i class="fas fa-chart-line mr-1"></i> Graph | ||
| + </button> | ||
| + <button type="button" class="btn toggle-btn" id="show-table-btn"> | ||
| + <i class="fas fa-table mr-1"></i> Table | ||
| + </button> | ||
| + </div> | ||
| + </div> | ||
| + <div class="d-flex align-items-center"> | ||
| + <div class="btn-group toggle-btn-group-mode mr-3" role="group" aria-label="Data mode"> | ||
| + <button type="button" class="btn toggle-btn active" id="show-cumulative-btn"> | ||
| + Cumulative | ||
| + </button> | ||
| + <button type="button" class="btn toggle-btn" id="show-daily-btn"> | ||
| + Daily | ||
| + </button> | ||
| + </div> | ||
| + <button type="button" class="btn export-csv-btn" id="export-csv-btn"> | ||
| + <i class="fas fa-download mr-1"></i> Export CSV | ||
| + </button> | ||
| + </div> | ||
| + </div> | ||
| + <div id="chart-view" style="position: relative; height: 500px; width: 100%;"> | ||
| + <canvas id="allocationUsageChart"></canvas> | ||
| + </div> | ||
| + <div id="table-view" class="table-responsive" style="display: none;"> | ||
| + <table id="allocationUsageTable" class="table table-bordered table-sm"> | ||
| + <thead> | ||
| + <!-- Populated by JS --> | ||
| + </thead> | ||
| + <tbody> | ||
| + <!-- Populated by JS --> | ||
| + </tbody> | ||
| + </table> | ||
| + </div> | ||
| + </div> | ||
| +</div> | ||
| + | ||
| {% if eulas %} | ||
| <div class="card mb-3"> | ||
| <div class="card-header"> | ||
| @@ -470,4 +525,13 @@ Allocation Detail | ||
| } | ||
| }) | ||
| </script> | ||
| -{% endblock %} | ||
| \ No newline at end of file | ||
| + | ||
| +<!-- Load Chart.js for NERC usage visualization --> | ||
| +<script src="{% static 'chartjs/chart.min.js' %}"></script> | ||
| + | ||
| +<link rel="stylesheet" href="{% static 'css/chart_tooltip.css' %}"> | ||
| +<link rel="stylesheet" href="{% static 'css/chart_controls.css' %}"> | ||
| +<script src="{% static 'js/chart_utils.js' %}"></script> | ||
| +<script src="{% static 'js/chart_config.js' %}"></script> | ||
| +<script src="{% static 'js/chart_tooltip.js' %}"></script> | ||
| +<script src="{% static 'js/allocation_detail.js' %}"></script> | ||
| +{% endblock %} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # Frontend Tests | ||
|
|
||
| How to run the chart and UI tests. | ||
|
|
||
| ## Setup | ||
|
|
||
| From `src/static/`: | ||
|
|
||
| ```bash | ||
| npm install | ||
| ``` | ||
|
|
||
| For visual tests (Playwright), install the browser once: | ||
|
|
||
| ```bash | ||
| npx playwright install chromium | ||
| ``` | ||
|
|
||
| ## Running Tests | ||
|
|
||
| All commands run from `src/static/`: | ||
|
|
||
| **Unit tests** (Vitest, tests chart logic like missing data, daily calculations, responsive tick intervals): | ||
|
|
||
| ```bash | ||
| npm run test:unit | ||
| ``` | ||
|
|
||
| **Unit tests in watch mode** (re-runs on file changes): | ||
|
|
||
| ```bash | ||
| npx vitest | ||
| ``` | ||
|
|
||
| **Visual tests** (Playwright, loads the chart in a browser and checks rendering at different breakpoints): | ||
|
|
||
| ```bash | ||
| npm run test:visual | ||
| ``` | ||
|
|
||
| **Both unit and visual tests:** | ||
|
|
||
| ```bash | ||
| npm test | ||
| ``` | ||
|
|
||
| ## Visual Test Notes | ||
|
|
||
| The first time you run visual tests, Playwright creates baseline screenshots in `tests/visual/snapshots/`. Commit those to git so CI and future runs have something to compare against. | ||
|
|
||
| If you intentionally change how the chart looks and need to refresh the baselines: | ||
|
|
||
| ```bash | ||
| npx playwright test tests/visual --update-snapshots | ||
| ``` | ||
|
|
||
| To see the browser while tests run (useful for debugging): | ||
|
|
||
| ```bash | ||
| npx playwright test tests/visual --headed | ||
| ``` |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The production template markup added in this patch does not give the SU costs card an id, but the JS (allocation_detail.js) expects an element with id="su-costs-card" (used for hide/show logic and tests). As-is, the card will not be hidden in the real page when there is no data, and the production DOM will diverge from the test fixture.
Suggestion: add id="su-costs-card" to the outer card element (or update the JS to target the actual element you render).