Skip to content

Commit

Permalink
Merge branch 'main' into 12110-dashboard-list-item-spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
mnigh authored Jan 10, 2025
2 parents c87cf97 + 10a6f7a commit 90ccdea
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 31 deletions.
17 changes: 16 additions & 1 deletion api/app/Generators/ApplicationDocGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,22 @@ public function generate(): self
}

if (isset($snapshot['experiences'])) {
$experiences = Experience::hydrateSnapshot($snapshot['experiences']);
$snapshotExperiences = $snapshot['experiences'];

// the snapshot stores the department and classification models connected by relation
// to render with GeneratesUserDoc, map the model to a string with the appropriate property name
foreach ($snapshotExperiences as &$experience) {
if ($experience['__typename'] === 'WorkExperience') {
if (isset($experience['department'])) {
$experience['departmentId'] = $experience['department']['id'];
}
if (isset($experience['classification'])) {
$experience['classificationId'] = $experience['classification']['id'];
}
}
}

$experiences = Experience::hydrateSnapshot($snapshotExperiences);
$this->experiences($section, collect($experiences), false, 2);
}

Expand Down
21 changes: 20 additions & 1 deletion api/app/Models/WorkExperience.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\Models;

use App\Enums\CafForce;
use App\Enums\EmploymentCategory;
use App\Models\Scopes\MatchExperienceType;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand Down Expand Up @@ -83,7 +85,24 @@ class WorkExperience extends Experience

public function getTitle(?string $lang = 'en'): string
{
return sprintf('%s %s %s', $this->role, Lang::get('common.at', [], $lang), $this->organization);
if ($this->employment_category === EmploymentCategory::EXTERNAL_ORGANIZATION->name) {
return sprintf('%s %s %s', $this->role, Lang::get('common.with', [], $lang), $this->organization);
}

if ($this->employment_category === EmploymentCategory::GOVERNMENT_OF_CANADA->name) {
/** @var Department | null $department */
$department = $this->department_id ? Department::find($this->department_id) : null;

return sprintf('%s %s %s', $this->role, Lang::get('common.with', [], $lang), $department ? $department->name[$lang] : Lang::get('common.not_found', [], $lang));
}

if ($this->employment_category === EmploymentCategory::CANADIAN_ARMED_FORCES->name) {
$caf_force = $this->caf_force ? CafForce::localizedString($this->caf_force)[$lang] : Lang::get('common.not_found', [], $lang);

return sprintf('%s %s %s', $this->role, Lang::get('common.with', [], $lang), $caf_force);
}

return sprintf('%s %s %s', $this->role, Lang::get('common.with', [], $lang), $this->organization);
}

