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

feat: use PeriodDimension in ThematicDialog #3407

Open
wants to merge 56 commits into
base: master
Choose a base branch
from

Conversation

BRaimbault
Copy link
Collaborator

@BRaimbault BRaimbault commented Nov 18, 2024

Implement: DHIS2-15796
Linked @dhis2/analytics PR: dhis2/analytics#1735


Overview

Main changes are:

  1. Support of multiple periods selection
  2. Use new PeriodDimension period selector (transfer-style) for preset periods (in thematic dialog)
  3. Use new StartEndDate for start-end dates periods (in thematic, events and tracked entity dialogs)
  4. Update of RenderingStrategy that controls the use of single map / timeline / split-map (in thematic dialog)
  5. Use new SegmentedControl to switch between preset periods and start-end dates (in thematic dialog)
  6. Refactoring of Timeline component to support multiple periods and from class to functional component (for thematic layers)

Also improved keyboard navigation is introduced. The original object was to only to enable typing dates properly. In the end a number of files are modified to introduce consistency. Reviewing them should be quick so it might be a good idea to start here. A few other quality of life improvements included as well. All these changes are listed at the end.

1. Multiple periods selection

filename comments specific jest test specific cypress test
src/components/edit/thematic/ThematicDialog.js Update tests from !period to periods?.length === 0. Use new getPeriodsFromFilters utility function form util/analytics.js. Use new getRelativePeriodsName from @dhis2/analytics to have name for defaultPeriod. No Yes
src/constants/actionTypes.js Support LAYER_EDIT_PERIODS_SET. No No
src/loaders/thematicLoader.js Use getPeriodsFromFilters from utils/analytics.js in legend and analyticsRequest. No No
src/reducers/layerEdit.js Update LAYER_EDIT_PERIOD_SET. Support LAYER_EDIT_PERIODS_SET (new period selector). No No
src/components/interpretations/InterpretationMap.js Use new getPeriodsFromFilters utility function form util/analytics.js. Update test to detect if at least one relative period is present. No No
src/util/analytics.js New utility functions: getPeriodsFromFilters and setFiltersFromPeriods. Yes No

2. PeriodDimension

image

The new period selector used is PeriodDimension (transfer-style) is defined in @dhis2/analytics.

filename comments specific jest test specific cypress test
src/components/edit/thematic/ThematicDialog.js Use new PeriodDimension component. No Yes
src/components/edit/LayerEdit.js Switching to large modal. No No

3. StartEndDate

image

We updated and rename StartEndDates to StartEndDate to align with the Linelisting app but with an updated date picker CalendarInput from @dhis2/ui which supports multiple calendars.

EventDialog and TrackedEntityDialog are also updated to use StartEndDate.

filename comments specific jest test specific cypress test
src/components/periods/StartEndDate.js Use new CalendarInput from @dhis2/ui which support non-gregorian calendars. Correction on typing. Yes Yes
src/util/date.js StartEndDate keyboard input validation. Yes No
src/components/edit/thematic/ThematicDialog.js Use new StartEndDate component. Handle switching between period types (resets startDate endDate). Add periodError rendering div and hide periodError when period is being modified. No Yes
src/components/edit/event/EventDialog.js Use new StartEndDate component. Handle switching between period types (resets startDate endDate). Add periodError rendering div and hide periodError when period is being modified. No Yes
src/components/edit/trackedEntity/TrackedEntityDialog.js Use new StartEndDate component. Add periodError rendering div and hide periodError when period is being modified. No Yes

4. RenderingStrategy

image

We updated the logic to account for multiple periods selection.

filename comments specific jest test specific cypress test
src/components/edit/thematic/ThematicDialog.js Use updated RenderingStrategy. No Yes
src/components/periods/RenderingStrategy.js Control that selected period presets are compatible with rendering types. Yes Yes
src/components/core/RadioGroup.js Additional styling options: boldLabel and compact. Yes No
src/util/periods.js Utility functions for periods counting in RenderingStrategy. Yes No
src/util/helpers.js New sumObjectValues helper that sum all numbers in an object recursively. Yes No

5. SegmentedControl

image

filename comments specific jest test specific cypress test
src/components/edit/thematic/ThematicDialog.js Use new SegmentedControl. Handle switching between period types (resets periods/ startDate endDate). No Yes
src/components/edit/trackedEntity/PeriodTypeSelect.js Update to use updated setPeriodType action and be compatible with SegmentedControl used in ThematicDialog. No No

6. Timeline

image

filename comments specific jest test specific cypress test
src/components/periods/Timeline.js Support multiple periods. Display period types on separate y axes, periods of shortest duration are the closest to the x axis. Play by period startDate, if multiple, start with the period type with the longest duration. Refactor to functional component. Use new utility functions form util/periods.js. Resize component properly. Yes Yes
src/util/periods.js Utility functions for periods sorting, combined periods duration evaluation and checking last period in Timeline. Yes No
src/components/map/layers/ThematicLayer.js Select correct first period for Timeline. No Yes

Smaller quality of life improvements are included:

Keyboard navigation

filename comments
src/hooks/useKeyDown.js Support keyboard interactions short and long press.
src/components/periods/StartEndDate.js Proper support of 'Tab' navigation.
src/components/edit/LayerEdit.js Press "Enter" to save changes and close component. Press "Esc" to discard changes and close component.
src/components/map/Popup.js Press "Esc" to close component.
src/components/layers/overlays/AddLayerPopover.js Press "Esc" to close component.
src/components/layerSources/ManageLayerSourcesModal.js Press "Esc" to close component.
src/components/download/DownloadSettings.js Press "Esc" to close component.
src/components/orgunits/OrgUnitProfile.js Long press "Esc" to close component.
src/components/interpretations/InterpretationsToggle.js Long press "Esc" to close component.
src/components/datatable/BottomPanel.js Long press "Esc" to close component.

