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

Import configuration/mapping preview #1664

Merged
merged 51 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1a50dcd
create MappingPreview
kaulfield23 Nov 15, 2023
94624a6
implement preview previous, next data
kaulfield23 Nov 16, 2023
040b2d6
create empty boxes which indicates no previews
kaulfield23 Nov 16, 2023
f3bcdfb
empty grey box to indicate empty value
kaulfield23 Nov 16, 2023
c31a55d
fetch data from store
kaulfield23 Nov 17, 2023
e271950
Merge branch 'import-configuration/mapping' into import-configuration…
kaulfield23 Nov 21, 2023
baeb138
fetch column fields names first and render it for testing
kaulfield23 Nov 21, 2023
398ec5e
render column and row at the same time
kaulfield23 Nov 22, 2023
6ef708d
display fields in preview
kaulfield23 Nov 22, 2023
da380bc
fix empty box length
kaulfield23 Nov 22, 2023
56e1c32
Merge branch 'import-configuration/mapping' into import-configuration…
kaulfield23 Nov 22, 2023
2b3b2d2
render ID column
kaulfield23 Nov 23, 2023
15d019a
separate preview with values component
kaulfield23 Nov 23, 2023
60ab630
display org's name when org column is mapped
kaulfield23 Nov 23, 2023
6f7d3b2
change name
kaulfield23 Nov 23, 2023
e5ef2d8
display tags in preview
kaulfield23 Nov 23, 2023
48b0e29
fix style for many columns in preview
kaulfield23 Nov 24, 2023
d49db3e
change prop name, height
kaulfield23 Nov 24, 2023
a22a254
remove fake data
kaulfield23 Nov 24, 2023
8d08f59
change components name
kaulfield23 Nov 24, 2023
1798969
add key to mappedPreivew
kaulfield23 Nov 27, 2023
4dfaaec
remove tenary operator
kaulfield23 Nov 27, 2023
8a98438
create RowValue, and render empty message when row value is empty
kaulfield23 Nov 29, 2023
ff6b581
Merge branch 'epic-1595/import' into import-configuration/mapping-pre…
kaulfield23 Nov 29, 2023
e1ca8a4
render different value depends on column kind
kaulfield23 Nov 29, 2023
3ba3349
display number of additioanl tags
kaulfield23 Nov 29, 2023
c645901
fix reduce logic, add tagColumnIndex in object in mapping
kaulfield23 Nov 29, 2023
4c1411c
Merge branch 'epic-1595/import' into import-configuration/mapping-pre…
kaulfield23 Nov 30, 2023
79c9d87
create usePersonPerview and FieldsPreview. Render fields only
kaulfield23 Nov 30, 2023
3310493
create PreviewGrid, refactor field column
kaulfield23 Nov 30, 2023
2a92c59
create TagsPreview, fix prepareImportOperations when tags are dupilic…
kaulfield23 Nov 30, 2023
c418cf1
multiple unmapped values in tag column, render tags
kaulfield23 Nov 30, 2023
0376230
display grey box when tags columns are selected. Remove them when the…
kaulfield23 Dec 1, 2023
4a5cc6f
remove RowValue component, add rowValue prop instead. Fix tags column…
kaulfield23 Dec 1, 2023
9a7c284
add condition for Id field
kaulfield23 Dec 1, 2023
ae5662c
remove MappedPreview, fix logic for duplicated orgIds in prepareOps, …
kaulfield23 Dec 3, 2023
c5d7b08
add test for duplicated ids
kaulfield23 Dec 3, 2023
b9ef482
create prepareImportOperationsForRow and its test
kaulfield23 Dec 3, 2023
309a06b
use prepareImportOperationsForRow in usePersonPreview changes relevan…
kaulfield23 Dec 3, 2023
305ab54
disable choosing multiple orgs in select
kaulfield23 Dec 4, 2023
12e07eb
fix prepareImportOps returing one org column's orgIds
kaulfield23 Dec 4, 2023
5159a5e
pass org instead of array of orgs to OrgPreview
kaulfield23 Dec 4, 2023
708121a
change idField logic for id null
kaulfield23 Dec 4, 2023
16e24b1
rename fields to data
kaulfield23 Dec 4, 2023
1ca001f
separate createPreviewData function. Rename key organizations
kaulfield23 Dec 4, 2023
1d5eae2
fix tags logic in createPreviewData when tag has id but its value is …
kaulfield23 Dec 4, 2023
fa4a35d
rename organization to organizations
kaulfield23 Dec 5, 2023
e8d9df2
remove inner describe
kaulfield23 Dec 5, 2023
6ec157b
use globalMessages to column header for idField
kaulfield23 Dec 5, 2023
c020a2d
use prev instead of presonIndex, give hard coded number to margin
kaulfield23 Dec 5, 2023
ed5ca34
add emptyLabel prop, move empty value component to PreviewGrid
kaulfield23 Dec 5, 2023
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
47 changes: 47 additions & 0 deletions src/features/import/components/Configure/Preview/FieldsPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import globalMessageIds from 'core/i18n/globalMessageIds';
import messageIds from 'features/import/l10n/messageIds';
import PreviewGrid from './PreviewGrid';
import useColumnOptions from 'features/import/hooks/useColumnOptions';
import { useMessages } from 'core/i18n';
import { useNumericRouteParams } from 'core/hooks';
import { CellData, ColumnKind } from 'features/import/utils/types';

