Skip to content

Commit

Permalink
[Directory] fixes nav inside widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
Elorfin committed Oct 26, 2023
1 parent 209420a commit 33be2f5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
19 changes: 14 additions & 5 deletions src/main/app/Resources/modules/content/list/containers/source.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ const ListSource = props => {
primaryAction={get(props.source, 'primaryAction') ? (row) => {
const definedAction = get(props.source, 'primaryAction')(row)
if (definedAction instanceof Promise) {
return definedAction.then(action => makeAbsolute(action))
return definedAction.then(action => props.absolute ? makeAbsolute(action) : action)
}

return makeAbsolute(definedAction)
return props.absolute ? makeAbsolute(definedAction) : definedAction
} : undefined}
actions={get(props.parameters, 'actions') && get(props.source, 'actions') ? (rows) => {
const definedActions = get(props.source, 'actions')(rows)
if (definedActions instanceof Promise) {
return definedActions.then(actions => actions.map(action => makeAbsolute(action)))
return definedActions.then(actions => actions.map(action => props.absolute ? makeAbsolute(action) : action))
}
return definedActions.map(action => makeAbsolute(action))
return definedActions.map(action => props.absolute ? makeAbsolute(action) : action)
} : undefined}

definition={computedDefinition}
Expand Down Expand Up @@ -101,7 +101,16 @@ ListSource.propTypes = {
// list configuration
parameters: T.shape(
ListParametersTypes.propTypes
)
),

// do we need to convert all link actions into url ?
// this is useful when a list is embedded inside a widget app,
// and we don't want the embedded router to catch our links (aka open links directly inside the widget)
absolute: T.bool
}

ListSource.defaultProps = {
absolute: false
}

export {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import get from 'lodash/get'
import isEmpty from 'lodash/isEmpty'
import merge from 'lodash/merge'

import {url} from '#/main/app/api'
import {trans} from '#/main/app/intl/translation'
import {LINK_BUTTON, URL_BUTTON} from '#/main/app/buttons'
import {makeAbsolute} from '#/main/app/action/utils'
import {LINK_BUTTON} from '#/main/app/buttons'
import {ListSource} from '#/main/app/content/list/containers/source'
import {ListParameters as ListParametersTypes} from '#/main/app/content/list/parameters/prop-types'
import {Alert} from '#/main/app/alert/components/alert'
Expand All @@ -29,12 +29,8 @@ import {getActions, getDefaultAction} from '#/main/core/resource/utils'
* @return {object}
*/
function transformAction(action, resourceNodes, embedded = false) {
if (embedded && LINK_BUTTON === action.type && -1 === resourceNodes.findIndex(node => 'directory' === node.meta.type)) {
// make the action a URL button to escape the embedded router
return merge({}, action, {
type: URL_BUTTON,
target: url(['claro_index'])+'#'+action.target
})
if (embedded && -1 === resourceNodes.findIndex(node => 'directory' === node.meta.type)) {
return makeAbsolute(action)
}

return action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ListWidget extends Component {
}}
source={this.state.source}
parameters={this.props.parameters}
absolute={true}
/>
)
}
Expand Down

0 comments on commit 33be2f5

Please sign in to comment.