Added "x" close modal buttons:

filename comments
src/components/edit/LayerEdit.js "x" button to close component.
src/components/layerSources/ManageLayerSourcesModal.js "x" button to close component.

Small bug fixes

filename comments
src/components/layers/overlays/styles/AddLayerButton.module.css Remove outline.
src/components/map/layers/EventPopup.js "Not set" text should be displayed also for data item with option sets.
src/components/map/layers/TrackedEntityPopup.js "Not set" text should be displayed also for data item with option sets.
src/util/time.js Empty date should not be considered a valid date format.

Missing:

  • feat: Restore previous values when jumping between period types.
  • bug: StartEndDate validation bug: '2025-01-0'.
  • bug: StartEndDate validation bug after clearing date on an existing layer (errorPeriod not showing).
  • doc: Update documentation to reflect changes.

Checklist:

  • Jest tests added
  • Cypress tests added
  • Manual testing complete
  • Dashboard tested
  • Update @dhis2/analytics dependency (to not point to d2-ci)
  • Update JIRA

@dhis2-bot
Copy link
Contributor

dhis2-bot commented Nov 18, 2024

🚀 Deployed on https://pr-3407.maps.netlify.dhis2.org

@dhis2-bot dhis2-bot temporarily deployed to netlify November 18, 2024 16:58 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify November 25, 2024 15:58 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify December 2, 2024 16:05 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify December 3, 2024 08:49 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify December 3, 2024 14:40 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify December 4, 2024 14:58 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify December 5, 2024 12:36 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify December 5, 2024 16:04 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify December 6, 2024 10:42 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify December 6, 2024 17:04 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify December 9, 2024 17:54 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify December 28, 2024 00:44 Inactive
@BRaimbault BRaimbault marked this pull request as ready for review December 28, 2024 01:29
@@ -10,6 +10,10 @@
height: 36px;
}

.radioGroup.compact fieldset>div>div>label {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to use the same spacing as is on line 25?

/>
)}
{periodError && (
<div key="error" className={styles.error}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the purpose of the key attribute?

display: flex;
align-items: center;
line-height: 1;
gap: 8px;
Copy link
Collaborator

Choose a reason for hiding this comment

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

use spacers-dp8

@dhis2-bot dhis2-bot temporarily deployed to netlify January 9, 2025 08:24 Inactive
@jenniferarnesen
Copy link
Collaborator

I noticed a few things when entering the start or end date. Maybe it's working as expected, or maybe it should be improved, not sure:

  1. I entered a date by typing it in rather than selecting from the calendar that pops up. Then out of habit I pressed . The modal closed and the map was displayed with the correct dates. So maybe everything works as expected. But I was a little confused when the modal just disappeared like that.
  2. When entering the date by hand, I tried to type the "-", which wasn't allowed. I finally understood to keep entering the date numbers (YYYY-MM-DD) but it would have been preferable if there was some formatting in the input field so the hyphens were displayed so I was aware I didn't need to type them myself.

@jenniferarnesen
Copy link
Collaborator

The line heights feel a little tight here, especially since there is room to make a little more space:
image

@jenniferarnesen
Copy link
Collaborator

jenniferarnesen commented Jan 9, 2025

The info says that at least 2 periods must be added in order to enable timeline or split view.
image

But if I add just 1 period, both timeline and split view are enabled.
image

Ok, so I see that if I had chosen only "This month", then those options would still be disabled. But if I choose only "Last 6 months", then they are enabled. I guess "this month" counts as a single period, while "last 6 months" counts as 6 periods? If that's the case, then I think maybe the info text needs to be a little clearer.

@dhis2-bot dhis2-bot temporarily deployed to netlify January 9, 2025 17:07 Inactive
@jenniferarnesen
Copy link
Collaborator

Just to confirm, with this implementation, the "bug" mentioned in this Jira issue will go away. Is it confirmed that we want the start/end dates to not be cleared even if they aren't in use?

return this
}

/* eslint-disable max-params */
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe send an object instead of disabling max-params

.validateStage('Inpatient morbidity and mortality')
.selectTab('Period')
.selectPeriodType('Start/end dates')
.typeStartDate(`${CURRENT_YEAR - 5}-02-01`)
Copy link
Collaborator

@jenniferarnesen jenniferarnesen Jan 10, 2025

Choose a reason for hiding this comment

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

With the use of the "-5" in several places I wonder if it might be informative to future us to create a test object, for example:

{
programName: 'Inpatient morbitity and mortality',
yearWithData: CURRENT_YEAR - 5
}

Maybe other properties as well?

@dhis2-bot dhis2-bot temporarily deployed to netlify January 10, 2025 11:49 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify January 10, 2025 11:56 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify January 10, 2025 12:04 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify January 10, 2025 13:35 Inactive
excludedPeriodTypes={
systemSettings.hiddenPeriods
}
height={'250px'}
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 you need the curly braces.

@@ -631,15 +701,14 @@ class ThematicDialog extends Component {
)
}

if (!period && periodType !== START_END_DATES) {
if (periods?.length === 0 && periodType !== START_END_DATES) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If periods is undefined, then this first condition will not be true. Is that expected behavior?

@@ -23,8 +24,15 @@ const ManageLayerSourcesModal = ({ onClose }) => {
const { managedLayerSources, showLayerSource, hideLayerSource } =
useManagedLayerSourcesStore()

useKeyDown('Escape', onClose)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm thinking that maybe we should pull changes that aren't related to the period dimension into a separate PR.

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.

3 participants