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 UGN-232 - toast that warns about matching one field twice #58

Merged
merged 3 commits into from
Mar 11, 2022
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
2 changes: 1 addition & 1 deletion src/components/Selects/MatchColumnSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ interface Props {
export const MatchColumnSelect = ({ onChange, value, options, placeholder }: Props) => {
return (
<Select
value={value}
value={value || null}
onChange={onChange}
placeholder={placeholder}
options={options}
Expand Down
24 changes: 22 additions & 2 deletions src/steps/MatchColumnsStep/MatchColumnsStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { Field } from "../../types"
import { getMatchedColumns } from "./utils/getMatchedColumns"
import { UnmatchedFieldsAlert } from "../../components/Alerts/UnmatchedFieldsAlert"
import { findUnmatchedRequiredFields } from "./utils/findUnmatchedRequiredFields"
import { useToast } from "@chakra-ui/react"

export type MatchColumnsProps = {
data: string[][]
Expand Down Expand Up @@ -62,8 +63,9 @@ export type Column<T extends string> =
export type Columns<T extends string> = Column<T>[]

export const MatchColumnsStep = <T extends string>({ data, headerValues, onContinue }: MatchColumnsProps) => {
const toast = useToast()
const dataExample = data.slice(0, 2)
const { fields, autoMapHeaders, autoMapDistance } = useRsi<T>()
const { fields, autoMapHeaders, autoMapDistance, translations } = useRsi<T>()
const [columns, setColumns] = useState<Columns<T>>(
headerValues.map((value, index) => ({ type: ColumnType.empty, index, header: value })),
)
Expand All @@ -72,8 +74,26 @@ export const MatchColumnsStep = <T extends string>({ data, headerValues, onConti
const onChange = useCallback(
(value: T, columnIndex: number) => {
const field = fields.find((field) => field.key === value) as unknown as Field<T>
const existingFieldIndex = columns.findIndex((column) => "value" in column && column.value === field.key)
setColumns(
columns.map<Column<T>>((column, index) => (columnIndex === index ? setColumn(column, field, data) : column)),
columns.map<Column<T>>((column, index) => {
columnIndex === index ? setColumn(column, field, data) : column
if (columnIndex === index) {
return setColumn(column, field, data)
} else if (index === existingFieldIndex) {
toast({
status: "warning",
variant: "left-accent",
position: "bottom-left",
title: translations.matchColumnsStep.duplicateColumnWarningTitle,
description: translations.matchColumnsStep.duplicateColumnWarningDescription,
isClosable: true,
})
return setColumn(column)
} else {
return column
}
}),
)
},
[columns, setColumns],
Expand Down
2 changes: 2 additions & 0 deletions src/steps/UploadFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const UploadFlow = ({ nextStep }: Props) => {
variant: "left-accent",
position: "bottom-left",
title: `${translations.uploadStep.maxRecordsExceeded(maxRecords.toString())}`,
isClosable: true,
})
}
setState({ type: Type.selectHeader, data: mapWorkbook(workbook) })
Expand All @@ -82,6 +83,7 @@ export const UploadFlow = ({ nextStep }: Props) => {
variant: "left-accent",
position: "bottom-left",
title: `${translations.uploadStep.maxRecordsExceeded(maxRecords.toString())}`,
isClosable: true,
})
}
setState({ type: Type.selectHeader, data: mapWorkbook(state.workbook, sheetName) })
Expand Down
1 change: 1 addition & 0 deletions src/steps/UploadStep/components/DropZone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const DropZone = ({ onContinue }: DropZoneProps) => {
position: "bottom-left",
title: `${fileRejection.file.name} ${translations.uploadStep.dropzone.errorToastDescription}`,
description: fileRejection.errors[0].message,
isClosable: true,
})
})
},
Expand Down
2 changes: 2 additions & 0 deletions src/translationsRSIProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const translations = {
subSelectPlaceholder: "Select...",
matchDropdownTitle: "Match",
unmatched: "Unmatched",
duplicateColumnWarningTitle: "Another column unselected",
duplicateColumnWarningDescription: "Columns cannot duplicate",
},
validationStep: {
title: "Validate data",
Expand Down