Skip to content
Snippets Groups Projects
Commit b6dfa759 authored by Tamlyn Rhodes's avatar Tamlyn Rhodes
Browse files

Update fragment actions for top level fragment API

Allow passing a falsy value as the collection and construct the appropriate URL
parent 9debb4e5
No related branches found
No related tags found
1 merge request!126Update fragment actions for top level fragment API
Pipeline #2940 passed with stage
in 1 minute and 32 seconds
...@@ -2,19 +2,10 @@ import * as api from '../helpers/api' ...@@ -2,19 +2,10 @@ import * as api from '../helpers/api'
import * as T from './types' import * as T from './types'
export const fragmentUrl = (collection, fragment) => { export const fragmentUrl = (collection, fragment) => {
let url = `/collections/${collection.id}/fragments` let url = ''
if (collection) url += `/collections/${collection.id}`
if (fragment.id) url += `/${fragment.id}` url += '/fragments'
if (fragment && fragment.id) url += `/${fragment.id}`
return url
}
export const collectionUrl = (collection, suffix) => {
let url = '/collections'
if (collection) url += `/${collection.id}`
if (suffix) url += `/${suffix}`
return url return url
} }
...@@ -46,7 +37,7 @@ export function getFragments(collection, options) { ...@@ -46,7 +37,7 @@ export function getFragments(collection, options) {
return dispatch => { return dispatch => {
dispatch(getFragmentsRequest(collection)) dispatch(getFragmentsRequest(collection))
let url = collectionUrl(collection, 'fragments') let url = fragmentUrl(collection)
if (options && options.fields) { if (options && options.fields) {
url += '?fields=' + encodeURIComponent(options.fields.join(',')) url += '?fields=' + encodeURIComponent(options.fields.join(','))
......
...@@ -36,7 +36,8 @@ describe('fragments actions', () => { ...@@ -36,7 +36,8 @@ describe('fragments actions', () => {
}) })
describeAction('createFragment', { describeAction('createFragment', {
firstarg: mockcol, // no collection routes to top level fragment endpoint
firstarg: null,
secondarg: { secondarg: {
title: 'mock fragment', title: 'mock fragment',
type: 'some_fragment', type: 'some_fragment',
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment