Skip to content
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

feat: Showed delimiter on multi-select dropdown only #687

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions apps/web/components/imports/forms/ColumnForm.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import Link from 'next/link';
import { modals } from '@mantine/modals';
import { Controller, useForm } from 'react-hook-form';
import { Stack, TextInput as Input, Text, Divider, SimpleGrid, Title, Group, CloseButton, Select } from '@mantine/core';
import {
Stack,
TextInput as Input,
Text,
Divider,
SimpleGrid,
Title,
Group,
CloseButton,
Select,
useMantineColorScheme,
} from '@mantine/core';

import { ColumnTypesEnum, DEFAULT_VALUES, IColumn } from '@impler/shared';
import { colors, COLUMN_TYPES, DELIMITERS, MODAL_KEYS, MODAL_TITLES } from '@config';
Expand All @@ -19,6 +30,7 @@ interface ColumnFormProps {
}

export function ColumnForm({ onSubmit, data, isLoading }: ColumnFormProps) {
const { colorScheme } = useMantineColorScheme();
const {
watch,
control,
Expand All @@ -29,6 +41,7 @@ export function ColumnForm({ onSubmit, data, isLoading }: ColumnFormProps) {
defaultValues: data,
});
const typeValue = watch('type');
const multiSelectValue = watch('allowMultiSelect');

const onClose = () => {
modals.close(MODAL_KEYS.COLUMN_UPDATE);
Expand Down Expand Up @@ -129,21 +142,6 @@ export function ColumnForm({ onSubmit, data, isLoading }: ColumnFormProps) {
/>
)}
/>
<Controller
name="delimiter"
control={control}
render={({ field: { value, onChange } }) => (
<Select
label="Delimiter"
data={DELIMITERS}
placeholder="Comma (,)"
value={value}
data-autofocus
onChange={onChange}
description="Delimiter used to separate multiple select values"
/>
)}
/>
</>
) : null}
{typeValue === ColumnTypesEnum.DATE ? (
Expand Down Expand Up @@ -199,7 +197,7 @@ export function ColumnForm({ onSubmit, data, isLoading }: ColumnFormProps) {
)}
/>
</Stack>
<Stack spacing="sm" p="xs" bg={colors.BGSecondaryDark}>
<Stack spacing="sm" p="xs" bg={colorScheme === 'dark' ? colors.BGSecondaryDark : colors.BGSecondaryLight}>
<Title order={5}>Column Validations</Title>
<Checkbox
label="Required Values"
Expand Down Expand Up @@ -237,6 +235,24 @@ export function ColumnForm({ onSubmit, data, isLoading }: ColumnFormProps) {
description="Users will be required to resolve any duplicated values inside of this column prior to import."
/>
)}
{multiSelectValue && typeValue === ColumnTypesEnum.SELECT ? (
<Controller
name="delimiter"
control={control}
render={({ field: { value, onChange } }) => (
<Select
label="Delimiter"
data={DELIMITERS}
placeholder="Comma (,)"
value={value}
data-autofocus
defaultValue=","
onChange={onChange}
description="Delimiter used to separate multiple select values"
/>
)}
/>
) : null}
<Checkbox
label="Freeze Column"
register={register('isFrozen')}
Expand Down
Loading