Skip to content

Commit

Permalink
Code improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinebhs committed Oct 31, 2023
1 parent 2dd0318 commit 0f8104a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/components/dialogs/filter/expert/expert-filter-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import { fields, OPERATOR_OPTIONS } from './expert-filter-constants';
import { IntlShape } from 'react-intl';
import { EMPTY_GROUP, INCORRECT_RULE } from 'components/utils/field-constants';
import { EMPTY_RULE } from '../../../utils/field-constants';
import { DataType } from './expert-filter.type';
import {
DataType,
RuleGroupTypeExport,
RuleTypeExport,
} from './expert-filter.type';

const getDataType = (fieldName: string) => {
const generatorField = fields().GENERATOR.find(
Expand Down Expand Up @@ -62,18 +66,6 @@ export const getOperators = (fieldName: string, intl: IntlShape) => {
return defaultOperators;
};

interface RuleTypeExport {
field: string;
operator: string;
value: string | number;
dataType: string;
}

interface RuleGroupTypeExport {
combinator: string;
rules: (RuleTypeExport | RuleGroupTypeExport)[];
}

export function getExpertRules(query: RuleGroupType): RuleGroupTypeExport {
function transformRule(rule: RuleType): RuleTypeExport {
return {
Expand All @@ -84,11 +76,7 @@ export function getExpertRules(query: RuleGroupType): RuleGroupTypeExport {
};
}

function transformGroup(group: RuleGroupType): {
combinator: string;
dataType: string;
rules: (RuleGroupTypeExport | RuleTypeExport)[];
} {
function transformGroup(group: RuleGroupType): RuleGroupTypeExport {
// Recursively transform the rules within the group
const transformedRules = group.rules.map((ruleOrGroup) => {
if ('rules' in ruleOrGroup) {
Expand Down
13 changes: 13 additions & 0 deletions src/components/dialogs/filter/expert/expert-filter.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ export enum DataType {
BOOLEAN = 'BOOLEAN',
COMBINATOR = 'COMBINATOR',
}

export interface RuleTypeExport {
field: string;
operator: string;
value: string | number;
dataType: DataType;
}

export interface RuleGroupTypeExport {
combinator: string;
dataType: DataType;
rules: (RuleTypeExport | RuleGroupTypeExport)[];
}

0 comments on commit 0f8104a

Please sign in to comment.