Skip to content
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

EREGCSC-2346 -- Internal Docs in Reader Sidebar #1107

Merged
merged 35 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
14ac19a
feat: right sidebar login banner
PhilR8 Dec 13, 2023
eab0819
test: update doctype label snapshot test assertion to use appropriate…
PhilR8 Dec 13, 2023
e3d19fe
feat: conditionally show public DocTypelabel
PhilR8 Dec 13, 2023
4d371e0
Enable debug mode
cgodwin1 Jan 2, 2024
8803873
Fix 500 error when repo categories are present
cgodwin1 Jan 2, 2024
3284c5d
Remove debug = true
cgodwin1 Jan 2, 2024
1d53bc5
Merge branch '2345-bugfix-test' into 2346-internal-docs-sidebar
PhilR8 Jan 3, 2024
7bcfc34
feat: api method and container component setup
PhilR8 Jan 8, 2024
21863d4
feat: further table setting; get categories
PhilR8 Jan 8, 2024
4392311
fix: inherit from correct mixin for section and subpart queries
PhilR8 Jan 9, 2024
cf8724d
feat: get selected section and fetch on hash change
PhilR8 Jan 10, 2024
ef3b3c5
feat: add mitt eventbus to replace deprecated vue 2.x root methods
PhilR8 Jan 11, 2024
4949b93
feat: clear eventbus listeners before destroy/unmount
PhilR8 Jan 11, 2024
f4da307
feat: fetch and watch logic
PhilR8 Jan 11, 2024
1842664
feat: display crude item list
PhilR8 Jan 12, 2024
1fd6d88
feat: transform and load props in correct formats
PhilR8 Jan 12, 2024
7229b16
feat: getFileTypeButton moved to utils
PhilR8 Jan 12, 2024
a01ce7a
feat: logic cleanup
PhilR8 Jan 12, 2024
cff4d03
feat: tweaks to bettery style doc lists
PhilR8 Jan 17, 2024
1987a80
feat: iron out styling
PhilR8 Jan 17, 2024
a72a06f
chore: refactor existing categories method
PhilR8 Jan 17, 2024
0b246c7
chore: remove comments
PhilR8 Jan 18, 2024
149840a
Merge branch 'main' into 2346-internal-docs-sidebar
PhilR8 Jan 18, 2024
5a61b9c
emit and listen to clear sections event
PhilR8 Jan 18, 2024
3384444
chore: formatting
PhilR8 Jan 18, 2024
cfaa4e8
feat: add more space to bottom of right sidebar
PhilR8 Jan 18, 2024
8f6cc8b
fix: tweak show if empty logic and category description logic
PhilR8 Jan 18, 2024
82b5a4e
test: update API test suite
PhilR8 Jan 18, 2024
6ad4d0b
feat: tweak login call to action
PhilR8 Jan 19, 2024
e411370
test: add unit tests for formatResourceCategories utility method
PhilR8 Jan 19, 2024
d907a4f
chore: improve jsdoc documentation
PhilR8 Jan 19, 2024
34b67bb
test: add e2e test coverage
PhilR8 Jan 22, 2024
cf5c43d
test: update contains assertion to take env into account
PhilR8 Jan 23, 2024
bccfd19
test: remove potentially flaky assertions
PhilR8 Jan 23, 2024
23c3aa2
feat: remove unneeded styles that introduced side effect
PhilR8 Jan 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions solution/backend/content_search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
from common.mixins import PAGINATION_PARAMS, OptionalPaginationMixin
from file_manager.models import AbstractRepoCategory, DocumentType, Subject
from resources.models import AbstractCategory, AbstractLocation
from resources.views.mixins import LocationExplorerViewSetMixin
from resources.views.mixins import LocationFiltererMixin
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inherit from correct mixin to allow querying by section


from .models import ContentIndex
from .serializers import ContentListSerializer, ContentSearchSerializer, ContentUpdateSerializer


class ContentSearchViewset(LocationExplorerViewSetMixin, OptionalPaginationMixin, viewsets.ReadOnlyModelViewSet):
class ContentSearchViewset(LocationFiltererMixin, OptionalPaginationMixin, viewsets.ReadOnlyModelViewSet):
model = ContentIndex
queryset = ContentIndex.objects.all()
paginate_by_default = True
Expand Down Expand Up @@ -52,7 +52,7 @@ class ContentSearchViewset(LocationExplorerViewSetMixin, OptionalPaginationMixin
OpenApiQueryParameter("resource-type",
"Limit results to only resources found within this resource type. Internal, External,"
"all. Use \"&resource-type=external\"", str, ''),
] + LocationExplorerViewSetMixin.PARAMETERS + OptionalPaginationMixin.PARAMETERS + PAGINATION_PARAMS
] + LocationFiltererMixin.PARAMETERS + OptionalPaginationMixin.PARAMETERS + PAGINATION_PARAMS
)
def list(self, request):
locations = self.request.GET.getlist("locations")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="div__login-sidebar">
{% if user.is_authenticated %}
Resources you can access include policy documents internal to CMCS.
{% else %}
CMCS staff participating in the Policy Repository pilot can
<a id="loginSidebar" href="{% url 'login' %}?next={{ request.path }}"
>sign in</a
>
to see internal resources.
{% endif %}
</div>
Original file line number Diff line number Diff line change
@@ -1,23 +1,49 @@
{% load string_formatters %}

