Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new columns in alerts table #2334

Merged
merged 6 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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>();
tomer-shvadron marked this conversation as resolved.
Show resolved Hide resolved
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>
);
tomer-shvadron marked this conversation as resolved.
Show resolved Hide resolved
},
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
Original file line number Diff line number Diff line change
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',
tomer-shvadron marked this conversation as resolved.
Show resolved Hide resolved
id: counterparty.endUser.id,
correlationId: counterparty.endUser.correlationId,
name: `${counterparty.endUser.firstName} ${counterparty.endUser.lastName}`,
},
decision: state,
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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;
}
};
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
} from '@prisma/client';
import {
IsBoolean,
IsDate,
IsDateString,
IsEnum,
IsNotEmpty,
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading