-
Notifications
You must be signed in to change notification settings - Fork 4
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 #367 from codaco/feature/migrate-to-asset-manifest
Update to new asset manifest protocol format
- Loading branch information
Showing
14 changed files
with
242 additions
and
153 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
11 changes: 11 additions & 0 deletions
11
src/components/StageEditor/sections/ContentGrid/withFilteredFieldErrors.js
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,11 @@ | ||
import { withPropsOnChange } from 'recompose'; | ||
import { get } from 'lodash'; | ||
|
||
const withFilteredFieldErrors = withPropsOnChange( | ||
['errors', 'fieldId'], | ||
({ errors, fieldId }) => ({ | ||
errors: get(errors, fieldId), | ||
}), | ||
); | ||
|
||
export default withFilteredFieldErrors; |
34 changes: 34 additions & 0 deletions
34
src/components/StageEditor/sections/ContentGrid/withItemMeta.js
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,34 @@ | ||
import { connect } from 'react-redux'; | ||
import { get } from 'lodash'; | ||
|
||
// TODO: move to selectors | ||
const getAssetManifest = state => | ||
get(state, 'protocol.present.assetManifest', {}); | ||
|
||
const mapStateToProps = (state, { fieldId, form }) => { | ||
const field = form.getValues(state, `${fieldId}`); | ||
|
||
if (!field) { return {}; } | ||
|
||
if (field.type !== 'asset') { | ||
return { item: field }; | ||
} | ||
|
||
const assetManifest = getAssetManifest(state); | ||
const itemMeta = get(assetManifest, field.content, {}); | ||
const item = { | ||
...field, | ||
...itemMeta, | ||
content: itemMeta.source, | ||
}; | ||
|
||
return { | ||
item, | ||
}; | ||
}; | ||
|
||
const withItemMeta = connect( | ||
mapStateToProps, | ||
); | ||
|
||
export default withItemMeta; |
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
5 changes: 2 additions & 3 deletions
5
src/components/StageEditor/sections/NameGeneratorListPrompts/withDataSourceOptions.js
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
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,48 @@ | ||
/* eslint-env jest */ | ||
import fs from 'fs'; | ||
import getAssetData from '../getAssetData'; | ||
|
||
const mockData = { | ||
nodes: [], | ||
edges: [], | ||
}; | ||
|
||
fs.readFile = jest.fn( | ||
(path, format, resolve) => | ||
resolve(null, JSON.stringify(mockData)), | ||
); | ||
|
||
describe('getAssetData', () => { | ||
it('can load a json network', (done) => { | ||
const source = '/dev/null/myMockSource.json'; | ||
const type = 'network'; | ||
|
||
getAssetData(source, type).then( | ||
(data) => { | ||
expect(data).toEqual(mockData); | ||
|
||
done(); | ||
}, | ||
); | ||
}); | ||
|
||
it('it caches responses', (done) => { | ||
const source = '/dev/null/myMockSource.json'; | ||
const type = 'network'; | ||
|
||
Promise.all([ | ||
getAssetData(source, type), | ||
getAssetData(source, type), | ||
]).then( | ||
(results) => { | ||
const isSameObject = results.every( | ||
(result, index, all) => result === all[0], | ||
); | ||
|
||
expect(isSameObject).toBe(true); | ||
|
||
done(); | ||
}, | ||
); | ||
}); | ||
}); |
Oops, something went wrong.