Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/client/src/ts/session/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export type School = {
id: string; // "09772a06-1362-4802-a475-66a87d9cb679"
name: string; // "MY DEV SCHOOL"
UAI: string; // "1111888G"
exports: string[]; // ["GAR-P0"]
exports: string[] | null; // ["GAR-P0"]
};
export type UserProfile = Array<
'Student' | 'Teacher' | 'Relative' | 'Personnel' | 'Guest'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.school-widget {
Copy link
Member

Choose a reason for hiding this comment

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

dans le forntend framework le css n'est pas pris en compte si il est dans les composant (on s'en rendra compte uniquement lorsqu'on importera le ticket dans un projet).
Il faut donc créer un fichier .scss (exemple)
Cela permet aussi d'utiliser les variables sass mais surtout de gerer tout le style dans bootstrap

Copy link
Collaborator

Choose a reason for hiding this comment

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

Bon attention, goût personnel, mais c'est un truc que j'aimerais bien retirer, le fait de ne pas avoir le css dans les composants ça m'emmerde, ça rend la lecture compliquée et la maintenance pas intuitive.
Mais c'est pas un chantier pour maintenant, on verra plus tard. Donc en attendant oui, on garde les guidelines de FF et direction le package bootstrap.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Par contre très bien les vars scopées sur le composant lui-même.

--school-widget-border-color: #ffe5a3;
--school-widget-bg-color: #fefaec;
--school-widget-selected-color: #383838;
}

