Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
cb51f13e
Commit
cb51f13e
authored
Mar 11, 2019
by
ryan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
torkel feedback
parent
6494c17c
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
17 deletions
+17
-17
packages/grafana-ui/src/components/Table/TableInputCSV.tsx
+11
-11
packages/grafana-ui/src/utils/processTableData.ts
+6
-6
No files found.
packages/grafana-ui/src/components/Table/TableInputCSV.tsx
View file @
cb51f13e
import
React
from
'react'
;
import
debounce
from
'lodash/debounce'
;
import
{
ParseConfig
,
parseCSV
,
ParseDetails
}
from
'../../utils/processTableData'
;
import
{
parseCSV
,
TableParseOptions
,
Table
ParseDetails
}
from
'../../utils/processTableData'
;
import
{
TableData
}
from
'../../types/data'
;
import
{
AutoSizer
}
from
'react-virtualized'
;
interface
Props
{
config
?:
ParseConfig
;
options
?:
TableParseOptions
;
text
:
string
;
onTableParsed
:
(
table
:
TableData
,
text
:
string
)
=>
void
;
}
...
...
@@ -13,7 +13,7 @@ interface Props {
interface
State
{
text
:
string
;
table
:
TableData
;
details
:
ParseDetails
;
details
:
Table
ParseDetails
;
}
/**
...
...
@@ -24,9 +24,9 @@ class TableInputCSV extends React.PureComponent<Props, State> {
super
(
props
);
// Shoud this happen in onComponentMounted?
const
{
text
,
config
,
onTableParsed
}
=
props
;
const
{
text
,
options
,
onTableParsed
}
=
props
;
const
details
=
{};
const
table
=
parseCSV
(
text
,
config
,
details
);
const
table
=
parseCSV
(
text
,
options
,
details
);
this
.
state
=
{
text
,
table
,
...
...
@@ -37,13 +37,13 @@ class TableInputCSV extends React.PureComponent<Props, State> {
readCSV
=
debounce
(()
=>
{
const
details
=
{};
const
table
=
parseCSV
(
this
.
state
.
text
,
this
.
props
.
config
,
details
);
const
table
=
parseCSV
(
this
.
state
.
text
,
this
.
props
.
options
,
details
);
this
.
setState
({
table
,
details
});
},
150
);
componentDidUpdate
(
prevProps
:
Props
,
prevState
:
State
)
{
const
{
text
}
=
this
.
state
;
if
(
text
!==
prevState
.
text
||
this
.
props
.
config
!==
prevProps
.
config
)
{
if
(
text
!==
prevState
.
text
||
this
.
props
.
options
!==
prevProps
.
options
)
{
this
.
readCSV
();
}
// If the props text has changed, replace our local version
...
...
@@ -56,7 +56,7 @@ class TableInputCSV extends React.PureComponent<Props, State> {
}
}
handle
FooterClicked
=
(
event
:
any
)
=>
{
on
FooterClicked
=
(
event
:
any
)
=>
{
console
.
log
(
'Errors'
,
this
.
state
);
const
message
=
this
.
state
.
details
.
errors
!
.
map
(
err
=>
{
...
...
@@ -66,7 +66,7 @@ class TableInputCSV extends React.PureComponent<Props, State> {
alert
(
'CSV Parsing Errors:
\
n'
+
message
);
};
handle
Change
=
(
event
:
any
)
=>
{
onText
Change
=
(
event
:
any
)
=>
{
this
.
setState
({
text
:
event
.
target
.
value
});
};
...
...
@@ -80,8 +80,8 @@ class TableInputCSV extends React.PureComponent<Props, State> {
<
AutoSizer
>
{
({
height
,
width
})
=>
(
<
div
className=
"gf-table-input-csv"
style=
{
{
width
,
height
}
}
>
<
textarea
placeholder=
"Enter CSV here..."
value=
{
this
.
state
.
text
}
onChange=
{
this
.
handle
Change
}
/>
<
footer
onClick=
{
this
.
handle
FooterClicked
}
className=
{
footerClassNames
}
>
<
textarea
placeholder=
"Enter CSV here..."
value=
{
this
.
state
.
text
}
onChange=
{
this
.
onText
Change
}
/>
<
footer
onClick=
{
this
.
on
FooterClicked
}
className=
{
footerClassNames
}
>
Rows:
{
table
.
rows
.
length
}
, Columns:
{
table
.
columns
.
length
}
{
hasErrors
?
<
i
className=
"fa fa-exclamation-triangle"
/>
:
<
i
className=
"fa fa-check-circle"
/>
}
</
footer
>
...
...
packages/grafana-ui/src/utils/processTableData.ts
View file @
cb51f13e
...
...
@@ -3,7 +3,7 @@ import { TableData, Column } from '../types/index';
import
Papa
,
{
ParseError
,
ParseMeta
}
from
'papaparse'
;
// Subset of all parse options
export
interface
ParseConfig
{
export
interface
TableParseOptions
{
headerIsFirstLine
?:
boolean
;
// Not a papa-parse option
delimiter
?:
string
;
// default: ","
newline
?:
string
;
// default: "\r\n"
...
...
@@ -12,7 +12,7 @@ export interface ParseConfig {
comments
?:
boolean
|
string
;
// default: false
}
export
interface
ParseDetails
{
export
interface
Table
ParseDetails
{
meta
?:
ParseMeta
;
errors
?:
ParseError
[];
}
...
...
@@ -87,11 +87,11 @@ function makeColumns(values: any[]): Column[] {
* Convert CSV text into a valid TableData object
*
* @param text
* @param
config
* @param
options
* @param details, if exists the result will be filled with debugging details
*/
export
function
parseCSV
(
text
:
string
,
config
?:
ParseConfig
,
details
?:
ParseDetails
):
TableData
{
const
results
=
Papa
.
parse
(
text
,
{
...
config
,
dynamicTyping
:
true
,
skipEmptyLines
:
true
});
export
function
parseCSV
(
text
:
string
,
options
?:
TableParseOptions
,
details
?:
Table
ParseDetails
):
TableData
{
const
results
=
Papa
.
parse
(
text
,
{
...
options
,
dynamicTyping
:
true
,
skipEmptyLines
:
true
});
const
{
data
,
meta
,
errors
}
=
results
;
// Fill the parse details for debugging
...
...
@@ -121,7 +121,7 @@ export function parseCSV(text: string, config?: ParseConfig, details?: ParseDeta
}
// Assume the first line is the header unless the config says its not
const
headerIsNotFirstLine
=
config
&&
config
.
headerIsFirstLine
===
false
;
const
headerIsNotFirstLine
=
options
&&
options
.
headerIsFirstLine
===
false
;
const
header
=
headerIsNotFirstLine
?
[]
:
results
.
data
.
shift
();
return
matchRowSizes
({
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment