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

Revamp Spotlight state landing page #477

Merged
merged 15 commits into from
Sep 13, 2021
Merged

Conversation

nasaownsky
Copy link
Collaborator

@nasaownsky nasaownsky commented Aug 19, 2021

Description of the change

Revamp Spotlight state landing page

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Configuration change (adjusts configuration to achieve some end related to functionality, development, performance, or security)

Related issues

Closes #476

Checklists

Development

These boxes should be checked by the submitter prior to merging:

  • Manual testing against realistic data has been performed locally

Code review

These boxes should be checked by reviewers prior to merging:

  • This pull request has a descriptive title and information useful to a reviewer
  • This pull request has been moved out of a Draft state, has no "Work In Progress" label, and has assigned reviewers
  • Potential security implications or infrastructural changes have been considered, if relevant

Copy link
Member

@jessex jessex left a comment

Choose a reason for hiding this comment

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

Holding off on a more thorough review for now, since there's not a whole lot to comment on just yet!

@nasaownsky
Copy link
Collaborator Author

@jessex Hey, Josh! So I have something like this for now:

screencapture-localhost-3000-us-nd-2021-08-24-20_02_16

@cawarren suggested using other charts to preview sentencing and parole data and they are much easier to manage.

The solution for the preview is using a boolean flag, depending on which we render different charts. The only thing I need to do is to get rid of prison population minimap. Maybe @macfarlandian know simple and effective solution for that?

@macfarlandian
Copy link
Collaborator

@nasaownsky hmm tricky .... I don't think that can be disabled, probably you will have to sub out the MinimapXYFrame component for a plain XYFrame in preview mode. It should take all of the same props with the exception of minimap so hopefully that won't be too bad

@hobuobi
Copy link

hobuobi commented Aug 25, 2021

One quick thing: is it possible for this to be deployed to the staging site (spotlight-staging.recidiviz.org)? This would make it easy for @agronomic and I to review!

Copy link
Member

@jessex jessex left a comment

Choose a reason for hiding this comment

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

Looking good so far, @nasaownsky! Local testing went smoothly.

@@ -91,6 +102,41 @@ const NarrativeLink: React.FC<{
from: { opacity: 0 },
}));

const renderChartPreview = () => {
if (tenantId === "US_ND") {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if there's a better approach for scaling this over time than just having to keep appending to this conditional block with new state codes. For example, would it be possible to configure which charts correspond to which narrative per state in /src/contentApi/sources/? Then all that renderChartPreview would need to do is invoke retrieveContent(tenantId) and then return the appropriate MetricVizMapper depending on the current narrative.id.

That would seem preferable because /src/contentApi/sources/ is already the location where we expect to add more content and config with each new state, so adding one more thing there means we won't miss it. But if we add one more thing that has to be updated with each new state here in this part of the codebase, we will inevitably miss it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thinking about implementation... If we'll have more states, then we still would need this conditional statement, telling us which exactly types of charts needed for a given state. Or you mean explicitly specify in api files (us_nd, us_pa) some sort of flag or list, that would tell us which charts to use as preview? This will need more exploration in types system. @jessex @macfarlandian any thoughts?

Also, other requested changes are resolved.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes I think expanding the us_nd and us_pa content objects to include this configuration sounds like a good idea - that has generally been the pattern we try to follow in this application. That configuration might look similar to what sections looks like for a narrative: an array of objects that specify a MetricTypeId and whatever other metadata you might need, if any.

It's fine to change the type definition for those content objects as needed, there aren't really any restrictions on what we can include there. It's just meant to collect as much tenant-specific configuration as possible in one place for visibility and ease of making changes.

spotlight-client/src/PageTenant/PageTenant.tsx Outdated Show resolved Hide resolved
@jessex
Copy link
Member

jessex commented Aug 25, 2021

@macfarlandian I would deploy the frontend to staging myself but it looks like the .ZIP file with the env vars in 1Password is empty for spotlight-client. Would you 1) be able to update that and make sure it's complete and accurate so I can do these deploys myself going forward, and 2) deploy from this branch to staging so that @hobuobi can test? Thanks!

@macfarlandian
Copy link
Collaborator

@jessex uh oh i'll get on that

@macfarlandian
Copy link
Collaborator

@hobuobi latest version here is on staging now

@coveralls
Copy link

coveralls commented Aug 27, 2021

Pull Request Test Coverage Report for Build 1217031816

  • 46 of 58 (79.31%) changed or added relevant lines in 9 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.1%) to 85.089%

