Minor refacto and fixes on Remotes updates (#5438)
In this PR - Code refactoring - v0 of adding "updates available" info in Connection sync status <img width="835" alt="Capture d’écran 2024-05-16 à 17 02 07" src="https://github.com/twentyhq/twenty/assets/51697796/9674d3ca-bed2-4520-a5a6-ba37bc242d06"> - fix distant table columns with not-camel case names are always considered as new
This commit is contained in:
@ -250,6 +250,14 @@ export type DeleteOneRelationInput = {
|
||||
id: Scalars['UUID']['input'];
|
||||
};
|
||||
|
||||
/** Schema update on a table */
|
||||
export enum DistantTableUpdate {
|
||||
ColumnsAdded = 'COLUMNS_ADDED',
|
||||
ColumnsDeleted = 'COLUMNS_DELETED',
|
||||
ColumnsTypeChanged = 'COLUMNS_TYPE_CHANGED',
|
||||
TableDeleted = 'TABLE_DELETED'
|
||||
}
|
||||
|
||||
export type EmailPasswordResetLink = {
|
||||
__typename?: 'EmailPasswordResetLink';
|
||||
/** Boolean that confirms query was dispatched */
|
||||
@ -330,8 +338,6 @@ export enum FileFolder {
|
||||
export type FindManyRemoteTablesInput = {
|
||||
/** The id of the remote server. */
|
||||
id: Scalars['ID']['input'];
|
||||
/** Indicates if data from distant tables should be refreshed. */
|
||||
refreshData?: InputMaybe<Scalars['Boolean']['input']>;
|
||||
};
|
||||
|
||||
export type FullName = {
|
||||
@ -812,7 +818,7 @@ export type RemoteTable = {
|
||||
id?: Maybe<Scalars['UUID']['output']>;
|
||||
name: Scalars['String']['output'];
|
||||
schema?: Maybe<Scalars['String']['output']>;
|
||||
schemaPendingUpdates?: Maybe<Array<TableUpdate>>;
|
||||
schemaPendingUpdates?: Maybe<Array<DistantTableUpdate>>;
|
||||
status: RemoteTableStatus;
|
||||
};
|
||||
|
||||
@ -857,14 +863,6 @@ export type Support = {
|
||||
supportFrontChatId?: Maybe<Scalars['String']['output']>;
|
||||
};
|
||||
|
||||
/** Schema update on a table */
|
||||
export enum TableUpdate {
|
||||
ColumnsAdded = 'COLUMNS_ADDED',
|
||||
ColumnsDeleted = 'COLUMNS_DELETED',
|
||||
ColumnsTypeChanged = 'COLUMNS_TYPE_CHANGED',
|
||||
TableDeleted = 'TABLE_DELETED'
|
||||
}
|
||||
|
||||
export type Telemetry = {
|
||||
__typename?: 'Telemetry';
|
||||
anonymizationEnabled: Scalars['Boolean']['output'];
|
||||
@ -1261,7 +1259,7 @@ export type RelationEdge = {
|
||||
|
||||
export type RemoteServerFieldsFragment = { __typename?: 'RemoteServer', id: string, createdAt: any, foreignDataWrapperId: string, foreignDataWrapperOptions?: any | null, foreignDataWrapperType: string, updatedAt: any, schema?: string | null, userMappingOptions?: { __typename?: 'UserMappingOptionsUser', user?: string | null } | null };
|
||||
|
||||
export type RemoteTableFieldsFragment = { __typename?: 'RemoteTable', id?: any | null, name: string, schema?: string | null, status: RemoteTableStatus, schemaPendingUpdates?: Array<TableUpdate> | null };
|
||||
export type RemoteTableFieldsFragment = { __typename?: 'RemoteTable', id?: any | null, name: string, schema?: string | null, status: RemoteTableStatus, schemaPendingUpdates?: Array<DistantTableUpdate> | null };
|
||||
|
||||
export type CreateServerMutationVariables = Exact<{
|
||||
input: CreateRemoteServerInput;
|
||||
@ -1282,14 +1280,14 @@ export type SyncRemoteTableMutationVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type SyncRemoteTableMutation = { __typename?: 'Mutation', syncRemoteTable: { __typename?: 'RemoteTable', id?: any | null, name: string, schema?: string | null, status: RemoteTableStatus, schemaPendingUpdates?: Array<TableUpdate> | null } };
|
||||
export type SyncRemoteTableMutation = { __typename?: 'Mutation', syncRemoteTable: { __typename?: 'RemoteTable', id?: any | null, name: string, schema?: string | null, status: RemoteTableStatus, schemaPendingUpdates?: Array<DistantTableUpdate> | null } };
|
||||
|
||||
export type UnsyncRemoteTableMutationVariables = Exact<{
|
||||
input: RemoteTableInput;
|
||||
}>;
|
||||
|
||||
|
||||
export type UnsyncRemoteTableMutation = { __typename?: 'Mutation', unsyncRemoteTable: { __typename?: 'RemoteTable', id?: any | null, name: string, schema?: string | null, status: RemoteTableStatus, schemaPendingUpdates?: Array<TableUpdate> | null } };
|
||||
export type UnsyncRemoteTableMutation = { __typename?: 'Mutation', unsyncRemoteTable: { __typename?: 'RemoteTable', id?: any | null, name: string, schema?: string | null, status: RemoteTableStatus, schemaPendingUpdates?: Array<DistantTableUpdate> | null } };
|
||||
|
||||
export type UpdateServerMutationVariables = Exact<{
|
||||
input: UpdateRemoteServerInput;
|
||||
@ -1310,7 +1308,7 @@ export type GetManyRemoteTablesQueryVariables = Exact<{
|
||||
}>;
|
||||
|
||||
|
||||
export type GetManyRemoteTablesQuery = { __typename?: 'Query', findAvailableRemoteTablesByServerId: Array<{ __typename?: 'RemoteTable', id?: any | null, name: string, schema?: string | null, status: RemoteTableStatus, schemaPendingUpdates?: Array<TableUpdate> | null }> };
|
||||
export type GetManyRemoteTablesQuery = { __typename?: 'Query', findAvailableRemoteTablesByServerId: Array<{ __typename?: 'RemoteTable', id?: any | null, name: string, schema?: string | null, status: RemoteTableStatus, schemaPendingUpdates?: Array<DistantTableUpdate> | null }> };
|
||||
|
||||
export type GetOneDatabaseConnectionQueryVariables = Exact<{
|
||||
input: RemoteServerIdInput;
|
||||
|
||||
@ -10,13 +10,11 @@ import {
|
||||
type UseGetDatabaseConnectionTablesParams = {
|
||||
connectionId: string;
|
||||
skip?: boolean;
|
||||
refreshData?: boolean;
|
||||
};
|
||||
|
||||
export const useGetDatabaseConnectionTables = ({
|
||||
connectionId,
|
||||
skip,
|
||||
refreshData,
|
||||
}: UseGetDatabaseConnectionTablesParams) => {
|
||||
const apolloMetadataClient = useApolloMetadataClient();
|
||||
|
||||
@ -29,7 +27,6 @@ export const useGetDatabaseConnectionTables = ({
|
||||
variables: {
|
||||
input: {
|
||||
id: connectionId,
|
||||
refreshData: refreshData,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@ -25,13 +25,23 @@ export const SettingsIntegrationDatabaseConnectionSyncStatus = ({
|
||||
(table) => table.status === RemoteTableStatus.Synced,
|
||||
);
|
||||
|
||||
const updatesAvailable = tables.some(
|
||||
(table) =>
|
||||
table.schemaPendingUpdates?.length &&
|
||||
table.schemaPendingUpdates.length > 0,
|
||||
);
|
||||
|
||||
return (
|
||||
<Status
|
||||
color="green"
|
||||
color={updatesAvailable ? 'yellow' : 'green'}
|
||||
text={
|
||||
syncedTables.length === 1
|
||||
? `1 tracked table`
|
||||
: `${syncedTables.length} tracked tables`
|
||||
? `1 tracked table${
|
||||
updatesAvailable ? ' (with pending schema updates)' : ''
|
||||
}`
|
||||
: `${syncedTables.length} tracked tables${
|
||||
updatesAvailable ? ' (with pending schema updates)' : ''
|
||||
}`
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
@ -7,9 +7,9 @@ import { useUnsyncRemoteTable } from '@/databases/hooks/useUnsyncRemoteTable';
|
||||
import { SettingsListCard } from '@/settings/components/SettingsListCard';
|
||||
import { SettingsIntegrationRemoteTableSyncStatusToggle } from '@/settings/integrations/components/SettingsIntegrationRemoteTableSyncStatusToggle';
|
||||
import {
|
||||
DistantTableUpdate,
|
||||
RemoteTable,
|
||||
RemoteTableStatus,
|
||||
TableUpdate,
|
||||
} from '~/generated-metadata/graphql';
|
||||
import { isDefined } from '~/utils/isDefined';
|
||||
|
||||
@ -39,20 +39,22 @@ const StyledText = styled.h3`
|
||||
margin: 0;
|
||||
`;
|
||||
|
||||
const getTableUpdatesText = (schemaPendingUpdates: TableUpdate[]) => {
|
||||
if (schemaPendingUpdates.includes(TableUpdate.TableDeleted)) {
|
||||
const getDistantTableUpdatesText = (
|
||||
schemaPendingUpdates: DistantTableUpdate[],
|
||||
) => {
|
||||
if (schemaPendingUpdates.includes(DistantTableUpdate.TableDeleted)) {
|
||||
return 'Table has been deleted';
|
||||
}
|
||||
if (
|
||||
schemaPendingUpdates.includes(TableUpdate.ColumnsAdded) &&
|
||||
schemaPendingUpdates.includes(TableUpdate.ColumnsDeleted)
|
||||
schemaPendingUpdates.includes(DistantTableUpdate.ColumnsAdded) &&
|
||||
schemaPendingUpdates.includes(DistantTableUpdate.ColumnsDeleted)
|
||||
) {
|
||||
return 'Columns have been added and other deleted';
|
||||
}
|
||||
if (schemaPendingUpdates.includes(TableUpdate.ColumnsAdded)) {
|
||||
if (schemaPendingUpdates.includes(DistantTableUpdate.ColumnsAdded)) {
|
||||
return 'Columns have been added';
|
||||
}
|
||||
if (schemaPendingUpdates.includes(TableUpdate.ColumnsDeleted)) {
|
||||
if (schemaPendingUpdates.includes(DistantTableUpdate.ColumnsDeleted)) {
|
||||
return 'Columns have been deleted';
|
||||
}
|
||||
return null;
|
||||
@ -71,7 +73,7 @@ export const SettingsIntegrationDatabaseTablesListCard = ({
|
||||
...table,
|
||||
id: table.name,
|
||||
updatesText: table.schemaPendingUpdates
|
||||
? getTableUpdatesText(table.schemaPendingUpdates)
|
||||
? getDistantTableUpdatesText(table.schemaPendingUpdates)
|
||||
: null,
|
||||
})),
|
||||
);
|
||||
|
||||
@ -42,7 +42,6 @@ export const useDatabaseConnection = () => {
|
||||
const { tables } = useGetDatabaseConnectionTables({
|
||||
connectionId,
|
||||
skip: !connection,
|
||||
refreshData: true,
|
||||
});
|
||||
|
||||
return { connection, integration, databaseKey, tables };
|
||||
|
||||
Reference in New Issue
Block a user