Skip to content

Commit

Permalink
Merge pull request #8602 from ever-co/fix/#8583-objective-creation
Browse files Browse the repository at this point in the history
[Fix] Issues in the Objective Screen for the Employee and Admin users
  • Loading branch information
rahul-rocket authored Dec 21, 2024
2 parents e3e1550 + 943d792 commit 34f4bda
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,8 @@ export class GoalTemplateSelectComponent extends TranslationBaseComponent implem
}

async createGoal() {
if (!!this.selectedGoalTemplate && !!this.form.valid) {
if (!!this.selectedGoalTemplate && this.form.valid) {
const formValue = this.form.value;
delete formValue.level;

const { id: organizationId, tenantId } = this.organization;
const goal = {
Expand All @@ -150,59 +149,90 @@ export class GoalTemplateSelectComponent extends TranslationBaseComponent implem
};
goal[
this.form.value.level === GoalLevelEnum.EMPLOYEE
? 'ownerEmployee'
? 'ownerEmployeeId'
: this.form.value.level === GoalLevelEnum.TEAM
? 'ownerTeam'
: 'organization'
] = this.form.value.owner;
delete goal.owner;
delete goal.keyResults;
const goalCreated = await this.goalService.createGoal(goal);
if (goalCreated) {
const kpiCreatedPromise = [];
this.selectedGoalTemplate.keyResults.forEach(async (keyResult) => {
? 'ownerTeamId'
: 'organizationId'
] = this.form.value.ownerId;

const { owner, keyResults, ...goalData } = goal;
const newGoal = {
...goalData,
organizationId,
tenantId
};

try {
// Create the goal
const goalCreated = await this.goalService.createGoal(newGoal);
if (!goalCreated) {
this.toastrService.error(this.getTranslation('TOASTR.MESSAGE.GOAL_CREATION_FAILED'));
return;
}

// Create associated KPIs
const kpiPromises = this.selectedGoalTemplate.keyResults.map(async (keyResult) => {
if (keyResult.type === KeyResultTypeEnum.KPI) {
const kpiData = {
...keyResult.kpi,
organization: this.orgId
};
await this.goalSettingsService.createKPI(kpiData).then((res) => {
if (res) {
keyResult.kpiId = res.id;
}
kpiCreatedPromise.push(keyResult);
});
try {
const res = await this.goalSettingsService.createKPI(kpiData);
keyResult.kpiId = res?.id;
this.toastrService.success(
this.getTranslation('TOASTR.MESSAGE.KPI_CREATED', { name: keyResult.name })
);
} catch (error) {
this.toastrService.warning(
this.getTranslation('TOASTR.MESSAGE.KPI_CREATION_FAILED', { name: keyResult.name })
);
}
return keyResult;
}
return keyResult;
});
Promise.all(kpiCreatedPromise).then(async () => {
const keyResults = this.selectedGoalTemplate.keyResults.map((keyResult) => {
delete keyResult.kpi;
delete keyResult.goalId;
return {
...keyResult,
goalId: goalCreated.id,
description: ' ',
progress: 0,
update: keyResult.initialValue,
ownerId: this.employees[0].id,
organizationId,
tenantId,
status: 'none',
weight: KeyResultWeightEnum.DEFAULT
};
});

await this.keyResultService.createBulkKeyResult(keyResults).then((res) => {
if (res) {
this.toastrService.success(this.getTranslation('TOASTR.MESSAGE.KEY_RESULTS_CREATED'));
this.closeDialog('done');
}
});
const KEY_RESULT_DEFAULTS = {
description: ' ',
progress: 0,
status: 'none',
weight: KeyResultWeightEnum.DEFAULT
};

// Wait for all KPI promises to complete
const updatedKeyResults = await Promise.all(kpiPromises);

// Prepare Key Results for bulk creation
const keyResults = updatedKeyResults.map((keyResult) => {
const { kpi, goalId, ...keyResultData } = keyResult;
return {
...keyResultData,
...KEY_RESULT_DEFAULTS,
goalId: goalCreated.id,
update: keyResult.initialValue,
ownerId: this.form.value.ownerId,
organizationId,
tenantId
};
});

// Create Key Results in bulk
const keyResultsCreated = await this.keyResultService.createBulkKeyResult(keyResults);
if (keyResultsCreated) {
this.toastrService.success(this.getTranslation('TOASTR.MESSAGE.KEY_RESULTS_CREATED'));
this.closeDialog('done');
}
} catch (error) {
console.error('Goal creation failed:', error);
this.toastrService.error(
this.getTranslation('TOASTR.MESSAGE.GOAL_CREATION_ERROR', {
error: error.message || 'Unknown error'
})
);
}
}
}

previousStep() {
this.stepper.previous();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
<div
[formGroup]="parentFormGroup"
*ngIf="alignedGoal ? !!parentFormGroup.value.assignAsObjective : true"
>
<div [formGroup]="parentFormGroup" *ngIf="alignedGoal ? !!parentFormGroup.value.assignAsObjective : true">
<div [ngClass]="{ row: enableHelperText }">
<div
[ngClass]="{ 'col-md-7': enableHelperText }"
(mouseenter)="
enableHelperText ? (helperText = 'objective-level') : null
"
(mouseenter)="enableHelperText ? (helperText = 'objective-level') : null"
(mouseleave)="enableHelperText ? (helperText = '') : null"
>
<label for="objective-level" class="label mt-3">
Expand All @@ -17,32 +12,20 @@
id="objective-level"
formControlName="level"
[placeholder]="'GOALS_PAGE.FORM.PLACEHOLDERS.LEVEL' | translate"
(selectedChange)="$event === goalLevelEnum.TEAM ? getTeams() : null"
(selectedChange)="onLevelChange($event)"
fullWidth
>
<nb-option
*ngFor="let level of goalLevelEnum | keyvalue"
[hidden]="
hideOrg
? level.value === goalLevelEnum.ORGANIZATION
: false || hideEmployee
? level.value === goalLevelEnum.EMPLOYEE
: false || hideTeam
? level.value === goalLevelEnum.TEAM
: false
"
[hidden]="isLevelHidden(level.value)"
[value]="level.value"
>{{
'GOALS_PAGE.LEVELS.' + level.key | translate
}}</nb-option
>
{{ 'GOALS_PAGE.LEVELS.' + level.key | translate }}
</nb-option>
</nb-select>
</div>
<div class="col-md-5 position-relative helper-text">
<div
class="mt-3 position-absolute"
*ngIf="helperText == 'objective-level'"
>
<div class="mt-3 position-absolute" *ngIf="helperText == 'objective-level'">
<p>
{{ 'GOALS_PAGE.HELPER_TEXT.OBJECTIVE_LEVEL' | translate }}
</p>
Expand All @@ -54,9 +37,7 @@
<div
*ngIf="alignedGoal ? !!parentFormGroup.value.level : true"
[ngClass]="{ 'col-md-7': enableHelperText }"
(mouseenter)="
enableHelperText ? (helperText = 'objective-owner') : null
"
(mouseenter)="enableHelperText ? (helperText = 'objective-owner') : null"
(mouseleave)="enableHelperText ? (helperText = '') : null"
>
<label for="objective-owner" class="label mt-3">
Expand All @@ -75,10 +56,7 @@
></ga-employee-multi-select>
</div>
<div class="col-md-5 position-relative helper-text">
<div
class="mt-3 position-absolute"
*ngIf="helperText == 'objective-owner'"
>
<div class="mt-3 position-absolute" *ngIf="helperText == 'objective-owner'">
<p>
{{ 'GOALS_PAGE.HELPER_TEXT.OBJECTIVE_OWNER' | translate }}
</p>
Expand All @@ -91,9 +69,7 @@
*ngIf="parentFormGroup.value.level === goalLevelEnum.TEAM"
(selectedChange)="selectEmployee($event, 'owner')"
[ngClass]="{ 'col-md-7': enableHelperText }"
(mouseenter)="
enableHelperText ? (helperText = 'objective-owner') : null
"
(mouseenter)="enableHelperText ? (helperText = 'objective-owner') : null"
(mouseleave)="enableHelperText ? (helperText = '') : null"
>
<nb-select
Expand All @@ -113,9 +89,7 @@
<div
*ngIf="parentFormGroup?.value.level === goalLevelEnum.ORGANIZATION"
[ngClass]="{ 'col-md-7': enableHelperText }"
(mouseenter)="
enableHelperText ? (helperText = 'objective-owner') : null
"
(mouseenter)="enableHelperText ? (helperText = 'objective-owner') : null"
(mouseleave)="enableHelperText ? (helperText = '') : null"
>
<nb-select
Expand All @@ -136,9 +110,7 @@
<div *ngIf="!alignedGoal" [ngClass]="{ row: enableHelperText }">
<div
[ngClass]="{ 'col-md-7': enableHelperText }"
(mouseenter)="
enableHelperText ? (helperText = 'objective-lead') : null
"
(mouseenter)="enableHelperText ? (helperText = 'objective-lead') : null"
(mouseleave)="enableHelperText ? (helperText = '') : null"
>
<label for="objective-lead" class="label mt-3">
Expand All @@ -151,17 +123,12 @@
[label]="false"
(selectedChange)="selectEmployee($event, 'lead')"
id="objective-lead"
placeholder="{{
'GOALS_PAGE.FORM.LABELS.LEAD_OPTIONAL' | translate
}}"
placeholder="{{ 'GOALS_PAGE.FORM.LABELS.LEAD_OPTIONAL' | translate }}"
class="header-selector employee-selector"
></ga-employee-multi-select>
</div>
<div class="col-md-5 position-relative helper-text">
<div
class="mt-3 position-absolute"
*ngIf="helperText == 'objective-lead'"
>
<div class="mt-3 position-absolute" *ngIf="helperText == 'objective-lead'">
<p>
{{ 'GOALS_PAGE.HELPER_TEXT.OBJECTIVE_LEAD' | translate }}
</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,20 @@ export class GoalLevelSelectComponent {
}
}
}

onLevelChange(selectedLevel: GoalLevelEnum) {
this.parentFormGroup.patchValue({ level: selectedLevel });

if (selectedLevel === this.goalLevelEnum.TEAM) {
this.getTeams();
}
}

isLevelHidden(level: GoalLevelEnum): boolean {
return (
(this.hideOrg && level === this.goalLevelEnum.ORGANIZATION) ||
(this.hideEmployee && level === this.goalLevelEnum.EMPLOYEE) ||
(this.hideTeam && level === this.goalLevelEnum.TEAM)
);
}
}

0 comments on commit 34f4bda

Please sign in to comment.