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

Don't display unmatched columns in csv import #6037

Merged
merged 4 commits into from
Jun 26, 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 @@ -12,7 +12,7 @@ import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/Snac
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { Modal } from '@/ui/layout/modal/components/Modal';

import { MatchColumnsStep } from './MatchColumnsStep/MatchColumnsStep';
import { Columns, MatchColumnsStep } from './MatchColumnsStep/MatchColumnsStep';
import { SelectHeaderStep } from './SelectHeaderStep/SelectHeaderStep';
import { SelectSheetStep } from './SelectSheetStep/SelectSheetStep';
import { UploadStep } from './UploadStep/UploadStep';
Expand Down Expand Up @@ -52,6 +52,7 @@ export type StepState =
| {
type: StepType.validateData;
data: any[];
importedColumns: Columns<string>;
}
| {
type: StepType.loading;
Expand Down Expand Up @@ -216,6 +217,7 @@ export const UploadFlow = ({ nextStep, prevStep }: UploadFlowProps) => {
setState({
type: StepType.validateData,
data,
importedColumns: columns,
});
setPreviousState(state);
nextStep();
Expand All @@ -233,6 +235,7 @@ export const UploadFlow = ({ nextStep, prevStep }: UploadFlowProps) => {
return (
<ValidationStep
initialData={state.data}
importedColumns={state.importedColumns}
file={uploadedFile}
onSubmitStart={() =>
setState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { Heading } from '@/spreadsheet-import/components/Heading';
import { StepNavigationButton } from '@/spreadsheet-import/components/StepNavigationButton';
import { Table } from '@/spreadsheet-import/components/Table';
import { useSpreadsheetImportInternal } from '@/spreadsheet-import/hooks/useSpreadsheetImportInternal';
import {
Columns,
ColumnType,
} from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep';
import { Data } from '@/spreadsheet-import/types';
import { addErrorsAndRunHooks } from '@/spreadsheet-import/utils/dataMutations';
import { useDialogManager } from '@/ui/feedback/dialog-manager/hooks/useDialogManager';
Expand Down Expand Up @@ -62,13 +66,15 @@ const StyledNoRowsContainer = styled.div`

type ValidationStepProps<T extends string> = {
initialData: Data<T>[];
importedColumns: Columns<string>;
file: File;
onSubmitStart?: () => void;
onBack: () => void;
};

export const ValidationStep = <T extends string>({
initialData,
importedColumns,
file,
onSubmitStart,
onBack,
Expand All @@ -88,6 +94,7 @@ export const ValidationStep = <T extends string>({
ReadonlySet<number | string>
>(new Set());
const [filterByErrors, setFilterByErrors] = useState(false);
const [showUnmatchedColumns, setShowUnmatchedColumns] = useState(false);

const updateData = useCallback(
(rows: typeof data) => {
Expand Down Expand Up @@ -127,7 +134,24 @@ export const ValidationStep = <T extends string>({
[data, updateData],
);

const columns = useMemo(() => generateColumns(fields), [fields]);
const columns = useMemo(
() =>
generateColumns(fields)
.map((column) => {
const hasBeenImported =
importedColumns.filter(
(importColumn) =>
(importColumn.type === ColumnType.matched &&
importColumn.value === column.key) ||
column.key === 'select-row',
).length > 0;

if (!hasBeenImported && !showUnmatchedColumns) return null;
return column;
})
.filter(Boolean),
[fields, importedColumns, showUnmatchedColumns],
);

const tableData = useMemo(() => {
if (filterByErrors) {
Expand Down Expand Up @@ -212,6 +236,15 @@ export const ValidationStep = <T extends string>({
Show only rows with errors
</StyledErrorToggleDescription>
</StyledErrorToggle>
<StyledErrorToggle>
<Toggle
value={showUnmatchedColumns}
onChange={() => setShowUnmatchedColumns(!showUnmatchedColumns)}
/>
<StyledErrorToggleDescription>
Show unmatched columns
</StyledErrorToggleDescription>
</StyledErrorToggle>
<Button
Icon={IconTrash}
title="Remove"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Providers } from '@/spreadsheet-import/components/Providers';
import { ValidationStep } from '@/spreadsheet-import/steps/components/ValidationStep/ValidationStep';
import {
editableTableInitialData,
importedColums,
mockRsiValues,
} from '@/spreadsheet-import/tests/mockRsiValues';
import { DialogManagerScope } from '@/ui/feedback/dialog-manager/scopes/DialogManagerScope';
Expand All @@ -28,6 +29,7 @@ export const Default = () => (
<ValidationStep
initialData={editableTableInitialData}
file={file}
importedColumns={importedColums}
onBack={() => Promise.resolve()}
/>
</ModalWrapper>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defaultSpreadsheetImportProps } from '@/spreadsheet-import/provider/components/SpreadsheetImport';
import { Columns } from '@/spreadsheet-import/steps/components/MatchColumnsStep/MatchColumnsStep';
import { Fields, SpreadsheetOptions } from '@/spreadsheet-import/types';
import { sleep } from '~/utils/sleep';

Expand Down Expand Up @@ -88,6 +89,33 @@ const fields = [
},
] as Fields<string>;

export const importedColums: Columns<string> = [
{
header: 'Name',
index: 0,
type: 2,
value: 'name',
},
{
header: 'Surname',
index: 1,
type: 2,
value: 'surname',
},
{
header: 'Age',
index: 2,
type: 2,
value: 'age',
},
{
header: 'Team',
index: 3,
type: 2,
value: 'team',
},
];

const mockComponentBehaviourForTypes = <T extends string>(
props: SpreadsheetOptions<T>,
) => props;
Expand Down
67 changes: 34 additions & 33 deletions packages/twenty-front/src/testing/graphqlMocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,43 +157,44 @@ export const graphqlMocks = {
graphql.query('FindDuplicateCompany', () => {
return HttpResponse.json({
data: {
companyDuplicates: {
edges: [
{
node: {
...duplicateCompanyMock,
favorites: {
edges: [],
__typename: 'FavoriteConnection',
},
attachments: {
edges: [],
__typename: 'AttachmentConnection',
},
people: {
edges: [],
__typename: 'PersonConnection',
},
opportunities: {
edges: [],
__typename: 'OpportunityConnection',
},
activityTargets: {
edges: [],
__typename: 'ActivityTargetConnection',
companyDuplicates: [
{
edges: [
{
node: {
...duplicateCompanyMock,
favorites: {
edges: [],
__typename: 'FavoriteConnection',
},
attachments: {
edges: [],
__typename: 'AttachmentConnection',
},
people: {
edges: [],
__typename: 'PersonConnection',
},
opportunities: {
edges: [],
__typename: 'OpportunityConnection',
},
activityTargets: {
edges: [],
__typename: 'ActivityTargetConnection',
},
},
cursor: null,
},
cursor: null,
],
pageInfo: {
hasNextPage: false,
hasPreviousPage: false,
startCursor: null,
endCursor: null,
},
],
pageInfo: {
hasNextPage: false,
hasPreviousPage: false,
startCursor: null,
endCursor: null,
},
totalCount: 1,
},
],
},
});
}),
Expand Down
Loading