generated from eea/volto-addon-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove schema if content type is not the same as for the schema (#…
…184) * fix: remove schema if content type is not the same as for the schema * clean up * fix tests * Automated release 1.25.1 * bump version * Automated release 1.26.0 --------- Co-authored-by: EEA Jenkins <@users.noreply.github.com>
- Loading branch information
Showing
11 changed files
with
140 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './schema'; |
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,5 @@ | ||
export function removeSchema() { | ||
return { | ||
type: 'REMOVE_SCHEMA', | ||
}; | ||
} |
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,24 @@ | ||
import { useEffect } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { removeSchema } from '@eeacms/volto-eea-website-theme/actions'; | ||
|
||
function RemoveSchema({ removeSchema, content, schema }) { | ||
useEffect(() => { | ||
if ( | ||
schema.schema && | ||
(!content || (content && schema.contentType !== content['@type'])) | ||
) { | ||
removeSchema(); | ||
} | ||
}, [removeSchema, content, schema]); | ||
|
||
return null; | ||
} | ||
|
||
export default connect( | ||
(state) => ({ | ||
content: state.content.data, | ||
schema: state.schema, | ||
}), | ||
{ removeSchema }, | ||
)(RemoveSchema); |
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,11 @@ | ||
export default function apiEnhencar(middlewares) { | ||
return [ | ||
() => (next) => (action) => { | ||
if (action.request) { | ||
return next({ ...action, _request: action.request }); | ||
} | ||
return next(action); | ||
}, | ||
...middlewares, | ||
]; | ||
} |
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,10 @@ | ||
import apiEnhancer from './apiEnhancer'; | ||
|
||
export default function applyConfig(config) { | ||
config.settings.storeExtenders = [ | ||
...(config.settings.storeExtenders || []), | ||
apiEnhancer, | ||
]; | ||
|
||
return config; | ||
} |
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,17 @@ | ||
import RemoveSchema from '@eeacms/volto-eea-website-theme/components/theme/AppExtras/RemoveSchema'; | ||
|
||
import schema from './schema'; | ||
|
||
export default function applyConfig(config) { | ||
config.addonReducers.schema = schema; | ||
|
||
config.settings.appExtras = [ | ||
...(config.settings.appExtras || []), | ||
{ | ||
match: '*', | ||
component: RemoveSchema, | ||
}, | ||
]; | ||
|
||
return config; | ||
} |
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 @@ | ||
import voltoSchema from '@plone/volto/reducers/schema/schema'; | ||
|
||
const initialState = { | ||
contentUrl: null, | ||
contentType: null, | ||
error: null, | ||
loaded: false, | ||
loading: false, | ||
schema: null, | ||
post: { | ||
loaded: false, | ||
loading: false, | ||
error: null, | ||
}, | ||
update: { | ||
loaded: false, | ||
loading: false, | ||
error: null, | ||
}, | ||
put: { | ||
loaded: false, | ||
loading: false, | ||
error: null, | ||
}, | ||
}; | ||
|
||
export default function schema(state = initialState, action = {}) { | ||
if (action.type === 'REMOVE_SCHEMA') { | ||
return { | ||
...state, | ||
error: null, | ||
loading: false, | ||
loaded: true, | ||
schema: null, | ||
}; | ||
} | ||
|
||
if (action.type === 'GET_SCHEMA_SUCCESS') { | ||
const [contentUrl, contentType] = action._request.path.split('/@types/'); | ||
return { | ||
...voltoSchema(state, action), | ||
contentUrl, | ||
contentType, | ||
}; | ||
} | ||
|
||
return voltoSchema(state, action); | ||
} |