Skip to content

Commit

Permalink
Merge pull request novuhq#5237 from novuhq/nv-3519-translations-chang…
Browse files Browse the repository at this point in the history
…es-not-showing-details

fix: show changes details for translations
  • Loading branch information
ainouzgali authored Feb 29, 2024
2 parents df51622 + a60cb9c commit 45e8cae
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .source
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
import { ChangeEntityTypeEnum } from '@novu/shared';
import { ChangesResponseDto } from '../../dtos/change-response.dto';
import { GetChangesCommand } from './get-changes.command';
import { ApiException } from '../../../shared/exceptions/api.exception';
import { ModuleRef } from '@nestjs/core';

interface IViewEntity {
templateName: string;
Expand All @@ -32,7 +34,8 @@ export class GetChanges {
private messageTemplateRepository: MessageTemplateRepository,
private notificationGroupRepository: NotificationGroupRepository,
private feedRepository: FeedRepository,
private layoutRepository: LayoutRepository
private layoutRepository: LayoutRepository,
protected moduleRef: ModuleRef
) {}

async execute(command: GetChangesCommand): Promise<ChangesResponseDto> {
Expand Down Expand Up @@ -65,6 +68,12 @@ export class GetChanges {
if (change.type === ChangeEntityTypeEnum.DEFAULT_LAYOUT) {
item = await this.getTemplateDataForDefaultLayout(change._entityId, command.environmentId);
}
if (change.type === ChangeEntityTypeEnum.TRANSLATION) {
item = await this.getTemplateDataForTranslation(change._entityId, command.environmentId);
}
if (change.type === ChangeEntityTypeEnum.TRANSLATION_GROUP) {
item = await this.getTemplateDataForTranslationGroup(change._entityId, command.environmentId);
}

list.push({
...change,
Expand Down Expand Up @@ -133,6 +142,54 @@ export class GetChanges {
};
}

private async getTemplateDataForTranslationGroup(
entityId: string,
environmentId: string
): Promise<IViewEntity | Record<string, unknown>> {
try {
if (process.env.NOVU_ENTERPRISE === 'true' || process.env.CI_EE_TEST === 'true') {
if (!require('@novu/ee-translation')?.TranslationsService) {
throw new ApiException('Translation module is not loaded');
}
const service = this.moduleRef.get(require('@novu/ee-translation')?.TranslationsService, { strict: false });
const { name, identifier } = await service.getTranslationGroupData(environmentId, entityId);

return {
templateId: identifier,
templateName: name,
};
}
} catch (e) {
Logger.error(e, `Unexpected error while importing enterprise modules`, 'TranslationsService');
}

return {};
}

private async getTemplateDataForTranslation(
entityId: string,
environmentId: string
): Promise<IViewEntity | Record<string, unknown>> {
try {
if (process.env.NOVU_ENTERPRISE === 'true' || process.env.CI_EE_TEST === 'true') {
if (!require('@novu/ee-translation')?.TranslationsService) {
throw new ApiException('Translation module is not loaded');
}
const service = this.moduleRef.get(require('@novu/ee-translation')?.TranslationsService, { strict: false });
const { name, group } = await service.getTranslationData(environmentId, entityId);

return {
templateName: name,
translationGroup: group,
};
}
} catch (e) {
Logger.error(e, `Unexpected error while importing enterprise modules`, 'TranslationsService');
}

return {};
}

private async getTemplateDataForNotificationGroup(
entityId: string,
environmentId: string
Expand Down
3 changes: 2 additions & 1 deletion apps/web/src/pages/changes/components/ChangesTableLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const ChangesTable = ({
Cell: withCellLoading(
({
row: {
original: { type, templateName, messageType, previousDefaultLayout },
original: { type, templateName, messageType, previousDefaultLayout, translationGroup },
},
}) => (
<div data-test-id="change-type">
Expand Down Expand Up @@ -88,6 +88,7 @@ export const ChangesTable = ({
</Text>
)}
<Text data-test-id="change-content" rows={1} mt={5}>
{translationGroup ? `${translationGroup}, ` : null}
{templateName}
{messageType ? `, ${messageType}` : null}
</Text>
Expand Down

0 comments on commit 45e8cae

Please sign in to comment.