This repository has been archived by the owner on Nov 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
277 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import React, { useState } from "react"; | ||
import PropTypes from "prop-types"; | ||
|
||
import { Button } from "@buffetjs/core"; | ||
import { Row } from "../common"; | ||
import { TableWrapper } from "./styles"; | ||
|
||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; | ||
import { faTrashAlt } from "@fortawesome/free-solid-svg-icons"; | ||
|
||
function DataMapper({ data, mapper, onSuccess, onCancel }) { | ||
const { fieldsInfo, parsedData } = data; | ||
const [importItems, setImportItems] = useState(parsedData); | ||
|
||
console.log(mapper); | ||
|
||
const deleteItem = (item) => () => { | ||
const importItemsFiltered = importItems.filter( | ||
(importItems) => importItems !== item | ||
); | ||
setImportItems(importItemsFiltered); | ||
}; | ||
|
||
const handleUploadItems = () => onSuccess(importItems); | ||
return ( | ||
<div className="pt-3 col-12"> | ||
<Row> | ||
<h2>Map the Import Data to Destination Field</h2> | ||
<TableWrapper> | ||
<table> | ||
<thead> | ||
<tr> | ||
{fieldsInfo.map(({ fieldName }) => ( | ||
<th key={fieldName}>{fieldName}</th> | ||
))} | ||
<th>Del</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{importItems.map((row, i) => ( | ||
<tr key={i}> | ||
{fieldsInfo.map(({ fieldName }, j) => { | ||
const cell = row[fieldName]; | ||
|
||
if (cell === undefined || cell === null) | ||
return <td key={j}>-</td>; | ||
|
||
if (typeof cell === "object") | ||
return <td key={j}>{JSON.stringify(cell)}</td>; | ||
|
||
return <td key={j}>{`${cell}`}</td>; | ||
})} | ||
<td> | ||
<button onClick={deleteItem(row)}> | ||
<FontAwesomeIcon icon={faTrashAlt} /> | ||
</button> | ||
</td> | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</TableWrapper> | ||
</Row> | ||
<Row> | ||
{ | ||
<p> | ||
Count of Items to Import: <strong>{importItems.length}</strong> | ||
</p> | ||
} | ||
</Row> | ||
<Row> | ||
<Button label="Import Data" onClick={handleUploadItems} /> | ||
<Button | ||
className="ml-3" | ||
label="Cancel" | ||
color="delete" | ||
onClick={onCancel} | ||
/> | ||
</Row> | ||
</div> | ||
); | ||
} | ||
|
||
DataMapper.defaultProps = { | ||
data: {}, | ||
mapper: {}, | ||
onSuccess: () => {}, | ||
onCancel: () => {}, | ||
}; | ||
|
||
DataMapper.propTypes = { | ||
data: PropTypes.any, | ||
mapper: PropTypes.any, | ||
onSuccess: PropTypes.func, | ||
onCancel: PropTypes.func, | ||
}; | ||
|
||
export default DataMapper; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import styled from "styled-components"; | ||
|
||
const TableWrapper = styled.div` | ||
width: 100%; | ||
overflow-x: auto; | ||
background: white; | ||
margin-top: 1rem; | ||
border-radius: 4px; | ||
border: 1px solid #e3e9f3; | ||
max-height: 250px; | ||
table { | ||
width: 100%; | ||
text-align: center; | ||
th, | ||
td { | ||
padding: 15px; | ||
} | ||
th { | ||
min-width: 15ch; | ||
background-color: #f3f3f4; | ||
font-weight: bold; | ||
} | ||
th:last-child { | ||
min-width: 50px; | ||
width: 50px; | ||
} | ||
td:last-child { | ||
opacity: 0.5; | ||
border-left: 1px solid #ccc; | ||
cursor: pointer; | ||
max-width: 50px; | ||
padding: 0; | ||
button { | ||
border: none; | ||
outline: none; | ||
padding: 15px; | ||
background: transparent; | ||
font-size: 1.2rem; | ||
} | ||
&:hover { | ||
opacity: 1; | ||
} | ||
} | ||
tbody { | ||
tr { | ||
&:nth-child(even) { | ||
background-color: #fafafa; | ||
} | ||
&:hover { | ||
background-color: #efefef; | ||
} | ||
} | ||
} | ||
td { | ||
max-width: 15ch; | ||
white-space: nowrap; | ||
overflow: hidden; | ||
text-overflow: ellipsis; | ||
} | ||
} | ||
`; | ||
|
||
export { TableWrapper }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters