Skip to content

Commit c795255

Browse files
committed
[inspector] Warning if no objects
1 parent 5f315af commit c795255

File tree

1 file changed

+38
-8
lines changed

1 file changed

+38
-8
lines changed

src/store-inspector/Body.tsx

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
/** @jsx createElement */
22

3+
import {arrayIsEmpty, arrayMap} from '../common/array';
34
import {
45
createElement,
56
useCallback,
67
useLayoutEffect,
78
useRef,
89
useState,
910
} from '../ui-react/common';
11+
import {isUndefined, mathFloor} from '../common/other';
1012
import {
13+
useIndexes,
1114
useIndexesIds,
15+
useMetrics,
1216
useMetricsIds,
17+
useQueries,
1318
useQueriesIds,
19+
useRelationships,
1420
useRelationshipsIds,
21+
useStore,
1522
useStoreIds,
1623
useValues,
1724
} from '../ui-react';
@@ -23,8 +30,6 @@ import {RelationshipsView} from './RelationshipsView';
2330
import {StoreProp} from './types';
2431
import {StoreView} from './StoreView';
2532
import {SyntheticEvent} from 'react';
26-
import {arrayMap} from '../common/array';
27-
import {mathFloor} from '../common/other';
2833

2934
export const Body = ({s}: StoreProp) => {
3035
const articleRef = useRef<HTMLElement>(null);
@@ -62,30 +67,55 @@ export const Body = ({s}: StoreProp) => {
6267
[s],
6368
);
6469

65-
return (
70+
const store = useStore();
71+
const storeIds = useStoreIds();
72+
const metrics = useMetrics();
73+
const metricsIds = useMetricsIds();
74+
const indexes = useIndexes();
75+
const indexesIds = useIndexesIds();
76+
const relationships = useRelationships();
77+
const relationshipsIds = useRelationshipsIds();
78+
const queries = useQueries();
79+
const queriesIds = useQueriesIds();
80+
81+
return isUndefined(store) &&
82+
arrayIsEmpty(storeIds) &&
83+
isUndefined(metrics) &&
84+
arrayIsEmpty(metricsIds) &&
85+
isUndefined(indexes) &&
86+
arrayIsEmpty(indexesIds) &&
87+
isUndefined(relationships) &&
88+
arrayIsEmpty(relationshipsIds) &&
89+
isUndefined(queries) &&
90+
arrayIsEmpty(queriesIds) ? (
91+
<span className="warn">
92+
There are no Stores or other objects to inspect. Make sure you placed the
93+
StoreInspector inside a Provider component.
94+
</span>
95+
) : (
6696
<article ref={articleRef} onScroll={handleScroll}>
6797
<StoreView s={s} />
68-
{arrayMap(useStoreIds(), (storeId) => (
98+
{arrayMap(storeIds, (storeId) => (
6999
<StoreView storeId={storeId} key={storeId} s={s} />
70100
))}
71101
<MetricsView s={s} />
72-
{arrayMap(useMetricsIds(), (metricsId) => (
102+
{arrayMap(metricsIds, (metricsId) => (
73103
<MetricsView metricsId={metricsId} key={metricsId} s={s} />
74104
))}
75105
<IndexesView s={s} />
76-
{arrayMap(useIndexesIds(), (indexesId) => (
106+
{arrayMap(indexesIds, (indexesId) => (
77107
<IndexesView indexesId={indexesId} key={indexesId} s={s} />
78108
))}
79109
<RelationshipsView s={s} />
80-
{arrayMap(useRelationshipsIds(), (relationshipsId) => (
110+
{arrayMap(relationshipsIds, (relationshipsId) => (
81111
<RelationshipsView
82112
relationshipsId={relationshipsId}
83113
key={relationshipsId}
84114
s={s}
85115
/>
86116
))}
87117
<QueriesView s={s} />
88-
{arrayMap(useQueriesIds(), (queriesId) => (
118+
{arrayMap(queriesIds, (queriesId) => (
89119
<QueriesView queriesId={queriesId} key={queriesId} s={s} />
90120
))}
91121
</article>

0 commit comments

Comments
 (0)