diff --git a/app/actions/api.ts b/app/actions/api.ts index 2dd6dd78..8dc31906 100644 --- a/app/actions/api.ts +++ b/app/actions/api.ts @@ -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 @@ -448,7 +448,7 @@ 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', @@ -456,9 +456,10 @@ export function initDataset (filepath: string, name: string, dir: string): ApiAc endpoint: 'init/', method: 'POST', params: { - filepath, + sourcebodypath, name, - dir + dir, + mkdir } } } @@ -466,13 +467,13 @@ export function initDataset (filepath: string, name: string, dir: string): ApiAc } } -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 @@ -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) + } +} diff --git a/app/components/App.tsx b/app/components/App.tsx index 3275995a..42887272 100644 --- a/app/components/App.tsx +++ b/app/components/App.tsx @@ -128,7 +128,6 @@ export default class App extends React.Component { onSubmit={this.props.initDataset} onDismissed={async () => setModal(NoModal)} setWorkingDataset={this.props.setWorkingDataset} - fetchMyDatasets={this.props.fetchMyDatasets} /> { } } - // 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') } } diff --git a/app/components/modals/CreateDataset.tsx b/app/components/modals/CreateDataset.tsx index ab24df10..37f8bd41 100644 --- a/app/components/modals/CreateDataset.tsx +++ b/app/components/modals/CreateDataset.tsx @@ -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 + onSubmit: (path: string, name: string, dir: string, mkdir: string) => Promise setWorkingDataset: (peername: string, name: string, isLinked: boolean, published: boolean) => Promise - fetchMyDatasets: () => Promise } // setWorkingDataset -const CreateDataset: React.FunctionComponent = ({ onDismissed, onSubmit, setWorkingDataset, fetchMyDatasets }) => { +const CreateDataset: React.FunctionComponent = ({ onDismissed, onSubmit, setWorkingDataset }) => { const [datasetName, setDatasetName] = React.useState('') const [path, setPath] = React.useState('') const [filePath, setFilePath] = React.useState('') @@ -117,11 +117,13 @@ const CreateDataset: React.FunctionComponent = ({ 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) diff --git a/app/reducers/selections.ts b/app/reducers/selections.ts index 06bd2390..f951d5c2 100644 --- a/app/reducers/selections.ts +++ b/app/reducers/selections.ts @@ -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 }