Create new type position (#4336)
* Create new type position * Remove position filter type --------- Co-authored-by: Thomas Trompette <thomast@twenty.com>
This commit is contained in:
@ -192,6 +192,7 @@ export enum FieldMetadataType {
|
|||||||
Number = 'NUMBER',
|
Number = 'NUMBER',
|
||||||
Numeric = 'NUMERIC',
|
Numeric = 'NUMERIC',
|
||||||
Phone = 'PHONE',
|
Phone = 'PHONE',
|
||||||
|
Position = 'POSITION',
|
||||||
Probability = 'PROBABILITY',
|
Probability = 'PROBABILITY',
|
||||||
Rating = 'RATING',
|
Rating = 'RATING',
|
||||||
Relation = 'RELATION',
|
Relation = 'RELATION',
|
||||||
|
|||||||
@ -168,6 +168,7 @@ export enum FieldMetadataType {
|
|||||||
Number = 'NUMBER',
|
Number = 'NUMBER',
|
||||||
Numeric = 'NUMERIC',
|
Numeric = 'NUMERIC',
|
||||||
Phone = 'PHONE',
|
Phone = 'PHONE',
|
||||||
|
Position = 'POSITION',
|
||||||
Probability = 'PROBABILITY',
|
Probability = 'PROBABILITY',
|
||||||
Rating = 'RATING',
|
Rating = 'RATING',
|
||||||
Relation = 'RELATION',
|
Relation = 'RELATION',
|
||||||
|
|||||||
@ -32,6 +32,7 @@ export const generateEmptyFieldValue = (
|
|||||||
}
|
}
|
||||||
case FieldMetadataType.Number:
|
case FieldMetadataType.Number:
|
||||||
case FieldMetadataType.Rating:
|
case FieldMetadataType.Rating:
|
||||||
|
case FieldMetadataType.Position:
|
||||||
case FieldMetadataType.Numeric: {
|
case FieldMetadataType.Numeric: {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,6 +35,7 @@ export enum FieldMetadataType {
|
|||||||
SELECT = 'SELECT',
|
SELECT = 'SELECT',
|
||||||
MULTI_SELECT = 'MULTI_SELECT',
|
MULTI_SELECT = 'MULTI_SELECT',
|
||||||
RELATION = 'RELATION',
|
RELATION = 'RELATION',
|
||||||
|
POSITION = 'POSITION',
|
||||||
}
|
}
|
||||||
|
|
||||||
@Entity('fieldMetadata')
|
@Entity('fieldMetadata')
|
||||||
|
|||||||
@ -41,6 +41,7 @@ type FieldMetadataDefaultValueMapping = {
|
|||||||
| FieldMetadataDynamicDefaultValueNow;
|
| FieldMetadataDynamicDefaultValueNow;
|
||||||
[FieldMetadataType.BOOLEAN]: FieldMetadataDefaultValueBoolean;
|
[FieldMetadataType.BOOLEAN]: FieldMetadataDefaultValueBoolean;
|
||||||
[FieldMetadataType.NUMBER]: FieldMetadataDefaultValueNumber;
|
[FieldMetadataType.NUMBER]: FieldMetadataDefaultValueNumber;
|
||||||
|
[FieldMetadataType.POSITION]: FieldMetadataDefaultValueNumber;
|
||||||
[FieldMetadataType.NUMERIC]: FieldMetadataDefaultValueString;
|
[FieldMetadataType.NUMERIC]: FieldMetadataDefaultValueString;
|
||||||
[FieldMetadataType.PROBABILITY]: FieldMetadataDefaultValueNumber;
|
[FieldMetadataType.PROBABILITY]: FieldMetadataDefaultValueNumber;
|
||||||
[FieldMetadataType.LINK]: FieldMetadataDefaultValueLink;
|
[FieldMetadataType.LINK]: FieldMetadataDefaultValueLink;
|
||||||
|
|||||||
@ -34,6 +34,7 @@ export function generateTargetColumnMap(
|
|||||||
case FieldMetadataType.RATING:
|
case FieldMetadataType.RATING:
|
||||||
case FieldMetadataType.SELECT:
|
case FieldMetadataType.SELECT:
|
||||||
case FieldMetadataType.MULTI_SELECT:
|
case FieldMetadataType.MULTI_SELECT:
|
||||||
|
case FieldMetadataType.POSITION:
|
||||||
return {
|
return {
|
||||||
value: columnName,
|
value: columnName,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -23,6 +23,7 @@ export type BasicFieldMetadataType =
|
|||||||
| FieldMetadataType.NUMBER
|
| FieldMetadataType.NUMBER
|
||||||
| FieldMetadataType.PROBABILITY
|
| FieldMetadataType.PROBABILITY
|
||||||
| FieldMetadataType.BOOLEAN
|
| FieldMetadataType.BOOLEAN
|
||||||
|
| FieldMetadataType.POSITION
|
||||||
| FieldMetadataType.DATE_TIME;
|
| FieldMetadataType.DATE_TIME;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|||||||
@ -19,6 +19,7 @@ export const fieldMetadataTypeToColumnType = <Type extends FieldMetadataType>(
|
|||||||
return 'numeric';
|
return 'numeric';
|
||||||
case FieldMetadataType.NUMBER:
|
case FieldMetadataType.NUMBER:
|
||||||
case FieldMetadataType.PROBABILITY:
|
case FieldMetadataType.PROBABILITY:
|
||||||
|
case FieldMetadataType.POSITION:
|
||||||
return 'float';
|
return 'float';
|
||||||
case FieldMetadataType.BOOLEAN:
|
case FieldMetadataType.BOOLEAN:
|
||||||
return 'boolean';
|
return 'boolean';
|
||||||
|
|||||||
@ -66,6 +66,7 @@ export class WorkspaceMigrationFactory {
|
|||||||
],
|
],
|
||||||
[FieldMetadataType.NUMERIC, { factory: this.basicColumnActionFactory }],
|
[FieldMetadataType.NUMERIC, { factory: this.basicColumnActionFactory }],
|
||||||
[FieldMetadataType.NUMBER, { factory: this.basicColumnActionFactory }],
|
[FieldMetadataType.NUMBER, { factory: this.basicColumnActionFactory }],
|
||||||
|
[FieldMetadataType.POSITION, { factory: this.basicColumnActionFactory }],
|
||||||
[
|
[
|
||||||
FieldMetadataType.PROBABILITY,
|
FieldMetadataType.PROBABILITY,
|
||||||
{ factory: this.basicColumnActionFactory },
|
{ factory: this.basicColumnActionFactory },
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { PositionScalarType } from './position.scalar';
|
||||||
import { CursorScalarType } from './cursor.scalar';
|
import { CursorScalarType } from './cursor.scalar';
|
||||||
import { BigFloatScalarType } from './big-float.scalar';
|
import { BigFloatScalarType } from './big-float.scalar';
|
||||||
import { BigIntScalarType } from './big-int.scalar';
|
import { BigIntScalarType } from './big-int.scalar';
|
||||||
@ -22,4 +23,5 @@ export const scalars = [
|
|||||||
TimeScalarType,
|
TimeScalarType,
|
||||||
UUIDScalarType,
|
UUIDScalarType,
|
||||||
CursorScalarType,
|
CursorScalarType,
|
||||||
|
PositionScalarType,
|
||||||
];
|
];
|
||||||
|
|||||||
@ -0,0 +1,38 @@
|
|||||||
|
import { GraphQLScalarType, Kind } from 'graphql';
|
||||||
|
|
||||||
|
type PositionType = 'first' | 'last' | number;
|
||||||
|
|
||||||
|
const isValidStringPosition = (value: string): boolean =>
|
||||||
|
typeof value === 'string' && (value === 'first' || value === 'last');
|
||||||
|
|
||||||
|
const isValidNumberPosition = (value: number): boolean =>
|
||||||
|
typeof value === 'number' && value >= 0;
|
||||||
|
|
||||||
|
const checkPosition = (value: any): PositionType => {
|
||||||
|
if (isValidNumberPosition(value) || isValidStringPosition(value)) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
throw new Error('Invalid position found');
|
||||||
|
};
|
||||||
|
|
||||||
|
export const PositionScalarType = new GraphQLScalarType({
|
||||||
|
name: 'Position',
|
||||||
|
description:
|
||||||
|
'A custom scalar type for representing record position in a list',
|
||||||
|
serialize: checkPosition,
|
||||||
|
parseValue: checkPosition,
|
||||||
|
parseLiteral(ast): PositionType {
|
||||||
|
if (
|
||||||
|
ast.kind == Kind.STRING &&
|
||||||
|
(ast.value === 'first' || ast.value === 'last')
|
||||||
|
) {
|
||||||
|
return ast.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ast.kind == Kind.INT || ast.kind == Kind.FLOAT) {
|
||||||
|
return parseFloat(ast.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error('Invalid position found');
|
||||||
|
},
|
||||||
|
});
|
||||||
@ -34,6 +34,7 @@ import {
|
|||||||
} from 'src/workspace/workspace-schema-builder/graphql-types/input';
|
} from 'src/workspace/workspace-schema-builder/graphql-types/input';
|
||||||
import { OrderByDirectionType } from 'src/workspace/workspace-schema-builder/graphql-types/enum';
|
import { OrderByDirectionType } from 'src/workspace/workspace-schema-builder/graphql-types/enum';
|
||||||
import { BigFloatScalarType } from 'src/workspace/workspace-schema-builder/graphql-types/scalars';
|
import { BigFloatScalarType } from 'src/workspace/workspace-schema-builder/graphql-types/scalars';
|
||||||
|
import { PositionScalarType } from 'src/workspace/workspace-schema-builder/graphql-types/scalars/position.scalar';
|
||||||
|
|
||||||
export interface TypeOptions<T = any> {
|
export interface TypeOptions<T = any> {
|
||||||
nullable?: boolean;
|
nullable?: boolean;
|
||||||
@ -66,6 +67,7 @@ export class TypeMapperService {
|
|||||||
[FieldMetadataType.NUMERIC, BigFloatScalarType],
|
[FieldMetadataType.NUMERIC, BigFloatScalarType],
|
||||||
[FieldMetadataType.PROBABILITY, GraphQLFloat],
|
[FieldMetadataType.PROBABILITY, GraphQLFloat],
|
||||||
[FieldMetadataType.RELATION, GraphQLID],
|
[FieldMetadataType.RELATION, GraphQLID],
|
||||||
|
[FieldMetadataType.POSITION, PositionScalarType],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return typeScalarMapping.get(fieldMetadataType);
|
return typeScalarMapping.get(fieldMetadataType);
|
||||||
@ -96,6 +98,7 @@ export class TypeMapperService {
|
|||||||
[FieldMetadataType.NUMERIC, BigFloatFilterType],
|
[FieldMetadataType.NUMERIC, BigFloatFilterType],
|
||||||
[FieldMetadataType.PROBABILITY, FloatFilterType],
|
[FieldMetadataType.PROBABILITY, FloatFilterType],
|
||||||
[FieldMetadataType.RELATION, UUIDFilterType],
|
[FieldMetadataType.RELATION, UUIDFilterType],
|
||||||
|
[FieldMetadataType.POSITION, FloatFilterType],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return typeFilterMapping.get(fieldMetadataType);
|
return typeFilterMapping.get(fieldMetadataType);
|
||||||
@ -118,6 +121,7 @@ export class TypeMapperService {
|
|||||||
[FieldMetadataType.RATING, OrderByDirectionType],
|
[FieldMetadataType.RATING, OrderByDirectionType],
|
||||||
[FieldMetadataType.SELECT, OrderByDirectionType],
|
[FieldMetadataType.SELECT, OrderByDirectionType],
|
||||||
[FieldMetadataType.MULTI_SELECT, OrderByDirectionType],
|
[FieldMetadataType.MULTI_SELECT, OrderByDirectionType],
|
||||||
|
[FieldMetadataType.POSITION, OrderByDirectionType],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return typeOrderByMapping.get(fieldMetadataType);
|
return typeOrderByMapping.get(fieldMetadataType);
|
||||||
|
|||||||
Reference in New Issue
Block a user