interface FieldsPreviewProps {
fieldKey: string | null;
fields: Record<string, CellData> | undefined;
kind: ColumnKind;
}
const FieldsPreview = ({ fieldKey, fields, kind }: FieldsPreviewProps) => {
const { orgId } = useNumericRouteParams();
const columnOptions = useColumnOptions(orgId);
const globalMessages = useMessages(globalMessageIds);
const messages = useMessages(messageIds);

let idColumnHeader = '';

if (kind === ColumnKind.ID_FIELD) {
idColumnHeader =
fieldKey === 'id'
? globalMessages.personFields.id()
: fieldKey === 'ext_id'
? globalMessages.personFields.ext_id()
: '';
}

let fieldColumnHeader = '';
columnOptions.forEach((columnOp) => {
if (columnOp.value === `field:${fieldKey}`) {
fieldColumnHeader = columnOp.label;
}
});
const fieldValue = fields?.[fieldKey!];
return (
<PreviewGrid
columnHeader={idColumnHeader || fieldColumnHeader}
emptyLabel={!fieldValue ? messages.configuration.preview.noValue() : ''}
rowValue={(fieldKey === null && fields?.['null']) || fieldValue || ''}
/>
);
};

export default FieldsPreview;
32 changes: 32 additions & 0 deletions src/features/import/components/Configure/Preview/OrgPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import messageIds from 'features/import/l10n/messageIds';
import PreviewGrid from './PreviewGrid';
import { useMessages } from 'core/i18n';
import { ZetkinOrganization } from 'utils/types/zetkin';
import { ColumnKind, Sheet } from 'features/import/utils/types';

interface OrgPreviewProps {
currentSheet: Sheet;
org: Pick<ZetkinOrganization, 'title' | 'id'> | undefined;
}

const OrgPreview = ({ currentSheet, org }: OrgPreviewProps) => {
const messages = useMessages(messageIds);

const hasMapped = currentSheet.columns.some(
(column) =>
column.kind === ColumnKind.ORGANIZATION && column.mapping.length > 0
);

return (
<PreviewGrid
columnHeader={messages.configuration.preview.columnHeader.org()}
emptyLabel={
hasMapped && !org ? messages.configuration.preview.noOrg() : ''
}
rowValue={hasMapped && org ? org.title : null}
unmappedRow={!hasMapped}
/>
);
};

export default OrgPreview;
82 changes: 82 additions & 0 deletions src/features/import/components/Configure/Preview/PreviewGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { ReactElement } from 'react';
import { Box, Typography, useTheme } from '@mui/material';

