This repository has been archived by the owner on Jan 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3411 from product-os/generic-charting
Create a generic chart lens and use it for pull requests
- Loading branch information
Showing
19 changed files
with
4,506 additions
and
618 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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
"slug": "view-all-pull-requests", | ||
"name": "All pull requests", | ||
"type": "[email protected]", | ||
"markers": [], | ||
"markers": [ "org-balena" ], | ||
"data": { | ||
"allOf": [ | ||
{ | ||
|
@@ -25,7 +25,7 @@ | |
"lenses": [ | ||
"lens-list", | ||
"lens-kanban", | ||
"lens-pull-request-chart" | ||
"lens-chart" | ||
] | ||
} | ||
} |
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,7 +1,8 @@ | ||
env: | ||
browser: true | ||
node: false | ||
|
||
parserOptions: | ||
ecmaVersion: 11 | ||
rules: | ||
arrow-body-style: | ||
off | ||
0 |
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,37 @@ | ||
/* | ||
* Copyright (C) Balena.io - All Rights Reserved | ||
* Unauthorized copying of this file, via any medium is strictly prohibited. | ||
* Proprietary and confidential. | ||
*/ | ||
|
||
import React, { | ||
Suspense | ||
} from 'react' | ||
import ErrorBoundary from '@balena/jellyfish-ui-components/lib/shame/ErrorBoundary' | ||
import Splash from './Splash' | ||
|
||
const SafeLazy = ({ | ||
children | ||
}) => { | ||
return ( | ||
<ErrorBoundary> | ||
<Suspense fallback={<Splash />}> | ||
{children} | ||
</Suspense> | ||
</ErrorBoundary> | ||
) | ||
} | ||
|
||
export const createLazyComponent = (fn) => { | ||
const LazyComponent = React.lazy(fn) | ||
|
||
return (props) => { | ||
return ( | ||
<SafeLazy> | ||
<LazyComponent {...props}/> | ||
</SafeLazy> | ||
) | ||
} | ||
} | ||
|
||
export default SafeLazy |
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,109 @@ | ||
/* | ||
* Copyright (C) Balena.io - All Rights Reserved | ||
* Unauthorized copying of this file, via any medium is strictly prohibited. | ||
* Proprietary and confidential. | ||
*/ | ||
|
||
import * as _ from 'lodash' | ||
import React, { | ||
useState | ||
} from 'react' | ||
import PlotlyEditor from 'react-chart-editor' | ||
import 'react-chart-editor/lib/react-chart-editor.css' | ||
import * as flatten from 'flat' | ||
import { | ||
createGlobalStyle | ||
} from 'styled-components' | ||
|
||
// HACK: Work-around for the fact that plotly throws a fit if you run it outside | ||
// of a browser environment. | ||
const plotly = window.isUnitTest ? null : require('plotly.js/dist/plotly') | ||
|
||
// The plotly styles don't render 100% correctly on JF, causing the panel | ||
// headers to get squashed. This fixes the issue | ||
const GlobalStyle = createGlobalStyle ` | ||
.plotly_editor .editor_controls .fold__top { | ||
height: 30px; | ||
} | ||
` | ||
|
||
const config = { | ||
editable: true | ||
} | ||
|
||
export default React.memo(({ | ||
tail | ||
}) => { | ||
// Flatten all the cards into single level objects so that plotly can handle | ||
// the data | ||
const getDataSources = React.useCallback(() => { | ||
const flattenedData = _.map(tail, flatten) | ||
const combinedFlatKeys = _.uniq(_.flatMap(flattenedData, _.keys)) | ||
|
||
const dataSources = _.mapValues(_.keyBy(combinedFlatKeys), (key) => _.map(flattenedData, key)) | ||
|
||
const dataSourceOptions = Object.keys(dataSources).map((name) => ({ | ||
value: name, | ||
label: name | ||
})) | ||
return { | ||
dataSources, dataSourceOptions | ||
} | ||
}, [ tail ]) | ||
|
||
const { | ||
dataSources, dataSourceOptions | ||
} = getDataSources() | ||
|
||
const defaultSettings = { | ||
data: [ | ||
// This config sets up a simple histogram that groups data by day, using | ||
// the `created_at` field. | ||
{ | ||
type: 'histogram', | ||
mode: 'markers', | ||
// eslint-disable-next-line id-length | ||
x: dataSources.created_at, | ||
xsrc: 'created_at', | ||
xbins: { | ||
size: 86400000 | ||
}, | ||
marker: { | ||
color: 'rgb(0, 174, 239)' | ||
} | ||
} | ||
], | ||
layout: { | ||
bargap: 0.09 | ||
}, | ||
frames: [] | ||
} | ||
|
||
const [ settings, setSettings ] = useState(defaultSettings) | ||
|
||
return ( | ||
<React.Fragment> | ||
<GlobalStyle /> | ||
|
||
<PlotlyEditor | ||
data={settings.data} | ||
layout={settings.layout} | ||
config={config} | ||
frames={settings.frame} | ||
dataSources={dataSources} | ||
dataSourceOptions={dataSourceOptions} | ||
plotly={plotly} | ||
onUpdate={(data, layout, frames) => { | ||
setSettings({ | ||
data, | ||
layout, | ||
frames | ||
}) | ||
}} | ||
useResizeHandler | ||
debug | ||
advancedTraceTypeSelector | ||
/> | ||
</React.Fragment> | ||
) | ||
}) |
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 was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
apps/ui/lens/misc/PullRequestChart/tests/PullRequestChart.spec.jsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.