Skip to content

Commit

Permalink
Rename component + add comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Trompette committed Apr 11, 2024
1 parent e633cd2 commit 28d98d5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import { z } from 'zod';
import { useSyncRemoteTable } from '@/databases/hooks/useSyncRemoteTable';
import { useUnsyncRemoteTable } from '@/databases/hooks/useUnsyncRemoteTable';
import { SettingsListCard } from '@/settings/components/SettingsListCard';
import { SettingsIntegrationSyncStatusToggle } from '@/settings/integrations/components/SettingsIntegrationSyncStatusToggle';
import { SettingsIntegrationRemoteTableSyncStatusToggle } from '@/settings/integrations/components/SettingsIntegrationRemoteTableSyncStatusToggle';
import { RemoteTable, RemoteTableStatus } from '~/generated-metadata/graphql';
import { isDefined } from '~/utils/isDefined';

export const settingsIntegrationsDatabaseTablesSchema = z.object({
syncedTablesByName: z.record(z.boolean()),
Expand Down Expand Up @@ -34,6 +35,7 @@ export const SettingsIntegrationDatabaseTablesListCard = ({
const { syncRemoteTable } = useSyncRemoteTable();
const { unsyncRemoteTable } = useUnsyncRemoteTable();

// We need to use a state because the table status update re-render the whole list of toggles
const [items] = useState(
tables.map((table) => ({
id: table.name,
Expand All @@ -43,10 +45,9 @@ export const SettingsIntegrationDatabaseTablesListCard = ({

const onSyncUpdate = useCallback(
async (value: boolean, tableName: string) => {
const table = items.filter((table) => table.name === tableName)[0];
const table = items.find((table) => table.name === tableName);

// eslint-disable-next-line @nx/workspace-explicit-boolean-predicates-in-if
if (!table) return;
if (!isDefined(table)) return;

if (value) {
await syncRemoteTable({
Expand All @@ -72,8 +73,8 @@ export const SettingsIntegrationDatabaseTablesListCard = ({
item: { id: string; name: string; status: RemoteTableStatus };
}) => (
<StyledRowRightContainer>
<SettingsIntegrationSyncStatusToggle
item={item}
<SettingsIntegrationRemoteTableSyncStatusToggle
table={item}
onSyncUpdate={onSyncUpdate}
/>
</StyledRowRightContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { useState } from 'react';
import { Toggle } from '@/ui/input/components/Toggle';
import { RemoteTableStatus } from '~/generated-metadata/graphql';

export const SettingsIntegrationSyncStatusToggle = ({
item: table,
export const SettingsIntegrationRemoteTableSyncStatusToggle = ({
table,
onSyncUpdate,
}: {
item: { id: string; name: string; status: RemoteTableStatus };
table: { id: string; name: string; status: RemoteTableStatus };
onSyncUpdate: (value: boolean, tableName: string) => Promise<void>;
}) => {
const [isToggleLoading, setIsToggleLoading] = useState(false);
Expand Down

0 comments on commit 28d98d5

Please sign in to comment.