-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[FE] Update remote table schema + refactor Tables list #5548
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
61dd790
03e95db
7b77bbc
02173ea
2817863
f986c7c
c6ee7f2
83fbadc
6266dc6
ae13924
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
import { REMOTE_TABLE_FRAGMENT } from '@/databases/graphql/fragments/remoteTableFragment'; | ||
|
||
export const SYNC_REMOTE_TABLE_SCHEMA_CHANGES = gql` | ||
${REMOTE_TABLE_FRAGMENT} | ||
mutation syncRemoteTableSchemaChanges($input: RemoteTableInput!) { | ||
syncRemoteTableSchemaChanges(input: $input) { | ||
...RemoteTableFields | ||
} | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ import { useCallback } from 'react'; | |
import { ApolloClient, useApolloClient, useMutation } from '@apollo/client'; | ||
|
||
import { SYNC_REMOTE_TABLE } from '@/databases/graphql/mutations/syncRemoteTable'; | ||
import { GET_MANY_REMOTE_TABLES } from '@/databases/graphql/queries/findManyRemoteTables'; | ||
import { modifyRemoteTableFromCache } from '@/databases/utils/modifyRemoteTableFromCache'; | ||
import { useApolloMetadataClient } from '@/object-metadata/hooks/useApolloMetadataClient'; | ||
import { useFindManyObjectMetadataItems } from '@/object-metadata/hooks/useFindManyObjectMetadataItems'; | ||
import { CoreObjectNameSingular } from '@/object-metadata/types/CoreObjectNameSingular'; | ||
|
@@ -12,6 +12,7 @@ import { | |
SyncRemoteTableMutation, | ||
SyncRemoteTableMutationVariables, | ||
} from '~/generated-metadata/graphql'; | ||
import { isDefined } from '~/utils/isDefined'; | ||
|
||
export const useSyncRemoteTable = () => { | ||
const apolloMetadataClient = useApolloMetadataClient(); | ||
|
@@ -23,7 +24,6 @@ export const useSyncRemoteTable = () => { | |
const { findManyRecordsQuery: findManyViewsQuery } = useFindManyRecordsQuery({ | ||
objectNameSingular: CoreObjectNameSingular.View, | ||
}); | ||
|
||
const [mutate] = useMutation< | ||
SyncRemoteTableMutation, | ||
SyncRemoteTableMutationVariables | ||
|
@@ -37,20 +37,19 @@ export const useSyncRemoteTable = () => { | |
variables: { | ||
input, | ||
}, | ||
awaitRefetchQueries: true, | ||
refetchQueries: [ | ||
{ | ||
query: GET_MANY_REMOTE_TABLES, | ||
variables: { | ||
input: { | ||
id: input.remoteServerId, | ||
update: (cache, { data }) => { | ||
if (isDefined(data)) { | ||
modifyRemoteTableFromCache({ | ||
cache: cache, | ||
remoteTableName: input.name, | ||
fieldModifiers: { | ||
status: () => data.syncRemoteTable.status, | ||
}, | ||
}, | ||
}, | ||
], | ||
}); | ||
} | ||
}, | ||
}); | ||
|
||
// TODO: we should return the tables with the columns and store in cache instead of refetching | ||
await refetchObjectMetadataItems(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @thomtrp what is this for? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without it, when you sync a table and go back to main app, you will not see the remote table displayed. You would need to refresh so it re-triggers this call. |
||
await apolloClient.query({ | ||
query: findManyViewsQuery, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useCallback } from 'react'; | ||
import { ApolloClient, useMutation } from '@apollo/client'; | ||
|
||
import { SYNC_REMOTE_TABLE_SCHEMA_CHANGES } from '@/databases/graphql/mutations/syncRemoteTableSchemaChanges'; | ||
import { modifyRemoteTableFromCache } from '@/databases/utils/modifyRemoteTableFromCache'; | ||
import { useApolloMetadataClient } from '@/object-metadata/hooks/useApolloMetadataClient'; | ||
import { | ||
RemoteTableInput, | ||
SyncRemoteTableSchemaChangesMutation, | ||
SyncRemoteTableSchemaChangesMutationVariables, | ||
} from '~/generated-metadata/graphql'; | ||
import { isDefined } from '~/utils/isDefined'; | ||
export const useSyncRemoteTableSchemaChanges = () => { | ||
ijreilly marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const apolloMetadataClient = useApolloMetadataClient(); | ||
|
||
const [mutate, mutationInformation] = useMutation< | ||
SyncRemoteTableSchemaChangesMutation, | ||
SyncRemoteTableSchemaChangesMutationVariables | ||
>(SYNC_REMOTE_TABLE_SCHEMA_CHANGES, { | ||
client: apolloMetadataClient ?? ({} as ApolloClient<any>), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fallback empty object cast for |
||
}); | ||
|
||
const syncRemoteTableSchemaChanges = useCallback( | ||
async (input: RemoteTableInput) => { | ||
const remoteTable = await mutate({ | ||
variables: { | ||
input, | ||
}, | ||
update: (cache, { data }) => { | ||
if (isDefined(data)) { | ||
modifyRemoteTableFromCache({ | ||
cache: cache, | ||
remoteTableName: input.name, | ||
fieldModifiers: { | ||
schemaPendingUpdates: () => | ||
data.syncRemoteTableSchemaChanges.schemaPendingUpdates || [], | ||
}, | ||
}); | ||
} | ||
}, | ||
}); | ||
|
||
return remoteTable; | ||
}, | ||
[mutate], | ||
); | ||
|
||
return { | ||
syncRemoteTableSchemaChanges, | ||
isLoading: mutationInformation.loading, | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: Check if we have an issue when we migrate between the show page of two databases that have a table with the same name. If so we could add connectionId to the cache id to make it unique