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 17, 2020
1 parent db2d9ac commit 0e3878c
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 56 deletions.
3 changes: 2 additions & 1 deletion RELEASE_PROCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ This will only work if you are internal to Qri and have the correct keys
- app-builder is modifying the contents of the zip, which is messing up the notarization. The -o flag indicates an output file that app-builder can futz with without ruining the integrity of the original app
- take the updated file into from size, sha512 and blockMapSize
- update the `/release/latest-mac.yml` with that info
- replace `FILENAME.zip` to the release page
- replace `FILENAME.zip` to the release page
12) **remember to change website link give details of where here**
3 changes: 0 additions & 3 deletions app/actions/selections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export const setActiveTab = (activeTab: string) => {
}

export const setSelectedListItem = (type: string, selectedListItem: string) => {
if (type === 'commit') {
console.log('setting to', selectedListItem)
}
return {
type: SELECTIONS_SET_SELECTED_LISTITEM,
payload: {
Expand Down
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 0e3878c

Please sign in to comment.