refactor: rename ui/filter-n-sort to ui/view-bar (#1475)
Closes #1473 Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { FilterOperand } from '../types/FilterOperand';
|
||||
|
||||
export function getOperandLabel(operand: FilterOperand | null | undefined) {
|
||||
switch (operand) {
|
||||
case FilterOperand.Contains:
|
||||
return 'Contains';
|
||||
case FilterOperand.DoesNotContain:
|
||||
return "Doesn't contain";
|
||||
case FilterOperand.GreaterThan:
|
||||
return 'Greater than';
|
||||
case FilterOperand.LessThan:
|
||||
return 'Less than';
|
||||
case FilterOperand.Is:
|
||||
return 'Is';
|
||||
case FilterOperand.IsNot:
|
||||
return 'Is not';
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
export function getOperandLabelShort(
|
||||
operand: FilterOperand | null | undefined,
|
||||
) {
|
||||
switch (operand) {
|
||||
case FilterOperand.Is:
|
||||
case FilterOperand.Contains:
|
||||
return ': ';
|
||||
case FilterOperand.IsNot:
|
||||
case FilterOperand.DoesNotContain:
|
||||
return ': Not';
|
||||
case FilterOperand.GreaterThan:
|
||||
return '\u00A0> ';
|
||||
case FilterOperand.LessThan:
|
||||
return '\u00A0< ';
|
||||
default:
|
||||
return ': ';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { FilterOperand } from '../types/FilterOperand';
|
||||
import { FilterType } from '../types/FilterType';
|
||||
|
||||
export function getOperandsForFilterType(
|
||||
filterType: FilterType | null | undefined,
|
||||
): FilterOperand[] {
|
||||
switch (filterType) {
|
||||
case 'text':
|
||||
return [FilterOperand.Contains, FilterOperand.DoesNotContain];
|
||||
case 'number':
|
||||
case 'date':
|
||||
return [FilterOperand.GreaterThan, FilterOperand.LessThan];
|
||||
case 'entity':
|
||||
return [FilterOperand.Is, FilterOperand.IsNot];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
import { QueryMode } from '~/generated/graphql';
|
||||
|
||||
import { Filter } from '../types/Filter';
|
||||
import { FilterOperand } from '../types/FilterOperand';
|
||||
|
||||
export function turnFilterIntoWhereClause(filter: Filter) {
|
||||
switch (filter.type) {
|
||||
case 'text':
|
||||
switch (filter.operand) {
|
||||
case FilterOperand.Contains:
|
||||
return {
|
||||
[filter.key]: {
|
||||
contains: filter.value,
|
||||
mode: QueryMode.Insensitive,
|
||||
},
|
||||
};
|
||||
case FilterOperand.DoesNotContain:
|
||||
return {
|
||||
[filter.key]: {
|
||||
not: {
|
||||
contains: filter.value,
|
||||
mode: QueryMode.Insensitive,
|
||||
},
|
||||
},
|
||||
};
|
||||
default:
|
||||
throw new Error(
|
||||
`Unknown operand ${filter.operand} for ${filter.type} filter`,
|
||||
);
|
||||
}
|
||||
case 'number':
|
||||
switch (filter.operand) {
|
||||
case FilterOperand.GreaterThan:
|
||||
return {
|
||||
[filter.key]: {
|
||||
gte: parseFloat(filter.value),
|
||||
},
|
||||
};
|
||||
case FilterOperand.LessThan:
|
||||
return {
|
||||
[filter.key]: {
|
||||
lte: parseFloat(filter.value),
|
||||
},
|
||||
};
|
||||
default:
|
||||
throw new Error(
|
||||
`Unknown operand ${filter.operand} for ${filter.type} filter`,
|
||||
);
|
||||
}
|
||||
case 'date':
|
||||
switch (filter.operand) {
|
||||
case FilterOperand.GreaterThan:
|
||||
return {
|
||||
[filter.key]: {
|
||||
gte: filter.value,
|
||||
},
|
||||
};
|
||||
case FilterOperand.LessThan:
|
||||
return {
|
||||
[filter.key]: {
|
||||
lte: filter.value,
|
||||
},
|
||||
};
|
||||
default:
|
||||
throw new Error(
|
||||
`Unknown operand ${filter.operand} for ${filter.type} filter`,
|
||||
);
|
||||
}
|
||||
case 'entity':
|
||||
switch (filter.operand) {
|
||||
case FilterOperand.Is:
|
||||
return {
|
||||
[filter.key]: {
|
||||
equals: filter.value,
|
||||
},
|
||||
};
|
||||
case FilterOperand.IsNot:
|
||||
return {
|
||||
[filter.key]: {
|
||||
not: { equals: filter.value },
|
||||
},
|
||||
};
|
||||
default:
|
||||
throw new Error(
|
||||
`Unknown operand ${filter.operand} for ${filter.type} filter`,
|
||||
);
|
||||
}
|
||||
default:
|
||||
throw new Error('Unknown filter type');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user