Changes Missing Coverage Covered Lines Changed/Added Lines %
spotlight-client/src/VizDemographicsByCategory/VizDemographicsByCategory.tsx 3 4 75.0%
spotlight-client/src/OtherNarrativeLinksPreview/OtherNarrativeLinksPreview.tsx 22 27 81.48%
spotlight-client/src/charts/WindowedTimeSeries.tsx 4 10 40.0%
Files with Coverage Reduction New Missed Lines %
spotlight-client/src/OtherNarrativeLinks/OtherNarrativeLinks.tsx 1 75.0%
Totals Coverage Status
Change from base Build 1134040090: 0.1%
Covered Lines: 1976
Relevant Lines: 2201

💛 - Coveralls

@nasaownsky nasaownsky marked this pull request as ready for review August 27, 2021 15:19
@nasaownsky
Copy link
Collaborator Author

@jessex Hey! In case you have missed this - take a look, it should be ready to go!

Copy link
Member

@jessex jessex left a comment

Choose a reason for hiding this comment

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

This is looking good to me! Thanks so much for this, @nasaownsky. Functionality looks solid in local testing, UI looks like the mocks, and I have no more code comments.

@macfarlandian, would you mind taking a pass through this this week? Ilya has shifted back to some final pre-launch updates for the Cost Calculator for the rest of this week so you have some time. But since this has some non-trivial modeling updates, I want to make sure you're on board before we merge.

