Skip to content

Commit

Permalink
refactor: Improve types (no-changelog) (#9930)
Browse files Browse the repository at this point in the history
  • Loading branch information
despairblue authored Jul 3, 2024
1 parent bbe69d7 commit d468433
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 96 deletions.
5 changes: 4 additions & 1 deletion packages/editor-ui/src/components/FilterConditions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ const getTargetType = (type: FilterOperatorType) => {
return 'string';
};

const convertToType = (value: NodeParameterValue, type: FilterOperatorType): NodeParameterValue => {
const convertToType = (
value: NodeParameterValue | NodeParameterValue[],
type: FilterOperatorType,
): NodeParameterValue | NodeParameterValue[] => {
if (type === 'any') return value;

const fallback = type === 'boolean' ? false : value;
Expand Down
4 changes: 2 additions & 2 deletions packages/workflow/src/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2474,9 +2474,9 @@ export interface FilterOperatorValue {

export type FilterConditionValue = {
id: string;
leftValue: NodeParameterValue;
leftValue: NodeParameterValue | NodeParameterValue[];
operator: FilterOperatorValue;
rightValue: NodeParameterValue;
rightValue: NodeParameterValue | NodeParameterValue[];
};

export type FilterOptionsValue = {
Expand Down
171 changes: 78 additions & 93 deletions packages/workflow/test/FilterParameter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,29 +1044,26 @@ describe('FilterParameter', () => {
it.each([
{ left: ['foo', 'bar'], right: 'foo', expected: true },
{ left: ['foo', 'bar'], right: 'ba', expected: false },
] as unknown as Tests)(
'array:contains($left,$right) === $expected',
({ left, right, expected }) => {
const result = executeFilter(
filterFactory({
conditions: [
{
id: '1',
leftValue: left,
rightValue: right,
operator: { operation: 'contains', type: 'array', rightType: 'any' },
},
],
}),
);
expect(result).toBe(expected);
},
);
] as Tests)('array:contains($left,$right) === $expected', ({ left, right, expected }) => {
const result = executeFilter(
filterFactory({
conditions: [
{
id: '1',
leftValue: left,
rightValue: right,
operator: { operation: 'contains', type: 'array', rightType: 'any' },
},
],
}),
);
expect(result).toBe(expected);
});

it.each([
{ left: ['foo', 'bar'], right: 'foo', expected: false },
{ left: ['foo', 'bar'], right: 'ba', expected: true },
] as unknown as Tests)(
] as Tests)(
'array:notContains($left,$right) === $expected',
({ left, right, expected }) => {
const result = executeFilter(
Expand All @@ -1089,7 +1086,7 @@ describe('FilterParameter', () => {
{ left: ['foo', 'bar'], right: 2, expected: true },
{ left: [], right: 0, expected: true },
{ left: ['foo', 'bar'], right: 1, expected: false },
] as unknown as Tests)(
] as Tests)(
'array:lengthEquals($left,$right) === $expected',
({ left, right, expected }) => {
const result = executeFilter(
Expand All @@ -1112,7 +1109,7 @@ describe('FilterParameter', () => {
{ left: ['foo', 'bar'], right: 2, expected: false },
{ left: [], right: 0, expected: false },
{ left: ['foo', 'bar'], right: 1, expected: true },
] as unknown as Tests)(
] as Tests)(
'array:lengthNotEquals($left,$right) === $expected',
({ left, right, expected }) => {
const result = executeFilter(
Expand All @@ -1135,96 +1132,84 @@ describe('FilterParameter', () => {
{ left: ['foo', 'bar'], right: 2, expected: false },
{ left: [], right: 0, expected: false },
{ left: ['foo', 'bar'], right: 1, expected: true },
] as unknown as Tests)(
'array:lengthGt($left,$right) === $expected',
({ left, right, expected }) => {
const result = executeFilter(
filterFactory({
conditions: [
{
id: '1',
leftValue: left,
rightValue: right,
operator: { operation: 'lengthGt', type: 'array', rightType: 'number' },
},
],
}),
);
expect(result).toBe(expected);
},
);
] as Tests)('array:lengthGt($left,$right) === $expected', ({ left, right, expected }) => {
const result = executeFilter(
filterFactory({
conditions: [
{
id: '1',
leftValue: left,
rightValue: right,
operator: { operation: 'lengthGt', type: 'array', rightType: 'number' },
},
],
}),
);
expect(result).toBe(expected);
});

it.each([
{ left: ['foo', 'bar'], right: 2, expected: false },
{ left: [], right: 0, expected: false },
{ left: ['foo', 'bar'], right: 1, expected: false },
{ left: ['foo', 'bar'], right: 3, expected: true },
] as unknown as Tests)(
'array:lengthLt($left,$right) === $expected',
({ left, right, expected }) => {
const result = executeFilter(
filterFactory({
conditions: [
{
id: '1',
leftValue: left,
rightValue: right,
operator: { operation: 'lengthLt', type: 'array', rightType: 'number' },
},
],
}),
);
expect(result).toBe(expected);
},
);
] as Tests)('array:lengthLt($left,$right) === $expected', ({ left, right, expected }) => {
const result = executeFilter(
filterFactory({
conditions: [
{
id: '1',
leftValue: left,
rightValue: right,
operator: { operation: 'lengthLt', type: 'array', rightType: 'number' },
},
],
}),
);
expect(result).toBe(expected);
});

it.each([
{ left: ['foo', 'bar'], right: 2, expected: true },
{ left: [], right: 0, expected: true },
{ left: ['foo', 'bar'], right: 1, expected: true },
{ left: ['foo', 'bar'], right: 3, expected: false },
] as unknown as Tests)(
'array:lengthGte($left,$right) === $expected',
({ left, right, expected }) => {
const result = executeFilter(
filterFactory({
conditions: [
{
id: '1',
leftValue: left,
rightValue: right,
operator: { operation: 'lengthGte', type: 'array', rightType: 'number' },
},
],
}),
);
expect(result).toBe(expected);
},
);
] as Tests)('array:lengthGte($left,$right) === $expected', ({ left, right, expected }) => {
const result = executeFilter(
filterFactory({
conditions: [
{
id: '1',
leftValue: left,
rightValue: right,
operator: { operation: 'lengthGte', type: 'array', rightType: 'number' },
},
],
}),
);
expect(result).toBe(expected);
});

it.each([
{ left: ['foo', 'bar'], right: 2, expected: true },
{ left: [], right: 0, expected: true },
{ left: ['foo', 'bar'], right: 1, expected: false },
{ left: ['foo', 'bar'], right: 3, expected: true },
] as unknown as Tests)(
'array:lengthLte($left,$right) === $expected',
({ left, right, expected }) => {
const result = executeFilter(
filterFactory({
conditions: [
{
id: '1',
leftValue: left,
rightValue: right,
operator: { operation: 'lengthLte', type: 'array', rightType: 'number' },
},
],
}),
);
expect(result).toBe(expected);
},
);
] as Tests)('array:lengthLte($left,$right) === $expected', ({ left, right, expected }) => {
const result = executeFilter(
filterFactory({
conditions: [
{
id: '1',
leftValue: left,
rightValue: right,
operator: { operation: 'lengthLte', type: 'array', rightType: 'number' },
},
],
}),
);
expect(result).toBe(expected);
});
});

describe('object', () => {
Expand Down

0 comments on commit d468433

Please sign in to comment.