Skip to content

Commit

Permalink
feat: init dataset ui
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswhong committed Sep 6, 2019
1 parent b9e9180 commit 704a2da
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 34 deletions.
34 changes: 26 additions & 8 deletions app/actions/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ export function fetchWorkingHistory (page: number = 1, pageSize: number = pageSi

export function fetchWorkingStatus (): ApiActionThunk {
return async (dispatch, getState) => {
const { selections } = getState()
const { peername, name, isLinked } = selections
const { workingDataset } = getState()
const { peername, name, linkpath } = workingDataset
const action = {
type: 'status',
[CALL_API]: {
endpoint: 'status',
method: 'GET',
params: { fsi: isLinked },
params: { fsi: linkpath !== '' },
segments: {
peername: peername,
name: name
Expand Down Expand Up @@ -448,31 +448,32 @@ export function addDatasetAndFetch (peername: string, name: string): ApiActionTh
}
}

export function initDataset (filepath: string, name: string, dir: string): ApiActionThunk {
export function initDataset (sourcebodypath: string, name: string, dir: string, mkdir: string): ApiActionThunk {
return async (dispatch) => {
const action = {
type: 'init',
[CALL_API]: {
endpoint: 'init/',
method: 'POST',
params: {
filepath,
sourcebodypath,
name,
dir
dir,
mkdir
}
}
}
return dispatch(action)
}
}

export function initDatasetAndFetch (filepath: string, name: string, format: string): ApiActionThunk {
export function initDatasetAndFetch (sourcebodypath: string, name: string, dir: string, mkdir: string): ApiActionThunk {
return async (dispatch, getState) => {
const whenOk = chainSuccess(dispatch, getState)
let response: Action

try {
response = await initDataset(filepath, name, format)(dispatch, getState)
response = await initDataset(sourcebodypath, name, dir, mkdir)(dispatch, getState)
response = await whenOk(fetchMyDatasets())(response)
} catch (action) {
throw action
Expand Down Expand Up @@ -597,3 +598,20 @@ export function discardChanges (component: ComponentType): ApiActionThunk {
return response
}
}

export function removeDataset (peername: string, name: string): ApiActionThunk {
return async (dispatch) => {
const action = {
type: 'add',
[CALL_API]: {
endpoint: 'add',
method: 'POST',
segments: {
peername,
name
}
}
}
return dispatch(action)
}
}
1 change: 0 additions & 1 deletion app/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export default class App extends React.Component<AppProps, AppState> {
onSubmit={this.props.initDataset}
onDismissed={async () => setModal(NoModal)}
setWorkingDataset={this.props.setWorkingDataset}
fetchMyDatasets={this.props.fetchMyDatasets}
/>
</CSSTransition>
<CSSTransition
Expand Down
35 changes: 20 additions & 15 deletions app/components/Dataset.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as React from 'react'
import { Action } from 'redux'
import * as _ from 'underscore'
import classNames from 'classnames'
import ReactTooltip from 'react-tooltip'
import { remote, ipcRenderer, shell } from 'electron'
Expand Down Expand Up @@ -160,22 +161,26 @@ export default class Dataset extends React.Component<DatasetProps> {
}
}

// make sure that the component we are trying to show actually exists in this version of the dataset
// TODO (ramfox): there is a bug here when we try to switch to body, but body hasn't finished fetching yet
// this will prematurely decide to switch away from body.
if ((workingDatasetIsLoading && !nextProps.workingDataset.isLoading && nextProps.selections.activeTab === 'status') ||
(activeTab === 'history' && nextProps.selections.activeTab === 'status')) {
const { workingDataset, selections, setSelectedListItem } = nextProps
const { component } = selections
const { status } = workingDataset
if (component === '' || !status[component]) {
if (status['meta']) {
setSelectedListItem('component', 'meta')
if (!_.isEmpty(nextProps.workingDataset.status)) {
// make sure that the component we are trying to show actually exists in this version of the dataset
// TODO (ramfox): there is a bug here when we try to switch to body, but body hasn't finished fetching yet
// this will prematurely decide to switch away from body.
if ((workingDatasetIsLoading && !nextProps.workingDataset.isLoading && nextProps.selections.activeTab === 'status') ||
(activeTab === 'history' && nextProps.selections.activeTab === 'status')) {
const { workingDataset, selections, setSelectedListItem } = nextProps
const { component } = selections
const { status } = workingDataset
console.log('STATUS', status)
if (component === '' || !status[component]) {
if (status['meta']) {
setSelectedListItem('component', 'meta')
}
if (status['body']) {
setSelectedListItem('component', 'body')
}
console.log('HERE')
setSelectedListItem('component', 'schema')
}
if (status['body']) {
setSelectedListItem('component', 'body')
}
setSelectedListItem('component', 'schema')
}
}

Expand Down
16 changes: 9 additions & 7 deletions app/components/modals/CreateDataset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import Error from './Error'
import Buttons from './Buttons'
// import Tabs from './Tabs'
import ButtonInput from '../form/ButtonInput'
import { DatasetSummary } from '../../models/store'

interface CreateDatasetProps {
onDismissed: () => void
onSubmit: (path: string, name: string, format: string) => Promise<ApiAction>
onSubmit: (path: string, name: string, dir: string, mkdir: string) => Promise<ApiAction>
setWorkingDataset: (peername: string, name: string, isLinked: boolean, published: boolean) => Promise<ApiAction>
fetchMyDatasets: () => Promise<ApiAction>
}

// setWorkingDataset
const CreateDataset: React.FunctionComponent<CreateDatasetProps> = ({ onDismissed, onSubmit, setWorkingDataset, fetchMyDatasets }) => {
const CreateDataset: React.FunctionComponent<CreateDatasetProps> = ({ onDismissed, onSubmit, setWorkingDataset }) => {
const [datasetName, setDatasetName] = React.useState('')
const [path, setPath] = React.useState('')
const [filePath, setFilePath] = React.useState('')
Expand Down Expand Up @@ -117,11 +117,13 @@ const CreateDataset: React.FunctionComponent<CreateDatasetProps> = ({ onDismisse
setLoading(true)
error && setError('')
if (!onSubmit) return
onSubmit(filePath, datasetName, `${path}/${datasetName}`)
.then(({ peername, name, isLinked, published }) => {
onSubmit(filePath, datasetName, path, datasetName)
.then(({ payload }) => {
const { data } = payload
// make sure the dataset we just added is in the list
const { peername, name, fsipath, published } = data.find((dataset: DatasetSummary) => dataset.name === datasetName)
setWorkingDataset(peername, name, fsipath !== '', published)
onDismissed()
setWorkingDataset(peername, name, isLinked, published)
fetchMyDatasets()
})
.catch((action: any) => {
setLoading(false)
Expand Down
6 changes: 3 additions & 3 deletions app/reducers/selections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ export default (state = initialState, action: AnyAction) => {
// if there is no peername + name in selections, use the first one on the list
if (state.peername === '' && state.name === '') {
if (action.payload.data.length === 0) return state
const { peername: firstPeername, name: firstName, isLinked: firstIsLinked, published } = action.payload.data[0]
const { peername: firstPeername, name: firstName, fsipath: firstIsLinked, published } = action.payload.data[0]
localStore().setItem('peername', firstPeername)
localStore().setItem('name', firstName)
localStore().setItem('isLinked', firstIsLinked)
localStore().setItem('isLinked', JSON.stringify(!!firstIsLinked))
localStore().setItem('published', published)
return Object.assign({}, state, { peername: firstPeername, name: firstName, isLinked: firstIsLinked, published })
return Object.assign({}, state, { peername: firstPeername, name: firstName, fsipath: firstIsLinked, published })
} else {
return state
}
Expand Down

0 comments on commit 704a2da

Please sign in to comment.