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 Required in multi select & streamline column add form #703

Merged
merged 2 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ export class BaseReview {
keyword: 'emptyCheck',
schema: false,
compile: () => {
return (data) => (data === undefined || data === null || data === '' ? false : true);
return (data) =>
data === undefined || data === null || data === '' || (Array.isArray(data) && data.length === 0)
? false
: true;
},
});

Expand Down
36 changes: 18 additions & 18 deletions apps/web/components/imports/forms/ColumnForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,24 @@ export function ColumnForm({ onSubmit, data, isLoading }: ColumnFormProps) {
)}
/>
) : null}
{typeValue === ColumnTypesEnum.REGEX && (
<>
<Input
required
{...register('regex')}
label="Regular expression"
error={errors.regex?.message}
placeholder="Regular expression"
/>
<Textarea
autosize
minRows={2}
label="Regular expression description"
placeholder="Regular expression description"
register={register('regexDescription')}
/>
</>
)}
<Controller
name="defaultValue"
control={control}
Expand Down Expand Up @@ -204,24 +222,6 @@ export function ColumnForm({ onSubmit, data, isLoading }: ColumnFormProps) {
register={register('isRequired')}
description="User have to map this column with uploaded column during map column step and value must be filled during review step."
/>
{typeValue === ColumnTypesEnum.REGEX && (
<>
<Input
required
{...register('regex')}
label="Regular expression"
error={errors.regex?.message}
placeholder="Regular expression"
/>
<Textarea
autosize
minRows={2}
label="Regular expression description"
placeholder="Regular expression description"
register={register('regexDescription')}
/>
</>
)}
{typeValue === ColumnTypesEnum.SELECT ? (
<Checkbox
label="Multi Select Values"
Expand Down
22 changes: 16 additions & 6 deletions apps/web/components/imports/schema/ColumnsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ColumnsTableProps {
}

export function ColumnsTable({ templateId }: ColumnsTableProps) {
const SelectRef = useRef(false);
const ValidationRef = useRef(false);

const {
columns,
Expand Down Expand Up @@ -52,7 +52,7 @@ export function ColumnsTable({ templateId }: ColumnsTableProps) {
onSubmit={(e) => {
handleSubmit();
e.preventDefault();
SelectRef.current = false;
ValidationRef.current = false;
}}
id="columns"
>
Expand Down Expand Up @@ -128,19 +128,29 @@ export function ColumnsTable({ templateId }: ColumnsTableProps) {
placeholder="Select Type"
variant="default"
register={field}
autoFocus={SelectRef.current}
onFocus={() => (SelectRef.current = true)}
/>
)}
/>
<Button size="xs" color="green" onClick={onValidationsButtonClick}>
<Button
size="xs"
color="green"
onClick={() => {
ValidationRef.current = true;
onValidationsButtonClick();
}}
>
Validations
</Button>
</Flex>
</td>
<td style={{ borderLeft: 'none' }}>
<Flex justify={'end'}>
<ActionIcon color="blue" type="submit" loading={isColumnCreateLoading}>
<ActionIcon
color="blue"
type="submit"
autoFocus={ValidationRef.current}
loading={isColumnCreateLoading}
>
<CheckIcon color={colors.blue} />
</ActionIcon>
<ActionIcon color="red" onClick={() => setShowAddRow(false)}>
Expand Down
17 changes: 16 additions & 1 deletion apps/web/hooks/useSchema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,22 @@ export function useSchema({ templateId }: UseSchemaProps) {
hasExtraColumnKeys: boolean;
},
});
reset({});
reset({
name: undefined,
key: undefined,
type: 'String',
alternateKeys: [],
isRequired: false,
isUnique: false,
isFrozen: false,
regex: undefined,
delimiter: undefined,
dateFormats: [],
defaultValue: undefined,
regexDescription: undefined,
selectValues: [],
allowMultiSelect: false,
});
setFocus('name');
},
onError: (error: IErrorObject) => {
Expand Down
Loading