Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature relatable #1090

Merged
merged 5 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@
},
"dependencies": {
"@neo4j/browser-lambda-parser": "1.0.4",
"@relate-by-ui/css": "^1.0.4",
"@relate-by-ui/css": "1.0.5",
"@relate-by-ui/relatable": "1.0.1",
"@relate-by-ui/saved-scripts": "^1.0.4",
"ascii-data-table": "^2.1.1",
"canvg": "^1.5.3",
Expand Down
7 changes: 6 additions & 1 deletion src/browser/modules/D3Visualization/components/Explorer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import neoGraphStyle from '../graphStyle'
import { InspectorComponent } from './Inspector'
import { LegendComponent } from './Legend'
import { StyledFullSizeContainer } from './styled'
import { getMaxFieldItems } from 'shared/modules/settings/settingsDuck'
import { connect } from 'react-redux'

const deduplicateNodes = nodes => {
return nodes.reduce(
Expand Down Expand Up @@ -231,6 +233,7 @@ export class ExplorerComponent extends Component {
setGraph={this.props.setGraph}
/>
<InspectorComponent
hasTruncatedFields={this.props.hasTruncatedFields}
fullscreen={this.props.fullscreen}
hoveredItem={this.state.hoveredItem}
selectedItem={this.state.selectedItem}
Expand All @@ -241,4 +244,6 @@ export class ExplorerComponent extends Component {
)
}
}
export const Explorer = ExplorerComponent
export const Explorer = connect(state => ({
maxFieldItems: getMaxFieldItems(state)
}))(ExplorerComponent)
9 changes: 9 additions & 0 deletions src/browser/modules/D3Visualization/components/Inspector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ import { GrassEditor } from './GrassEditor'
import { RowExpandToggleComponent } from './RowExpandToggle'
import ClickableUrls from '../../../components/clickable-urls'
import numberToUSLocale from 'shared/utils/number-to-US-locale'
import { StyledTruncatedMessage } from 'browser/modules/Stream/styled'
import { Icon } from 'semantic-ui-react'
import Ellipsis from 'browser-components/Ellipsis'

const mapItemProperties = itemProperties =>
itemProperties
Expand Down Expand Up @@ -149,6 +152,12 @@ export class InspectorComponent extends Component {
<StyledInlineList className="list-inline">
<StyledInspectorFooterRowListPair className="pair" key="pair">
<StyledInspectorFooterRowListValue className="value">
{this.props.hasTruncatedFields && (
<StyledTruncatedMessage>
<Icon name="warning sign" /> Record fields have been
truncated.&nbsp;
</StyledTruncatedMessage>
)}
{description}
</StyledInspectorFooterRowListValue>
</StyledInspectorFooterRowListPair>
Expand Down
44 changes: 34 additions & 10 deletions src/browser/modules/Stream/CypherFrame/AsciiView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React, { Component } from 'react'
import React, { Component, useMemo } from 'react'
import asciitable from 'ascii-data-table'
import Render from 'browser-components/Render'
import Ellipsis from 'browser-components/Ellipsis'
Expand All @@ -29,17 +29,22 @@ import {
StyledBodyMessage,
StyledRightPartial,
StyledWidthSliderContainer,
StyledWidthSlider
StyledWidthSlider,
StyledTruncatedMessage
} from '../styled'
import {
getBodyAndStatusBarMessages,
getRecordsToDisplayInTable,
transformResultRecordsToResultArray,
stringifyResultArray
stringifyResultArray,
resultHasTruncatedFields
} from './helpers'
import { stringModifier } from 'services/bolt/cypherTypesFormatting'
import { getMaxFieldItems } from 'shared/modules/settings/settingsDuck'
import { connect } from 'react-redux'
import { Icon } from 'semantic-ui-react'

export class AsciiView extends Component {
export class AsciiViewComponent extends Component {
state = {
serializedRows: [],
bodyMessage: ''
Expand Down Expand Up @@ -73,7 +78,7 @@ export class AsciiView extends Component {
}

makeState(props) {
const { result, maxRows } = props
const { result, maxRows, maxFieldItems } = props
const { bodyMessage = null } =
getBodyAndStatusBarMessages(result, maxRows) || {}
this.setState({ bodyMessage })
Expand All @@ -82,7 +87,7 @@ export class AsciiView extends Component {
const serializedRows =
stringifyResultArray(
stringModifier,
transformResultRecordsToResultArray(records)
transformResultRecordsToResultArray(records, maxFieldItems)
) || []
this.setState({ serializedRows })
const maxColWidth = asciitable.maxColumnWidth(serializedRows)
Expand Down Expand Up @@ -110,12 +115,17 @@ export class AsciiView extends Component {
}
}

export class AsciiStatusbar extends Component {
export const AsciiView = connect(state => ({
maxFieldItems: getMaxFieldItems(state)
}))(AsciiViewComponent)

export class AsciiStatusbarComponent extends Component {
state = {
maxSliderWidth: 140,
minSliderWidth: 3,
maxColWidth: 70,
statusBarMessage: ''
statusBarMessage: '',
hasTruncatedFields: false
}

componentDidUpdate() {
Expand All @@ -126,7 +136,11 @@ export class AsciiStatusbar extends Component {
this.setMaxSliderWidth(props._asciiMaxColWidth)
const { statusBarMessage = null } =
getBodyAndStatusBarMessages(props.result, props.maxRows) || {}
this.setState({ statusBarMessage })
const hasTruncatedFields = resultHasTruncatedFields(
props.result,
props.maxFieldItems
)
this.setState({ statusBarMessage, hasTruncatedFields })
}

shouldComponentUpdate(props, state) {
Expand Down Expand Up @@ -156,13 +170,19 @@ export class AsciiStatusbar extends Component {
render() {
const hasRecords =
this.props.result.records && this.props.result.records.length
const { maxColWidth, maxSliderWidth } = this.state
const { maxColWidth, maxSliderWidth, hasTruncatedFields } = this.state
return (
<StyledStatsBar>
<Render if={!hasRecords}>
<Ellipsis>{this.state.statusBarMessage}</Ellipsis>
</Render>
<Render if={hasRecords}>
{hasTruncatedFields && (
<StyledTruncatedMessage>
<Icon name="warning sign" /> Record fields have been
truncated.&nbsp;
</StyledTruncatedMessage>
)}
<StyledRightPartial>
<StyledWidthSliderContainer>
Max column width:
Expand All @@ -180,3 +200,7 @@ export class AsciiStatusbar extends Component {
)
}
}

export const AsciiStatusbar = connect(state => ({
maxFieldItems: getMaxFieldItems(state)
}))(AsciiStatusbarComponent)
5 changes: 4 additions & 1 deletion src/browser/modules/Stream/CypherFrame/AsciiView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import React from 'react'
import { render } from '@testing-library/react'
import neo4j from 'neo4j-driver'

import { AsciiView, AsciiStatusbar } from './AsciiView'
import {
AsciiViewComponent as AsciiView,
AsciiStatusbarComponent as AsciiStatusbar
} from './AsciiView'

describe('AsciiViews', () => {
describe('AsciiView', () => {
Expand Down
42 changes: 35 additions & 7 deletions src/browser/modules/Stream/CypherFrame/CodeView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ import {
StyledTd,
StyledExpandable
} from '../styled'
import { TableStatusbar } from './TableView'
import {
RelatableStatusbar,
RelatableStatusbarComponent
} from './relatable-view'
import { getMaxFieldItems } from 'shared/modules/settings/settingsDuck'
import { connect } from 'react-redux'
import { map, take } from 'lodash-es'

class ExpandableContent extends Component {
state = {}
Expand All @@ -54,16 +60,33 @@ class ExpandableContent extends Component {
}
}

export class CodeView extends Component {
const fieldLimiterFactory = maxFieldItems => (key, val) => {
if (!maxFieldItems || key !== '_fields') {
return val
}

return map(val, field => {
return Array.isArray(field) ? take(field, maxFieldItems) : field
})
}

export class CodeViewComponent extends Component {
shouldComponentUpdate(props) {
return !this.props.result || !deepEquals(props.result, this.props.result)
}

render() {
const { request = {}, query } = this.props
const { request = {}, query, maxFieldItems } = this.props
if (request.status !== 'success') return null
const resultJson = JSON.stringify(request.result.records, null, 2)
const summaryJson = JSON.stringify(request.result.summary, null, 2)
const resultJson = JSON.stringify(
request.result.records,
fieldLimiterFactory(maxFieldItems),
2
)
const summaryJson = JSON.stringify(
request.result.summary,
fieldLimiterFactory(maxFieldItems),
2
)
return (
<PaddedDiv>
<StyledTable>
Expand Down Expand Up @@ -97,4 +120,9 @@ export class CodeView extends Component {
}
}

export const CodeStatusbar = TableStatusbar
export const CodeView = connect(state => ({
maxFieldItems: getMaxFieldItems(state)
}))(CodeViewComponent)

export const CodeStatusbarComponent = RelatableStatusbarComponent
export const CodeStatusbar = RelatableStatusbar
5 changes: 4 additions & 1 deletion src/browser/modules/Stream/CypherFrame/CodeView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ import React from 'react'
import { render } from '@testing-library/react'
import neo4j from 'neo4j-driver'

import { CodeView, CodeStatusbar } from './CodeView'
import {
CodeViewComponent as CodeView,
CodeStatusbarComponent as CodeStatusbar
} from './CodeView'

describe('CodeViews', () => {
describe('CodeView', () => {
Expand Down
Loading