// extends dateRange, check if the end date is in the future and append a message if needed
Expand Down
6 changes: 3 additions & 3 deletions api/app/Traits/Generator/GeneratesUserDoc.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function experience(Section $section, AwardExperience|CommunityExperience
sprintf(
'%s %s %s',
$experience->role,
Lang::get('common.at', [], $this->lang),
Lang::get('common.with', [], $this->lang),
$this->localizeEnum($experience->caf_force,
CafForce::class),
),
Expand All @@ -362,12 +362,12 @@ public function experience(Section $section, AwardExperience|CommunityExperience
);
} elseif ($experience->employment_category === EmploymentCategory::GOVERNMENT_OF_CANADA->name) {
/** @var Department | null $department */
$department = Department::find($experience->department_id);
$department = $experience->department_id ? Department::find($experience->department_id) : null;
$section->addTitle(
sprintf(
'%s %s %s',
$experience->role,
Lang::get('common.at', [], $this->lang),
Lang::get('common.with', [], $this->lang),
$department ? $department->name[$this->lang] : Lang::get('common.not_found', [], $this->lang),
),
$headingRank
Expand Down
1 change: 1 addition & 0 deletions api/lang/en/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'status' => 'Status',
'present' => 'Present',
'at' => 'at',
'with' => 'with',
'not_provided' => 'Not provided',
'not_sure' => 'Not sure',
'expected_end_date' => '(Expected end date)',
Expand Down
1 change: 1 addition & 0 deletions api/lang/fr/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'status' => 'Statut',
'present' => 'Aujourd’hui',
'at' => 'à',
'with' => 'à',
'not_provided' => 'Renseignements manquants',
'not_sure' => 'Pas certain',
'expected_end_date' => '(Date de fin prévue)',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ const GovFields = ({ labels }: SubExperienceFormProps) => {
label={labels.classificationGroup}
name="classificationGroup"
nullSelection={intl.formatMessage(
uiMessages.nullSelectionOptionLevel,
uiMessages.nullSelectionOptionGroup,
)}
rules={{
required: intl.formatMessage(errorMessages.required),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useIntl, defineMessage, MessageDescriptor } from "react-intl";
import { useQuery } from "urql";
import { useFormContext, useWatch } from "react-hook-form";
import { useEffect } from "react";
import { useEffect, useRef } from "react";

import {
FieldLabels,
Expand Down Expand Up @@ -102,6 +102,9 @@ const WorkFields = ({

const { resetField, formState } = useFormContext<WorkFormValues>();

const prevEmploymentCategory = useRef<EmploymentCategory | null | undefined>(
formState.defaultValues?.employmentCategory,
);
const watchEmploymentCategory = useWatch<{
employmentCategory: EmploymentCategory;
}>({
Expand All @@ -128,7 +131,7 @@ const WorkFields = ({
resetField(name, { keepDirty: false, defaultValue: null });
};

if (formState.dirtyFields.employmentCategory) {
if (prevEmploymentCategory.current !== watchEmploymentCategory) {
resetDirtyField("team"); // both external and goc

// external fields
Expand Down Expand Up @@ -156,7 +159,9 @@ const WorkFields = ({
resetDirtyField("currentRole");
resetDirtyField("endDate");
}
}, [formState.dirtyFields, watchEmploymentCategory, resetField]);

prevEmploymentCategory.current = watchEmploymentCategory;
}, [watchEmploymentCategory, resetField]);

return (
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,9 @@ const FormFields = ({
id="currentClassificationGroup"
label={labels.currentClassificationGroup}
name="currentClassificationGroup"
nullSelection={intl.formatMessage({
defaultMessage: "Select a group",
id: "9Upe1V",
description: "Null selection for form.",
})}
nullSelection={intl.formatMessage(
uiMessages.nullSelectionOptionGroup,
)}
rules={{
required: intl.formatMessage(errorMessages.required),
}}
Expand Down
4 changes: 0 additions & 4 deletions apps/web/src/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -2263,10 +2263,6 @@
"defaultMessage": "Organisation",
"description": "Label displayed on Work Experience form for organization input"
},
"9Upe1V": {
"defaultMessage": "Sélectionnez un groupe",
"description": "Null selection for form."
},
"9VPBwR": {
"defaultMessage": "Homme danseur en régalia traditionnelle.",
"description": "Indigenous Apprenticeship lower back image text alternative"
Expand Down
14 changes: 4 additions & 10 deletions apps/web/src/pages/Pools/PoolLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
ThrowNotFound,
useAnnouncer,
} from "@gc-digital-talent/ui";
import { getLocalizedName } from "@gc-digital-talent/i18n";
import {
FragmentType,
PoolLayoutFragment,
Expand Down Expand Up @@ -58,12 +57,9 @@ export const PoolLayout_Fragment = graphql(/* GraphQL */ `
en
fr
}
team {
id
name
displayName {
en
fr
community {
name {
localized
}
}
classification {
Expand Down Expand Up @@ -132,9 +128,7 @@ const PoolHeader = ({ poolQuery }: PoolHeaderProps) => {
});
const currentPage = useCurrentPage<PageNavKeys>(pages);

const subTitle = pool.team
? getLocalizedName(pool.team?.displayName, intl)
: currentPage?.subtitle;
const subTitle = pool.community?.name?.localized ?? currentPage?.subtitle;

const heroTitleValue = heroTitle({ currentPage, intl, pool });
const heroSubtitleValue = heroSubtitle({ currentPage, subTitle });
Expand Down
33 changes: 30 additions & 3 deletions apps/web/src/utils/experienceUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,41 @@ const getWorkExperienceDefaultValues = (
cafForce,
cafRank,
} = experience;

const isIndeterminate =
govEmploymentType?.value === WorkExperienceGovEmployeeType.Indeterminate;
const indeterminateActing =
isIndeterminate && govPositionType?.value === GovPositionType.Acting;
const indeterminateAssignment =
isIndeterminate && govPositionType?.value === GovPositionType.Assignment;
const indeterminateSecondment =
isIndeterminate && govPositionType?.value === GovPositionType.Secondment;

const expectedEndDate =
govEmploymentType?.value === WorkExperienceGovEmployeeType.Student ||
govEmploymentType?.value === WorkExperienceGovEmployeeType.Casual ||
govEmploymentType?.value === WorkExperienceGovEmployeeType.Term ||
indeterminateActing ||
indeterminateAssignment ||
indeterminateSecondment;

let currentRole = false;

if (endDate) {
currentRole = false;
if (expectedEndDate) {
currentRole = endDate >= strToFormDate(new Date().toISOString());
}
} else {
currentRole = true;
}

return {
role,
organization,
team: division,
startDate,
currentRole: endDate
? endDate >= strToFormDate(new Date().toISOString()) // today's date
: true,
currentRole,
endDate,
employmentCategory: employmentCategory?.value,
extSizeOfOrganization: extSizeOfOrganization?.value,
Expand Down
4 changes: 4 additions & 0 deletions packages/i18n/src/lang/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,10 @@
"defaultMessage": "Technologie de l’information",
"description": "Full name of abbreviation for IT"
},
"nICORU": {
"defaultMessage": "Sélectionnez un groupe",
"description": "Null selection og group for select input."
},
"nMX0n8": {
"defaultMessage": "Vous n’avez ajouté aucune expérience de ce type.",
"description": "Message to user when no experiences of that type exist."
Expand Down
5 changes: 5 additions & 0 deletions packages/i18n/src/messages/uiMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ const uiMessages = defineMessages({
id: "xEkbvy",
description: "Null selection of level for select input",
},
nullSelectionOptionGroup: {
defaultMessage: "Select a group",
id: "nICORU",
description: "Null selection og group for select input.",
},
});

export default uiMessages;

0 comments on commit 90ccdea

Please sign in to comment.