feat: add Tables settings to Settings/Integrations/Database/Connectio… (#4851)

…n page

Closes #4560
This commit is contained in:
Thaïs
2024-04-05 18:12:54 +02:00
committed by GitHub
parent f4017119ab
commit bbdb926687
5 changed files with 112 additions and 31 deletions

View File

@ -0,0 +1,50 @@
import { Controller, useFormContext } from 'react-hook-form';
import styled from '@emotion/styled';
import { z } from 'zod';
import { SettingsListCard } from '@/settings/components/SettingsListCard';
import { Toggle } from '@/ui/input/components/Toggle';
export const settingsIntegrationsDatabaseTablesSchema = z.object({
syncedTablesById: z.record(z.boolean()),
});
export type SettingsIntegrationsDatabaseTablesFormValues = z.infer<
typeof settingsIntegrationsDatabaseTablesSchema
>;
type SettingsIntegrationDatabaseTablesListCardProps = {
tables: { id: string; name: string; isSynced?: boolean }[];
};
const StyledRowRightContainer = styled.div`
align-items: center;
display: flex;
gap: ${({ theme }) => theme.spacing(1)};
`;
export const SettingsIntegrationDatabaseTablesListCard = ({
tables,
}: SettingsIntegrationDatabaseTablesListCardProps) => {
const { control } =
useFormContext<SettingsIntegrationsDatabaseTablesFormValues>();
return (
<SettingsListCard
items={tables}
RowRightComponent={({ item: table }) => (
<StyledRowRightContainer>
<Controller
name={`syncedTablesById.${table.id}`}
control={control}
defaultValue={!!table.isSynced}
render={({ field: { onChange, value } }) => (
<Toggle value={value} onChange={onChange} />
)}
/>
</StyledRowRightContainer>
)}
getItemLabel={(table) => table.name}
/>
);
};