{{ categories|json_script:"categories" }}
{{ node_list|json_script:"node_list" }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safely output a Python object as JSON, wrapped in a <script> tag, ready for use with JavaScript.

https://docs.djangoproject.com/en/5.0/ref/templates/builtins/#std-templatefilter-json_script


<section id="right-sidebar" data-cache-key="sidebar" data-cache-value="{{label_id}}">
{% include "regulations/partials/view-button.html" %}
<print-btn btn_type="labeled-icon"></print-btn>
<hr />

{% if node_list %}
<supplemental-content
api-url="{{ API_BASE }}"
title="{{ title }}"
part="{{ reg_part }}"
resources-url="{% url 'resources' %}"
:resource-display=true
:sections="{{ node_list.sections }}"
:subparts="{{ node_list.subparts }}"
>
<template #login-banner>
{% include "regulations/partials/login_sidebar_banner.html" %}
</template>
{% if user.is_authenticated %}
<template #public-label>
<div class="label__container">
<doc-type-label icon-type="external" doc-type="Public" />
</div>
</template>
{% endif %}
</supplemental-content>
{% if user.is_authenticated %}
<div class="authed__container">
<hr />
<div class="label__container label__container--internal">
<doc-type-label icon-type="internal" doc-type="Internal" />
</div>

<supplemental-content
api-url="{{ API_BASE }}"
title="{{ title }}"
part="{{ reg_part }}"
resources-url="{% url 'resources' %}"
:resource-display=true
:sections="{{ node_list.sections }}"
:subparts="{{ node_list.subparts }}"
></supplemental-content>
<internal-docs-container
api-url="{{ API_BASE }}"
title="{{ title }}"
part="{{ reg_part }}"
></internal-docs-container>
</div>
<div class="login__spacer"></div>
{% endif %}
{% endif %}

</section>
4 changes: 3 additions & 1 deletion solution/ui/e2e/cypress/e2e/api.spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ const SPECIAL_CHARACTERS = [

const API_ENDPOINTS_V3 = [
`/v3/acts`,
`/v3/content-search`,
`/v3/ecfr_parser_result/${TITLE}`,
`v3/file-manager/subjects`,
`/v3/file-manager/categories`,
`/v3/file-manager/subjects`,
`/v3/parser_config`,
`/v3/resources/`,
`/v3/resources/categories`,
Expand Down
71 changes: 70 additions & 1 deletion solution/ui/e2e/cypress/e2e/part.spec.cy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
const username = Cypress.env("TEST_USERNAME");
const password = Cypress.env("TEST_PASSWORD");

describe("Part View", () => {
beforeEach(() => {
cy.clearIndexedDB();
Expand Down Expand Up @@ -63,6 +66,72 @@ describe("Part View", () => {
});
});

it("has a login call to action in the right sidebar of a subpart view", () => {
cy.viewport("macbook-15");
cy.visit("/42/433/51");

cy.get(".div__login-sidebar").contains(
"CMCS staff participating in the Policy Repository pilot can sign in to see internal resources."
);

cy.get("a#loginSidebar")
.should("have.attr", "href")
.and("include", "/admin/login/?next=")
.and("include", "/42/433/Subpart-B/");
});

it("has a login confirmation banner and internal documents in the right sidebar of a subpart view when logged in", () => {
cy.intercept("**/v3/resources/?&locations=42.431.A**").as("resources");
cy.intercept("**/v3/file-manager/categories", {
fixture: "categories-internal.json",
}).as("internal-categories");
cy.intercept(
"**/v3/content-search/?resource-type=internal&locations=42.431.A**",
{
fixture: "42.431.internal.json",
}
).as("internal431");
cy.viewport("macbook-15");
cy.eregsLogin({ username, password });
cy.visit("/42/431/10");

cy.get(".div__login-sidebar").contains(
"Resources you can access include policy documents internal to CMCS."
);
cy.get("#loginIndicator").should("be.visible");
cy.get("a#loginSidebar").should("not.exist");

cy.wait("@resources").then(() => {
cy.get(".right-sidebar").scrollTo("bottom");
cy.get(`button[data-test=TestCat]`).click({
force: true,
});
cy.wait(250);
cy.get(".right-sidebar").scrollTo("bottom");
cy.get(`button[data-test=TestSubCat]`).click({
force: true,
});
cy.wait(250);
cy.get(".right-sidebar").scrollTo("bottom");
cy.get(
".internal-docs__container div[data-test=TestSubCat] .supplemental-content"
)
.first()
.get(".supplemental-content-date")
.contains("August 30, 2023");
cy.get(
".internal-docs__container div[data-test=TestSubCat] .supplemental-content"
)
.first()
.get(".supplemental-content-description")
.contains("42 431 test");
cy.get(".show-more-button")
.contains("+ Show More (6)")
.click({ force: true })
.contains("- Show Less (6)");
});
});

it("loads a subpart view in a mobile width", () => {
cy.viewport("iphone-x");
cy.visit("/42/433/");
Expand Down Expand Up @@ -176,7 +245,7 @@ describe("Part View", () => {
// it recently broke because the latest year changed from 2021 to 2022
// so I'm commenting it out for now until we can figure out a better way
//cy.get(
//"#433-8 .reg-history-link-container .tooltip.clicked .gov-info-links a:nth-child(1)"
//"#433-8 .reg-history-link-container .tooltip.clicked .gov-info-links a:nth-child(1)"
//).contains("2021");
cy.get(
"#433-8 .reg-history-link-container .tooltip.clicked .gov-info-links a:nth-child(1)"
Expand Down
Loading
Loading