Feat/metadata add update and delete on frontend (#2102)
* Reworked metadata creation * Wip * Fix from PR * Removed consolelog * Post merge * Fixed seeds
This commit is contained in:
@ -1,11 +1,13 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
import { isFlexibleBackendEnabledState } from '@/client-config/states/isFlexibleBackendEnabledState';
|
||||
import { MetadataObjectsQuery } from '~/generated-metadata/graphql';
|
||||
|
||||
import { GET_ALL_OBJECTS } from '../graphql/queries';
|
||||
import { useApolloMetadataClient } from '../hooks/useApolloClientMetadata';
|
||||
import { FIND_MANY_METADATA_OBJECTS } from '../graphql/queries';
|
||||
import { useApolloMetadataClient } from '../hooks/useApolloMetadataClient';
|
||||
import { useCreateOneObject } from '../hooks/useCreateOneObject';
|
||||
import { useFindManyObjects } from '../hooks/useFindManyObjects';
|
||||
import { useSeedCustomObjectsTemp } from '../hooks/useSeedCustomObjectsTemp';
|
||||
import { metadataObjectsState } from '../states/metadataObjectsState';
|
||||
import { MetadataObject } from '../types/MetadataObject';
|
||||
@ -20,13 +22,44 @@ export const FetchMetadataEffect = () => {
|
||||
|
||||
const seedCustomObjectsTemp = useSeedCustomObjectsTemp();
|
||||
|
||||
const { createOneObject } = useCreateOneObject({
|
||||
objectNamePlural: 'suppliers',
|
||||
});
|
||||
|
||||
const { objects: suppliers, loading } = useFindManyObjects({
|
||||
objectNamePlural: 'suppliers',
|
||||
});
|
||||
|
||||
const [created, setCreated] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!created && !loading && suppliers.length === 0 && createOneObject) {
|
||||
createOneObject({
|
||||
name: 'Supplier 1',
|
||||
city: 'City 1',
|
||||
});
|
||||
|
||||
createOneObject({
|
||||
name: 'Supplier 2',
|
||||
city: 'City 2',
|
||||
});
|
||||
|
||||
createOneObject({
|
||||
name: 'Supplier 3',
|
||||
city: 'City 3',
|
||||
});
|
||||
|
||||
setCreated(true);
|
||||
}
|
||||
}, [suppliers, createOneObject, loading, created]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isFlexibleBackendEnabled) return;
|
||||
|
||||
(async () => {
|
||||
if (apolloMetadataClient && metadataObjects.length === 0) {
|
||||
const objects = await apolloMetadataClient.query<MetadataObjectsQuery>({
|
||||
query: GET_ALL_OBJECTS,
|
||||
query: FIND_MANY_METADATA_OBJECTS,
|
||||
});
|
||||
|
||||
if (
|
||||
@ -48,7 +81,7 @@ export const FetchMetadataEffect = () => {
|
||||
|
||||
const objects =
|
||||
await apolloMetadataClient.query<MetadataObjectsQuery>({
|
||||
query: GET_ALL_OBJECTS,
|
||||
query: FIND_MANY_METADATA_OBJECTS,
|
||||
});
|
||||
|
||||
const formattedObjects: MetadataObject[] =
|
||||
|
||||
@ -10,7 +10,7 @@ import { savedSortsFamilyState } from '@/ui/data/view-bar/states/savedSortsFamil
|
||||
import { sortsScopedState } from '@/ui/data/view-bar/states/sortsScopedState';
|
||||
import { useRecoilScopeId } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopeId';
|
||||
|
||||
import { useFindManyCustomObjects } from '../hooks/useFindManyCustomObjects';
|
||||
import { useFindManyObjects } from '../hooks/useFindManyObjects';
|
||||
import { useSetObjectDataTableData } from '../hooks/useSetDataTableData';
|
||||
|
||||
export const ObjectDataTableEffect = ({
|
||||
@ -22,7 +22,7 @@ export const ObjectDataTableEffect = ({
|
||||
}) => {
|
||||
const setDataTableData = useSetObjectDataTableData();
|
||||
|
||||
const { objects } = useFindManyCustomObjects({
|
||||
const { objects } = useFindManyObjects({
|
||||
objectNamePlural: objectNamePlural,
|
||||
});
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ export const ObjectTable = ({
|
||||
/>
|
||||
<ViewBarContext.Provider
|
||||
value={{
|
||||
defaultViewName: 'All Suppliers',
|
||||
defaultViewName: '???',
|
||||
onCurrentViewSubmit: submitCurrentView,
|
||||
onViewCreate: createView,
|
||||
onViewEdit: updateView,
|
||||
|
||||
Reference in New Issue
Block a user