Files
twenty/packages/twenty-front/src/modules/settings/integrations/database-connection/components/SettingsIntegrationDatabaseConnectionSyncStatus.tsx
T
Marie d741f4a5bd 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
2024-05-16 17:31:34 +02:00

49 lines
1.3 KiB
TypeScript

import { useGetDatabaseConnectionTables } from '@/databases/hooks/useGetDatabaseConnectionTables';
import { Status } from '@/ui/display/status/components/Status';
import { RemoteTableStatus } from '~/generated-metadata/graphql';
import { isDefined } from '~/utils/isDefined';
type SettingsIntegrationDatabaseConnectionSyncStatusProps = {
connectionId: string;
skip?: boolean;
};
export const SettingsIntegrationDatabaseConnectionSyncStatus = ({
connectionId,
skip,
}: SettingsIntegrationDatabaseConnectionSyncStatusProps) => {
const { tables, error } = useGetDatabaseConnectionTables({
connectionId,
skip,
});
if (isDefined(error)) {
return <Status color="red" text="Connection failed" />;
}
const syncedTables = tables.filter(
(table) => table.status === RemoteTableStatus.Synced,
);
const updatesAvailable = tables.some(
(table) =>
table.schemaPendingUpdates?.length &&
table.schemaPendingUpdates.length > 0,
);
return (
<Status
color={updatesAvailable ? 'yellow' : 'green'}
text={
syncedTables.length === 1
? `1 tracked table${
updatesAvailable ? ' (with pending schema updates)' : ''
}`
: `${syncedTables.length} tracked tables${
updatesAvailable ? ' (with pending schema updates)' : ''
}`
}
/>
);
};