mirror of
https://github.com/twentyhq/twenty.git
synced 2024-11-27 11:03:40 +03:00
Object creation triggers view creation
This commit is contained in:
parent
4a493b6ecf
commit
6713ac589d
@ -1,6 +1,8 @@
|
|||||||
import { ApolloClient, useMutation } from '@apollo/client';
|
import { ApolloClient, useApolloClient, useMutation } from '@apollo/client';
|
||||||
import { getOperationName } from '@apollo/client/utilities';
|
import { getOperationName } from '@apollo/client/utilities';
|
||||||
|
|
||||||
|
import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
|
||||||
|
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
|
||||||
import {
|
import {
|
||||||
CreateObjectInput,
|
CreateObjectInput,
|
||||||
CreateOneObjectMetadataItemMutation,
|
CreateOneObjectMetadataItemMutation,
|
||||||
@ -14,6 +16,10 @@ import { useApolloMetadataClient } from './useApolloMetadataClient';
|
|||||||
|
|
||||||
export const useCreateOneObjectMetadataItem = () => {
|
export const useCreateOneObjectMetadataItem = () => {
|
||||||
const apolloMetadataClient = useApolloMetadataClient();
|
const apolloMetadataClient = useApolloMetadataClient();
|
||||||
|
const apolloClient = useApolloClient();
|
||||||
|
const { findManyRecordsQuery } = useObjectMetadataItem({
|
||||||
|
objectNameSingular: CoreObjectNameSingular.View,
|
||||||
|
});
|
||||||
|
|
||||||
const [mutate] = useMutation<
|
const [mutate] = useMutation<
|
||||||
CreateOneObjectMetadataItemMutation,
|
CreateOneObjectMetadataItemMutation,
|
||||||
@ -23,16 +29,20 @@ export const useCreateOneObjectMetadataItem = () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const createOneObjectMetadataItem = async (input: CreateObjectInput) => {
|
const createOneObjectMetadataItem = async (input: CreateObjectInput) => {
|
||||||
return await mutate({
|
const createdObjectMetadata = await mutate({
|
||||||
variables: {
|
variables: {
|
||||||
input: { object: input },
|
input: { object: input },
|
||||||
},
|
},
|
||||||
awaitRefetchQueries: true,
|
awaitRefetchQueries: true,
|
||||||
refetchQueries: [
|
refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''],
|
||||||
getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? '',
|
|
||||||
'FindManyRecordsMultipleMetadataItems',
|
|
||||||
],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
await apolloClient.query({
|
||||||
|
query: findManyRecordsQuery,
|
||||||
|
fetchPolicy: 'network-only',
|
||||||
|
});
|
||||||
|
|
||||||
|
return createdObjectMetadata;
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -490,8 +490,15 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt
|
|||||||
|
|
||||||
const view = await workspaceDataSource?.query(
|
const view = await workspaceDataSource?.query(
|
||||||
`INSERT INTO ${dataSourceMetadata.schema}."view"
|
`INSERT INTO ${dataSourceMetadata.schema}."view"
|
||||||
("objectMetadataId", "type", "name")
|
("objectMetadataId", "type", "name", "key", "icon")
|
||||||
VALUES ('${createdObjectMetadata.id}', 'table', 'All ${createdObjectMetadata.namePlural}') RETURNING *`,
|
VALUES ($1, $2, $3, $4, $5) RETURNING *`,
|
||||||
|
[
|
||||||
|
createdObjectMetadata.id,
|
||||||
|
'table',
|
||||||
|
`All ${createdObjectMetadata.namePlural}`,
|
||||||
|
'INDEX',
|
||||||
|
createdObjectMetadata.icon,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
createdObjectMetadata.fields.map(async (field, index) => {
|
createdObjectMetadata.fields.map(async (field, index) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user