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 #1611

Merged
merged 81 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
5d4b220
Create row component for the mapping.
ziggabyte Oct 30, 2023
e1e94e3
Change strings to single line to avoid missing blank spaces.
ziggabyte Oct 31, 2023
14104b7
Contol the state of the select and checkbox.
ziggabyte Oct 31, 2023
eb6c15d
Add message and button when value mapping is needed.
ziggabyte Oct 31, 2023
12b098b
Add message about results of mapping.
ziggabyte Oct 31, 2023
f3ada82
Add button to map values & set bg color when active.
ziggabyte Nov 1, 2023
50898fc
Move hook to its own file.
ziggabyte Nov 1, 2023
5ac1811
Merge branch 'main' of github.com:zetkin/app.zetkin.org into import-c…
ziggabyte Nov 1, 2023
3319944
Create Mapping component and first step of converting rows to columns…
ziggabyte Nov 1, 2023
305569c
Set column headers to first row or default headers.
ziggabyte Nov 1, 2023
12ae219
Add headers and dividers.
ziggabyte Nov 1, 2023
bbbf881
Create SheetSettings component an story.
ziggabyte Nov 1, 2023
68cd2e6
Move files into folders.
ziggabyte Nov 1, 2023
33734cb
Create Configure component with story and change types of ids.
ziggabyte Nov 1, 2023
fde806c
Style accordion.
ziggabyte Nov 1, 2023
10194ab
Remove acciental check for deep equality.
ziggabyte Nov 1, 2023
fc0fb6b
Add keys to mapped elements.
ziggabyte Nov 1, 2023
79cacc1
Remove unneccessary curly brackets.
ziggabyte Nov 1, 2023
4794e72
Style show/hide buttons.
ziggabyte Nov 1, 2023
91f88b9
Refactor accordions into its own component.
ziggabyte Nov 1, 2023
18f0783
Add state to keep track of which column is being mapped.
ziggabyte Nov 2, 2023
8b07a19
Add state to keep track of the id:s of selected columns.
ziggabyte Nov 2, 2023
dacdd1a
Get fields that don't need configuring and use in dropdown.
ziggabyte Nov 2, 2023
8cf862f
Reset selection when changing sheets.
ziggabyte Nov 2, 2023
d01c664
Add fields that need configuration to dropown.
ziggabyte Nov 2, 2023
d464ade
Move hook to its own file.
ziggabyte Nov 2, 2023
b595446
Add messages for Id configuration.
ziggabyte Nov 2, 2023
7b47028
Clear dropdown when de-selecting column.
ziggabyte Nov 2, 2023
e498794
Delete stories, since they are not needed any more.
ziggabyte Nov 2, 2023
00cce7a
Add type to currentlyMapping, and function to clear currentlyMapping …
ziggabyte Nov 2, 2023
8f63822
Add empty state to mapping section.
ziggabyte Nov 2, 2023
8d5aa92
Merge branch 'import-configuration/basics' of github.com:zetkin/app.z…
ziggabyte Nov 3, 2023
ab92d50
Put Mapping section in box instead of accordion.
ziggabyte Nov 3, 2023
ef478ed
Make the list of fields scroll.
ziggabyte Nov 3, 2023
95410a6
Change variable names.
ziggabyte Nov 3, 2023
ba18e30
Move Accordion into SheetSettings component.
ziggabyte Nov 3, 2023
a9b5ae4
Create Configuration component and move logic into there.
ziggabyte Nov 3, 2023
0b44d1b
Create basic UI for value mapping tags.
ziggabyte Nov 3, 2023
dee01ff
Change small variable name error in TagManager
ziggabyte Nov 3, 2023
4f70903
Get data for the tag config and create component for the rows.
ziggabyte Nov 3, 2023
380012e
Make the list of unique values scroll.
ziggabyte Nov 3, 2023
46e979d
Move column hooks into their own files.
ziggabyte Nov 3, 2023
81b50b8
Merge branch 'epic-1595/import' of github.com:zetkin/app.zetkin.org i…
ziggabyte Nov 8, 2023
6912214
Harmonize types with those created by @rebecarubio
ziggabyte Nov 9, 2023
7c343d2
Add types and simplify lists in parseFile.
ziggabyte Nov 9, 2023
d462c6a
Only keep one file in store, and update store action name.
ziggabyte Nov 9, 2023
703282b
Use file from store.
ziggabyte Nov 9, 2023
d27452b
Create hook to get sheets and sheet index from the store.
ziggabyte Nov 9, 2023
c7eb9fe
Keep the value for firstRowIsHeaders in the store and get value and f…
ziggabyte Nov 9, 2023
7d88e0a
Keep selected column ids in store and get them and update function vi…
ziggabyte Nov 9, 2023
15ac74c
Change types to better reflect what they do, get data inside SheetSet…
ziggabyte Nov 10, 2023
c551b93
Add columns to Sheet type, use store to save and create columns.
ziggabyte Nov 15, 2023
c649624
Move handling of what column is currently being configured to the sto…
ziggabyte Nov 15, 2023
c3a9e11
Create default column titles in component when title string is empty.
ziggabyte Nov 15, 2023
8d5d900
Refactor types and how selected field type is stored.
ziggabyte Nov 15, 2023
5218421
WIP of refactoring store and logic to be correct.
ziggabyte Nov 17, 2023
8c94cff
Create useColumn hook to hold the function to update a column.
ziggabyte Nov 17, 2023
302a905
Rename fields to columnOptions.
ziggabyte Nov 17, 2023
4ade0ba
Update logic to display the TagConfigRows correctly.
ziggabyte Nov 17, 2023
1fc7872
Fix so the column select displays and gets the correct values.
ziggabyte Nov 17, 2023
b35161b
Map tags to values.
ziggabyte Nov 20, 2023
796f5f5
Update mapping message to match design.
ziggabyte Nov 20, 2023
3dfdd1d
Create ID config.
ziggabyte Nov 21, 2023
b5f3d11
Create organization config.
ziggabyte Nov 22, 2023
d6865e0
Solve error in counting how many rows had values mapped.
ziggabyte Nov 22, 2023
346b993
Update name of variable to match what it does.
ziggabyte Nov 22, 2023
1a5700d
Use opacity to clarify when you can use the select for mapping.
ziggabyte Nov 22, 2023
3691e94
Place empty config state icon in middle.
ziggabyte Nov 22, 2023
a36f550
Clear currently configuring when changing sheet.
ziggabyte Nov 22, 2023
3d658e7
Make the correct container scroll.
ziggabyte Nov 22, 2023
d9b307b
Go back to using number array for tagIds instead of tag array.
ziggabyte Nov 22, 2023
2f74a1e
Merge branch 'epic-1595/import' of github.com:zetkin/app.zetkin.org i…
ziggabyte Nov 22, 2023
c4224ab
Update little incosistencies.
ziggabyte Nov 24, 2023
624124c
Interpret cells with falsy value as empty cells.
ziggabyte Nov 24, 2023
66c4548
Merge branch 'epic-1595/import' of github.com:zetkin/app.zetkin.org i…
ziggabyte Nov 24, 2023
a06266d
Fix wrapping of long strings and some minor styling.
ziggabyte Nov 24, 2023
8fa45af
Apply same styling to tag config row.
ziggabyte Nov 24, 2023
5116174
Update PeopleActionButton to match correct props.
ziggabyte Nov 24, 2023
bc377ae
Create hook with function to disable fields that can only be selected…
ziggabyte Nov 28, 2023
61aacee
Rename hook to useColumnMutations.
ziggabyte Nov 28, 2023
f487ddb
Make UIColumnData generic and use correct types.
ziggabyte Nov 28, 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
135 changes: 135 additions & 0 deletions src/features/import/components/Configure/Configuration/IdConfig.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import { FC } from 'react';
import {
Alert,
Box,
Divider,
Radio,
RadioGroup,
Typography,
useTheme,
} from '@mui/material';

