Skip to content

Commit

Permalink
Accède à la propriété niveau_access de la collectivité depuis le tr…
Browse files Browse the repository at this point in the history
…acking de pages vues PostHog
  • Loading branch information
farnoux committed Jan 20, 2025
1 parent 7eb1bc9 commit f265f9b
Show file tree
Hide file tree
Showing 90 changed files with 345 additions and 269 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ export const SelectCollectivite = (props: HeaderPropsWithModalState) => {
{currentCollectivite.nom}
</b>
<BadgeNiveauAcces
acces={currentCollectivite.niveau_acces}
isAuditeur={currentCollectivite.est_auditeur}
acces={currentCollectivite.niveauAcces}
isAuditeur={currentCollectivite.role === 'auditeur'}
className="ml-4"
/>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Header = () => {
const auth = useAuth();
const currentCollectivite = useCurrentCollectivite();
const { data: panier } = useNbActionsDansPanier(
currentCollectivite?.collectivite_id!
currentCollectivite?.collectiviteId!
);
const maintenance = useMaintenance();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ const isVisiteur = ({
user: UserData | null;
collectivite: CurrentCollectivite;
}) =>
collectivite.niveau_acces === null &&
collectivite.niveauAcces === null &&
!user?.isSupport &&
!collectivite.est_auditeur;
!collectivite.isRoleAuditeur;

const makeNavItemsBase = (
collectivite: CurrentCollectivite,
user: UserData | null,
panierId: string | undefined
): TNavItemsList => {
const collectiviteId = collectivite.collectivite_id;
const collectiviteId = collectivite.collectiviteId;
const confidentiel =
collectivite.acces_restreint && collectivite.niveau_acces === null;
collectivite.accesRestreint && collectivite.niveauAcces === null;
const hideToVisitor = isVisiteur({ user, collectivite });

// items communs qque soient les droits de l'utilisateur courant
Expand Down Expand Up @@ -178,7 +178,7 @@ const makeNavItemsBase = (
{
confidentiel,
title: "Plans d'action",
urlPrefix: [`${collectivite.collectivite_id}/plans/`],
urlPrefix: [`${collectivite.collectiviteId}/plans/`],
dataTest: 'nav-pa',
items: [
{
Expand Down Expand Up @@ -227,7 +227,7 @@ const makeNavItemsBase = (
confidentiel,
title: 'Indicateurs',
dataTest: 'nav-ind',
urlPrefix: [`${collectivite.collectivite_id}/indicateurs/`],
urlPrefix: [`${collectivite.collectiviteId}/indicateurs/`],
items: [
{
label: 'Tous les indicateurs',
Expand Down Expand Up @@ -273,10 +273,10 @@ const filtreItems = (items: TNavItemsList): TNavItemsList =>
export const makeSecondaryNavItems = (
collectivite: CurrentCollectivite
): TNavItemsList => {
const collectiviteId = collectivite.collectivite_id;
const collectiviteId = collectivite.collectiviteId;

const confidentiel =
collectivite.acces_restreint && collectivite.niveau_acces === null;
collectivite.accesRestreint && collectivite.niveauAcces === null;

return filtreItems([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ const Accueil = (): JSX.Element => {
const { count: ficheActionCount } = useFicheActionCount();

const { data: panier } = useNbActionsDansPanier(
collectivite?.collectivite_id!
collectivite?.collectiviteId!
);

if (!collectivite?.collectivite_id) return <></>;
if (!collectivite?.collectiviteId) return <></>;

const { collectivite_id: collectiviteId } = collectivite;
const { collectiviteId: collectiviteId } = collectivite;

return (
<main
Expand Down Expand Up @@ -100,7 +100,7 @@ const Accueil = (): JSX.Element => {
}`}
description="Centralisez et réalisez le suivi des plans d'actions de transition écologique de votre collectivité. Collaborez à plusieurs sur les fiches action pour planifier et piloter leur mise en oeuvre !"
buttons={[
collectivite.readonly
collectivite.readOnly
? {
children: 'Aller sur le tableau de bord de la collectivité',
href: makeTableauBordUrl({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const AddRapportButton = (props: TAddDocsButtonProps) => {
const [opened, setOpened] = useState(false);
const handlers = useAddPreuveToAudit(props.audit_id);
const currentCollectivite = useCurrentCollectivite();
if (!currentCollectivite || currentCollectivite.readonly) {
if (!currentCollectivite || currentCollectivite.readOnly) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const useAudit = () => {
* collectivité courante */
export const useIsAuditeur = () => {
const collectivite = useCurrentCollectivite();
return collectivite?.est_auditeur || false;
return collectivite?.isRoleAuditeur || false;
};

/** Liste des auditeurs pour la collectivité et le référentiel courant */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const useExportAuditScores = (
collectivite: CurrentCollectivite | null
) => {
const tracker = useFonctionTracker();
const collectivite_id = collectivite?.collectivite_id;
const collectivite_id = collectivite?.collectiviteId;

return useMutation(
['export_audit_score', collectivite_id, referentiel],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useCollectiviteId } from '@/app/core-logic/hooks/params';
import { useCurrentCollectivite } from '@/app/core-logic/hooks/useCurrentCollectivite';
import PreuveDoc from '@/app/ui/shared/preuves/Bibliotheque/PreuveDoc';
import {
TPreuveAuditEtLabellisation,
TPreuveRapport,
} from '@/app/ui/shared/preuves/Bibliotheque/types';
import { usePreuvesParType } from '@/app/ui/shared/preuves/Bibliotheque/usePreuves';
import { TrackPageView } from '@/ui';
import { pick } from 'es-toolkit';
import { AddRapportVisite } from './AddRapportVisite';
import { PreuvesLabellisation } from './PreuveLabellisation';
import { PreuvesTabs } from './PreuvesTabs';
Expand Down Expand Up @@ -50,7 +51,7 @@ export const BibliothequeDocs = ({
};

const BibliothequeDocsConnected = () => {
const collectivite_id = useCollectiviteId()!;
const collectivite = useCurrentCollectivite()!;
const preuves = usePreuvesParType({
preuve_types: ['audit', 'labellisation', 'rapport'],
});
Expand All @@ -62,7 +63,11 @@ const BibliothequeDocsConnected = () => {
<>
<TrackPageView
pageName="app/parametres/bibliotheque"
properties={{ collectivite_id }}
properties={pick(collectivite, [
'collectiviteId',
'niveauAcces',
'role',
])}
/>
<BibliothequeDocs
labellisationEtAudit={labellisationEtAudit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ export const RouteEnAccesRestreint = (props: RouteProps) => {
<Route
{...other}
render={({ location }) =>
collectivite.acces_restreint && collectivite.niveau_acces === null ? (
collectivite.accesRestreint && collectivite.niveauAcces === null ? (
<Redirect
to={makeCollectiviteAccueilUrl({
collectiviteId: collectivite.collectivite_id,
collectiviteId: collectivite.collectiviteId,
})}
/>
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ const Accueil = (): JSX.Element => {

const { user } = useAuth();

if (!collectivite?.collectivite_id) return <></>;
if (!collectivite?.collectiviteId) return <></>;

/** Vérifie que l'utilisateur peut accéder à la collectivité */
const hasNoAccessToCollectivite =
collectivite.acces_restreint &&
collectivite.niveau_acces === null &&
collectivite.accesRestreint &&
collectivite.niveauAcces === null &&
!user?.isSupport &&
!collectivite.est_auditeur;
!collectivite.isRoleAuditeur;

/** S'il ne peut pas, on affiche un message */
if (hasNoAccessToCollectivite) {
Expand Down Expand Up @@ -64,7 +64,7 @@ const AccueilNonConfidentielle = ({
eciPotentiel,
} = useProgressionReferentiel();

const { collectivite_id: collectiviteId, readonly } = collectivite;
const { collectiviteId: collectiviteId, readOnly: readonly } = collectivite;
const { data: referents } = useMembres({ collectiviteId, estReferent: true });
const referentsParFonction = groupeParFonction(referents || []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const EtatDesLieuxGraphs = ({
onOpenModal={() =>
collectiviteId &&
trackEvent('zoom_graph', {
collectivite_id: collectiviteId,
collectiviteId: collectiviteId,
referentiel,
type: 'phase',
})
Expand All @@ -97,7 +97,7 @@ const EtatDesLieuxGraphs = ({
onDownload={() =>
collectiviteId &&
trackEvent('export_graph', {
collectivite_id: collectiviteId,
collectiviteId: collectiviteId,
referentiel,
type: 'phase',
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCollectiviteId } from '@/app/core-logic/hooks/params';
import { useCurrentCollectivite } from '@/app/core-logic/hooks/useCurrentCollectivite';
import { TrackPageView } from '@/ui';
import { pick } from 'es-toolkit';
import { HistoriqueListe } from './HistoriqueListe';
import { THistoriqueProps } from './types';
import { useHistoriqueItemListe } from './useHistoriqueItemListe';
Expand All @@ -10,21 +11,25 @@ import { useHistoriqueItemListe } from './useHistoriqueItemListe';
export const JournalActivite = (props: THistoriqueProps) => {
return (
<main data-test="JournalActivite" className="fr-container mt-9 mb-16">
<h1 className="text-center fr-mt-6w fr-mb-6w">Journal d'activité</h1>
<h1 className="text-center fr-mt-6w fr-mb-6w">{"Journal d'activité"}</h1>
<hr />
<HistoriqueListe {...props} />
</main>
);
};

const JournalActiviteConnected = () => {
const collectivite_id = useCollectiviteId()!;
const historique = useHistoriqueItemListe(collectivite_id);
const collectivite = useCurrentCollectivite()!;
const historique = useHistoriqueItemListe(collectivite.collectiviteId);
return (
<>
<TrackPageView
pageName="app/parametres/historique"
properties={{ collectivite_id }}
properties={pick(collectivite, [
'collectiviteId',
'niveauAcces',
'role',
])}
/>
<JournalActivite {...historique} />;
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const FichesActionLiees = (props: TFichesActionProps) => {

const { mutate: updateFichesActionLiees } =
useUpdateFichesActionLiees(definition);
const isReadonly = collectivite?.readonly ?? false;
const isReadonly = collectivite?.readOnly ?? false;

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const IndicateurPersonnaliseBase = ({
const { description, unite, titre, rempli } = definition;
const { mutate: updateDefinition } = useUpdateIndicateurDefinition();
const collectivite = useCurrentCollectivite();
const isReadonly = !collectivite || collectivite?.readonly;
const isReadonly = !collectivite || collectivite?.readOnly;
const { mutate: exportIndicateurs, isLoading } = useExportIndicateurs(
'app/indicateurs/perso',
[definition]
Expand All @@ -37,7 +37,7 @@ const IndicateurPersonnaliseBase = ({
name: 'description' | 'commentaire' | 'unite' | 'titre',
value: string
) => {
const collectivite_id = collectivite?.collectivite_id;
const collectivite_id = collectivite?.collectiviteId;
const nouveau = value?.trim();
if (collectivite_id && nouveau !== definition[name]) {
updateDefinition({ ...definition, [name]: nouveau });
Expand Down Expand Up @@ -67,7 +67,7 @@ const IndicateurPersonnaliseBase = ({

const [showConfirm, setShowConfirm] = useState(false);
const { mutate: deleteIndicateurPerso } = useDeleteIndicateurPerso(
collectivite?.collectivite_id as number,
collectivite?.collectiviteId as number,
definition.id
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { IndicateurValuesTabs } from '@/app/app/pages/collectivite/Indicateurs/I
import { useIndicateurImportSources } from '@/app/app/pages/collectivite/Indicateurs/Indicateur/detail/useImportSources';
import { FichesActionLiees } from '@/app/app/pages/collectivite/Indicateurs/Indicateur/FichesActionLiees';
import ActionsLieesListe from '@/app/app/pages/collectivite/PlansActions/FicheAction/ActionsLiees/ActionsLieesListe';
import { useCollectiviteId } from '@/app/core-logic/hooks/params';
import { useCurrentCollectivite } from '@/app/core-logic/hooks/useCurrentCollectivite';
import ScrollTopButton from '@/app/ui/buttons/ScrollTopButton';
import { ToolbarIconButton } from '@/app/ui/buttons/ToolbarIconButton';
import { BadgeACompleter } from '@/app/ui/shared/Badge/BadgeACompleter';
import TextareaControlled from '@/app/ui/shared/form/TextareaControlled';
import { Badge, Field, TrackPageView } from '@/ui';
import { pick } from 'es-toolkit';
import { TIndicateurDefinition } from '../types';
import { IndicateurCompose } from './detail/IndicateurCompose';
import { IndicateurSidePanelToolbar } from './IndicateurSidePanelToolbar';
Expand All @@ -29,21 +29,19 @@ export const IndicateurPredefiniBase = ({
}) => {
const { commentaire } = definition;
const { mutate: updateDefinition } = useUpdateIndicateurDefinition();
const collectivite = useCurrentCollectivite();
const isReadonly = !collectivite || collectivite?.readonly;
const collectivite = useCurrentCollectivite()!;
const isReadonly = !collectivite || collectivite?.readOnly;
const { mutate: exportIndicateurs, isLoading } = useExportIndicateurs(
'app/indicateurs/predefini',
[definition]
);

const collectivite_id = useCollectiviteId()!;

const { sources, currentSource, setCurrentSource } =
useIndicateurImportSources(definition.id);

// génère les fonctions d'enregistrement des modifications
const handleUpdate = (name: 'commentaire', value: string) => {
const collectivite_id = collectivite?.collectivite_id;
const collectivite_id = collectivite?.collectiviteId;
const nouveau = value?.trim();
if (collectivite_id && nouveau !== definition[name]) {
updateDefinition({ ...definition, [name]: nouveau });
Expand All @@ -54,7 +52,10 @@ export const IndicateurPredefiniBase = ({
<>
<TrackPageView
pageName="app/indicateurs/predefini"
properties={{ collectivite_id, indicateur_id: definition.identifiant! }}
properties={{
...pick(collectivite, ['collectiviteId', 'niveauAcces', 'role']),
indicateurId: definition.identifiant!,
}}
/>
<h5 className="sticky top-0 mb-0 py-8 px-12 text-[#3a3a3a] text-lg bg-bf925 z-40">
{definition.titre}
Expand Down
Loading

0 comments on commit f265f9b

Please sign in to comment.