Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

[DSR] Utiliser la réponse de la requête simulation #59

Merged
merged 28 commits into from
Jul 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4bf1d63
Add dotation result state and reducers
LoicPoullain Jul 15, 2020
59eaf35
Handle dotations response in reducers
LoicPoullain Jul 15, 2020
9ce9222
Convert Parameter to TS
LoicPoullain Jul 15, 2020
6cb4e17
Make amendementValue optional in Parameter
LoicPoullain Jul 15, 2020
2ff0319
Add ResultValues component
LoicPoullain Jul 15, 2020
aaa73ca
Use redux state in CommuneSummary
LoicPoullain Jul 15, 2020
32c058e
Use redux state in CommuneStrateDetailsTable
LoicPoullain Jul 16, 2020
6821a01
Use redux state in CommuneType
LoicPoullain Jul 16, 2020
ea6a595
Replace plfToAmendement with baseToPlf
LoicPoullain Jul 20, 2020
1ae3581
Add RequestBody in simulate-dotations.ts
LoicPoullain Jul 20, 2020
a439b97
Add strates in request
LoicPoullain Jul 20, 2020
b572eb6
Use baseTo in CommuneSummary
LoicPoullain Jul 20, 2020
a3db2d3
Do not show "non éligible" when no data
LoicPoullain Jul 20, 2020
28fcb8d
Add fake data
LoicPoullain Jul 20, 2020
0ee7056
Merge branch 'master' into dsr-response2
LoicPoullain Jul 20, 2020
149aa62
Remove useless interface
LoicPoullain Jul 20, 2020
f59d7a3
Use TS
LoicPoullain Jul 20, 2020
cedb74c
Fix bad merge
LoicPoullain Jul 20, 2020
de954e7
Add image explaining the application state.
LoicPoullain Jul 20, 2020
b3c0816
Handle infinity inhabitants in strates.
LoicPoullain Jul 20, 2020
6a4259f
Make spacing consistent with <Parameter />
LoicPoullain Jul 20, 2020
296f233
Fix linting
LoicPoullain Jul 20, 2020
212058c
Put real data in descriptions/
LoicPoullain Jul 22, 2020
91be4bf
Remove fake data
LoicPoullain Jul 22, 2020
d713e7e
Fix spacing
LoicPoullain Jul 22, 2020
9d7b88d
Allow to only display n decimals
LoicPoullain Jul 22, 2020
f266298
Manage result rates and PLF undefined values.
LoicPoullain Jul 22, 2020
1caec39
Fix linting
LoicPoullain Jul 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ LexImpact has two components:
- [leximpact-server](https://github.com/betagouv/leximpact-server/): a Python application using [OpenFisca-France](https://github.com/openfisca/openfisca-france) and providing a Web API responding to requests on the impact of a change of the tax law,
- Here, [leximpact-client](https://github.com/betagouv/leximpact-client/): a web interface interacting with leximpact-server API and providing to the users a web site to set law tax changes and see the results calculated by the API.

## Organisation de l'état redux
## Organisation de l'état de l'application

![Etat de l'application](./redux-state.png)

L'état redux est en cours de re-factorisation. Voici la manière dont il se présentera à terme:

Expand Down Expand Up @@ -60,7 +62,7 @@ L'état redux est en cours de re-factorisation. Voici la manière dont il se pr
- baseToPlf # Résultats comparant le PLF avec le code existant
- ir
- dotations
- plfToAmendement # Résultats comparant le PLF avec les valeurs proposées par l'utilisateur
- baseToAmendement # Résultats comparant les valeurs proposées par l'utilisateur avec le code existant
- ir
- dotations
- interfaces # Descriptions des états (identiques dans amendement, base et plf)
Expand All @@ -80,9 +82,9 @@ L'état redux est en cours de re-factorisation. Voici la manière dont il se pr
Les données asynchrones (comme les résultats de la simulation) sont décrites par cette interface:

```typescript
export interface AsyncItems<T> {
export interface AsyncState<T> {
isFetching: boolean;
items: T;
state: T | null;
}
```

Expand Down
100 changes: 0 additions & 100 deletions components/articles-inputs/parameter/Parameter.jsx

This file was deleted.

9 changes: 3 additions & 6 deletions components/articles-inputs/parameter/Parameter.module.scss
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
@import 'styles/variables.scss';

$input-margin: 0.3rem;

.baseValue {
font-weight: bold;
margin-left: $input-margin;
text-decoration-color: $amendement-bg-color;
}

.crossedOut {
text-decoration-line: line-through;
}

.plfValue {
font-weight: bold;
margin-left: $input-margin;
color: $plf-color;
}

Expand All @@ -29,8 +28,6 @@ $input-margin: 0.3rem;

.amendementValue {
font-weight: bold;
margin-left: $input-margin !important;
margin-right: $input-margin !important;
}

.amendementValueModified {
Expand Down
108 changes: 108 additions & 0 deletions components/articles-inputs/parameter/Parameter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import classNames from "classnames";
import { PureComponent } from "react";

import { PlfTooltip, ReformTooltip } from "../../tooltips";
import { formatNumber } from "../../utils";
import { NumberInput } from "./number-input";
import styles from "./Parameter.module.scss";

function withTooltip(
Tooltip: any, title: string|JSX.Element|undefined|null, element: JSX.Element,
): JSX.Element {
if (title == null || title === undefined) {
return element;
}

return (
<Tooltip
placement="bottom-start"
title={title}>
{element}
</Tooltip>
);
}

/* The |null are added because we have JS files using this component. */
interface Props {
amendementInputSize?: "small"|"xl"|null;
amendementTitle?: string|JSX.Element|null;
amendementValue?: number;
baseValue?: number|null;
decimals?: number;
editable?: boolean,
onAmendementChange?: (value: number) => void,
plfTitle?: string|JSX.Element|null;
plfValue?: number|null;
}

export class Parameter extends PureComponent<Props> {
render() {
const {
amendementInputSize, amendementTitle, amendementValue, baseValue,
decimals, editable, onAmendementChange, plfTitle, plfValue,
} = this.props;
const equal = baseValue === amendementValue;

function isDefined(value: number|null|undefined): value is number {
// The "=== null" checks is still needed because there are .jsx files using defaultProps.
return value !== null && value !== undefined;
}

return (
<span className={styles.noOverflow}>
{
!isDefined(baseValue) && !isDefined(plfValue) && !isDefined(amendementValue)
&& "-"
}
{
isDefined(plfValue) && withTooltip(
PlfTooltip,
plfTitle,
<span className={styles.plfValue}>{formatNumber(plfValue, { decimals })}</span>,
)
}
{
isDefined(plfValue) && (isDefined(baseValue) || isDefined(amendementValue))
&& <span>&nbsp;&nbsp;</span>
}
{
isDefined(baseValue) && !equal
&& (
<span className={classNames({
[styles.baseValue]: true,
[styles.crossedOut]: amendementValue !== undefined,
})}>
{formatNumber(baseValue, { decimals })}
</span>
)
}
{
isDefined(baseValue) && isDefined(amendementValue) && !equal && <span>&nbsp;&nbsp;</span>
}
{
isDefined(amendementValue) && withTooltip(ReformTooltip, amendementTitle, editable
? (
<NumberInput
className={classNames({
[styles.amendementInput]: true,
[styles.amendementValue]: true,
[styles.amendementValueModified]: !equal,
[styles.smallInput]: amendementInputSize === "small",
[styles.xlInput]: amendementInputSize === "xl",
})}
value={amendementValue}
onChange={onAmendementChange || (() => {})} />
)
: (
<span className={classNames({
[styles.amendementValue]: true,
[styles.amendementValueModified]: !equal,
})}>
{formatNumber(amendementValue, { decimals })}
</span>
))
}
</span>
);
}
}
29 changes: 29 additions & 0 deletions components/articles-inputs/parameter/ResultValues.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// eslint-disable-next-line no-unused-vars
import { connect, ConnectedProps } from "react-redux";

// eslint-disable-next-line no-unused-vars
import { RootState } from "../../../redux/reducers";
import { getResultNumberValues } from "../../../redux/utils";
import { Parameter } from "./Parameter";

const mapStateToProps = ({ results }: RootState, { path }) => getResultNumberValues(results, path);

const connector = connect(mapStateToProps);

type PropsFromRedux = ConnectedProps<typeof connector>

type Props = PropsFromRedux & {
decimals?: number;
path: string;
plfTitle?: string|JSX.Element;
amendementInputSize?: "small"|"xl";
amendementTitle?: string|JSX.Element;
}

function ResultValues(props: Props) {
return <Parameter {...props} />;
}

const ConnectedResultValues = connector(ResultValues);

export { ConnectedResultValues as ResultValues };
2 changes: 1 addition & 1 deletion components/articles-inputs/parameter/StateParameter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Props = PropsFromRedux & {
editable?: boolean;
path: string;
plfTitle?: string|JSX.Element;
amendementInputSize?: "small"|"large"|"xl";
amendementInputSize?: "small"|"xl";
amendementTitle?: string|JSX.Element;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { Parameter } from "./Parameter";
export { ResultValues } from "./ResultValues";
export { StateParameter } from "./StateParameter";
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,23 @@ class ArticleAlinea3 extends PureComponent {
) : null}
3. Le montant de l&apos;impôt résultant de l&apos;application des
dispositions précédentes est réduit de
{" "}
{baseOutputInput("plafond_qf.abat_dom.taux_GuadMarReu")}
{" "}
%, dans la limite de
{" "}
{baseOutputInput("plafond_qf.abat_dom.plaf_GuadMarReu")}
{" "}
€ pour les
contribuables domiciliés dans les départements de la Guadeloupe, de
la Martinique et de la Réunion ; cette réduction est égale à
{" "}
{baseOutputInput("plafond_qf.abat_dom.taux_GuyMay")}
{" "}
%, dans la limite de
{" "}
{baseOutputInput("plafond_qf.abat_dom.plaf_GuyMay")}
{" "}
€, pour les contribuables domiciliés dans les départements de la
Guyane et de Mayotte ;
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ class Alinea4a extends PureComponent {
de la différence entre
{" "}
{baseOutputInput("decote.seuil_celib")}
{" "}
€ et
{" "}
{baseOutputInput("decote.taux")}
{" "}
% de son montant pour les contribuables célibataires, divorcés ou
veufs et de la différence entre
{" "}
{baseOutputInput("decote.seuil_couple")}
{" "}
€ et
{" "}
{formulaOutputInput("decote.taux")}
{" "}
% de son montant pour les contribuables soumis à imposition
commune.
</Fragment>
Expand Down