From 038c3c3b8a7ab8e4bb5588c91ba136794a44c566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Ricks?= Date: Thu, 30 Aug 2018 14:24:08 +0200 Subject: [PATCH] Load related tag resources from redux store Update ResourceList to load the entity resources from the redux store. --- gsa/src/web/pages/tags/resourcelist.js | 84 ++++++++++++++++++++------ 1 file changed, 64 insertions(+), 20 deletions(-) diff --git a/gsa/src/web/pages/tags/resourcelist.js b/gsa/src/web/pages/tags/resourcelist.js index e913c2f66e..a50275836e 100644 --- a/gsa/src/web/pages/tags/resourcelist.js +++ b/gsa/src/web/pages/tags/resourcelist.js @@ -26,13 +26,12 @@ import _ from 'gmp/locale'; import styled from 'styled-components'; +import {connect} from 'react-redux'; + import Filter from 'gmp/models/filter'; import {pluralizeType, normalizeType} from 'gmp/utils/entitytype'; import {isDefined} from 'gmp/utils/identity'; -import PropTypes from 'web/utils/proptypes'; -import withGmp from 'web/utils/withGmp'; - import ListIcon from 'web/components/icon/listicon'; import Divider from 'web/components/layout/divider'; @@ -42,6 +41,16 @@ import Loading from 'web/components/loading/loading'; import {MAX_RESOURCES} from 'web/pages/tags/component'; +import { + createLoadEntities, + createEntitiesActions, +} from 'web/store/entities/utils/actions'; +import {createSelector} from 'web/store/entities/utils/selectors'; + +import compose from 'web/utils/compose'; +import PropTypes from 'web/utils/proptypes'; +import withGmp from 'web/utils/withGmp'; + const Spacer = styled.div` height: 12px, `; @@ -80,24 +89,16 @@ class ResourceList extends React.Component { } componentDidMount() { - const {gmp, entity} = this.props; - if (isDefined(entity)) { - const {id, resourceType} = entity; - const filter = 'tag_id="' + id + '" rows=' + MAX_RESOURCES; - gmp[pluralizeType(resourceType)].get({filter}) - .then(resources => - this.setState({ - isLoading: false, - res: resources.data, - }) - ); + const {loadResources} = this.props; + + if (isDefined(loadResources)) { + loadResources(); } } render() { - const {entity} = this.props; + const {entity, resources = [], isLoading} = this.props; const {id, resourceCount, resourceType} = entity; - const {isLoading, res} = this.state; const showNotification = resourceCount > MAX_RESOURCES; return ( @@ -113,7 +114,7 @@ class ResourceList extends React.Component { }