From c80232b306a5a8f19ee53c35a48afa960ce78f4f Mon Sep 17 00:00:00 2001 From: Xavier Carron <33637571+xav-car@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:16:13 +0100 Subject: [PATCH 1/4] refactor(orga): change sidebar to gjs component --- orga/app/components/layout/sidebar.gjs | 164 +++++++++++++++++++++++++ orga/app/components/layout/sidebar.hbs | 77 ------------ orga/app/components/layout/sidebar.js | 78 ------------ 3 files changed, 164 insertions(+), 155 deletions(-) create mode 100644 orga/app/components/layout/sidebar.gjs delete mode 100644 orga/app/components/layout/sidebar.hbs delete mode 100644 orga/app/components/layout/sidebar.js diff --git a/orga/app/components/layout/sidebar.gjs b/orga/app/components/layout/sidebar.gjs new file mode 100644 index 00000000000..51ccda806a8 --- /dev/null +++ b/orga/app/components/layout/sidebar.gjs @@ -0,0 +1,164 @@ +import PixNavigation from '@1024pix/pix-ui/components/pix-navigation'; +import PixNavigationButton from '@1024pix/pix-ui/components/pix-navigation-button'; +import PixNavigationSeparator from '@1024pix/pix-ui/components/pix-navigation-separator'; +import { LinkTo } from '@ember/routing'; +import { service } from '@ember/service'; +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { t } from 'ember-intl'; + +import OrganizationPlacesOrCreditInfo from './organization-places-or-credit-info'; +import SchoolSessionManagement from './school-session-management'; +import UserLoggedMenu from './user-logged-menu'; + +export default class SidebarMenu extends Component { + @service currentUser; + @service url; + + @tracked canShowCredit; + + handleCanShowCredit = (value) => { + this.canShowCredit = value; + }; + + get redirectionRoute() { + if (this.shouldDisplayMissionsEntry) { + return 'authenticated.missions'; + } else { + return 'authenticated.campaigns'; + } + } + + get documentationUrl() { + return this.currentUser.organization.documentationUrl; + } + + get shouldDisplayCertificationsEntry() { + return this.currentUser.isAdminInOrganization && this.currentUser.isSCOManagingStudents; + } + + get shouldDisplayAttestationsEntry() { + return this.currentUser.canAccessAttestationsPage; + } + + get shouldDisplayPlacesEntry() { + return this.currentUser.canAccessPlacesPage; + } + + get shouldDisplayMissionsEntry() { + return this.currentUser.canAccessMissionsPage; + } + + get shouldDisplayCampaignsEntry() { + return this.currentUser.canAccessCampaignsPage; + } + + get shouldDisplayStatisticsEntry() { + return this.currentUser.canAccessStatisticsPage; + } + + get shouldDisplaySeparator() { + return this.shouldDisplayMissionsEntry || this.shouldDisplayPlacesEntry || this.canShowCredit; + } + + get organizationLearnersList() { + if (this.currentUser.isSCOManagingStudents) { + return { + route: 'authenticated.sco-organization-participants', + label: 'navigation.main.sco-organization-participants', + }; + } else if (this.currentUser.isSUPManagingStudents) { + return { + route: 'authenticated.sup-organization-participants', + label: 'navigation.main.sup-organization-participants', + }; + } else if (this.currentUser.canAccessMissionsPage) { + return { + route: 'authenticated.organization-participants', + label: 'navigation.main.sco-organization-participants', + }; + } else { + return { + route: 'authenticated.organization-participants', + label: 'navigation.main.organization-participants', + }; + } + } + + +} diff --git a/orga/app/components/layout/sidebar.hbs b/orga/app/components/layout/sidebar.hbs deleted file mode 100644 index 271dc13a21a..00000000000 --- a/orga/app/components/layout/sidebar.hbs +++ /dev/null @@ -1,77 +0,0 @@ - - <:brand> - - - - - <:navElements> - {{#if this.shouldDisplayCampaignsEntry}} - - {{t "navigation.main.campaigns"}} - {{/if}} - - {{#if this.shouldDisplayCertificationsEntry}} - - {{t "navigation.main.certifications"}} - {{/if}} - - {{#if this.shouldDisplayAttestationsEntry}} - - {{t "navigation.main.attestations"}} - {{/if}} - - {{#if this.shouldDisplayMissionsEntry}} - - {{t "navigation.main.missions"}} - - {{/if}} - - - {{t this.organizationLearnersList.label}} - - - - {{t "navigation.main.team"}} - - - {{#if this.shouldDisplayStatisticsEntry}} - - {{t "navigation.main.statistics"}} - - {{/if}} - - {{#if this.shouldDisplayPlacesEntry}} - - {{t "navigation.main.places"}} - - {{/if}} - - {{#if this.documentationUrl}} - - {{t "navigation.main.documentation"}} - - {{/if}} - - {{#if this.shouldDisplayMissionsEntry}} - - {{t "navigation.main.support"}} - - {{/if}} - - <:footer> - - - {{#if this.shouldDisplaySeparator}} - - {{/if}} - - - \ No newline at end of file diff --git a/orga/app/components/layout/sidebar.js b/orga/app/components/layout/sidebar.js deleted file mode 100644 index b840065fc7b..00000000000 --- a/orga/app/components/layout/sidebar.js +++ /dev/null @@ -1,78 +0,0 @@ -import { service } from '@ember/service'; -import Component from '@glimmer/component'; -import { tracked } from '@glimmer/tracking'; - -export default class SidebarMenu extends Component { - @service currentUser; - @service url; - - @tracked canShowCredit; - - handleCanShowCredit = (value) => { - this.canShowCredit = value; - }; - - get redirectionRoute() { - if (this.shouldDisplayMissionsEntry) { - return 'authenticated.missions'; - } else { - return 'authenticated.campaigns'; - } - } - - get documentationUrl() { - return this.currentUser.organization.documentationUrl; - } - - get shouldDisplayCertificationsEntry() { - return this.currentUser.isAdminInOrganization && this.currentUser.isSCOManagingStudents; - } - - get shouldDisplayAttestationsEntry() { - return this.currentUser.canAccessAttestationsPage; - } - - get shouldDisplayPlacesEntry() { - return this.currentUser.canAccessPlacesPage; - } - - get shouldDisplayMissionsEntry() { - return this.currentUser.canAccessMissionsPage; - } - - get shouldDisplayCampaignsEntry() { - return this.currentUser.canAccessCampaignsPage; - } - - get shouldDisplayStatisticsEntry() { - return this.currentUser.canAccessStatisticsPage; - } - - get shouldDisplaySeparator() { - return this.shouldDisplayMissionsEntry || this.shouldDisplayPlacesEntry || this.canShowCredit; - } - - get organizationLearnersList() { - if (this.currentUser.isSCOManagingStudents) { - return { - route: 'authenticated.sco-organization-participants', - label: 'navigation.main.sco-organization-participants', - }; - } else if (this.currentUser.isSUPManagingStudents) { - return { - route: 'authenticated.sup-organization-participants', - label: 'navigation.main.sup-organization-participants', - }; - } else if (this.currentUser.canAccessMissionsPage) { - return { - route: 'authenticated.organization-participants', - label: 'navigation.main.sco-organization-participants', - }; - } else { - return { - route: 'authenticated.organization-participants', - label: 'navigation.main.organization-participants', - }; - } - } -} From 764b7a21fb9425a4ebd2429dbc7f5db483f7f19f Mon Sep 17 00:00:00 2001 From: Xavier Carron <33637571+xav-car@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:16:44 +0100 Subject: [PATCH 2/4] refactor(orga): change user logged menu to gjs component --- ...er-logged-menu.js => user-logged-menu.gjs} | 25 +++++++++++++++++++ .../components/layout/user-logged-menu.hbs | 17 ------------- 2 files changed, 25 insertions(+), 17 deletions(-) rename orga/app/components/layout/{user-logged-menu.js => user-logged-menu.gjs} (67%) delete mode 100644 orga/app/components/layout/user-logged-menu.hbs diff --git a/orga/app/components/layout/user-logged-menu.js b/orga/app/components/layout/user-logged-menu.gjs similarity index 67% rename from orga/app/components/layout/user-logged-menu.js rename to orga/app/components/layout/user-logged-menu.gjs index b371e362710..71fd66be5a4 100644 --- a/orga/app/components/layout/user-logged-menu.js +++ b/orga/app/components/layout/user-logged-menu.gjs @@ -1,6 +1,9 @@ import { action } from '@ember/object'; import { service } from '@ember/service'; import Component from '@glimmer/component'; +import PixStructureSwitcher from '@1024pix/pix-ui/components/pix-structure-switcher'; +import PixButtonLink from '@1024pix/pix-ui/components/pix-button-link'; +import { t } from 'ember-intl'; export default class UserLoggedMenu extends Component { @service currentUser; @@ -51,4 +54,26 @@ export default class UserLoggedMenu extends Component { await this.currentUser.load(); this.args.onChangeOrganization(); } + + } diff --git a/orga/app/components/layout/user-logged-menu.hbs b/orga/app/components/layout/user-logged-menu.hbs deleted file mode 100644 index ed421ecd16a..00000000000 --- a/orga/app/components/layout/user-logged-menu.hbs +++ /dev/null @@ -1,17 +0,0 @@ -

- - {{this.currentUser.prescriber.firstName}} - {{this.currentUser.prescriber.lastName}} - -
- {{this.organizationNameAndExternalId}} -

-{{#if this.belongsToSeveralOrganizations}} - -{{/if}} -{{t "navigation.user-logged-menu.logout"}} \ No newline at end of file From eba907aa8ef35917396576f21202a76bac58a83d Mon Sep 17 00:00:00 2001 From: Xavier Carron <33637571+xav-car@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:22:25 +0100 Subject: [PATCH 3/4] fix(api): add seed without extarnalId --- api/db/seeds/data/common/organization-builder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/db/seeds/data/common/organization-builder.js b/api/db/seeds/data/common/organization-builder.js index a938d366fa9..f14a87b537b 100644 --- a/api/db/seeds/data/common/organization-builder.js +++ b/api/db/seeds/data/common/organization-builder.js @@ -96,7 +96,7 @@ async function _createProOrganization(databaseBuilder) { type: 'PRO', name: 'PRO Classic', isManagingStudents: false, - externalId: 'PRO_NOT_MANAGING', + externalId: null, adminIds: [USER_ID_ADMIN_ORGANIZATION], memberIds: [USER_ID_MEMBER_ORGANIZATION], features: [ From 2827ab71dc7d31d71266e6a8faec61e343d79b9d Mon Sep 17 00:00:00 2001 From: Xavier Carron <33637571+xav-car@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:46:43 +0100 Subject: [PATCH 4/4] fix(orga): add test on user logged menu without externalId --- .../components/layout/user-logged-menu.gjs | 20 ++++++--- .../layout/user-logged-menu-test.js | 4 +- .../unit/components/user-logged-menu-test.js | 41 ------------------- 3 files changed, 16 insertions(+), 49 deletions(-) delete mode 100644 orga/tests/unit/components/user-logged-menu-test.js diff --git a/orga/app/components/layout/user-logged-menu.gjs b/orga/app/components/layout/user-logged-menu.gjs index 71fd66be5a4..e47a750e47a 100644 --- a/orga/app/components/layout/user-logged-menu.gjs +++ b/orga/app/components/layout/user-logged-menu.gjs @@ -1,8 +1,8 @@ +import PixButtonLink from '@1024pix/pix-ui/components/pix-button-link'; +import PixStructureSwitcher from '@1024pix/pix-ui/components/pix-structure-switcher'; import { action } from '@ember/object'; import { service } from '@ember/service'; import Component from '@glimmer/component'; -import PixStructureSwitcher from '@1024pix/pix-ui/components/pix-structure-switcher'; -import PixButtonLink from '@1024pix/pix-ui/components/pix-button-link'; import { t } from 'ember-intl'; export default class UserLoggedMenu extends Component { @@ -25,10 +25,18 @@ export default class UserLoggedMenu extends Component { } return memberships .slice() - .map((membership) => ({ - label: `${membership.organization.get('name')} (${membership.organization.get('externalId')})`, - value: membership.organization.get('id'), - })) + .map((membership) => { + let label = `${membership.organization.get('name')}`; + + if (membership.organization.get('externalId')) { + label = label.concat(` (${membership.organization.get('externalId')})`); + } + + return { + label, + value: membership.organization.get('id'), + }; + }) .sort((a, b) => a.label.localeCompare(b.label)); } diff --git a/orga/tests/integration/components/layout/user-logged-menu-test.js b/orga/tests/integration/components/layout/user-logged-menu-test.js index 34dae84780e..91ec9fa4dd9 100644 --- a/orga/tests/integration/components/layout/user-logged-menu-test.js +++ b/orga/tests/integration/components/layout/user-logged-menu-test.js @@ -24,7 +24,7 @@ module('Integration | Component | Layout::UserLoggedMenu', function () { }), }); organization2 = Object.create({ id: '2', name: 'Organization 2', externalId: 'EXT2' }); - organization3 = Object.create({ id: '3', name: 'Organization 3', externalId: 'EXT3' }); + organization3 = Object.create({ id: '3', name: 'Organization 3' }); loadStub = sinon.stub(); class CurrentUserStub extends Service { @@ -75,7 +75,7 @@ module('Integration | Component | Layout::UserLoggedMenu', function () { // then assert.ok(await screen.findByRole('option', { name: `${organization2.name} (${organization2.externalId})` })); - assert.ok(await screen.findByRole('option', { name: `${organization3.name} (${organization3.externalId})` })); + assert.ok(await screen.findByRole('option', { name: `${organization3.name}` })); }); test('should redirect to authenticated route before reload the current user', async function (assert) { diff --git a/orga/tests/unit/components/user-logged-menu-test.js b/orga/tests/unit/components/user-logged-menu-test.js deleted file mode 100644 index 6f86f24bfe5..00000000000 --- a/orga/tests/unit/components/user-logged-menu-test.js +++ /dev/null @@ -1,41 +0,0 @@ -import { setupTest } from 'ember-qunit'; -import { module, test } from 'qunit'; - -import createGlimmerComponent from '../../helpers/create-glimmer-component'; - -module('Unit | Component | user-logged-menu', (hooks) => { - setupTest(hooks); - - let component; - - hooks.beforeEach(function () { - component = createGlimmerComponent('component:layout/user-logged-menu'); - }); - - module('organizationNameAndExternalId', () => { - test('should return the organization name if the externalId is not defined', function (assert) { - // given - const expectedOrganizationName = 'expectedOrganizationName'; - const currentUser = { organization: { name: expectedOrganizationName } }; - component.currentUser = currentUser; - - // when - const computedOrganizationName = component.organizationNameAndExternalId; - // then - assert.strictEqual(computedOrganizationName, expectedOrganizationName); - }); - - test('should return the organization name and externalId if the externalId is defined', function (assert) { - // given - const expectedOrganizationName = 'expectedOrganizationName'; - const expectedExternalId = 'expectedExternalId'; - const currentUser = { organization: { name: expectedOrganizationName, externalId: expectedExternalId } }; - component.currentUser = currentUser; - - // when - const computedOrganizationName = component.organizationNameAndExternalId; - // then - assert.strictEqual(computedOrganizationName, `${expectedOrganizationName} (${expectedExternalId})`); - }); - }); -});