-
Notifications
You must be signed in to change notification settings - Fork 4
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
Test adresse comparateur #938
Draft
martinratinaud
wants to merge
16
commits into
dev
Choose a base branch
from
test_adresse_comparateur
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
dc65de0
Desactive le bouton quand il est loading
martinratinaud d8f4baa
Augment le padding dans le Sticky form pour que ca soit plus aéré
martinratinaud 356f95a
Utilise le bouton UI dans le StickyForm
martinratinaud 7573ec7
Utilise une modal dans le StickyForm au lieu de inline
martinratinaud 6090dfb
Mets les test d'eligibilité dans une modale sur le sticky form et le …
martinratinaud 65c6919
Centre correctement le StickyForm et enlève le bleu au profit du noir
martinratinaud 6f41a59
Supprime l'affichage bizarre odd et even sur la page des villes
martinratinaud c3433c1
Affiche le comparateur uniquement pour le Collectif
martinratinaud 50a3109
Harmonise l'import des mappings publicodes
martinratinaud e3c421c
N'affiche pas les PAC dans les résultats du comparateur
martinratinaud 03b7a6b
Ouvre le comparateur dans un autre onglet pour éviter à l'utilisateur…
martinratinaud 11c7a81
Ajoute la demande de test dans une modale sur les fiches réseau
martinratinaud 2e1b468
Remplace withPins par withSoughtAddresses pour être plus cohérent ave…
martinratinaud 8708f95
Fixe le initialCenter sur la map
martinratinaud ae49698
Fixe typo
martinratinaud aed7c58
Supprime le scroller vers les résultats du test car maintenant dans u…
martinratinaud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
124 changes: 124 additions & 0 deletions
124
src/components/ComparateurPublicodes/ComparateurPublicodesWidget.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,124 @@ | ||
import { fr } from '@codegouvfr/react-dsfr'; | ||
import React from 'react'; | ||
|
||
import { FormProvider } from '@components/form/publicodes/FormProvider'; | ||
import Heading from '@components/ui/Heading'; | ||
import { Table, type ColumnDef } from '@components/ui/Table'; | ||
import { LocationInfoResponse } from '@pages/api/location-infos'; | ||
import { postFetchJSON } from '@utils/network'; | ||
import { ObjectEntries } from '@utils/typescript'; | ||
|
||
import { addresseToPublicodesRules, modesDeChauffage } from './mappings'; | ||
import { simulatorTabs } from './Placeholder'; | ||
import useSimulatorEngine from './useSimulatorEngine'; | ||
|
||
type ComparateurPublicodesWidgetProps = React.HTMLAttributes<HTMLDivElement> & { | ||
coords?: [longitude?: number, latitude?: number]; | ||
city?: string; | ||
cityCode?: string; | ||
address?: string; | ||
}; | ||
|
||
export type TabId = (typeof simulatorTabs)[number]['tabId']; | ||
const ComparateurPublicodesWidget: React.FC<ComparateurPublicodesWidgetProps> = ({ | ||
children, | ||
coords, | ||
city, | ||
cityCode, | ||
address, | ||
...props | ||
}) => { | ||
const engine = useSimulatorEngine(); | ||
|
||
React.useEffect(() => { | ||
if (!coords || !city || !cityCode) { | ||
return; | ||
} | ||
const loadInfos = async () => { | ||
const infos: LocationInfoResponse = await postFetchJSON('/api/location-infos', { | ||
lon: coords[0], | ||
lat: coords[1], | ||
city, | ||
cityCode, | ||
}); | ||
|
||
engine.setSituation( | ||
ObjectEntries(addresseToPublicodesRules).reduce( | ||
(acc, [key, infoGetter]) => ({ | ||
...acc, | ||
[key]: infoGetter(infos) ?? null, | ||
}), | ||
{} | ||
) | ||
); | ||
}; | ||
loadInfos(); | ||
}, [coords, city, cityCode]); | ||
|
||
const modesDeChauffageToDisplay = modesDeChauffage | ||
.filter(({ type, label }) => (type as any).includes('collectif') && !label.includes('PAC')) | ||
.map((typeInstallation) => ({ | ||
id: typeInstallation.label, | ||
label: typeInstallation.label, | ||
bilan: engine.getFieldAsNumber(`Bilan x ${typeInstallation.coutPublicodeKey} . total avec aides`), | ||
emissionsCO2: engine.getFieldAsNumber(`env . Installation x ${typeInstallation.emissionsCO2PublicodesKey} . Total`), | ||
})) | ||
.sort((a, b) => a.bilan - b.bilan); | ||
|
||
const columns: ColumnDef<{ label: string; bilan: number }>[] = [ | ||
{ | ||
headerName: 'Mode de chauffage', | ||
field: 'label', | ||
flex: 3, | ||
}, | ||
{ | ||
headerName: 'Coût annuel chauffage', | ||
flex: 2, | ||
field: 'bilan', | ||
renderCell: ({ value }) => value.toLocaleString('fr-FR', { currency: 'EUR', maximumFractionDigits: 0, style: 'currency' }), | ||
}, | ||
{ | ||
headerName: 'Émissions CO2', | ||
flex: 2, | ||
field: 'emissionsCO2', | ||
renderCell: ({ value }) => `${value.toLocaleString('fr-FR', { maximumFractionDigits: 0 })} kgCO2e`, | ||
}, | ||
]; | ||
|
||
return ( | ||
<div {...props}> | ||
<FormProvider engine={engine}> | ||
<Heading as="h2" size="h4"> | ||
Comparaison des modes de chauffage | ||
</Heading> | ||
<Table | ||
style={{ width: '100%' }} | ||
getRowClassName={({ id }) => (id === 'Réseau de chaleur' ? fr.cx('fr-text--bold') : '')} | ||
columns={columns} | ||
hideFooter | ||
rows={modesDeChauffageToDisplay} | ||
autosizeOnMount | ||
disableRowSelectionOnClick | ||
autoHeight | ||
pageSize={20} | ||
/> | ||
<div className={fr.cx('fr-text--sm', 'fr-mt-2w')} style={{ textAlign: 'right', fontStyle: 'italic' }}> | ||
Accéder au{' '} | ||
<a | ||
href={`/outils/comparateur-performances?address=${encodeURIComponent( | ||
address as string | ||
)}&modes-de-chauffage=${encodeURIComponent( | ||
modesDeChauffageToDisplay.map(({ label }) => label).join(',') | ||
)}&tabId=modes-de-chauffage`} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
> | ||
comparateur complet | ||
</a> | ||
</div> | ||
</FormProvider> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ComparateurPublicodesWidget; |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalement on ne devrait pas avoir besoin du cast car il y a que 2 choix possibles. Mais c'est plus à voir avec la définition où il faudrait ajouter un type sur type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oui le type est mal inféré et je n'ai pas trouvé comment faire, donc je veux bien ton aide