.school-widget {
border: 1px solid var(--school-widget-border-color);
border-radius: 2.4rem;

background-color: var(--school-widget-bg-color);
background-image: url('./SchoolWidgetBackground.svg');
Copy link
Collaborator

Choose a reason for hiding this comment

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

C'est une image qui va être lié aux préférénces de couleur qui seront accessibles dans le panneau de configuration. Pas en v1 mais faudra y penser.

Copy link
Member

Choose a reason for hiding this comment

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

Ah. bien vu, mais c'est un comportement qu'on va devoir mettre en place à plusieurs endroit. Tu as une idée de comment faire ? on peut passer des proriétés à un svg ?

background-repeat: no-repeat;
background-position: bottom right;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import type { Meta, StoryObj } from '@storybook/react';
import SchoolWidget, { SchoolWidgetProps } from './SchoolWidget';

const meta: Meta<typeof SchoolWidget> = {
title: 'Modules/Homepage/SchoolWidget',
component: SchoolWidget,
decorators: [
(Story) => (
<div style={{ height: '35em' }}>
<div id="portal" />
<Story />
</div>
),
],
parameters: {
docs: {
description: {
component:
"Ce storybook documente le composant SchoolWidget, un widget de sélection d'école avec plusieurs variantes possibles.",
},
},
},
};

export default meta;
type Story = StoryObj<typeof SchoolWidget>;

const renderWithProps = (props: SchoolWidgetProps) => () => (
<div style={{ maxWidth: 397 }}>
<SchoolWidget {...props} />
</div>
);

const schools = [
{
id: 'school-1',
name: 'Collège Jean Moulin',
UAI: '0012345A',
classes: [],
exports: [],
},
{
id: 'school-2',
name: 'Lycée Jeanne Ferry de Loisette en Royan',
UAI: '0098765Z',
classes: [],
exports: [],
},
];

export const MultipleSchools: Story = {
render: renderWithProps({
schools,
selectedSchool: {
id: 'school-2',
name: 'Lycée Jeanne Ferry de Loisette en Royan',
UAI: '0098765Z',
classes: [],
exports: [],
},
onSelectedSchoolChange: (idx) =>
alert(
`School id=${schools[idx].id} UAI=${schools[idx].UAI} is selected.`,
),
}),
parameters: {
docs: {
description: {
story: `
Affiche une liste de plusieurs écoles avec sélection active.
<ul>
<li>2 écoles disponibles (Collège Jean Moulin, Lycée Jeanne Ferry de Loisette en Royan)</li>
<li>École sélectionnée : Lycée Jeanne Ferry</li>
<li>Callback au changement de sélection</li>
</ul>`,
},
},
},
};

export const SingleSchool: Story = {
render: renderWithProps({
schools: [schools[0]],
selectedSchool: schools[0],
}),
parameters: {
docs: {
description: {
story: `Affiche une seule école`,
},
},
},
};

export const Empty: Story = {
render: renderWithProps({ selectedSchool: undefined }),
parameters: {
docs: {
description: {
story: `État vide (aucune école)`,
},
},
},
};
Comment on lines +95 to +104
Copy link
Member

Choose a reason for hiding this comment

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

C'est vraiment utile ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

J'aime bien avoir la possibilité de voir les Edge Case dans storybook, ça retire pas mal de questionnements quand on regarde le composant

Copy link
Member

Choose a reason for hiding this comment

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

est ce que le cas avec aucune ecole est possible ?

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { School } from '@edifice.io/client';
import { useTranslation } from 'react-i18next';
import { Dropdown, Flex, IconButton, useToggle } from '../../../..';
import { IconRafterDown } from '../../../../modules/icons/components';
import './SchoolWidget.css';

export interface SchoolWidgetProps {
selectedSchool: School | undefined;
onSelectedSchoolChange?: (schoolIndex: number) => void;
schools?: School[];
}

const SchoolWidget = ({
schools,
selectedSchool,
onSelectedSchoolChange,
}: SchoolWidgetProps) => {
const [isExpanded, toggleExpanded] = useToggle(false);
const { t } = useTranslation();

const hasManySchools = schools && schools.length > 1;

const widgetStyle = { padding: '1.4rem 0.4rem' };
Copy link
Member

Choose a reason for hiding this comment

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

mettre le css en dehors du composant et au même endroit, dans le fichier .scss (cf commentaire precedent). C'est un point important à acter pour le rester du projet

Copy link
Collaborator

Choose a reason for hiding this comment

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

Tout ce style doit être dans un fichier CSS ou SCSS.
Les seuls styles inlines qu'on va s'autoriser sont ceux qui sont calculés en fonction d'un state ou d'une variable du composant.

const containerStyle = { padding: '0.8rem' };
const selectedSchoolStyle = {
padding: '.4rem 2.9rem',
Copy link
Member

Choose a reason for hiding this comment

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

pour les espacement, dans les application on utiliser les classes bootstrap (p-8, p12,...), dans le FF il faut utiliser les spacer (qui ne peut que être utilisé dans les fichiers sass dans bootstrap justement, exemple)

Ici il s'agit d'un spacer 1.2 (12pixel sur figma)

Image

fontSize: '1.6rem',
lineHeight: '2.2rem',
color: 'var(--school-widget-selected-color)',
};

if (!selectedSchool) return null;

return (
<div className="school-widget" style={widgetStyle}>
<div style={containerStyle}>
<Flex
style={selectedSchoolStyle}
justify="center"
gap="4"
align="center"
>
<b>{selectedSchool.name}</b>
{hasManySchools && (
<Dropdown placement={'bottom-end'} onToggle={toggleExpanded}>
{(
triggerProps: React.ComponentPropsWithRef<typeof IconButton>,
) => (
<>
<IconButton
{...triggerProps}
aria-label={t('show')}
color="tertiary"
variant="ghost"
icon={
<IconRafterDown
Copy link
Member

Choose a reason for hiding this comment

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

wahou chiant d'avoir dû reimplementer ça. J'ai fait un commentaire à simon https://www.figma.com/design/UbAKNC5vk5XOj62z6CI4Qm?node-id=2146-36161#1690319223

className="w-16 min-w-0"
style={{
transition: 'rotate 0.2s ease-out',
rotate: isExpanded ? '0deg' : '-180deg',
}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Si tu peux mettre un TODO pour récupérer ce que j'ai fait sur le composant de Partage

Copy link
Member

Choose a reason for hiding this comment

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

cad ? Tu peux mettre un lien sur le code en question

/>
}
/>
<Dropdown.Menu>
{schools.map((school, index) => (
<Dropdown.Item
key={school.id}
onClick={() => onSelectedSchoolChange?.(index)}
>
<Flex direction="column">
<p>{school.name}</p>
{school.UAI && <p>UAI : {school.UAI}</p>}
</Flex>
</Dropdown.Item>
))}
</Dropdown.Menu>
</>
)}
</Dropdown>
)}
</Flex>
</div>
</div>
);
};

SchoolWidget.displayName = 'SchoolWidget';

export default SchoolWidget;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
// packages/react/src/modules/homepage/components/SchoolWidget/useUserSchools.test.tsx
Copy link
Member

Choose a reason for hiding this comment

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

Comme pour le style, je pense qu'a la compilation , l'image ne sera pas ajoutée aux assets (tester en utilisant le composant dans Actualites par exemple).
Je vois qu'il y a un dossier react/modules/icons , sinon ajouter dans le dossier /bootstrap.
Quelle est la bonne pratique @pascalsaussier-edifice ?

import { act, renderHook, waitFor } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { useUserSchools } from './useUserSchools';

const mocks = vi.hoisted(() => ({
useEdificeClient: vi.fn(),
useWidgetPreferences: vi.fn(),
lookup: vi.fn(),
saveUserPreferences: vi.fn(),
}));

vi.mock('src/providers', () => ({
useEdificeClient: mocks.useEdificeClient,
}));

vi.mock('../../hooks/useWidgetPreferences', () => ({
default: mocks.useWidgetPreferences,
}));

vi.mock('@edifice.io/client', () => ({
WIDGET_NAME: { SCHOOL: 'SCHOOL' },
}));

describe('useUserSchools', () => {
const schools = [
{ id: 's1', name: 'School 1' },
{ id: 's2', name: 'School 2' },
] as any[];

beforeEach(() => {
vi.clearAllMocks();

mocks.useEdificeClient.mockReturnValue({
userDescription: { schools },
});

mocks.lookup.mockReturnValue(undefined);

mocks.useWidgetPreferences.mockReturnValue({
lookup: mocks.lookup,
saveUserPreferences: mocks.saveUserPreferences,
});
});

it('returns empty schools when user has no schools', () => {
mocks.useEdificeClient.mockReturnValue({
userDescription: { schools: null },
});

const { result } = renderHook(() => useUserSchools());

expect(result.current.schools).toEqual([]);
expect(result.current.selectedSchool).toBeUndefined();
});

it('selects preferred school when preference exists', async () => {
const userPref = { schoolId: 's2' };
mocks.lookup.mockReturnValue({ userPref });

const { result } = renderHook(() => useUserSchools());

await waitFor(() => {
expect(result.current.selectedSchool?.id).toBe('s2');
});

expect(mocks.lookup).toHaveBeenCalledWith('SCHOOL');
});

it('falls back to first school when preferred school is missing', async () => {
const userPref = { schoolId: 'missing-school' };
mocks.lookup.mockReturnValue({ userPref });

const { result } = renderHook(() => useUserSchools());

await waitFor(() => {
expect(result.current.selectedSchool?.id).toBe('s1');
});
});

it('keeps selectedSchool undefined when no user preference exists', async () => {
mocks.lookup.mockReturnValue(undefined);

const { result } = renderHook(() => useUserSchools());

await waitFor(() => {
expect(result.current.selectedSchool).toBeUndefined();
});
});

it('updates selected school and saves preference on change when userPref exists', async () => {
const userPref = { schoolId: 's1' };
mocks.lookup.mockReturnValue({ userPref });

const { result } = renderHook(() => useUserSchools());

await waitFor(() => {
expect(result.current.selectedSchool?.id).toBe('s1');
});

act(() => {
result.current.handleSelectedSchoolChange(schools[1] as any);
});

expect(result.current.selectedSchool?.id).toBe('s2');
expect(userPref.schoolId).toBe('s2');
expect(mocks.saveUserPreferences).toHaveBeenCalledTimes(1);
});

it('updates selected school but does not save when no userPref exists', () => {
mocks.lookup.mockReturnValue(undefined);

const { result } = renderHook(() => useUserSchools());

act(() => {
result.current.handleSelectedSchoolChange(schools[0] as any);
});

expect(result.current.selectedSchool?.id).toBe('s1');
expect(mocks.saveUserPreferences).not.toHaveBeenCalled();
});
});
Loading