import { CellData } from 'features/import/utils/types';

interface PreviewGridProps {
columnHeader?: string;
unmappedRow?: boolean;
rowValue: ReactElement | CellData;
emptyLabel?: string;
}
const PreviewGrid = ({
columnHeader,
unmappedRow,
rowValue,
emptyLabel,
}: PreviewGridProps) => {
const theme = useTheme();

return (
<Box
flexGrow={1}
sx={{
display: 'flex',
flexDirection: 'column',
minWidth: 'fit-content',
overflowX: 'auto',
padding: 2,
}}
>
<Box
sx={{
backgroundColor: columnHeader
? 'transparent'
: theme.palette.transparentGrey.light,
height: '14px',
mb: 0.5,
minWidth: '150px',
}}
>
<Typography
fontSize="12px"
sx={{
color: theme.palette.grey['600'],
letterSpacing: '1px',
textTransform: 'uppercase',
}}
variant="body1"
>
{columnHeader}
</Typography>
</Box>
<Box
sx={{
alignItems: 'center',
backgroundColor: unmappedRow
? theme.palette.transparentGrey.light
: 'transparent',
display: 'flex',
height: '14px',
minWidth: '150px',
mt: 0.5,
}}
>
{emptyLabel ? (
<Typography
sx={{
color: theme.palette.grey[400],
fontStyle: 'italic',
}}
>
({emptyLabel})
</Typography>
) : (
<Typography variant="body1">{rowValue}</Typography>
)}
</Box>
</Box>
);
};

export default PreviewGrid;
80 changes: 80 additions & 0 deletions src/features/import/components/Configure/Preview/TagsPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { makeStyles } from '@mui/styles';
import { Tooltip } from '@mui/material';
import { Box, Stack } from '@mui/system';

import messageIds from 'features/import/l10n/messageIds';
import PreviewGrid from './PreviewGrid';
import TagChip from 'features/tags/components/TagManager/components/TagChip';
import { useMessages } from 'core/i18n';
import { ZetkinTag } from 'utils/types/zetkin';
import { ColumnKind, Sheet } from 'features/import/utils/types';

interface TagPreviewProps {
currentSheet: Sheet;
tags: ZetkinTag[];
}

const useStyles = makeStyles((theme) => ({
chip: {
borderColor: theme.palette.grey[500],
borderRadius: '1em',
borderWidth: '1px',
color: theme.palette.text.secondary,
cursor: 'default',
display: 'flex',
lineHeight: 'normal',
marginRight: '0.1em',
overflow: 'hidden',
padding: '0.1em 0.7em',
textOverflow: 'ellipsis',
},
}));

const TagsPreview = ({ tags, currentSheet }: TagPreviewProps) => {
const messages = useMessages(messageIds);
const classes = useStyles();

const hasMapped = currentSheet.columns.some(
(column) => column.kind === ColumnKind.TAG && column.mapping.length > 0
);

const displayedTags = tags?.slice(0, 3);
const hiddenTags = tags?.slice(3);
const tooltipTitle = hiddenTags?.map((tag) => tag.title).join(', ');
return (
<PreviewGrid
columnHeader={messages.configuration.preview.columnHeader.tags()}
emptyLabel={
hasMapped && tags.length === 0
? messages.configuration.preview.noTags()
: ''
}
rowValue={
tags.length > 0 ? (
<Stack direction="row" maxWidth={'300px'} mt="5px" spacing={1}>
{displayedTags?.map((tag) => (
<TagChip
key={tag.id}
noWrappedLabel={true}
size="small"
tag={tag}
/>
))}
{hiddenTags!.length > 0 && (
<Tooltip title={tooltipTitle}>
<Box border={2} className={classes.chip}>
{`${displayedTags!.length > 0 ? '+' : ''}${
hiddenTags?.length
}`}
</Box>
</Tooltip>
)}
</Stack>
) : null
}
unmappedRow={!hasMapped}
/>
);
};

export default TagsPreview;
Loading
Loading