-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved scorecard header
- Loading branch information
Showing
17 changed files
with
301 additions
and
8 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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
17 changes: 17 additions & 0 deletions
17
...ain/components/ScorecardViewPage/components/DimensionFilterArea/components/BackButton.tsx
This file contains 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,17 @@ | ||
import i18n from "@dhis2/d2-i18n"; | ||
import { Button } from "@dhis2/ui"; | ||
import React from "react"; | ||
import { useNavigate } from "react-router-dom"; | ||
|
||
export function BackButton() { | ||
const navigate = useNavigate(); | ||
const onBackClick = () => { | ||
navigate("/"); | ||
}; | ||
|
||
return ( | ||
<Button onClick={onBackClick}> | ||
{i18n.t("Back to all scorecards")} | ||
</Button> | ||
); | ||
} |
29 changes: 29 additions & 0 deletions
29
...ain/components/ScorecardViewPage/components/DimensionFilterArea/components/HelpButton.tsx
This file contains 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,29 @@ | ||
import React from "react"; | ||
import { Button, IconQuestion24 } from "@dhis2/ui"; | ||
import i18n from "@dhis2/d2-i18n"; | ||
import { useBoolean } from "usehooks-ts"; | ||
import { Steps } from "intro.js-react"; | ||
import { STEP_OPTIONS } from "@scorecard/shared"; | ||
|
||
export interface HelpButtonProps { | ||
steps: any[]; | ||
} | ||
|
||
export function HelpButton({ steps }: HelpButtonProps) { | ||
const { value: hide, setTrue: onHide, setFalse: onShow } = useBoolean(true); | ||
|
||
return ( | ||
<> | ||
<Steps | ||
enabled={!hide} | ||
options={STEP_OPTIONS} | ||
initialStep={0} | ||
steps={steps} | ||
onExit={onHide} | ||
/> | ||
<Button onClick={onShow} icon={<IconQuestion24 />}> | ||
{i18n.t("Help")} | ||
</Button> | ||
</> | ||
); | ||
} |
18 changes: 18 additions & 0 deletions
18
...odules/Main/components/ScorecardViewPage/components/ScorecardActions/ScorecardActions.tsx
This file contains 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,18 @@ | ||
import { ButtonStrip } from "@dhis2/ui"; | ||
import { ScorecardOptionsControlButton } from "./components/ScorecardOptionsControlButton"; | ||
import { ScorecardEditButton } from "./components/ScorecardEditButton"; | ||
import { ScorecardDownloadButton } from "./components/ScorecardDownloadButton"; | ||
import { ScorecardResetButton } from "./components/ScorecardResetButton"; | ||
|
||
export function ScorecardActions() { | ||
return ( | ||
<div style={{ width: "100%", padding: "0 16px" }}> | ||
<ButtonStrip end> | ||
<ScorecardOptionsControlButton /> | ||
<ScorecardEditButton /> | ||
<ScorecardDownloadButton /> | ||
<ScorecardResetButton /> | ||
</ButtonStrip> | ||
</div> | ||
); | ||
} |
6 changes: 6 additions & 0 deletions
6
...ents/ScorecardViewPage/components/ScorecardActions/components/ScorecardDownloadButton.tsx
This file contains 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,6 @@ | ||
import { Button } from "@dhis2/ui"; | ||
import i18n from "@dhis2/d2-i18n"; | ||
|
||
export function ScorecardDownloadButton() { | ||
return <Button>{i18n.t("Download")}</Button>; | ||
} |
6 changes: 6 additions & 0 deletions
6
...mponents/ScorecardViewPage/components/ScorecardActions/components/ScorecardEditButton.tsx
This file contains 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,6 @@ | ||
import { Button } from "@dhis2/ui"; | ||
import i18n from "@dhis2/d2-i18n"; | ||
|
||
export function ScorecardEditButton() { | ||
return <Button>{i18n.t("Edit")}</Button>; | ||
} |
10 changes: 10 additions & 0 deletions
10
...corecardViewPage/components/ScorecardActions/components/ScorecardOptionsControlButton.tsx
This file contains 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,10 @@ | ||
import i18n from "@dhis2/d2-i18n"; | ||
import { Button } from "@dhis2/ui"; | ||
|
||
export function ScorecardOptionsControlButton() { | ||
return ( | ||
<> | ||
<Button>{i18n.t("Options")}</Button> | ||
</> | ||
); | ||
} |
6 changes: 6 additions & 0 deletions
6
...ponents/ScorecardViewPage/components/ScorecardActions/components/ScorecardResetButton.tsx
This file contains 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,6 @@ | ||
import { Button } from "@dhis2/ui"; | ||
import i18n from "@dhis2/d2-i18n"; | ||
|
||
export function ScorecardResetButton() { | ||
return <Button>{i18n.t("Reset")}</Button>; | ||
} |
59 changes: 59 additions & 0 deletions
59
packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardHeader.tsx
This file contains 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,59 @@ | ||
import JsxParser from "react-jsx-parser"; | ||
import { useScorecardConfigFromContext } from "../state/config"; | ||
import { head } from "lodash"; | ||
import { colors } from "@dhis2/ui"; | ||
import { useMemo } from "react"; | ||
import { PeriodUtility } from "@hisptz/dhis2-utils"; | ||
import { useScorecardState } from "../state/state"; | ||
|
||
export function ScorecardHeader() { | ||
const config = useScorecardConfigFromContext(); | ||
const { customHeader, title, subtitle, periodSelection } = config ?? {}; | ||
const periods = periodSelection.periods ?? []; | ||
|
||
const [state] = useScorecardState(); | ||
|
||
const period = useMemo(() => { | ||
if (periods.length > 1) { | ||
return; | ||
} | ||
return PeriodUtility.getPeriodById(head(periods)?.id as string); | ||
}, [periods]); | ||
|
||
if (!state.options.title) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className="row space-between" id={"scorecard-header"}> | ||
<div className="row"> | ||
{customHeader ? ( | ||
<JsxParser | ||
autoCloseVoidElements | ||
className="w-100" | ||
onError={console.error} | ||
bindings={{ | ||
title, | ||
subtitle, | ||
period: periods.length === 1 ? period?.name : "", | ||
}} | ||
jsx={customHeader} | ||
/> | ||
) : ( | ||
<div className="column center align-items-center"> | ||
<h1 | ||
style={{ margin: 8 }} | ||
id={"data-test-score-card-title"} | ||
> | ||
{title}{" "} | ||
{`${periods.length === 1 ? ` - ${period?.name}` : ""}`} | ||
</h1> | ||
<h3 style={{ color: colors.grey600, margin: 0 }}> | ||
{subtitle} | ||
</h3> | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
38 changes: 38 additions & 0 deletions
38
packages/app/src/modules/Main/components/ScorecardViewPage/components/ScorecardView.tsx
This file contains 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,38 @@ | ||
import { useScorecardState } from "../state/state"; | ||
import { ScorecardConfig } from "@hisptz/dhis2-analytics"; | ||
import { useDimensions } from "../hooks/dimensions"; | ||
import i18n from "@dhis2/d2-i18n"; | ||
import { colors } from "@dhis2/ui"; | ||
|
||
export interface ScorecardViewProps { | ||
config: ScorecardConfig; | ||
} | ||
|
||
export function ScorecardView({ config }: ScorecardViewProps) { | ||
const { noDimensionsSelected } = useDimensions(); | ||
const [state, setState] = useScorecardState(); | ||
|
||
if (noDimensionsSelected) { | ||
return ( | ||
<div className="h-100 w-100 column align-items-center justify-content-center"> | ||
<span | ||
style={{ | ||
color: colors.grey700, | ||
fontWeight: "bold", | ||
fontSize: 24, | ||
}} | ||
> | ||
{i18n.t( | ||
"Select organisation unit and period to view scorecard", | ||
)} | ||
</span> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="h-100 w-100 column align-items-center justify-content-center"> | ||
{/*<Scorecard config={config} state={state} setState={setState} />*/} | ||
</div> | ||
); | ||
} |
This file contains 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
28 changes: 28 additions & 0 deletions
28
packages/app/src/modules/Main/components/ScorecardViewPage/state/config.tsx
This file contains 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,28 @@ | ||
import { createContext, ReactNode, useContext } from "react"; | ||
import { ScorecardConfig } from "@hisptz/dhis2-analytics"; | ||
import i18n from "@dhis2/d2-i18n"; | ||
|
||
const ScorecardConfigContext = createContext<ScorecardConfig | null>(null); | ||
|
||
export function useScorecardConfigFromContext() { | ||
const config = useContext(ScorecardConfigContext); | ||
if (!config) { | ||
throw Error(i18n.t("Could not get scorecard config")); | ||
} | ||
|
||
return config; | ||
} | ||
|
||
export function ScorecardConfigProvider({ | ||
children, | ||
config, | ||
}: { | ||
children: ReactNode; | ||
config: ScorecardConfig; | ||
}) { | ||
return ( | ||
<ScorecardConfigContext.Provider value={config}> | ||
{children} | ||
</ScorecardConfigContext.Provider> | ||
); | ||
} |
Oops, something went wrong.