Skip to content

Commit

Permalink
Object creation triggers view creation
Browse files Browse the repository at this point in the history
  • Loading branch information
charlesBochet committed Mar 22, 2024
1 parent 4a493b6 commit 6713ac5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { ApolloClient, useMutation } from '@apollo/client';
import { ApolloClient, useApolloClient, useMutation } from '@apollo/client';
import { getOperationName } from '@apollo/client/utilities';

import { useObjectMetadataItem } from '@/object-metadata/hooks/useObjectMetadataItem';
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular';
import {
CreateObjectInput,
CreateOneObjectMetadataItemMutation,
Expand All @@ -14,6 +16,10 @@ import { useApolloMetadataClient } from './useApolloMetadataClient';

export const useCreateOneObjectMetadataItem = () => {
const apolloMetadataClient = useApolloMetadataClient();
const apolloClient = useApolloClient();
const { findManyRecordsQuery } = useObjectMetadataItem({
objectNameSingular: CoreObjectNameSingular.View,
});

const [mutate] = useMutation<
CreateOneObjectMetadataItemMutation,
Expand All @@ -23,16 +29,20 @@ export const useCreateOneObjectMetadataItem = () => {
});

const createOneObjectMetadataItem = async (input: CreateObjectInput) => {
return await mutate({
const createdObjectMetadata = await mutate({
variables: {
input: { object: input },
},
awaitRefetchQueries: true,
refetchQueries: [
getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? '',
'FindManyRecordsMultipleMetadataItems',
],
refetchQueries: [getOperationName(FIND_MANY_OBJECT_METADATA_ITEMS) ?? ''],
});

await apolloClient.query({
query: findManyRecordsQuery,
fetchPolicy: 'network-only',
});

return createdObjectMetadata;
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,15 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadataEnt

const view = await workspaceDataSource?.query(
`INSERT INTO ${dataSourceMetadata.schema}."view"
("objectMetadataId", "type", "name")
VALUES ('${createdObjectMetadata.id}', 'table', 'All ${createdObjectMetadata.namePlural}') RETURNING *`,
("objectMetadataId", "type", "name", "key", "icon")
VALUES ($1, $2, $3, $4, $5) RETURNING *`,
[
createdObjectMetadata.id,
'table',
`All ${createdObjectMetadata.namePlural}`,
'INDEX',
createdObjectMetadata.icon,
],
);

createdObjectMetadata.fields.map(async (field, index) => {
Expand Down

0 comments on commit 6713ac5

Please sign in to comment.