-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DRYD-1351: Rework Create Page (#246)
* Add redux action and reducer for service tags * Group procedures by tags in the create page * Add tag configuration object
- Loading branch information
1 parent
685656f
commit 83ab7b4
Showing
14 changed files
with
636 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { get } from 'lodash'; | ||
import getSession from '../helpers/session'; | ||
|
||
import { | ||
SERVICE_TAGS_READ_STARTED, | ||
SERVICE_TAGS_READ_FULFILLED, | ||
SERVICE_TAGS_READ_REJECTED, | ||
PROCEDURE_BY_TAG_READ_STARTED, | ||
PROCEDURE_BY_TAG_READ_FULFILLED, | ||
PROCEDURE_BY_TAG_READ_REJECTED, | ||
} from '../constants/actionCodes'; | ||
|
||
const doRead = (tag, dispatch) => { | ||
dispatch({ | ||
type: PROCEDURE_BY_TAG_READ_STARTED, | ||
meta: { | ||
tag: tag.name, | ||
}, | ||
}); | ||
|
||
const session = getSession(); | ||
const requestConfig = { | ||
params: { | ||
servicetag: tag.name, | ||
}, | ||
}; | ||
|
||
return session.read('servicegroups/procedure', requestConfig) | ||
.then((response) => dispatch({ | ||
type: PROCEDURE_BY_TAG_READ_FULFILLED, | ||
payload: response, | ||
meta: { | ||
tag: tag.name, | ||
}, | ||
})) | ||
.catch((error) => { | ||
dispatch({ | ||
type: PROCEDURE_BY_TAG_READ_REJECTED, | ||
meta: { | ||
tag: tag.name, | ||
}, | ||
}); | ||
return Promise.reject(error); | ||
}); | ||
}; | ||
|
||
const readProcedures = (response, dispatch) => { | ||
let tags = get(response, ['data', 'ns2:abstract-common-list', 'list-item']); | ||
if (!tags) { | ||
return Promise.resolve(); | ||
} | ||
|
||
if (!Array.isArray(tags)) { | ||
tags = [tags]; | ||
} | ||
|
||
const promises = tags.map((tag) => doRead(tag, dispatch)); | ||
return Promise.all(promises) | ||
.catch((error) => Promise.reject(error)); | ||
}; | ||
|
||
export default () => (dispatch) => { | ||
dispatch({ type: SERVICE_TAGS_READ_STARTED }); | ||
|
||
const session = getSession(); | ||
|
||
return session.read('servicegroups/procedure/tags') | ||
.then((response) => { | ||
dispatch({ type: SERVICE_TAGS_READ_FULFILLED }); | ||
return readProcedures(response, dispatch); | ||
}) | ||
.catch((error) => { | ||
dispatch({ | ||
type: SERVICE_TAGS_READ_REJECTED, | ||
payload: error, | ||
}); | ||
|
||
return Promise.reject(error); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.