-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: reuse existing mutation editor
- Loading branch information
Showing
26 changed files
with
59 additions
and
3,694 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,19 @@ | ||
import { EntityId, EntitySourceType, MutationWithSettings } from '@mweb/backend' | ||
import { useQueryClient } from '@tanstack/react-query' | ||
import { useMemo } from 'react' | ||
import { EntityId, EntitySourceType } from '@mweb/backend' | ||
import { useQuery } from '@tanstack/react-query' | ||
import { useEngine } from '../engine' | ||
|
||
export const useMutation = ( | ||
mutationId: EntityId | undefined | null, | ||
source: EntitySourceType = EntitySourceType.Origin | ||
) => { | ||
const queryClient = useQueryClient() | ||
const { engine } = useEngine() | ||
|
||
// ToDo: check it out | ||
const mutations = queryClient.getQueryData<MutationWithSettings[]>(['mutations']) ?? [] | ||
|
||
const mutation = useMemo( | ||
() => | ||
mutationId | ||
? mutations.find((mutation) => mutation.id === mutationId && mutation.source === source) ?? | ||
null | ||
: null, | ||
[mutations, mutationId, source] | ||
) | ||
const { data: mutation } = useQuery({ | ||
queryKey: ['mutation', { mutationId, source }], | ||
queryFn: () => | ||
mutationId ? engine.mutationService.getMutation(mutationId, source) : Promise.resolve(null), | ||
initialData: null, | ||
}) | ||
|
||
return { mutation } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
libs/shared-components/src/mini-overlay/pages/edit-mutation.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { EntitySourceType } from '@mweb/backend' | ||
import { useApplications, useMutation, useMutations, usePreferredSource } from '@mweb/react-engine' | ||
import React, { FC, useMemo } from 'react' | ||
import { useNavigate, useParams } from 'react-router' | ||
import { useEngine } from '../../contexts/engine-context' | ||
import { MutationEditorModal } from '../../multitable-panel/components/mutation-editor-modal' | ||
|
||
const EditMutation: FC = () => { | ||
const navigate = useNavigate() | ||
const params = useParams() | ||
const mutationId = `${params.authorId}/mutation/${params.localId}` | ||
|
||
const { loggedInAccountId } = useEngine() | ||
const { applications } = useApplications() | ||
const { preferredSource } = usePreferredSource(mutationId) | ||
const { mutation: baseMutation } = useMutation(mutationId, preferredSource ?? undefined) // ToDo: fix | ||
const { mutations, isLoading } = useMutations(null) // ToDo: need context? | ||
|
||
const localMutations = useMemo( | ||
() => mutations.filter((m) => m.source === EntitySourceType.Local), | ||
[mutations] | ||
) | ||
|
||
if (isLoading) { | ||
// ToDo: loader | ||
return null | ||
} | ||
|
||
return ( | ||
<MutationEditorModal | ||
apps={applications} | ||
baseMutation={baseMutation} | ||
localMutations={localMutations} | ||
loggedInAccountId={loggedInAccountId} | ||
onClose={() => navigate(-1)} | ||
/> | ||
) | ||
} | ||
|
||
export default EditMutation |
181 changes: 0 additions & 181 deletions
181
libs/shared-components/src/mini-overlay/pages/edit-mutation/alert.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.