mirror of
https://github.com/twentyhq/twenty.git
synced 2025-01-01 16:51:46 +03:00
parent
e053fba089
commit
60b1024efb
@ -18,6 +18,18 @@ import { generateUpdateOneObjectMutation } from '../utils/generateUpdateOneObjec
|
||||
|
||||
import { useFindManyObjectMetadataItems } from './useFindManyObjectMetadataItems';
|
||||
|
||||
const EMPTY_QUERY = gql`
|
||||
query EmptyQuery {
|
||||
empty
|
||||
}
|
||||
`;
|
||||
|
||||
const EMPTY_MUTATION = gql`
|
||||
mutation EmptyMutation {
|
||||
empty
|
||||
}
|
||||
`;
|
||||
|
||||
export const useFindOneObjectMetadataItem = ({
|
||||
objectNamePlural,
|
||||
objectNameSingular,
|
||||
@ -39,81 +51,64 @@ export const useFindOneObjectMetadataItem = ({
|
||||
objectMetadataItems.length === 0 ||
|
||||
(objectMetadataItems.length > 0 && !foundObjectMetadataItem);
|
||||
|
||||
const activeFields =
|
||||
foundObjectMetadataItem?.fields.filter(({ isActive }) => isActive) ?? [];
|
||||
|
||||
const columnDefinitions: ColumnDefinition<FieldMetadata>[] =
|
||||
foundObjectMetadataItem?.fields.map((field, index) =>
|
||||
formatMetadataFieldAsColumnDefinition({
|
||||
position: index,
|
||||
field,
|
||||
objectMetadataItem: foundObjectMetadataItem,
|
||||
icons,
|
||||
}),
|
||||
) ?? [];
|
||||
foundObjectMetadataItem
|
||||
? activeFields.map((field, index) =>
|
||||
formatMetadataFieldAsColumnDefinition({
|
||||
position: index,
|
||||
field,
|
||||
objectMetadataItem: foundObjectMetadataItem,
|
||||
icons,
|
||||
}),
|
||||
)
|
||||
: [];
|
||||
|
||||
const filterDefinitions: FilterDefinition[] =
|
||||
foundObjectMetadataItem?.fields.map((field) =>
|
||||
formatMetadataFieldAsFilterDefinition({
|
||||
field,
|
||||
icons,
|
||||
}),
|
||||
) ?? [];
|
||||
const filterDefinitions: FilterDefinition[] = activeFields.map((field) =>
|
||||
formatMetadataFieldAsFilterDefinition({
|
||||
field,
|
||||
icons,
|
||||
}),
|
||||
);
|
||||
|
||||
const sortDefinitions: SortDefinition[] =
|
||||
foundObjectMetadataItem?.fields.map((field) =>
|
||||
formatMetadataFieldAsSortDefinition({
|
||||
field,
|
||||
icons,
|
||||
}),
|
||||
) ?? [];
|
||||
const sortDefinitions: SortDefinition[] = activeFields.map((field) =>
|
||||
formatMetadataFieldAsSortDefinition({
|
||||
field,
|
||||
icons,
|
||||
}),
|
||||
);
|
||||
|
||||
const findManyQuery = foundObjectMetadataItem
|
||||
? generateFindManyCustomObjectsQuery({
|
||||
objectMetadataItem: foundObjectMetadataItem,
|
||||
})
|
||||
: gql`
|
||||
query EmptyQuery {
|
||||
empty
|
||||
}
|
||||
`;
|
||||
: EMPTY_QUERY;
|
||||
|
||||
const findOneQuery = foundObjectMetadataItem
|
||||
? generateFindOneCustomObjectQuery({
|
||||
objectMetadataItem: foundObjectMetadataItem,
|
||||
})
|
||||
: gql`
|
||||
query EmptyQuery {
|
||||
empty
|
||||
}
|
||||
`;
|
||||
: EMPTY_QUERY;
|
||||
|
||||
const createOneMutation = foundObjectMetadataItem
|
||||
? generateCreateOneObjectMutation({
|
||||
objectMetadataItem: foundObjectMetadataItem,
|
||||
})
|
||||
: gql`
|
||||
mutation EmptyMutation {
|
||||
empty
|
||||
}
|
||||
`;
|
||||
: EMPTY_MUTATION;
|
||||
|
||||
const updateOneMutation = foundObjectMetadataItem
|
||||
? generateUpdateOneObjectMutation({
|
||||
objectMetadataItem: foundObjectMetadataItem,
|
||||
})
|
||||
: gql`
|
||||
mutation EmptyMutation {
|
||||
empty
|
||||
}
|
||||
`;
|
||||
: EMPTY_MUTATION;
|
||||
|
||||
const deleteOneMutation = foundObjectMetadataItem
|
||||
? generateDeleteOneObjectMutation({
|
||||
objectMetadataItem: foundObjectMetadataItem,
|
||||
})
|
||||
: gql`
|
||||
mutation EmptyMutation {
|
||||
empty
|
||||
}
|
||||
`;
|
||||
: EMPTY_MUTATION;
|
||||
|
||||
return {
|
||||
foundObjectMetadataItem,
|
||||
|
@ -1,5 +1,7 @@
|
||||
import { IconComponent } from '@/ui/display/icon/types/IconComponent';
|
||||
import { FieldMetadata } from '@/ui/object/field/types/FieldMetadata';
|
||||
import { ColumnDefinition } from '@/ui/object/record-table/types/ColumnDefinition';
|
||||
import { Field } from '~/generated-metadata/graphql';
|
||||
|
||||
import { ObjectMetadataItem } from '../types/ObjectMetadataItem';
|
||||
|
||||
@ -12,9 +14,9 @@ export const formatMetadataFieldAsColumnDefinition = ({
|
||||
icons,
|
||||
}: {
|
||||
position: number;
|
||||
field: ObjectMetadataItem['fields'][0];
|
||||
field: Field;
|
||||
objectMetadataItem: Omit<ObjectMetadataItem, 'fields'>;
|
||||
icons: Record<string, any>;
|
||||
icons: Record<string, IconComponent>;
|
||||
}): ColumnDefinition<FieldMetadata> => ({
|
||||
position,
|
||||
fieldId: field.id,
|
||||
|
@ -1,15 +1,23 @@
|
||||
import { selectorFamily } from 'recoil';
|
||||
|
||||
import { availableTableColumnsScopedState } from '../availableTableColumnsScopedState';
|
||||
import { tableColumnsScopedState } from '../tableColumnsScopedState';
|
||||
|
||||
export const visibleTableColumnsScopedSelector = selectorFamily({
|
||||
key: 'visibleTableColumnsScopedSelector',
|
||||
get:
|
||||
(scopeId: string) =>
|
||||
({ get }) =>
|
||||
[
|
||||
...get(tableColumnsScopedState(scopeId)).filter(
|
||||
(column) => column.isVisible,
|
||||
),
|
||||
].sort((a, b) => a.position - b.position),
|
||||
({ get }) => {
|
||||
const columns = get(tableColumnsScopedState(scopeId));
|
||||
const availableColumnKeys = get(
|
||||
availableTableColumnsScopedState(scopeId),
|
||||
).map(({ fieldId }) => fieldId);
|
||||
|
||||
return columns
|
||||
.filter(
|
||||
(column) =>
|
||||
column.isVisible && availableColumnKeys.includes(column.fieldId),
|
||||
)
|
||||
.toSorted((a, b) => a.position - b.position);
|
||||
},
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user