Feat/add other metadata types v2 (#2224)

* Fix view fetch bug

* Finished types

* Removed console.log

* Fixed todo

* Reactivate no console

* Change no-console to warn
This commit is contained in:
Lucas Bordeau
2023-10-26 12:07:43 +02:00
committed by GitHub
parent 00dd046798
commit c335d19c97
20 changed files with 369 additions and 87 deletions

View File

@ -10,6 +10,10 @@ const parseFieldType = (fieldType: string): FieldType => {
return 'urlV2';
}
if (fieldType === 'money') {
return 'moneyAmountV2';
}
return fieldType as FieldType;
};

View File

@ -1,9 +1,9 @@
import { gql } from '@apollo/client';
import { FieldType } from '@/ui/data/field/types/FieldType';
import { MetadataObject } from '../types/MetadataObject';
import { mapFieldMetadataToGraphQLQuery } from './mapFieldMetadataToGraphQLQuery';
export const generateFindManyCustomObjectsQuery = ({
metadataObject,
_fromCursor,
@ -18,22 +18,7 @@ export const generateFindManyCustomObjectsQuery = ({
node {
id
${metadataObject.fields
.map((field) => {
// TODO: parse
const fieldType = field.type as FieldType;
if (fieldType === 'text') {
return field.name;
} else if (fieldType === 'url') {
return `
${field.name}
{
text
link
}
`;
}
})
.map(mapFieldMetadataToGraphQLQuery)
.join('\n')}
}
cursor

View File

@ -0,0 +1,44 @@
import { FieldType } from '@/ui/data/field/types/FieldType';
import { Field } from '~/generated/graphql';
export const mapFieldMetadataToGraphQLQuery = (field: Field) => {
// TODO: parse
const fieldType = field.type as FieldType;
const fieldIsSimpleValue = (
[
'text',
'phone',
'date',
'email',
'number',
'boolean',
'date',
] as FieldType[]
).includes(fieldType);
const fieldIsURL = fieldType === 'url' || fieldType === 'urlV2';
const fieldIsMoneyAmount =
fieldType === 'money' || fieldType === 'moneyAmountV2';
if (fieldIsSimpleValue) {
return field.name;
} else if (fieldIsURL) {
return `
${field.name}
{
text
link
}
`;
} else if (fieldIsMoneyAmount) {
return `
${field.name}
{
amount
currency
}
`;
}
};