Migrate view field to new data model - Part 2 (#2270)
* Migrate view field to new data model * Migrate view fields to new model
This commit is contained in:
@ -1,25 +1,13 @@
|
||||
import { getOperationName } from '@apollo/client/utilities';
|
||||
import { useRecoilCallback } from 'recoil';
|
||||
|
||||
import { viewObjectIdScopeState } from '@/views/states/viewObjectIdScopeState';
|
||||
import { viewTypeScopedState } from '@/views/states/viewTypeScopedState';
|
||||
import { View } from '@/views/types/View';
|
||||
import {
|
||||
useCreateViewMutation,
|
||||
useDeleteViewMutation,
|
||||
useUpdateViewMutation,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
import { GET_VIEWS } from '../../graphql/queries/getViews';
|
||||
|
||||
export const useViews = (scopeId: string) => {
|
||||
const [createViewMutation] = useCreateViewMutation();
|
||||
const [updateViewMutation] = useUpdateViewMutation();
|
||||
const [deleteViewMutation] = useDeleteViewMutation();
|
||||
|
||||
const createView = useRecoilCallback(
|
||||
({ snapshot }) =>
|
||||
async (view: Pick<View, 'id' | 'name'>) => {
|
||||
async (_view: Pick<View, 'id' | 'name'>) => {
|
||||
const viewObjectId = await snapshot
|
||||
.getLoadable(viewObjectIdScopeState({ scopeId }))
|
||||
.getValue();
|
||||
@ -31,34 +19,34 @@ export const useViews = (scopeId: string) => {
|
||||
if (!viewObjectId || !viewType) {
|
||||
return;
|
||||
}
|
||||
await createViewMutation({
|
||||
variables: {
|
||||
data: {
|
||||
...view,
|
||||
objectId: viewObjectId,
|
||||
type: viewType,
|
||||
},
|
||||
},
|
||||
refetchQueries: [getOperationName(GET_VIEWS) ?? ''],
|
||||
});
|
||||
// await createViewMutation({
|
||||
// variables: {
|
||||
// data: {
|
||||
// ...view,
|
||||
// objectId: viewObjectId,
|
||||
// type: viewType,
|
||||
// },
|
||||
// },
|
||||
// refetchQueries: [getOperationName(GET_VIEWS) ?? ''],
|
||||
// });
|
||||
},
|
||||
);
|
||||
|
||||
const updateView = async (view: View) => {
|
||||
await updateViewMutation({
|
||||
variables: {
|
||||
data: { name: view.name },
|
||||
where: { id: view.id },
|
||||
},
|
||||
refetchQueries: [getOperationName(GET_VIEWS) ?? ''],
|
||||
});
|
||||
const updateView = async (_view: View) => {
|
||||
// await updateViewMutation({
|
||||
// variables: {
|
||||
// data: { name: view.name },
|
||||
// where: { id: view.id },
|
||||
// },
|
||||
// refetchQueries: [getOperationName(GET_VIEWS) ?? ''],
|
||||
// });
|
||||
};
|
||||
|
||||
const deleteView = async (viewId: string) => {
|
||||
await deleteViewMutation({
|
||||
variables: { where: { id: viewId } },
|
||||
refetchQueries: [getOperationName(GET_VIEWS) ?? ''],
|
||||
});
|
||||
const deleteView = async (_viewId: string) => {
|
||||
// await deleteViewMutation({
|
||||
// variables: { where: { id: viewId } },
|
||||
// refetchQueries: [getOperationName(GET_VIEWS) ?? ''],
|
||||
// });
|
||||
};
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user