spotlight-client/src/App.test.tsx Outdated Show resolved Hide resolved
spotlight-client/src/App.test.tsx Outdated Show resolved Hide resolved
@@ -132,7 +160,6 @@ const OtherNarrativeLinks = (): React.ReactElement | null => {

const narrativesToDisplay = [
...Object.values(tenant.systemNarratives),
tenant.racialDisparitiesNarrative,
Copy link
Collaborator

Choose a reason for hiding this comment

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

bit of a problem here ... this component is also used at the bottom of each narrative page to provide navigation links to the other pages. The changes here break that feature, such that the link to Racial Disparities never shows up and all of these charts are rendered at the bottom of every page. I think this either needs to be broken out into a separate component (leaving the old component in place for uses other than the homepage) or it needs to have some kind of flag that puts it into "homepage mode" and causes it to render this new format with the chart previews and different link text. I think it would probably be more straightforward to just make a new component for the homepage and restore this one to its former state? It ought to be able to reuse all of the same styled components so hopefully that wouldn't lead to a lot of duplication.

@@ -151,6 +151,8 @@ type SystemNarrativeSection = NarrativeSection & {

export type SystemNarrativeContent = {
title: string;
subtitle?: string;
preview?: MetricTypeId;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think the preview field is actually optional in practice? could simplify things a little by just having it be required at the type level, we wouldn't have to check if it's defined before rendering

@@ -90,4 +89,4 @@ export type SystemNarrativeMapping = {
[key in SystemNarrativeTypeId]?: SystemNarrative;
};

export type Narrative = SystemNarrative | RacialDisparitiesNarrative;
Copy link
Collaborator

Choose a reason for hiding this comment

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

per comments about the links above, I don't think we are going to want to make this change in the end.

spotlight-client/src/charts/BubbleChart.tsx Show resolved Hide resolved
Comment on lines 208 to 231
axes={[
{
orient: "left",
tickFormat: formatAsNumber,
tickSize: 0,
},
]}
baseMarkProps={BASE_MARK_PROPS}
lines={data}
lineStyle={(d: DataSeries) => ({
fill:
highlighted && highlighted.label !== d.label
? highlightFade(d.color)
: d.color,
stroke: colors.background,
strokeWidth: 1,
})}
// @ts-expect-error Semiotic typedefs are incomplete, this works
lineType={{ type: "stackedarea", sort: null }}
// @ts-expect-error Semiotic typedefs are wrong, can be true for default matte
matte
pointStyle={{ display: "none" }}
xAccessor="date"
yAccessor="count"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think by doing it this way we are creating a bunch of expensive React and Semiotic stuff that we don't intend to render, as well as defining most of the props redundantly?

Rather than duplicating all these props, we should just collect them in a base object that we extend as needed with the additional props needed for the minimap. And instead of instantiating both Frame components we should just conditionally pick one ... could either store that as a variable or conditionally render {preview ? <XYFrame {...chartProps} /> : <MinimapXYFrame {...chartProps} />} instead of what's currently there.

spotlight-client/src/charts/WindowedTimeSeries.tsx Outdated Show resolved Hide resolved
@macfarlandian
Copy link
Collaborator

realized I forgot to post one other thing ... I noticed that the tooltips can be cut off in the "preview" charts if they are close to the right edge. example screenshots:

Screen Shot 2021-08-31 at 5 05 47 PM

Screen Shot 2021-08-31 at 5 05 40 PM

@nasaownsky
Copy link
Collaborator Author

Hey, @macfarlandian! So I've made all the changes you have requested. Check that out!

Copy link
Collaborator

@macfarlandian macfarlandian left a comment

Choose a reason for hiding this comment

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

getting very close, @nasaownsky ! other than a couple of nits I commented on here, the main remaining issue is with the navigation links at the bottom of the narrative pages.

If you were to look at, e.g., this page on the live site, it still looks a little different than it does with these changes:
Screen Shot 2021-09-08 at 9 59 42 AM

The layout is a bit tighter (can fit four to a row) and the labels don't say "Data" like they do on the new homepage design. We still want the links on those pages to remain unchanged from what they were before, so I think there needs to be even more separation between the components than you have here. And just to give you a heads-up, there is a further change coming (still being spec'ed out, will be a separate ticket) that will include the Racial Disparities link on the homepage but also reshuffle the order, so the functionality of the homepage versus the other pages will diverge even more. I don't think there's going to be much benefit in trying to adapt one component to render both versions, so if breaking the homepage links out into a whole new component makes this easier then you should feel free to make that change now

spotlight-client/src/charts/WindowedTimeSeries.tsx Outdated Show resolved Hide resolved
spotlight-client/src/SystemNarrativePage/constants.ts Outdated Show resolved Hide resolved
@nasaownsky
Copy link
Collaborator Author

@macfarlandian ok, I've added brand new component OtherNarrativeLinksPreview and since the Racial Disparities not included on the homepage, there is no need to modify types and extract NarrativeLink from both OtherNarrativeLinksPreview and OtherNarrativeLinks as its rely on different types and there is no specification for Racial Disparities for now.

Copy link
Collaborator

@macfarlandian macfarlandian left a comment

Choose a reason for hiding this comment

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

did one more QA pass and noticed that some of the preview labels didn't match the data we were showing ... noted them in the comments here. I think that should be the last thing on this PR

spotlight-client/src/contentApi/sources/us_nd.ts Outdated Show resolved Hide resolved
spotlight-client/src/contentApi/sources/us_nd.ts Outdated Show resolved Hide resolved
spotlight-client/src/contentApi/sources/us_pa.ts Outdated Show resolved Hide resolved
spotlight-client/src/contentApi/sources/us_pa.ts Outdated Show resolved Hide resolved
@nasaownsky
Copy link
Collaborator Author

Done!

Copy link
Collaborator

@macfarlandian macfarlandian left a comment

Choose a reason for hiding this comment

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

🚀

@jessex jessex merged commit 04286a9 into main Sep 13, 2021
@jessex jessex deleted the nasaownsky/state-landing-page branch September 13, 2021 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revamp Spotlight state landing page
5 participants