-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #321 from vzhyhunou/dev
export data
- Loading branch information
Showing
13 changed files
with
101 additions
and
97 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
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 was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1 +1 @@ | ||
export default src => process.env.REACT_APP_DATA && src().then(r => r.default); | ||
export default data => process.env.REACT_APP_DATA ? data().then(r => ({...r, data: r.default})) : Promise.resolve({}); |
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
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,69 @@ | ||
import fakeDataProvider from 'ra-data-fakerest'; | ||
|
||
const log = (params, response) => { | ||
if (console.group) { | ||
console.groupCollapsed('exchange', JSON.stringify(params)); | ||
console.log(response); | ||
console.groupEnd(); | ||
} else { | ||
console.log('FakeRest request ', 'exchange', params); | ||
console.log('FakeRest response', response); | ||
} | ||
}; | ||
|
||
export const getResponse = getLocale => (data, params) => { | ||
|
||
const locale = getLocale(); | ||
const {pages} = data; | ||
const {path} = params; | ||
const p = path.split('/'); | ||
|
||
switch (p[0]) { | ||
case 'pages': | ||
switch (p[2]) { | ||
case 'one': | ||
const page = pages.find(({id}) => id === p[3]); | ||
if (!page) { | ||
return false; | ||
} | ||
const {id, title, content, files} = page; | ||
return {data: { | ||
id, | ||
title: title[locale], | ||
content: content[locale], | ||
files: files && files.map(({name}) => name) | ||
}}; | ||
case 'menu': | ||
return {data: pages.filter(({tags}) => tags.some(({name}) => name === 'MENU')) | ||
.map(({id, title}) => ({ | ||
id, | ||
title: title[locale] | ||
})) | ||
}; | ||
default: | ||
return false; | ||
} | ||
default: | ||
return false; | ||
} | ||
}; | ||
|
||
export default (data, getResponse) => { | ||
|
||
const handle = params => { | ||
let response; | ||
try { | ||
response = getResponse(data, params); | ||
} catch (error) { | ||
console.error(error); | ||
return Promise.reject(error); | ||
} | ||
log(params, response); | ||
return Promise.resolve(response); | ||
}; | ||
|
||
return { | ||
...fakeDataProvider(data, true), | ||
exchange: params => handle(params) | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './admin'; | ||
export * from './commons'; | ||
export * from './pages'; | ||
export * from './pages'; | ||
export * from './data'; |