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
e2be194b
Commit
e2be194b
authored
Mar 09, 2019
by
ryan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
autofill space rather than force with/height values
parent
9134620c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
21 deletions
+42
-21
packages/grafana-ui/src/components/Table/TableInputCSV.story.tsx
+5
-4
packages/grafana-ui/src/components/Table/TableInputCSV.test.tsx
+2
-4
packages/grafana-ui/src/components/Table/TableInputCSV.tsx
+26
-10
packages/grafana-ui/src/components/Table/_TableInputCSV.scss
+9
-3
No files found.
packages/grafana-ui/src/components/Table/TableInputCSV.story.tsx
View file @
e2be194b
...
@@ -4,16 +4,17 @@ import { storiesOf } from '@storybook/react';
...
@@ -4,16 +4,17 @@ import { storiesOf } from '@storybook/react';
import
TableInputCSV
from
'./TableInputCSV'
;
import
TableInputCSV
from
'./TableInputCSV'
;
import
{
action
}
from
'@storybook/addon-actions'
;
import
{
action
}
from
'@storybook/addon-actions'
;
import
{
TableData
}
from
'../../types/data'
;
import
{
TableData
}
from
'../../types/data'
;
import
{
withCenteredStory
}
from
'../../utils/storybook/withCenteredStory'
;
const
TableInputStories
=
storiesOf
(
'UI/Table/Input'
,
module
);
const
TableInputStories
=
storiesOf
(
'UI/Table/Input'
,
module
);
TableInputStories
.
addDecorator
(
withCenteredStory
);
TableInputStories
.
add
(
'default'
,
()
=>
{
TableInputStories
.
add
(
'default'
,
()
=>
{
return
(
return
(
<
div
>
<
div
style=
{
{
width
:
'90%'
,
height
:
'90vh'
}
}
>
<
TableInputCSV
<
TableInputCSV
text=
"a,b,c\n1,2,3"
text=
{
'a,b,c
\
n1,2,3'
}
width=
{
'90%'
}
height=
{
'90vh'
}
onTableParsed=
{
(
table
:
TableData
,
text
:
string
)
=>
{
onTableParsed=
{
(
table
:
TableData
,
text
:
string
)
=>
{
console
.
log
(
'Table'
,
table
,
text
);
console
.
log
(
'Table'
,
table
,
text
);
action
(
'Table'
)(
table
,
text
);
action
(
'Table'
)(
table
,
text
);
...
...
packages/grafana-ui/src/components/Table/TableInputCSV.test.tsx
View file @
e2be194b
...
@@ -9,11 +9,9 @@ describe('TableInputCSV', () => {
...
@@ -9,11 +9,9 @@ describe('TableInputCSV', () => {
const
tree
=
renderer
const
tree
=
renderer
.
create
(
.
create
(
<
TableInputCSV
<
TableInputCSV
text=
"a,b,c\n1,2,3"
text=
{
'a,b,c
\
n1,2,3'
}
width=
{
100
}
height=
{
100
}
onTableParsed=
{
(
table
:
TableData
,
text
:
string
)
=>
{
onTableParsed=
{
(
table
:
TableData
,
text
:
string
)
=>
{
console
.
log
(
'Table:'
,
table
,
'from:'
,
text
);
//
console.log('Table:', table, 'from:', text);
}
}
}
}
/>
/>
)
)
...
...
packages/grafana-ui/src/components/Table/TableInputCSV.tsx
View file @
e2be194b
...
@@ -2,11 +2,10 @@ import React from 'react';
...
@@ -2,11 +2,10 @@ import React from 'react';
import
debounce
from
'lodash/debounce'
;
import
debounce
from
'lodash/debounce'
;
import
{
ParseConfig
,
parseCSV
,
ParseDetails
}
from
'../../utils/processTableData'
;
import
{
ParseConfig
,
parseCSV
,
ParseDetails
}
from
'../../utils/processTableData'
;
import
{
TableData
}
from
'../../types/data'
;
import
{
TableData
}
from
'../../types/data'
;
import
{
AutoSizer
}
from
'react-virtualized'
;
interface
Props
{
interface
Props
{
config
?:
ParseConfig
;
config
?:
ParseConfig
;
width
:
number
|
string
;
height
:
number
|
string
;
text
:
string
;
text
:
string
;
onTableParsed
:
(
table
:
TableData
,
text
:
string
)
=>
void
;
onTableParsed
:
(
table
:
TableData
,
text
:
string
)
=>
void
;
}
}
...
@@ -17,6 +16,9 @@ interface State {
...
@@ -17,6 +16,9 @@ interface State {
details
:
ParseDetails
;
details
:
ParseDetails
;
}
}
/**
* Expects the container div to have size set and will fill it 100%
*/
class
TableInputCSV
extends
React
.
PureComponent
<
Props
,
State
>
{
class
TableInputCSV
extends
React
.
PureComponent
<
Props
,
State
>
{
constructor
(
props
:
Props
)
{
constructor
(
props
:
Props
)
{
super
(
props
);
super
(
props
);
...
@@ -54,24 +56,38 @@ class TableInputCSV extends React.PureComponent<Props, State> {
...
@@ -54,24 +56,38 @@ class TableInputCSV extends React.PureComponent<Props, State> {
}
}
}
}
handleFooterClicked
=
(
event
:
any
)
=>
{
console
.
log
(
'Errors'
,
this
.
state
);
const
message
=
this
.
state
.
details
.
errors
!
.
map
(
err
=>
{
return
err
.
message
;
})
.
join
(
'
\
n'
);
alert
(
'CSV Parsing Errors:
\
n'
+
message
);
};
handleChange
=
(
event
:
any
)
=>
{
handleChange
=
(
event
:
any
)
=>
{
this
.
setState
({
text
:
event
.
target
.
value
});
this
.
setState
({
text
:
event
.
target
.
value
});
};
};
render
()
{
render
()
{
const
{
width
,
height
}
=
this
.
props
;
const
{
table
,
details
}
=
this
.
state
;
const
{
table
,
details
}
=
this
.
state
;
const
hasErrors
=
details
.
errors
&&
details
.
errors
.
length
>
0
;
const
hasErrors
=
details
.
errors
&&
details
.
errors
.
length
>
0
;
const
footerClassNames
=
hasErrors
?
'gf-table-input-csv-err'
:
''
;
return
(
return
(
<
div
className=
"gf-table-input-csv"
style=
{
{
width
,
height
}
}
>
<
AutoSizer
>
<
textarea
placeholder=
"Enter CSV here..."
value=
{
this
.
state
.
text
}
onChange=
{
this
.
handleChange
}
/>
{
({
height
,
width
})
=>
(
<
footer
>
<
div
className=
"gf-table-input-csv"
style=
{
{
width
,
height
}
}
>
Rows:
{
table
.
rows
.
length
}
, Columns:
{
table
.
columns
.
length
}
<
textarea
placeholder=
"Enter CSV here..."
value=
{
this
.
state
.
text
}
onChange=
{
this
.
handleChange
}
/>
{
hasErrors
?
<
i
className=
"fa fa-exclamation-triangle"
/>
:
<
i
className=
"fa fa-check-circle"
/>
}
<
footer
onClick=
{
this
.
handleFooterClicked
}
className=
{
footerClassNames
}
>
</
footer
>
Rows:
{
table
.
rows
.
length
}
, Columns:
{
table
.
columns
.
length
}
</
div
>
{
hasErrors
?
<
i
className=
"fa fa-exclamation-triangle"
/>
:
<
i
className=
"fa fa-check-circle"
/>
}
</
footer
>
</
div
>
)
}
</
AutoSizer
>
);
);
}
}
}
}
...
...
packages/grafana-ui/src/components/Table/_TableInputCSV.scss
View file @
e2be194b
...
@@ -10,9 +10,15 @@
...
@@ -10,9 +10,15 @@
.gf-table-input-csv
footer
{
.gf-table-input-csv
footer
{
position
:
absolute
;
position
:
absolute
;
bottom
:
20
px
;
bottom
:
15
px
;
right
:
20
px
;
right
:
15
px
;
border
:
1px
solid
#222
;
border
:
1px
solid
#222
;
background
:
#ccc
;
background
:
#ccc
;
padding
:
4px
10px
;
padding
:
1px
4px
;
font-size
:
80%
;
cursor
:
pointer
;
}
.gf-table-input-csv
footer
.gf-table-input-csv-err
{
background
:
yellow
;
}
}
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