diff --git a/packages/ra-supabase-ui-materialui/src/guessers/CreateGuesser.tsx b/packages/ra-supabase-ui-materialui/src/guessers/CreateGuesser.tsx index fbb7a4d..c474650 100644 --- a/packages/ra-supabase-ui-materialui/src/guessers/CreateGuesser.tsx +++ b/packages/ra-supabase-ui-materialui/src/guessers/CreateGuesser.tsx @@ -68,6 +68,10 @@ export const CreateGuesserView = ( } const inferredInputs = Object.keys(resourceDefinition.properties) .filter((source: string) => source !== 'id') + .filter( + source => + resourceDefinition.properties![source].format !== 'tsvector' + ) .map((source: string) => inferElementFromType({ name: source, diff --git a/packages/ra-supabase-ui-materialui/src/guessers/EditGuesser.tsx b/packages/ra-supabase-ui-materialui/src/guessers/EditGuesser.tsx index 3c9e8e1..62eab2c 100644 --- a/packages/ra-supabase-ui-materialui/src/guessers/EditGuesser.tsx +++ b/packages/ra-supabase-ui-materialui/src/guessers/EditGuesser.tsx @@ -72,6 +72,10 @@ export const EditGuesserView = ( } const inferredInputs = Object.keys(resourceDefinition.properties) .filter((source: string) => source !== 'id') + .filter( + source => + resourceDefinition.properties![source].format !== 'tsvector' + ) .map((source: string) => inferElementFromType({ name: source, diff --git a/packages/ra-supabase-ui-materialui/src/guessers/ListGuesser.tsx b/packages/ra-supabase-ui-materialui/src/guessers/ListGuesser.tsx index 9f28b6e..86bc6b9 100644 --- a/packages/ra-supabase-ui-materialui/src/guessers/ListGuesser.tsx +++ b/packages/ra-supabase-ui-materialui/src/guessers/ListGuesser.tsx @@ -9,6 +9,7 @@ import { InferredElement, listFieldTypes, editFieldTypes, + SearchInput, } from 'react-admin'; import type { ListProps, ListViewProps } from 'react-admin'; import { capitalize, singularize } from 'inflection'; @@ -79,8 +80,12 @@ export const ListGuesserView = ( if (!resourceDefinition || !resourceDefinition.properties) { return; } - const inferredFields = Object.keys(resourceDefinition.properties).map( - (source: string) => + const inferredFields = Object.keys(resourceDefinition.properties) + .filter( + source => + resourceDefinition.properties![source].format !== 'tsvector' + ) + .map((source: string) => inferElementFromType({ name: source, types: listFieldTypes, @@ -94,7 +99,7 @@ export const ListGuesserView = ( ? resourceDefinition.properties![source].type : 'string') as string, }) - ); + ); const inferredTable = new InferredElement( listFieldTypes.table, null, @@ -108,16 +113,49 @@ export const ListGuesserView = ( obj['$ref'].includes('rowFilter') ) .map(obj => obj['$ref'].split('.').pop()) ?? []; - const inferredInputsForFilters = rowFilters.map(source => { - const field = resourceDefinition.properties![source]; - return inferElementFromType({ - name: source, - types: editFieldTypes, - description: field.description, - format: field.format, - type: field.type as string, + const inferredInputsForFilters = rowFilters + .filter( + source => + resourceDefinition.properties![source].format !== 'tsvector' + ) + .map(source => { + const field = resourceDefinition.properties![source]; + return inferElementFromType({ + name: source, + types: editFieldTypes, + description: field.description, + format: field.format, + type: field.type as string, + }); }); - }); + if ( + rowFilters.some( + source => + resourceDefinition.properties![source].format === 'tsvector' + ) + ) { + const fullTextSearchSource = rowFilters.find( + source => + resourceDefinition.properties![source].format === 'tsvector' + ); + const field = resourceDefinition.properties![fullTextSearchSource!]; + inferredInputsForFilters.push( + inferElementFromType({ + name: `${fullTextSearchSource!}@fts`, + types: { + string: { + component: SearchInput, + representation: props => + ``, + }, + }, + description: field.description, + format: 'tsvector', + props: { alwaysOn: true }, + type: field.type as string, + }) + ); + } if (inferredInputsForFilters.length > 0) { const filterElements = inferredInputsForFilters .map(inferredInput => inferredInput.getElement()) diff --git a/packages/ra-supabase-ui-materialui/src/guessers/ShowGuesser.tsx b/packages/ra-supabase-ui-materialui/src/guessers/ShowGuesser.tsx index 0fa3187..3370950 100644 --- a/packages/ra-supabase-ui-materialui/src/guessers/ShowGuesser.tsx +++ b/packages/ra-supabase-ui-materialui/src/guessers/ShowGuesser.tsx @@ -56,8 +56,12 @@ export const ShowGuesserView = ( if (!resourceDefinition || !resourceDefinition.properties) { return; } - const inferredFields = Object.keys(resourceDefinition.properties).map( - (source: string) => + const inferredFields = Object.keys(resourceDefinition.properties) + .filter( + source => + resourceDefinition.properties![source].format !== 'tsvector' + ) + .map((source: string) => inferElementFromType({ name: source, types: showFieldTypes, @@ -71,7 +75,7 @@ export const ShowGuesserView = ( ? resourceDefinition.properties![source].type : 'string') as string, }) - ); + ); const inferredLayout = new InferredElement( showFieldTypes.show, null, diff --git a/packages/ra-supabase-ui-materialui/src/guessers/inferElementFromType.ts b/packages/ra-supabase-ui-materialui/src/guessers/inferElementFromType.ts index 28daf6f..0129e5b 100644 --- a/packages/ra-supabase-ui-materialui/src/guessers/inferElementFromType.ts +++ b/packages/ra-supabase-ui-materialui/src/guessers/inferElementFromType.ts @@ -11,6 +11,7 @@ export const inferElementFromType = ({ type, requiredFields, types, + props, }: { name: string; types: InferredTypeMap; @@ -18,6 +19,7 @@ export const inferElementFromType = ({ format?: string; type?: string; requiredFields?: string[]; + props?: any; }) => { if (name === 'id' && hasType('id', types)) { return new InferredElement(types.id, { source: 'id' }); @@ -31,6 +33,7 @@ export const inferElementFromType = ({ return new InferredElement(types.reference, { source: name, reference, + ...props, }); } if ( @@ -41,6 +44,7 @@ export const inferElementFromType = ({ return new InferredElement(types.referenceArray, { source: name, reference, + ...props, }); } if (type === 'array') { @@ -55,12 +59,14 @@ export const inferElementFromType = ({ return new InferredElement(types.email, { source: name, validate, + ...props, }); } if (['url', 'website'].includes(name) && hasType('url', types)) { return new InferredElement(types.url, { source: name, validate, + ...props, }); } if ( @@ -74,6 +80,7 @@ export const inferElementFromType = ({ return new InferredElement(types.date, { source: name, validate, + ...props, }); } } @@ -81,16 +88,19 @@ export const inferElementFromType = ({ return new InferredElement(types.number, { source: name, validate, + ...props, }); } if (type && hasType(type, types)) { return new InferredElement(types[type], { source: name, validate, + ...props, }); } return new InferredElement(types.string, { source: name, validate, + ...props, }); };