Skip to content

Commit eff321e

Browse files
CSV download in graph chart (#381)
* CSV file download in Graph Chart * Update pre-commit * Fixes * Move config order --------- Co-authored-by: Niels de Jong <[email protected]>
1 parent 77d7c4e commit eff321e

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

src/card/view/CardView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const NeoCardView = ({
103103
<></>
104104
);
105105
const localParameters = getLocalParameters(
106-
`${query }//${ settings.drilldownLink}` !== undefined ? settings.drilldownLink : ''
106+
`${query}//${settings.drilldownLink}` !== undefined ? settings.drilldownLink : ''
107107
);
108108
const reportTypes = getReportTypes(extensions);
109109
const withoutFooter =

src/chart/graph/GraphChart.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@ import { parseNodeIconConfig } from './util/NodeUtils';
1212
import { GraphChartVisualizationProps, layouts } from './GraphChartVisualization';
1313
import { handleExpand } from './util/ExplorationUtils';
1414
import { categoricalColorSchemes } from '../../config/ColorConfig';
15+
import { IconButton, Tooltip } from '@material-ui/core';
16+
import SaveAltIcon from '@material-ui/icons/SaveAlt';
17+
import { RenderSubValue } from '../../report/ReportRecordProcessing';
18+
import { downloadCSV } from '../ChartUtils';
1519
import { GraphChartContextMenu } from './component/GraphChartContextMenu';
1620
import { getSettings } from '../SettingsUtils';
21+
import { generateSafeColumnKey } from '../table/TableChart';
1722

1823
/**
1924
* Draws graph data using a force-directed-graph visualization.
@@ -33,7 +38,6 @@ const NeoGraphChart = (props: ChartProps) => {
3338

3439
const setNodePositions = (positions) =>
3540
props.updateReportSetting && props.updateReportSetting('nodePositions', positions);
36-
3741
const handleEntityClick = (item) => {
3842
setSelectedEntity(item);
3943
setContextMenuOpen(false);
@@ -213,6 +217,27 @@ const NeoGraphChart = (props: ChartProps) => {
213217
{settings.drilldownLink ? <NeoGraphChartDeepLinkButton {...chartProps} /> : <></>}
214218
<NeoGraphChartVisualization2D {...chartProps} />
215219
<NeoGraphChartInspectModal {...chartProps}></NeoGraphChartInspectModal>
220+
{settings.allowDownload && props.records && props.records.length > 0 ? (
221+
<Tooltip title='Download CSV' aria-label=''>
222+
<IconButton
223+
onClick={() => {
224+
const rows = props.records.map((record, rownumber) => {
225+
return Object.assign(
226+
{ id: rownumber },
227+
...record._fields.map((field, i) => ({ [generateSafeColumnKey(record.keys[i])]: field }))
228+
);
229+
});
230+
downloadCSV(rows);
231+
}}
232+
aria-label='download csv'
233+
style={{ bottom: '9px', left: '3px', position: 'absolute' }}
234+
>
235+
<SaveAltIcon style={{ fontSize: '1.3rem', zIndex: 5 }} fontSize='small'></SaveAltIcon>
236+
</IconButton>
237+
</Tooltip>
238+
) : (
239+
<></>
240+
)}
216241
</NeoGraphChartCanvas>
217242
</div>
218243
);

src/chart/map/layers/MarkerLayer.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,7 @@ export function createMarkers(data, props) {
4545
// TODO MOVE THIS DEPENDENCY OUT OF THE TOOLTIP GENERATION
4646

4747
return (
48-
<tr
49-
key={i}
50-
onClick={() => {
51-
52-
}}
53-
>
48+
<tr key={i} onClick={() => {}}>
5449
<td style={{ marginRight: '10px' }} key={0}>
5550
{k.toString()}:
5651
</td>

src/chart/table/TableChart.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ function ApplyColumnType(column, value) {
4848
return column;
4949
}
5050

51+
export const generateSafeColumnKey = (key) => {
52+
return key != 'id' ? key : `${key} `;
53+
};
54+
5155
const NeoTableChart = (props: ChartProps) => {
5256
const transposed = props.settings && props.settings.transposed ? props.settings.transposed : false;
5357
const allowDownload =
@@ -83,10 +87,6 @@ const NeoTableChart = (props: ChartProps) => {
8387

8488
const { records } = props;
8589

86-
const generateSafeColumnKey = (key) => {
87-
return key != 'id' ? key : `${key} `;
88-
};
89-
9090
const actionableFields = [];
9191

9292
const columns = transposed

src/config/ReportConfig.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ export const REPORT_TYPES = {
244244
placeholder: 'http://bloom.neo4j.io',
245245
default: '',
246246
},
247+
allowDownload: {
248+
label: 'Enable CSV Download',
249+
type: SELECTION_TYPES.LIST,
250+
values: [true, false],
251+
default: false,
252+
},
247253
hideSelections: {
248254
label: 'Hide Property Selection',
249255
type: SELECTION_TYPES.LIST,

0 commit comments

Comments
 (0)