Skip to content

Commit 5fb77a1

Browse files
author
marc
committed
Make store selectors dependent on loading
1 parent b521f24 commit 5fb77a1

File tree

1 file changed

+19
-12
lines changed
  • pkg/ui/src/views/reports/containers/stores

1 file changed

+19
-12
lines changed

pkg/ui/src/views/reports/containers/stores/index.tsx

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class Stores extends React.Component<StoresProps, {}> {
7272
);
7373
}
7474

75-
renderContent() {
75+
renderContent = () => {
7676
const nodeID = this.props.params[nodeIDAttr];
7777
if (!_.isNil(this.props.lastError)) {
7878
return (
@@ -114,36 +114,43 @@ class Stores extends React.Component<StoresProps, {}> {
114114
loading={this.props.loading}
115115
className="loading-image loading-image__spinner"
116116
image={spinner}
117-
>
118-
{this.renderContent()}
119-
</Loading>
117+
render={this.renderContent}
118+
/>
120119
</div>
121120
);
122121
}
123122
}
124123

125124
function selectStoresState(state: AdminUIState, props: StoresProps) {
126125
const nodeIDKey = storesRequestKey(storesRequestFromProps(props));
127-
return state.cachedData.stores[nodeIDKey] && state.cachedData.stores[nodeIDKey];
126+
return state.cachedData.stores[nodeIDKey];
128127
}
129128

130129
const selectStoresLoading = createSelector(
131130
selectStoresState,
132-
(stores) => _.isEmpty(stores.data),
131+
(stores) => _.isEmpty(stores) || _.isEmpty(stores.data),
133132
);
134133

135134
const selectSortedStores = createSelector(
135+
selectStoresLoading,
136136
selectStoresState,
137-
(stores) => (
138-
_.sortBy(stores.data.stores, (store) => store.store_id)
139-
),
137+
(loading, stores) => {
138+
if (loading) {
139+
return null;
140+
}
141+
return _.sortBy(stores.data.stores, (store) => store.store_id);
142+
},
140143
);
141144

142145
const selectStoresLastError = createSelector(
146+
selectStoresLoading,
143147
selectStoresState,
144-
(stores) => (
145-
stores.lastError
146-
),
148+
(loading, stores) => {
149+
if (loading) {
150+
return null;
151+
}
152+
return stores.lastError;
153+
},
147154
);
148155

149156
function mapStateToProps(state: AdminUIState, props: StoresProps) {

0 commit comments

Comments
 (0)