add new @WorkspaceIsSearchable decorator + updates services + add migration command (#10507)
closes https://github.com/twentyhq/core-team-issues/issues/345
This commit is contained in:
@ -7,7 +7,6 @@ import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSi
|
||||
import { EMPTY_QUERY } from '@/object-record/constants/EmptyQuery';
|
||||
import { useGenerateCombinedSearchRecordsQuery } from '@/object-record/multiple-objects/hooks/useGenerateCombinedSearchRecordsQuery';
|
||||
import { MultiObjectRecordQueryResult } from '@/object-record/multiple-objects/types/MultiObjectRecordQueryResult';
|
||||
import { isObjectMetadataItemSearchableInCombinedRequest } from '@/object-record/utils/isObjectMetadataItemSearchableInCombinedRequest';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
|
||||
export const useMultiObjectSearch = ({
|
||||
@ -21,14 +20,11 @@ export const useMultiObjectSearch = ({
|
||||
}) => {
|
||||
const objectMetadataItems = useRecoilValue(objectMetadataItemsState);
|
||||
|
||||
const selectableObjectMetadataItems = objectMetadataItems
|
||||
.filter(({ isSystem, isRemote }) => !isSystem && !isRemote)
|
||||
.filter(({ nameSingular }) => {
|
||||
return !excludedObjects?.includes(nameSingular as CoreObjectNameSingular);
|
||||
})
|
||||
.filter((objectMetadataItem) =>
|
||||
isObjectMetadataItemSearchableInCombinedRequest(objectMetadataItem),
|
||||
);
|
||||
const selectableObjectMetadataItems = objectMetadataItems.filter(
|
||||
({ nameSingular, isSearchable }) =>
|
||||
!excludedObjects?.includes(nameSingular as CoreObjectNameSingular) &&
|
||||
isSearchable,
|
||||
);
|
||||
|
||||
const { limitPerMetadataItem } = useLimitPerMetadataItem({
|
||||
objectMetadataItems,
|
||||
|
||||
@ -13,6 +13,7 @@ export const CREATE_ONE_OBJECT_METADATA_ITEM = gql`
|
||||
icon
|
||||
isCustom
|
||||
isActive
|
||||
isSearchable
|
||||
createdAt
|
||||
updatedAt
|
||||
labelIdentifierFieldMetadataId
|
||||
@ -98,6 +99,7 @@ export const UPDATE_ONE_OBJECT_METADATA_ITEM = gql`
|
||||
icon
|
||||
isCustom
|
||||
isActive
|
||||
isSearchable
|
||||
createdAt
|
||||
updatedAt
|
||||
labelIdentifierFieldMetadataId
|
||||
@ -119,6 +121,7 @@ export const DELETE_ONE_OBJECT_METADATA_ITEM = gql`
|
||||
icon
|
||||
isCustom
|
||||
isActive
|
||||
isSearchable
|
||||
createdAt
|
||||
updatedAt
|
||||
labelIdentifierFieldMetadataId
|
||||
|
||||
@ -23,6 +23,7 @@ export const FIND_MANY_OBJECT_METADATA_ITEMS = gql`
|
||||
imageIdentifierFieldMetadataId
|
||||
shortcut
|
||||
isLabelSyncedWithName
|
||||
isSearchable
|
||||
duplicateCriteria
|
||||
indexMetadatas(paging: { first: 100 }) {
|
||||
edges {
|
||||
|
||||
@ -13,6 +13,7 @@ export const query = gql`
|
||||
icon
|
||||
isCustom
|
||||
isActive
|
||||
isSearchable
|
||||
createdAt
|
||||
updatedAt
|
||||
labelIdentifierFieldMetadataId
|
||||
@ -79,6 +80,7 @@ export const responseData = {
|
||||
icon: '',
|
||||
isCustom: false,
|
||||
isActive: true,
|
||||
isSearchable: false,
|
||||
createdAt: '',
|
||||
updatedAt: '',
|
||||
labelIdentifierFieldMetadataId: '20202020-72ba-4e11-a36d-e17b544541e1',
|
||||
|
||||
@ -13,6 +13,7 @@ export const query = gql`
|
||||
icon
|
||||
isCustom
|
||||
isActive
|
||||
isSearchable
|
||||
createdAt
|
||||
updatedAt
|
||||
labelIdentifierFieldMetadataId
|
||||
@ -34,6 +35,7 @@ export const responseData = {
|
||||
icon: '',
|
||||
isCustom: false,
|
||||
isActive: true,
|
||||
isSearchable: false,
|
||||
createdAt: '',
|
||||
updatedAt: '',
|
||||
labelIdentifierFieldMetadataId: '20202020-72ba-4e11-a36d-e17b544541e1',
|
||||
|
||||
@ -21,6 +21,7 @@ describe('useLimitPerMetadataItem', () => {
|
||||
isCustom: true,
|
||||
isSystem: true,
|
||||
isRemote: false,
|
||||
isSearchable: true,
|
||||
labelPlural: 'labelPlural',
|
||||
labelSingular: 'labelSingular',
|
||||
namePlural: 'namePlural',
|
||||
|
||||
@ -20,6 +20,7 @@ export const objectMetadataItemSchema = z.object({
|
||||
isCustom: z.boolean(),
|
||||
isRemote: z.boolean(),
|
||||
isSystem: z.boolean(),
|
||||
isSearchable: z.boolean(),
|
||||
labelIdentifierFieldMetadataId: z.string().uuid(),
|
||||
labelPlural: metadataLabelSchema(),
|
||||
labelSingular: metadataLabelSchema(),
|
||||
|
||||
@ -17,6 +17,7 @@ const mockObjectMetadataItem: ObjectMetadataItem = {
|
||||
labelSingular: 'Company',
|
||||
labelPlural: 'Companies',
|
||||
isCustom: false,
|
||||
isSearchable: false,
|
||||
labelIdentifierFieldMetadataId: '20202020-dd4a-4ea4-bb7b-1c7300491b65',
|
||||
isActive: true,
|
||||
createdAt: new Date().toISOString(),
|
||||
|
||||
@ -6,7 +6,6 @@ import { objectMetadataItemsState } from '@/object-metadata/states/objectMetadat
|
||||
import { mapObjectMetadataToGraphQLQuery } from '@/object-metadata/utils/mapObjectMetadataToGraphQLQuery';
|
||||
import { RecordGqlOperationSignature } from '@/object-record/graphql/types/RecordGqlOperationSignature';
|
||||
import { getSearchRecordsQueryResponseField } from '@/object-record/utils/getSearchRecordsQueryResponseField';
|
||||
import { isObjectMetadataItemSearchable } from '@/object-record/utils/isObjectMetadataItemSearchable';
|
||||
import { capitalize } from 'twenty-shared';
|
||||
import { isNonEmptyArray } from '~/utils/isNonEmptyArray';
|
||||
|
||||
@ -55,8 +54,8 @@ export const useGenerateCombinedSearchRecordsQuery = ({
|
||||
);
|
||||
|
||||
const filteredQueryKeyWithObjectMetadataItemArray =
|
||||
queryKeyWithObjectMetadataItemArray.filter(({ objectMetadataItem }) =>
|
||||
isObjectMetadataItemSearchable(objectMetadataItem),
|
||||
queryKeyWithObjectMetadataItemArray.filter(
|
||||
({ objectMetadataItem }) => objectMetadataItem.isSearchable,
|
||||
);
|
||||
|
||||
return gql`
|
||||
|
||||
@ -29,6 +29,7 @@ const objectMetadataItemWithPositionField: ObjectMetadataItem = {
|
||||
isSystem: false,
|
||||
isCustom: false,
|
||||
isRemote: false,
|
||||
isSearchable: false,
|
||||
labelPlural: 'object1s',
|
||||
labelSingular: 'object1',
|
||||
isLabelSyncedWithName: true,
|
||||
|
||||
@ -18,6 +18,7 @@ describe('buildRecordGqlFieldsAggregateForView', () => {
|
||||
isActive: true,
|
||||
isSystem: false,
|
||||
isRemote: false,
|
||||
isSearchable: false,
|
||||
labelIdentifierFieldMetadataId: '06b33746-5293-4d07-9f7f-ebf5ad396064',
|
||||
imageIdentifierFieldMetadataId: null,
|
||||
isLabelSyncedWithName: true,
|
||||
|
||||
@ -12,6 +12,7 @@ describe('generateAggregateQuery', () => {
|
||||
labelIdentifierFieldMetadataId: '20202020-72ba-4e11-a36d-e17b544541e1',
|
||||
isCustom: false,
|
||||
isActive: true,
|
||||
isSearchable: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
fields: [],
|
||||
@ -50,6 +51,7 @@ describe('generateAggregateQuery', () => {
|
||||
labelIdentifierFieldMetadataId: '20202020-72ba-4e11-a36d-e17b544541e1',
|
||||
isCustom: false,
|
||||
isActive: true,
|
||||
isSearchable: false,
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
fields: [],
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
|
||||
const SEARCHABLE_STANDARD_OBJECTS_NAMES_PLURAL = [
|
||||
'companies',
|
||||
'people',
|
||||
'opportunities',
|
||||
];
|
||||
export const isObjectMetadataItemSearchable = (
|
||||
objectMetadataItem: ObjectMetadataItem,
|
||||
) => {
|
||||
return (
|
||||
objectMetadataItem.isCustom ||
|
||||
SEARCHABLE_STANDARD_OBJECTS_NAMES_PLURAL.includes(
|
||||
objectMetadataItem.namePlural,
|
||||
)
|
||||
);
|
||||
};
|
||||
@ -1,17 +0,0 @@
|
||||
import { ObjectMetadataItem } from '@/object-metadata/types/ObjectMetadataItem';
|
||||
|
||||
const SEARCHABLE_STANDARD_OBJECTS_IN_COMBINED_REQUEST_NAMES_PLURAL = [
|
||||
'companies',
|
||||
'people',
|
||||
'opportunities',
|
||||
];
|
||||
export const isObjectMetadataItemSearchableInCombinedRequest = (
|
||||
objectMetadataItem: ObjectMetadataItem,
|
||||
) => {
|
||||
return (
|
||||
objectMetadataItem.isCustom ||
|
||||
SEARCHABLE_STANDARD_OBJECTS_IN_COMBINED_REQUEST_NAMES_PLURAL.includes(
|
||||
objectMetadataItem.namePlural,
|
||||
)
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user