import { IDFieldColumn } from 'features/import/utils/types';
import messageIds from 'features/import/l10n/messageIds';
import { Msg } from 'core/i18n';
import { UIDataColumn } from 'features/import/hooks/useUIDataColumns';

interface IdConfigProps {
uiDataColumn: UIDataColumn<IDFieldColumn>;
}

const IdConfig: FC<IdConfigProps> = ({ uiDataColumn }) => {
const theme = useTheme();

return (
<Box
display="flex"
flexDirection="column"
overflow="hidden"
padding={2}
sx={{ overflowY: 'scroll' }}
>
<Typography sx={{ paddingBottom: 2 }} variant="h5">
<Msg id={messageIds.configuration.configure.ids.header} />
</Typography>
<Typography sx={{ paddingBottom: 1 }}>
<Msg id={messageIds.configuration.configure.ids.configExplanation} />
</Typography>
<RadioGroup
sx={{
display: 'flex',
flexDirection: 'row',
gap: 2,
justifyContent: 'space-between',
paddingBottom: 1,
}}
>
<Box
bgcolor="white"
border={1}
borderColor={theme.palette.divider}
borderRadius={2}
flex={1}
>
<Box alignItems="center" display="flex" padding={1}>
<Radio
checked={uiDataColumn.originalColumn.idField == 'ext_id'}
onChange={(event) => {
if (
event.target.value == 'ext_id' ||
event.target.value == 'id'
) {
uiDataColumn.updateIdField(event.target.value);
}
}}
sx={{ paddingRight: 1 }}
value="ext_id"
/>
<Typography>
<Msg id={messageIds.configuration.configure.ids.externalID} />
</Typography>
</Box>
<Divider />
<Box padding={1}>
<Typography sx={{ paddingBottom: 1 }}>
<Msg id={messageIds.configuration.configure.ids.externalIDFile} />
</Typography>
<Typography>
<Msg
id={
messageIds.configuration.configure.ids.externalIDExplanation
}
/>
</Typography>
</Box>
</Box>
<Box
bgcolor="white"
border={1}
borderColor={theme.palette.divider}
borderRadius={2}
flex={1}
>
<Box alignItems="center" display="flex" padding={1}>
<Radio
checked={uiDataColumn.originalColumn.idField == 'id'}
onChange={(event) => {
if (
event.target.value == 'ext_id' ||
(event.target.value == 'id' && !uiDataColumn.wrongIDFormat)
) {
uiDataColumn.updateIdField(event.target.value);
}
}}
sx={{ paddingRight: 1 }}
value="id"
/>
<Typography>
<Msg id={messageIds.configuration.configure.ids.zetkinID} />
</Typography>
</Box>
<Divider />
<Box padding={1}>
<Typography sx={{ paddingBottom: 1 }}>
<Msg id={messageIds.configuration.configure.ids.zetkinIDFile} />
</Typography>
<Typography>
<Msg
id={messageIds.configuration.configure.ids.zetkinIDExplanation}
/>
</Typography>
</Box>
</Box>
</RadioGroup>
{uiDataColumn.wrongIDFormat && (
<Alert severity="error">
<Msg
id={messageIds.configuration.configure.ids.wrongIDFormatWarning}
/>
</Alert>
)}
</Box>
);
};

