Skip to content

Commit

Permalink
feat validators bugfix types addition (#805)
Browse files Browse the repository at this point in the history
  • Loading branch information
chavda-bhavik authored Sep 21, 2024
2 parents 3f19f6b + 1411e3a commit afe7ed4
Show file tree
Hide file tree
Showing 23 changed files with 113 additions and 87 deletions.
7 changes: 4 additions & 3 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
"test": "cross-env TZ=UTC NODE_ENV=test E2E_RUNNER=true mocha --timeout 10000 --require ts-node/register --exit src/**/**/*.spec.ts"
},
"dependencies": {
"@impler/dal": "^0.24.1",
"@impler/services": "^0.24.1",
"@impler/shared": "^0.24.1",
"@impler/client": "workspace:^",
"@impler/dal": "workspace:^",
"@impler/services": "workspace:^",
"@impler/shared": "workspace:^",
"@nestjs/common": "^9.1.2",
"@nestjs/core": "^9.1.2",
"@nestjs/jwt": "^10.0.1",
Expand Down
3 changes: 2 additions & 1 deletion apps/api/src/app/column/commands/add-column.command.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ColumnDelimiterEnum, ColumnTypesEnum, ValidatorTypesEnum } from '@impler/shared';
import { ValidatorTypesEnum } from '@impler/client';
import { ColumnDelimiterEnum, ColumnTypesEnum } from '@impler/shared';

