This repository has been archived by the owner on May 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ErrorLogger): migrate error logger and refactor as functional co…
…mponent Signed-off-by: Diana Lease <[email protected]>
- Loading branch information
1 parent
56cdc24
commit 905975b
Showing
5 changed files
with
126 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
## Cicero-UI - ErrorLogger | ||
|
||
### Usage | ||
|
||
``` | ||
npm install @accordproject/cicero-ui | ||
``` | ||
|
||
``` | ||
import { ErrorLogger } from '@accordproject/cicero-ui'; | ||
const ErrorContainer = props => ( | ||
<ErrorComponent errors={props.errors}/> | ||
); | ||
``` | ||
|
||
### Props | ||
|
||
- `error` : An `array` which contains error objects. |
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,88 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import 'react-table/react-table.css'; | ||
import ReactTable from 'react-table'; | ||
|
||
/** | ||
* @param {object} d | ||
* @param {string} key | ||
*/ | ||
function buildMessage(d, key) { | ||
let result = 'Unknown'; | ||
|
||
if (d.fileLocation) { | ||
result = ''; | ||
if (d.fileLocation[key].line) { | ||
result += `Line: ${d.fileLocation[key].line}`; | ||
} | ||
|
||
if (d.fileLocation[key].column) { | ||
result += ` Col: ${d.fileLocation[key].column}`; | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* @param {object} d | ||
*/ | ||
function buildStartLocation(d) { | ||
return buildMessage(d, 'start'); | ||
} | ||
|
||
/** | ||
* @param {object} d | ||
*/ | ||
function buildEndLocation(d) { | ||
return buildMessage(d, 'end'); | ||
} | ||
|
||
|
||
const columns = [{ | ||
Header: 'Type', | ||
accessor: 'type', | ||
width: 100, | ||
}, | ||
{ | ||
Header: 'Name', | ||
accessor: 'name', | ||
width: 200, | ||
}, | ||
{ | ||
Header: 'File', | ||
accessor: 'fileName', | ||
width: 100, | ||
}, | ||
{ | ||
id: 'startLocation', | ||
Header: 'Start Location', | ||
accessor: d => buildStartLocation(d), | ||
width: 100, | ||
}, | ||
{ | ||
id: 'endLocation', | ||
Header: 'End Location', | ||
accessor: d => buildEndLocation(d), | ||
width: 100, | ||
}, | ||
{ | ||
Header: 'Message', | ||
accessor: 'shortMessage', | ||
width: 600, | ||
}, | ||
]; | ||
|
||
const ErrorLogger = props => ( | ||
<ReactTable | ||
data={props.errors} | ||
pageSize={5} | ||
columns={columns} | ||
/> | ||
); | ||
|
||
ErrorLogger.propTypes = { | ||
errors: PropTypes.array.isRequired, | ||
}; | ||
|
||
export default ErrorLogger; |
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 |
---|---|---|
@@ -1,6 +1,12 @@ | ||
import TemplateLibrary from './TemplateLibrary'; | ||
import ContractEditor from './ContractEditor'; | ||
import ErrorLogger from './ErrorLogger'; | ||
import TemplateLibrary from './TemplateLibrary'; | ||
import Tile from './Tile'; | ||
import 'semantic-ui-css/semantic.min.css'; | ||
|
||
export { ContractEditor, TemplateLibrary, Tile }; | ||
export { | ||
ContractEditor, | ||
ErrorLogger, | ||
TemplateLibrary, | ||
Tile, | ||
}; |