export default IdConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { FC } from 'react';
import { Box, Divider, Typography } from '@mui/material';

import messageIds from 'features/import/l10n/messageIds';
import { OrgColumn } from 'features/import/utils/types';
import OrgConfigRow from './OrgConfigRow';
import { UIDataColumn } from 'features/import/hooks/useUIDataColumns';
import useOrganizations from 'features/organizations/hooks/useOrganizations';
import { Msg, useMessages } from 'core/i18n';

interface OrgConfigProps {
uiDataColumn: UIDataColumn<OrgColumn>;
}

const OrgConfig: FC<OrgConfigProps> = ({ uiDataColumn }) => {
const messages = useMessages(messageIds);
const organizations = useOrganizations();

if (!organizations.data) {
return null;
}

return (
<Box
display="flex"
flexDirection="column"
overflow="hidden"
padding={2}
sx={{ overflowY: 'scroll' }}
>
<Typography sx={{ paddingBottom: 2 }} variant="h5">
<Msg id={messageIds.configuration.configure.orgs.header} />
</Typography>
<Box alignItems="center" display="flex" paddingY={2}>
<Box width="50%">
<Typography variant="body2">
{messages.configuration.configure.orgs.status().toLocaleUpperCase()}
</Typography>
</Box>
<Box width="50%">
<Typography variant="body2">
{messages.configuration.configure.orgs
.organizations()
.toLocaleUpperCase()}
</Typography>
</Box>
</Box>
{uiDataColumn.uniqueValues.map((uniqueValue, index) => (
<>
{index != 0 && <Divider sx={{ marginY: 1 }} />}
<OrgConfigRow
numRows={uiDataColumn.numRowsByUniqueValue[uniqueValue]}
onDeselectOrg={() => uiDataColumn.deselectOrg(uniqueValue)}
onSelectOrg={(orgId) => uiDataColumn.selectOrg(orgId, uniqueValue)}
orgs={organizations.data || []}
selectedOrgId={uiDataColumn.getSelectedOrgId(uniqueValue)}
title={uniqueValue.toString()}
/>
</>
))}
{uiDataColumn.numberOfEmptyRows > 0 && (
<>
<Divider sx={{ marginY: 1 }} />
<OrgConfigRow
italic
numRows={uiDataColumn.numberOfEmptyRows}
onDeselectOrg={() => uiDataColumn.deselectOrg(null)}
onSelectOrg={(orgId) => uiDataColumn.selectOrg(orgId, null)}
orgs={organizations.data || []}
selectedOrgId={uiDataColumn.getSelectedOrgId(null)}
title={messages.configuration.configure.tags.empty()}
/>
</>
)}
</Box>
);
};

export default OrgConfig;
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { FC } from 'react';
import { ArrowForward, Delete } from '@mui/icons-material';
import {
Box,
FormControl,
IconButton,
InputLabel,
MenuItem,
Select,
Typography,
useTheme,
} from '@mui/material';

import messageIds from 'features/import/l10n/messageIds';
import { ZetkinOrganization } from 'utils/types/zetkin';
import { Msg, useMessages } from 'core/i18n';

interface OrgConfigRowProps {
italic?: boolean;
numRows: number;
onSelectOrg: (orgId: number) => void;
onDeselectOrg: () => void;
orgs: Pick<ZetkinOrganization, 'id' | 'title'>[];
selectedOrgId: number | null;
title: string;
}

const OrgConfigRow: FC<OrgConfigRowProps> = ({
italic,
numRows,
onSelectOrg,
onDeselectOrg,
orgs,
selectedOrgId,
title,
}) => {
const theme = useTheme();
const messages = useMessages(messageIds);
return (
<Box display="flex" flexDirection="column">
<Box display="flex">
<Box
alignItems="flex-start"
display="flex"
justifyContent="space-between"
paddingTop={1}
width="50%"
>
<Box display="flex" sx={{ wordBreak: 'break-all' }} width="100%">
<Typography fontStyle={italic ? 'italic' : ''}>{title}</Typography>
</Box>
<ArrowForward color="secondary" sx={{ marginRight: 1 }} />
</Box>
<Box
alignItems="flex-start"
display="flex"
paddingRight={1}
width="50%"
>
<FormControl fullWidth size="small">
<InputLabel>
<Msg id={messageIds.configuration.configure.orgs.organizations} />
</InputLabel>
<Select
label={messages.configuration.configure.orgs.organizations()}
onChange={(event) => {
if (typeof event.target.value == 'number') {
onSelectOrg(event.target.value);
}
}}
value={selectedOrgId || ''}
>
{orgs.map((org) => (
<MenuItem key={org.id} value={org.id}>
{org.title}
</MenuItem>
))}
</Select>
</FormControl>
<IconButton
disabled={!selectedOrgId}
onClick={() => {
if (selectedOrgId) {
onDeselectOrg();
}
}}
>
<Delete
sx={{
color: selectedOrgId ? 'secondary' : theme.palette.grey[400],
}}
/>
</IconButton>
</Box>
</Box>
<Typography color="secondary">
<Msg
id={messageIds.configuration.configure.tags.numberOfRows}
values={{ numRows }}
/>
</Typography>
</Box>
);
};

export default OrgConfigRow;
Loading
Loading