export class ValidatorCommand {
validate: ValidatorTypesEnum;
Expand Down
6 changes: 4 additions & 2 deletions apps/api/src/app/column/dtos/column-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import {
ValidateNested,
} from 'class-validator';
import { Type } from 'class-transformer';

import { ValidatorTypesEnum } from '@impler/client';
import { IsValidRegex } from '@shared/framework/is-valid-regex.validator';
import { IsNumberOrString } from '@shared/framework/number-or-string.validator';
import { ColumnDelimiterEnum, ColumnTypesEnum, Defaults, ValidatorTypesEnum } from '@impler/shared';
import { IsGreaterThan } from '@shared/framework/is-greator-than.validator';
import { IsNumberOrString } from '@shared/framework/number-or-string.validator';
import { ColumnDelimiterEnum, ColumnTypesEnum, Defaults } from '@impler/shared';

export class ValidatorDto {
@ApiProperty({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ import * as customParseFormat from 'dayjs/plugin/customParseFormat';
import Ajv, { AnySchemaObject, ErrorObject, ValidateFunction } from 'ajv';

import { ValidatorErrorMessages } from '@shared/types/review.types';
import { ColumnTypesEnum, Defaults, ITemplateSchemaItem } from '@impler/shared';
import { SManager, BATCH_LIMIT, MAIN_CODE, ExecuteIsolateResult } from '@shared/services/sandbox';
import {
ColumnTypesEnum,
Defaults,
ITemplateSchemaItem,
LengthValidatorType,
RangeValidatorType,
ValidatorTypesEnum,
} from '@impler/shared';
import { ValidatorTypesEnum, LengthValidatorType, RangeValidatorType } from '@impler/client';

dayjs.extend(customParseFormat);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Writable } from 'stream';
import { Injectable, BadRequestException, InternalServerErrorException } from '@nestjs/common';

import { APIMessages } from '@shared/constants';
import { EMAIL_SUBJECT, ValidatorTypesEnum } from '@impler/shared';
import { EMAIL_SUBJECT } from '@impler/shared';
import { BaseReview } from './base-review.usecase';
import { ValidatorTypesEnum } from '@impler/client';
import { BATCH_LIMIT } from '@shared/services/sandbox';
import { StorageService, PaymentAPIService, EmailService } from '@impler/services';
import { ColumnTypesEnum, UploadStatusEnum, ITemplateSchemaItem, ColumnDelimiterEnum } from '@impler/shared';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { Writable } from 'stream';
import { ValidateFunction } from 'ajv';
import { Injectable, BadRequestException, InternalServerErrorException } from '@nestjs/common';

import { ValidatorTypesEnum } from '@impler/client';
import { UploadRepository, ValidatorRepository, DalService, TemplateEntity } from '@impler/dal';
import {
ColumnDelimiterEnum,
EMAIL_SUBJECT,
ColumnTypesEnum,
ITemplateSchemaItem,
UploadStatusEnum,
EMAIL_SUBJECT,
ValidatorTypesEnum,
ColumnDelimiterEnum,
ITemplateSchemaItem,
} from '@impler/shared';

import { APIMessages } from '@shared/constants';
Expand Down
6 changes: 3 additions & 3 deletions apps/queue-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"lint:fix": "pnpm lint -- --fix"
},
"dependencies": {
"@impler/dal": "^0.24.1",
"@impler/services": "^0.24.1",
"@impler/shared": "^0.24.1",
"@impler/dal": "workspace:^",
"@impler/services": "workspace:^",
"@impler/shared": "workspace:^",
"@sentry/node": "^7.112.2",
"axios": "1.6.2",
"dotenv": "^16.0.2",
Expand Down
5 changes: 3 additions & 2 deletions apps/web/components/imports/forms/ColumnForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
useMantineColorScheme,
} from '@mantine/core';

import { ColumnTypesEnum, DEFAULT_VALUES, IColumn, ValidatorTypesEnum } from '@impler/shared';
import { ValidatorTypesEnum } from '@impler/client';
import { ColumnTypesEnum, DEFAULT_VALUES, IColumn } from '@impler/shared';
import { colors, DELIMITERS, MODAL_KEYS, MODAL_TITLES, DOCUMENTATION_REFERENCE_LINKS } from '@config';

import { Button } from '@ui/button';
Expand Down Expand Up @@ -363,7 +364,7 @@ export function ColumnForm({ onSubmit, data, isLoading }: ColumnFormProps) {
index={fields.findIndex((field) => field.validate === ValidatorTypesEnum.UNIQUE_WITH)}
onCheckToggle={(status, index) => {
if (status) {
append({ validate: ValidatorTypesEnum.UNIQUE_WITH });
append({ validate: ValidatorTypesEnum.UNIQUE_WITH, uniqueKey: '' });
} else {
remove(index);
}
Expand Down
5 changes: 3 additions & 2 deletions apps/web/components/imports/schema/ValidationsGroup.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ColumnTypesEnum, IColumn, ValidatorTypesEnum } from '@impler/shared';
import { Group } from '@mantine/core';
import { Badge } from '@ui/badge';
import { getColorForText } from '@shared/utils';
import { ValidatorTypesEnum } from '@impler/client';
import { ColumnTypesEnum, IColumn } from '@impler/shared';

interface IValidationsGroupProps {
item: IColumn;
Expand Down Expand Up @@ -54,7 +55,7 @@ export function ValidationsGroup({ item }: IValidationsGroupProps) {
{item.validators?.map((validator) => {
if (validator.validate === ValidatorTypesEnum.UNIQUE_WITH) {
return (
<Badge variant="filled" key={ValidatorTypesEnum.UNIQUE_WITH} color={getColorForText(validator.uniqueKey!)}>
<Badge variant="filled" key={ValidatorTypesEnum.UNIQUE_WITH} color={getColorForText(validator.uniqueKey)}>
Unique with: {validator.uniqueKey}
</Badge>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const AutoHeightComponent: React.FC<AutoHeightComponentProps> = ({ isVisi
};

return (
<Collapse in={isExpanded} onTransitionEnd={handleTransitionEnd}>
<Collapse in={isExpanded} onTransitionEnd={handleTransitionEnd} w="100%">
{isRendered && children}
</Collapse>
);
Expand Down
2 changes: 1 addition & 1 deletion apps/web/design-system/validator/Validator.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Validator } from './Validator';
import { ValidatorTypesEnum } from '@impler/shared';
import { ValidatorTypesEnum } from '@impler/client';
import { ComponentStory, ComponentMeta } from '@storybook/react';

export default {
Expand Down
3 changes: 2 additions & 1 deletion apps/web/design-system/validator/Validator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import { AutoHeightComponent } from '@ui/auto-height-component';
import { ROUTES } from '@config';
import { Badge } from '@ui/badge';
import { Button } from '@ui/button';
import { IColumn } from '@impler/shared';
import { LockIcon } from '@assets/icons/Lock.icon';
import { ValidatorTypesEnum } from '@impler/client';
import { TooltipLabel } from '@components/guide-point';
import { IColumn, ValidatorTypesEnum } from '@impler/shared';

import useStyles from './Validator.styles';
import { MinMaxValidator } from './MinMaxValidator';
Expand Down
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@amplitude/analytics-browser": "^2.0.1",
"@emotion/react": "^11.10.5",
"@emotion/server": "^11.10.0",
"@impler/client": "workspace:^",
"@impler/react": "workspace:^",
"@impler/shared": "workspace:^",
"@mantine/carousel": "6.0.21",
Expand Down
4 changes: 3 additions & 1 deletion apps/web/pages/imports/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export default function ImportDetails({}) {
name: 'IMPORT CLICK',
properties: {},
});
showWidget({ colorScheme });
showWidget({
colorScheme,
});
};

return (
Expand Down
4 changes: 2 additions & 2 deletions apps/widget/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"@craco/craco": "^6.4.5",
"@emotion/react": "^11.10.5",
"@handsontable/react": "^14.1.0",
"@impler/client": "^0.24.1",
"@impler/shared": "^0.24.1",
"@impler/client": "workspace:^",
"@impler/shared": "workspace:^",
"@mantine/core": "6.0.21",
"@mantine/dropzone": "6.0.21",
"@mantine/hooks": "6.0.21",
Expand Down
2 changes: 1 addition & 1 deletion libs/dal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint:fix": "eslint src --fix"
},
"dependencies": {
"@impler/shared": "^0.24.1",
"@impler/shared": "workspace:^",
"class-transformer": "^0.5.1",
"date-fns": "^2.30.0",
"mongoose": "8.0.1",
Expand Down
2 changes: 1 addition & 1 deletion libs/services/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"@aws-sdk/client-ses": "^3.616.0",
"@aws-sdk/lib-storage": "^3.360.0",
"@aws-sdk/s3-request-presigner": "^3.276.0",
"@impler/shared": "^0.24.1",
"@impler/shared": "workspace:^",
"axios": "1.6.2",
"nodemailer": "^6.9.14",
"uuid": "^9.0.0"
Expand Down
28 changes: 1 addition & 27 deletions libs/shared/src/entities/Column/Column.interface.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,4 @@
export enum ValidatorTypesEnum {
RANGE = 'range',
LENGTH = 'length',
UNIQUE_WITH = 'unique_with',
}

export type RangeValidatorType = {
validate: ValidatorTypesEnum.RANGE;
min?: number;
max?: number;
errorMessage?: string;
};

export type LengthValidatorType = {
validate: ValidatorTypesEnum.LENGTH;
min?: number;
max?: number;
errorMessage?: string;
};

export type UniqueWithValidatorType = {
validate: ValidatorTypesEnum.UNIQUE_WITH;
uniqueKey?: string;
errorMessage?: string;
};

export type ValidatorType = RangeValidatorType | LengthValidatorType | UniqueWithValidatorType;
import { ValidatorType } from '@impler/client';

export interface IColumn {
_id: string;
Expand Down
2 changes: 1 addition & 1 deletion libs/shared/src/types/column/column.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ValidatorType } from '../../entities';
import { ValidatorType } from '@impler/client';

export enum ColumnTypesEnum {
'STRING' = 'String',
Expand Down
2 changes: 1 addition & 1 deletion packages/angular/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './services';
export { ColumnTypes, EventTypes } from '@impler/client';
export { ColumnTypes, EventTypes, ValidatorTypes } from '@impler/client';
export type { CustomTexts, ISchemaItem, EventCalls } from '@impler/client';
63 changes: 52 additions & 11 deletions packages/client/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { WIDGET_TEXTS } from './config';

// used for export
export const ColumnTypes = {
STRING: 'String',
NUMBER: 'Number',
Expand All @@ -12,6 +13,26 @@ export const ColumnTypes = {
IMAGE: 'Image',
} as const;

// used for export
export const ValidatorTypes = {
RANGE: 'range',
LENGTH: 'length',
UNIQUE_WITH: 'unique_with',
} as const;

// used for export
export const EventTypes = {
INIT_IFRAME: 'INIT_IFRAME',
WIDGET_READY: 'WIDGET_READY',
CLOSE_WIDGET: 'CLOSE_WIDGET',
AUTHENTICATION_VALID: 'AUTHENTICATION_VALID',
AUTHENTICATION_ERROR: 'AUTHENTICATION_ERROR',
UPLOAD_STARTED: 'UPLOAD_STARTED',
UPLOAD_TERMINATED: 'UPLOAD_TERMINATED',
UPLOAD_COMPLETED: 'UPLOAD_COMPLETED',
DATA_IMPORTED: 'DATA_IMPORTED',
} as const;

export interface IUpload {
_id: string;
_templateId: string;
Expand All @@ -36,17 +57,36 @@ export interface IUpload {
customChunkFormat: string;
}

export const EventTypes = {
INIT_IFRAME: 'INIT_IFRAME',
WIDGET_READY: 'WIDGET_READY',
CLOSE_WIDGET: 'CLOSE_WIDGET',
AUTHENTICATION_VALID: 'AUTHENTICATION_VALID',
AUTHENTICATION_ERROR: 'AUTHENTICATION_ERROR',
UPLOAD_STARTED: 'UPLOAD_STARTED',
UPLOAD_TERMINATED: 'UPLOAD_TERMINATED',
UPLOAD_COMPLETED: 'UPLOAD_COMPLETED',
DATA_IMPORTED: 'DATA_IMPORTED',
} as const;
export enum ValidatorTypesEnum {
RANGE = 'range',
LENGTH = 'length',
UNIQUE_WITH = 'unique_with',
}

export type RangeValidatorType = {
validate: 'range' | ValidatorTypesEnum.RANGE;
min?: number;
max?: number;
errorMessage?: string;
};

export type LengthValidatorType = {
validate: 'length' | ValidatorTypesEnum.LENGTH;
min?: number;
max?: number;
errorMessage?: string;
};

export type UniqueWithValidatorType = {
validate: 'unique_with' | ValidatorTypesEnum.UNIQUE_WITH;
uniqueKey: string;
errorMessage?: string;
};

export type ValidatorType =
| RangeValidatorType
| LengthValidatorType
| UniqueWithValidatorType;

export interface ISchemaItem {
key: string;
Expand All @@ -69,6 +109,7 @@ export interface ISchemaItem {
type?: keyof typeof ColumnTypes;
regex?: string;
allowMultiSelect?: boolean;
validators?: ValidatorType[];
}

export type UploadTemplateData = {
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './hooks';
export { ColumnTypes } from '@impler/client';
export type { ISchemaItem, CustomTexts } from '@impler/client';
export { ColumnTypes, ValidatorTypes } from '@impler/client';
export type { ISchemaItem, CustomTexts, ValidatorTypesEnum } from '@impler/client';
Loading

0 comments on commit afe7ed4

Please sign in to comment.