Skip to content

Commit

Permalink
Added new columns in alerts table (#2334)
Browse files Browse the repository at this point in the history
* feat: added new columns in alerts table

* Update apps/backoffice-v2/src/domains/alerts/fetchers.ts

Co-authored-by: Omri Levy <61207713+Omri-Levy@users.noreply.github.com>

* feat(lint): lint

* feat: merge fix

---------

Co-authored-by: Omri Levy <61207713+Omri-Levy@users.noreply.github.com>
  • Loading branch information
tomer-shvadron and Omri-Levy committed May 1, 2024
1 parent 6386367 commit 3e7d2f8
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 19 deletions.
Expand Up @@ -34,5 +34,6 @@ export const TextWithNAFallback: TTextWithNAFallback = forwardRef(
);
},
);

// @ts-ignore
TextWithNAFallback.displayName = 'TextWithNAFallback';
6 changes: 5 additions & 1 deletion apps/backoffice-v2/src/domains/alerts/fetchers.ts
Expand Up @@ -76,7 +76,11 @@ export const AlertsListSchema = z.array(
ObjectWithIdSchema.extend({
dataTimestamp: z.string().datetime(),
updatedAt: z.string().datetime(),
subject: ObjectWithIdSchema.extend({ name: z.string() }),
subject: ObjectWithIdSchema.extend({
name: z.string(),
correlationId: z.string(),
type: z.enum(['business', 'counterparty']),
}),
severity: z.enum(AlertSeverities),
label: z.string(),
alertDetails: z.string(),
Expand Down
Expand Up @@ -29,7 +29,7 @@ export const AlertsTable: FunctionComponent<IAlertsTableProps> = ({ data }) => {
{headers.map(header => (
<TableHead
key={header.id}
className={`sticky top-0 z-10 h-[34px] bg-white p-0 text-[14px] font-bold text-[#787981]`}
className={`sticky top-0 z-10 h-[34px] bg-white p-1 text-[14px] font-bold text-[#787981]`}
>
{header.column.id === 'select' && (
<span className={'pe-4'}>
Expand All @@ -38,7 +38,7 @@ export const AlertsTable: FunctionComponent<IAlertsTableProps> = ({ data }) => {
)}
{header.column.id !== 'select' && (
<button
className="flex h-9 flex-row items-center gap-x-2 px-3 text-[#A3A3A3]"
className="flex h-9 flex-row items-center gap-x-2 px-3 text-left text-[#A3A3A3]"
onClick={() => header.column.toggleSorting()}
>
<span>
Expand Down
Expand Up @@ -14,6 +14,8 @@ import { severityToClassName } from '@/pages/TransactionMonitoringAlerts/compone
import { IndeterminateCheckbox } from '@/common/components/atoms/IndeterminateCheckbox/IndeterminateCheckbox';
import { SnakeCase, titleCase } from 'string-ts';
import { toScreamingSnakeCase } from '@/common/utils/to-screaming-snake-case/to-screaming-snake-case';
import { useEllipsesWithTitle } from '@/common/hooks/useEllipsesWithTitle/useEllipsesWithTitle';
import { buttonVariants } from '@/common/components/atoms/Button/Button';

const columnHelper = createColumnHelper<
TAlertsList[number] & {
Expand Down Expand Up @@ -84,6 +86,39 @@ export const columns = [
},
header: 'Subject',
}),
columnHelper.accessor('subject.type', {
cell: info => {
const subjectType = info.getValue();

return (
<TextWithNAFallback className={`max-w-[12ch]`}>{titleCase(subjectType)}</TextWithNAFallback>
);
},
header: 'Subject Type',
}),
columnHelper.accessor('subject.correlationId', {
cell: info => {
// eslint-disable-next-line react-hooks/rules-of-hooks -- ESLint doesn't like `cell` not being `Cell`.
const { ref, styles } = useEllipsesWithTitle<HTMLSpanElement>();
const subjectId = info.getValue();

return (
<div className={`w-[11.8ch]`}>
<TextWithNAFallback
className={buttonVariants({
variant: 'link',
className: '!block cursor-pointer !p-0 text-sm !text-blue-500',
})}
style={styles}
ref={ref}
>
{subjectId}
</TextWithNAFallback>
</div>
);
},
header: 'Subject ID',
}),
columnHelper.accessor('severity', {
cell: info => {
const severity = info.getValue();
Expand All @@ -108,7 +143,7 @@ export const columns = [
cell: info => {
const alertDetails = info.getValue();

return <TextWithNAFallback>{alertDetails}</TextWithNAFallback>;
return <TextWithNAFallback className={`max-w-[40ch]`}>{alertDetails}</TextWithNAFallback>;
},
header: 'Alert Details',
}),
Expand Down
2 changes: 1 addition & 1 deletion services/workflows-service/prisma/data-migrations
Expand Up @@ -107,11 +107,15 @@ export class AlertControllerExternal {
alertDetails: alertDefinition.description,
subject: counterparty.business
? {
type: 'business',
id: counterparty.business.id,
name: counterparty.business.companyName,
correlationId: counterparty.business.correlationId,
}
: {
type: 'counterparty',
id: counterparty.endUser.id,
correlationId: counterparty.endUser.correlationId,
name: `${counterparty.endUser.firstName} ${counterparty.endUser.lastName}`,
},
decision: state,
Expand Down
Expand Up @@ -24,7 +24,6 @@ import {
ALERT_DEFINITIONS,
getAlertDefinitionCreateData,
} from '../../scripts/alerts/generate-alerts';
import { TExecutionDetails } from './types';

describe('AlertService', () => {
let prismaService: PrismaService;
Expand Down
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString, IsOptional, IsBoolean, IsEnum } from 'class-validator';
import { IsNotEmpty, IsString, IsOptional, IsBoolean } from 'class-validator';

export class CreateAlertDefinitionDto {
@ApiProperty({ example: '[Payments] - High Cumulative Amount - Inbound' })
Expand Down
6 changes: 3 additions & 3 deletions services/workflows-service/src/alert/types.ts
@@ -1,4 +1,4 @@
import { Alert, AlertDefinition, Business, User } from '@prisma/client';
import { Alert, AlertDefinition, Business, EndUser, User } from '@prisma/client';

export type TExecutionDetails = {
checkpoint: {
Expand All @@ -23,8 +23,8 @@ export type TAlertResponse = Alert & {
alertDefinition: Pick<AlertDefinition, 'description' | 'label'>;
assignee: Pick<User, 'id' | 'firstName' | 'lastName' | 'avatarUrl'>;
counterparty: {
business: Pick<Business, 'id' | 'companyName'>;
endUser: Pick<User, 'id' | 'firstName' | 'lastName'>;
business: Pick<Business, 'id' | 'companyName' | 'correlationId'>;
endUser: Pick<EndUser, 'id' | 'firstName' | 'lastName' | 'correlationId'>;
};
};

Expand Down
@@ -1,4 +1,4 @@
import { ArgumentsHost, Catch, HttpException, HttpStatus } from '@nestjs/common';
import { ArgumentsHost, Catch, HttpStatus } from '@nestjs/common';
import { BaseExceptionFilter, HttpAdapterHost } from '@nestjs/core';
import { Prisma } from '@prisma/client';
import { PRISMA_UNIQUE_CONSTRAINT_ERROR } from '@/prisma/prisma.util';
Expand Down
@@ -1,6 +1,6 @@
import { Injectable } from '@nestjs/common';
import { CustomerRepository } from '@/customer/customer.repository';
import { Prisma, Project } from '@prisma/client';
import { Prisma } from '@prisma/client';
import { TCustomerWithDefinitionsFeatures } from '@/customer/types';
import { ApiKeyService } from '@/customer/api-key/api-key.service';
import { generateHashedKey } from '@/customer/api-key/utils';
Expand Down
1 change: 1 addition & 0 deletions services/workflows-service/src/data-analytics/types.ts
@@ -1,5 +1,6 @@
import { TransactionDirection, PaymentMethod, TransactionRecordType } from '@prisma/client';
import { AggregateType, TIME_UNITS } from './consts';

export type InlineRule = {
id: string;
subjects: string[] | readonly string[];
Expand Down
7 changes: 4 additions & 3 deletions services/workflows-service/src/errors.ts
Expand Up @@ -85,6 +85,7 @@ export class ValidationError extends common.BadRequestException {

static fromClassValidator(error: ClassValidatorValidationError[]) {
const flattenedErrors = flattenValidationErrors(error);

return new ValidationError(
flattenedErrors.map(({ property, constraints = {}, value }, index) => ({
message: `${Object.values(constraints).join(', ')}.`,
Expand All @@ -95,9 +96,9 @@ export class ValidationError extends common.BadRequestException {
}
}

function flattenValidationErrors(
const flattenValidationErrors = (
errors: ClassValidatorValidationError[],
): ClassValidatorValidationError[] {
): ClassValidatorValidationError[] => {
const flattenedErrors: ClassValidatorValidationError[] = [];

for (const error of errors) {
Expand All @@ -111,4 +112,4 @@ function flattenValidationErrors(
}

return flattenedErrors;
}
};
Expand Up @@ -12,7 +12,6 @@ import { AppLoggerModule } from '@/common/app-logger/app-logger.module';
import { ClsMiddleware, ClsModule, ClsService } from 'nestjs-cls';
import { AuthKeyMiddleware } from '@/common/middlewares/auth-key.middleware';
import { CustomerModule } from '@/customer/customer.module';
import { CustomerService } from '@/customer/customer.service';
import { HttpModule } from '@nestjs/axios';
import { ApiKeyService } from '@/customer/api-key/api-key.service';

Expand Down
Expand Up @@ -12,7 +12,6 @@ import {
} from '@prisma/client';
import {
IsBoolean,
IsDate,
IsDateString,
IsEnum,
IsNotEmpty,
Expand Down
Expand Up @@ -17,9 +17,7 @@ import {
PaymentProcessor,
PaymentType,
Project,
ReviewStatus,
TransactionDirection,
TransactionRecordStatus,
TransactionRecordType,
} from '@prisma/client';
import { createProject } from '@/test/helpers/create-project';
Expand Down
Expand Up @@ -216,6 +216,7 @@ export class TransactionEntityMapper {
};

let brandName;

if (altDto.tx_product.toLowerCase() in PaymentBrandName) {
brandName = altDto.tx_product.toLowerCase() as PaymentBrandName;
} else {
Expand Down Expand Up @@ -267,6 +268,7 @@ export class TransactionEntityMapper {
}

const errors = validateSync(Object.assign(new TransactionCreateDto(), originalDto));

if (errors.length > 0) {
throw new ValidationError(errors as any);
} else {
Expand Down
Expand Up @@ -60,6 +60,7 @@ export class WebhooksService {

if (!config?.ongoingWorkflowDefinitionId) {
this.logger.error('No ongoing workflow definition found for project', { projectId });

return;
}

Expand Down

0 comments on commit 3e7d2f8

Please sign in to comment.