Skip to content

Commit 3802243

Browse files
committed
fix(Dataset, CommitDetails): make sure we have a component before attempting to show it
1 parent 3326dd5 commit 3802243

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed

app/components/CommitDetails.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react'
22
import moment from 'moment'
3-
import { Resizable } from '../components/resizable'
3+
import { Resizable } from '../components/Resizable'
44
import { Action } from 'redux'
55
import ComponentList from '../components/ComponentList'
66
import DatasetComponent from './DatasetComponent'
@@ -17,7 +17,7 @@ export interface CommitDetailsProps {
1717
name: string
1818
selectedCommitPath: string
1919
commit: Commit
20-
selectedComponent: string
20+
selectedComponent: 'meta' | 'body' | 'schema' | ''
2121
sidebarWidth: number
2222
setSelectedListItem: (type: string, activeTab: string) => Action
2323
setSidebarWidth: (type: string, sidebarWidth: number) => Action
@@ -80,6 +80,21 @@ const CommitDetails: React.FunctionComponent<CommitDetailsProps> = ({
8080
if (isLoadingRef.current !== commitDetails.isLoading) {
8181
isLoadingRef.current = commitDetails.isLoading
8282
}
83+
// make sure that the component we are trying to show actually exists in this version of the dataset
84+
if (!commitDetails.isLoading) {
85+
const { components } = commitDetails
86+
if (selectedComponent === '' || (!components[selectedComponent].value || components[selectedComponent].value.length === 0)) {
87+
if (status['meta']) {
88+
setSelectedListItem('commitComponent', 'meta')
89+
return
90+
}
91+
if (status['body']) {
92+
setSelectedListItem('commitComponent', 'body')
93+
return
94+
}
95+
setSelectedListItem('commitComponent', 'schema')
96+
}
97+
}
8398
}, [commitDetails.isLoading])
8499

85100
const { status } = commitDetails

app/components/Dataset.tsx

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import DatasetComponent from './DatasetComponent'
1111
import DatasetListContainer from '../containers/DatasetListContainer'
1212
import CommitDetailsContainer from '../containers/CommitDetailsContainer'
1313

14+
import { CSSTransition } from 'react-transition-group'
15+
1416
import { defaultSidebarWidth } from '../reducers/ui'
1517

1618
import {
@@ -21,8 +23,6 @@ import {
2123
Mutations
2224
} from '../models/store'
2325

24-
import { CSSTransition } from 'react-transition-group'
25-
2626
export interface DatasetProps {
2727
// redux state
2828
ui: UI
@@ -46,6 +46,8 @@ interface DatasetState {
4646
peername: string
4747
name: string
4848
saveIsLoading: boolean
49+
workingDatasetIsLoading: boolean
50+
activeTab: string
4951
}
5052

5153
const logo = require('../assets/qri-blob-logo-tiny.png') //eslint-disable-line
@@ -56,7 +58,9 @@ export default class Dataset extends React.Component<DatasetProps> {
5658
state = {
5759
peername: null,
5860
name: null,
59-
saveIsLoading: false
61+
saveIsLoading: false,
62+
workingDatasetIsLoading: true,
63+
activeTab: this.props.selections.activeTab
6064
}
6165

6266
componentDidMount () {
@@ -74,7 +78,7 @@ export default class Dataset extends React.Component<DatasetProps> {
7478
// working dataset is selected and trigger api call(s)
7579
static getDerivedStateFromProps (nextProps: DatasetProps, prevState: DatasetState) {
7680
const { peername: newPeername, name: newName } = nextProps.selections
77-
const { peername, name } = prevState
81+
const { peername, name, workingDatasetIsLoading, activeTab } = prevState
7882
// when new props arrive, compare selections.peername and selections.name to
7983
// previous. If either is different, fetch data
8084
if ((newPeername !== peername) || (newName !== name)) {
@@ -87,6 +91,23 @@ export default class Dataset extends React.Component<DatasetProps> {
8791
}
8892
}
8993

94+
// make sure that the component we are trying to show actually exists in this version of the dataset
95+
if ((workingDatasetIsLoading && !nextProps.workingDataset.isLoading && nextProps.selections.activeTab === 'status') ||
96+
(activeTab === 'history' && nextProps.selections.activeTab === 'status')) {
97+
const { workingDataset, selections, setSelectedListItem } = nextProps
98+
const { component } = selections
99+
const { status } = workingDataset
100+
if (component === '' || !status[component]) {
101+
if (status['meta']) {
102+
setSelectedListItem('component', 'meta')
103+
}
104+
if (status['body']) {
105+
setSelectedListItem('component', 'body')
106+
}
107+
setSelectedListItem('component', 'schema')
108+
}
109+
}
110+
90111
// check state to see if there was a successful save
91112
// successful save means mutations.save.isLoading was true and is now false,
92113
// and mutations.save.error is falsy
@@ -101,7 +122,9 @@ export default class Dataset extends React.Component<DatasetProps> {
101122
}
102123

103124
return {
104-
saveIsLoading: newSaveIsLoading
125+
saveIsLoading: newSaveIsLoading,
126+
activeTab: nextProps.selections.activeTab,
127+
workingDatasetIsLoading: nextProps.workingDataset.isLoading
105128
}
106129
}
107130

@@ -110,6 +133,7 @@ export default class Dataset extends React.Component<DatasetProps> {
110133
const { ui, selections, workingDataset } = this.props
111134
const { showDatasetList, datasetSidebarWidth } = ui
112135
const {
136+
name,
113137
activeTab,
114138
component: selectedComponent,
115139
commit: selectedCommit
@@ -197,7 +221,7 @@ export default class Dataset extends React.Component<DatasetProps> {
197221
/>
198222
</Resizable>
199223
<div className='content-wrapper'>
200-
{showDatasetList && <div className='overlay'></div>}
224+
{showDatasetList && <div className='overlay' onClick={toggleDatasetList}></div>}
201225
<div className='transition-group' >
202226
<CSSTransition
203227
in={activeTab === 'status'}
@@ -219,7 +243,6 @@ export default class Dataset extends React.Component<DatasetProps> {
219243
</CSSTransition>
220244
</div>
221245
</div>
222-
223246
</div>
224247
{
225248
showDatasetList && (

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@
472472
"@types/history" "*"
473473
"@types/react" "*"
474474

475-
"@types/react-tooltip@^3.9.3":
475+
"@types/react-tooltip@3.9.3":
476476
version "3.9.3"
477477
resolved "https://registry.yarnpkg.com/@types/react-tooltip/-/react-tooltip-3.9.3.tgz#2eb1e08e128bb691197c5c7f9063fda9ffd5ea42"
478478
integrity sha512-X9xuVWlZTLUQadIIrf5MnMPo/FE8izJPRo6c6f+XUs8eIaQ2vj+5Qw4Ttw9bMUPrqImmsJp7o7FY4t1qHLFf4g==
@@ -506,7 +506,7 @@
506506
version "1.0.1"
507507
resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-1.0.1.tgz#0a851d3bd96498fa25c33ab7278ed3bd65f06c3e"
508508

509-
"@types/underscore@^1.9.2":
509+
"@types/underscore@1.9.2":
510510
version "1.9.2"
511511
resolved "https://registry.yarnpkg.com/@types/underscore/-/underscore-1.9.2.tgz#2c4f7743287218f5c2d9a83db3806672aa48530d"
512512
integrity sha512-KgOKTAD+9X+qvZnB5S1+onqKc4E+PZ+T6CM/NA5ohRPLHJXb+yCJMVf8pWOnvuBuKFNUAJW8N97IA6lba6mZGg==
@@ -6242,7 +6242,7 @@ react-test-renderer@16.8.6, react-test-renderer@^16.0.0-0:
62426242
react-is "^16.8.6"
62436243
scheduler "^0.13.6"
62446244

6245-
react-tooltip@^3.10.0:
6245+
react-tooltip@3.10.0:
62466246
version "3.10.0"
62476247
resolved "https://registry.yarnpkg.com/react-tooltip/-/react-tooltip-3.10.0.tgz#268b5ef519fd8a1369288d1f086f42c90d5da7ef"
62486248
integrity sha512-GGdxJvM1zSFztkTP7gCQbLTstWr1OOoMpJ5WZUGhimj0nhRY+MPz+92MpEnKmj0cftJ9Pd/M6FfSl0sfzmZWkg==
@@ -7629,7 +7629,7 @@ uglify-js@^3.1.4:
76297629
commander "~2.20.0"
76307630
source-map "~0.6.1"
76317631

7632-
underscore@^1.9.1:
7632+
underscore@1.9.1:
76337633
version "1.9.1"
76347634
resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.9.1.tgz#06dce34a0e68a7babc29b365b8e74b8925203961"
76357635
integrity sha512-5/4etnCkd9c8gwgowi5/om/mYO5ajCaOgdzj/oW+0eQV9WxKBDZw5+ycmKmeaTXjInS/W0BzpGLo2xR2aBwZdg==

0 commit comments

Comments
 (0)