Skip to content

Commit

Permalink
fix(setWorkingDataset): don't clear workingDataset when setWorkingDat…
Browse files Browse the repository at this point in the history
…aset is called

Also adds an e2e test to confirm behavior
  • Loading branch information
ramfox committed Jan 16, 2020
1 parent db2d9ac commit 60707ae
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 52 deletions.
56 changes: 21 additions & 35 deletions app/components/Body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import * as React from 'react'
import BodyTable from './BodyTable'
import BodyJson from './BodyJson'
import { ApiAction } from '../store/api'
import { Structure } from '../models/dataset'

import Spinner from './chrome/Spinner'
import { PageInfo, WorkingDataset } from '../models/store'
import { Action } from 'redux'
import { DetailsType, Details, StatsDetails } from '../models/details'
Expand All @@ -15,6 +15,7 @@ export interface BodyProps {
name: string
path: string
value: any[]
structure: Structure
pageInfo: PageInfo
history: boolean
format: string
Expand All @@ -35,13 +36,12 @@ export interface Header {
type: string
}

const extractColumnHeaders = (workingDataset: WorkingDataset): undefined | object => {
const structure = workingDataset.components.structure.value
const extractColumnHeaders = (structure: any, value: any): undefined | object => {
const schema = structure.schema

if (!schema) {
// iterate over first row of body
const firstRow = workingDataset.components.body.value && workingDataset.components.body.value[0]
const firstRow = value && value[0]
if (!firstRow) return undefined

// need to take a slice from index 1 because we have mutated the
Expand All @@ -63,22 +63,19 @@ const Body: React.FunctionComponent<BodyProps> = (props) => {
const {
value,
pageInfo,
workingDataset,
history,
fetchBody,
format,
fetchCommitBody,
details,
setDetailsBar,
stats
stats,
structure
} = props

const onFetch = history ? fetchCommitBody : fetchBody

const headers = extractColumnHeaders(workingDataset)

// if there's no value or format, don't show anything yet
const showSpinner = !(value && format)
const headers = extractColumnHeaders(structure, value)

const makeStatsDetails = (stats: {[key: string]: any}, title: string, index: number): StatsDetails => {
return {
Expand Down Expand Up @@ -110,31 +107,20 @@ const Body: React.FunctionComponent<BodyProps> = (props) => {

return (
<div className='transition-group'>
<>
{ showSpinner &&
<div className='spinner-container'>
<Spinner />
</div>
}
{ !showSpinner &&
<>
{shouldDisplayTable(value, format)
? <BodyTable
headers={headers}
body={value}
pageInfo={pageInfo}
highlighedColumnIndex={details.type !== DetailsType.NoDetails ? details.index : undefined}
onFetch={onFetch}
setDetailsBar={handleToggleDetailsBar}
/>
: <BodyJson
body={value}
pageInfo={pageInfo}
/>
}
</>
}
</>
{shouldDisplayTable(value, format)
? <BodyTable
headers={headers}
body={value}
pageInfo={pageInfo}
highlighedColumnIndex={details.type !== DetailsType.NoDetails ? details.index : undefined}
onFetch={onFetch}
setDetailsBar={handleToggleDetailsBar}
/>
: <BodyJson
body={value}
pageInfo={pageInfo}
/>
}
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/DatasetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class DatasetList extends React.Component<DatasetListProps> {

return (<ContextMenuArea menuItems={menuItems} key={`${peername}/${name}`}>
<div
id={`${peername}/${name}`}
id={`${peername}-${name}`}
key={`${peername}/${name}`}
className={classNames('sidebar-list-item', 'sidebar-list-item-text', {
'selected': (peername === workingDataset.peername) && (name === workingDataset.name)
Expand Down
3 changes: 1 addition & 2 deletions app/containers/BodyContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const mapStateToProps = (state: Store) => {

var format = ''
if (history) {
format = workingDataset.components.structure.value.format
format = dataset.components.structure.value.format
} else {
format = state.workingDataset.status && state.workingDataset.status.body && state.workingDataset.status.body.filepath
? path.extname(state.workingDataset.status.body.filepath).slice(1)
Expand All @@ -36,7 +36,6 @@ const mapStateToProps = (state: Store) => {
format,
history,
details,
workingDataset,
stats
}
}
Expand Down
11 changes: 4 additions & 7 deletions app/containers/CommitDetailsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { setSelectedListItem } from '../actions/selections'
import { fetchCommitDetail } from '../actions/api'

const mapStateToProps = (state: Store) => {
const { workingDataset, selections, commitDetails } = state
const { selections, commitDetails } = state

const {
peername,
Expand All @@ -15,18 +15,15 @@ const mapStateToProps = (state: Store) => {
commitComponent: selectedComponent
} = selections

// find the currently selected commit
const selectedCommit = workingDataset.history.value
.find(d => d.path === selectedCommitPath)

return {
peername,
name,
selectedCommitPath: selectedCommitPath,
commit: selectedCommit,
commit: commitDetails.components.commit.value,
selectedComponent,
commitDetails,
structure: commitDetails.components.structure.value
structure: commitDetails.components.structure.value,
isLoading: commitDetails.isLoading
}
}

Expand Down
2 changes: 2 additions & 0 deletions app/reducers/selections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ export default (state = initialState, action: AnyAction) => {
case SELECTIONS_SET_WORKING_DATASET:
const { peername, name } = action.payload

if (peername === state.peername && name === state.name) return state

localStore().setItem('peername', peername)
localStore().setItem('name', name)
localStore().setItem('commit', '')
Expand Down
7 changes: 1 addition & 6 deletions app/reducers/workingDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import { ipcRenderer } from 'electron'
import bodyValue from '../utils/bodyValue'

import {
REMOVE_SUCC,
SELECTIONS_SET_WORKING_DATASET
REMOVE_SUCC
} from './selections'

const initialState: WorkingDataset = {
Expand All @@ -18,7 +17,6 @@ const initialState: WorkingDataset = {
name: '',
status: {},
isLoading: false,
isCommiting: false,
fsiPath: '',
published: true,
hasHistory: true,
Expand Down Expand Up @@ -271,9 +269,6 @@ const workingDatasetsReducer: Reducer = (state = initialState, action: AnyAction
stats: []
}

case SELECTIONS_SET_WORKING_DATASET:
return initialState

case RENAME_SUCC:
return {
...state,
Expand Down
30 changes: 29 additions & 1 deletion test/e2e/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Qri End to End tests', function spec () {
const password = '1234567890!!'

beforeAll(async () => {
jest.setTimeout(30000)
jest.setTimeout(60000)

// spin up a new mock backend with a mock registry server attached
backend = new TestBackendProcess()
Expand Down Expand Up @@ -206,6 +206,31 @@ describe('Qri End to End tests', function spec () {
await checkStatus('structure', 'added')
})

it ('navigate to collection and back to dataset', async () => {
const {
atLocation,
click,
expectTextToBe,
onHistoryTab
} = utils

await click('#history-tab')
await onHistoryTab()

await click('#collection')
// ensure we have redirected to the collection page
await atLocation('#/collection')
// click the dataset
const ref = `#${username}-${datasetName}`
await click(ref)
// ensure we have redirected to the dataset page
await atLocation('#/dataset')
// ensure we are still at the history tab
await onHistoryTab()
// ensure we have a commit title
await expectTextToBe('#commit-title', 'created dataset')
})

// checkout
it('checkout a dataset', async () => {
const {
Expand All @@ -219,6 +244,9 @@ describe('Qri End to End tests', function spec () {

// at dataset
await click('#dataset')
// at status
await click('#status-tab')
await onStatusTab()
// body is disabled
await exists(['#body-status.disabled'])
// click #checkout to open checkout modal
Expand Down

0 comments on commit 60707ae

Please sign in to comment.