Skip to content

Commit

Permalink
Clears the resourceURIMessage when clicking back into the edito… (#1027)
Browse files Browse the repository at this point in the history
Clears the resourceURIMessage when clicking back into the editor screen
  • Loading branch information
ndushay authored Jul 23, 2019
2 parents 932c56c + a568e2d commit c1b4231
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 10 deletions.
16 changes: 9 additions & 7 deletions __tests__/actionCreators/resources.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ describe('newResource', () => {
await store.dispatch(newResource(resourceTemplateId))
const actions = store.getActions()
expect(actions[0]).toEqual({ type: 'CLEAR_RESOURCE_TEMPLATES' })
expect(actions[1]).toEqual({ type: 'SET_RESOURCE', payload: { [resourceTemplateId]: {} } })
expect(actions[2]).toEqual({ type: 'RETRIEVE_RESOURCE_TEMPLATE_STARTED', payload: resourceTemplateId })
expect(actions[3]).toEqual({ type: 'SET_RESOURCE_TEMPLATE', payload: resourceTemplateResponse.response.body })
expect(actions[1]).toEqual({ type: 'CLEAR_RESOURCE_URI_MESSAGE' })
expect(actions[2]).toEqual({ type: 'SET_RESOURCE', payload: { [resourceTemplateId]: {} } })
expect(actions[3]).toEqual({ type: 'RETRIEVE_RESOURCE_TEMPLATE_STARTED', payload: resourceTemplateId })
expect(actions[4]).toEqual({ type: 'SET_RESOURCE_TEMPLATE', payload: resourceTemplateResponse.response.body })
})
})

Expand All @@ -116,10 +117,11 @@ describe('existingResource', () => {

await store.dispatch(existingResource(resource, 'http://localhost:8080/repository/stanford/888ea64d-f471-41bf-9d33-c9426ab83b5c'))
const actions = store.getActions()
expect(actions[0]).toEqual({ type: 'SET_RESOURCE', payload: { [resourceTemplateId]: {} } })
expect(actions[1]).toEqual({ type: 'SET_BASE_URL', payload: 'http://localhost:8080/repository/stanford/888ea64d-f471-41bf-9d33-c9426ab83b5c' })
expect(actions[2]).toEqual({ type: 'RETRIEVE_RESOURCE_TEMPLATE_STARTED', payload: undefined })
expect(actions[3]).toEqual({ type: 'SET_RESOURCE_TEMPLATE', payload: resourceTemplateResponse.response.body })
expect(actions[0]).toEqual({ type: 'CLEAR_RESOURCE_URI_MESSAGE' })
expect(actions[1]).toEqual({ type: 'SET_RESOURCE', payload: { [resourceTemplateId]: {} } })
expect(actions[2]).toEqual({ type: 'SET_BASE_URL', payload: 'http://localhost:8080/repository/stanford/888ea64d-f471-41bf-9d33-c9426ab83b5c' })
expect(actions[3]).toEqual({ type: 'RETRIEVE_RESOURCE_TEMPLATE_STARTED', payload: undefined })
expect(actions[4]).toEqual({ type: 'SET_RESOURCE_TEMPLATE', payload: resourceTemplateResponse.response.body })
})
})

Expand Down
18 changes: 17 additions & 1 deletion __tests__/reducers/inputs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {
removeMyItem, setItemsOrSelections, setBaseURL,
validate, showGroupChooser, closeGroupChooser, showRdfPreview,
showResourceURIMessage,
showResourceURIMessage, clearResourceURIMessage,
} from 'reducers/inputs'
import {
findNode,
Expand Down Expand Up @@ -377,6 +377,22 @@ describe('showResourceURIMessage', () => {
})
})

describe('clearResourceURIMessage', () => {
it('turns off the Resource URI message display', () => {
initialState.editor.resourceURIMessage = {
show: true,
uri: 'this message will disapear',
}

const result = clearResourceURIMessage(initialState, {
type: 'CLEAR_RESOURCE_URI_MESSAGE',
})

expect(result.editor.resourceURIMessage.show).toBe(false)
expect(result.editor.resourceURIMessage.uri).toEqual('')
})
})

describe('removeMyItem', () => {
it('removes an item from state', () => {
initialState.resource = {
Expand Down
3 changes: 3 additions & 0 deletions src/actionCreators/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
assignBaseURL, updateStarted, updateFinished,
retrieveResourceStarted, setResource, updateProperty,
toggleCollapse, appendResource, clearResourceTemplates,
clearResourceURIMessage,
} from 'actions/index'
import { fetchResourceTemplate } from 'actionCreators/resourceTemplates'
import { updateRDFResource, loadRDFResource } from 'sinopiaServer'
Expand Down Expand Up @@ -47,12 +48,14 @@ export const newResource = resourceTemplateId => (dispatch) => {
const resource = {}
resource[resourceTemplateId] = {}
dispatch(clearResourceTemplates())
dispatch(clearResourceURIMessage())
dispatch(setResource(resource))
dispatch(stubResource(true))
}

// A thunk that stubs out an existing new resource
export const existingResource = (resource, uri) => (dispatch) => {
dispatch(clearResourceURIMessage())
dispatch(setResource(resource))
dispatch(assignBaseURL(uri))
dispatch(stubResource(false))
Expand Down
4 changes: 4 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ export const showResourceURIMessage = resourceUri => ({
payload: resourceUri,
})

export const clearResourceURIMessage = () => ({
type: 'CLEAR_RESOURCE_URI_MESSAGE',
})

export const updateStarted = () => ({
type: 'UPDATE_STARTED',
})
Expand Down
5 changes: 3 additions & 2 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import { combineReducers } from 'redux'
import authenticate from './authenticate'
import {
removeMyItem, setItemsOrSelections, setBaseURL, showResourceURIMessage, setMyItemsLang,
showGroupChooser, closeGroupChooser, showRdfPreview,
removeMyItem, setItemsOrSelections, setBaseURL, showResourceURIMessage, clearResourceURIMessage,
setMyItemsLang, showGroupChooser, closeGroupChooser, showRdfPreview,
} from './inputs'
import {
setResourceTemplate, clearResourceTemplates, setResourceTemplateSummary,
Expand Down Expand Up @@ -111,6 +111,7 @@ const handlers = {
RETRIEVE_RESOURCE_TEMPLATE_STARTED: clearRetrieveError,
SET_BASE_URL: setBaseURL,
SHOW_RESOURCE_URI_MESSAGE: showResourceURIMessage,
CLEAR_RESOURCE_URI_MESSAGE: clearResourceURIMessage,
SHOW_SEARCH_RESULTS: showSearchResults,
SHOW_GROUP_CHOOSER: showGroupChooser,
CLOSE_GROUP_CHOOSER: closeGroupChooser,
Expand Down
13 changes: 13 additions & 0 deletions src/reducers/inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,19 @@ export const showResourceURIMessage = (state, action) => {
return newState
}

/**
* @param {Object} state the previous redux state
* @param {Object} action the payload of the action is the URI returned from saving the resource
* @return {Object} the next redux state
*/
export const clearResourceURIMessage = (state) => {
const newState = { ...state }

newState.editor.resourceURIMessage.show = false
newState.editor.resourceURIMessage.uri = ''
return newState
}

export const removeMyItem = (state, action) => {
const newState = { ...state }
const reduxPath = action.payload.reduxPath
Expand Down

0 comments on commit c1b4231

Please sign in to comment.