Skip to content

Commit

Permalink
[CORL-1195] Fix bug with displaying site dashboards (#3031)
Browse files Browse the repository at this point in the history
* fix bug where dashboard would not display data for sites beyond first page of results

* remove unused param

* remove unused file

* undo rename

* rename selectedSite to site

* check that sites.edges.length is greater than 0

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
tessalt and kodiakhq[bot] committed Jul 17, 2020
1 parent b221baf commit cdcc991
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
20 changes: 11 additions & 9 deletions src/core/client/admin/routes/Dashboard/DashboardContainer.tsx
Expand Up @@ -27,22 +27,24 @@ import DashboardSiteSelector from "./DashboardSiteSelector";

import styles from "./DashboardContainer.css";

interface Site {
name: string;
id: string;
}

interface Props {
query: QueryData | null;
relay: RelayPaginationProp;
selectedSiteID?: string;
site?: Site | null;
}
const DashboardContainer: React.FunctionComponent<Props> = (props) => {
if (!props.site) {
return null;
}
const sites = props.query
? props.query.sites.edges.map((edge) => edge.node)
: [];
const selectedSite = props.selectedSiteID
? sites.find((s) => s.id === props.selectedSiteID)
: sites[0];

if (!selectedSite) {
return null;
}
const [lastUpdated, setLastUpdated] = useState<string>(new Date().toString());
const [loadMore, isLoadingMore] = useLoadMore(props.relay, 10);
const [, isRefetching] = useRefetch<
Expand Down Expand Up @@ -76,7 +78,7 @@ const DashboardContainer: React.FunctionComponent<Props> = (props) => {
{({ toggleVisibility, ref, visible }) => (
<BaseButton onClick={toggleVisibility} ref={ref}>
<Flex>
<h2 className={styles.header}>{selectedSite.name}</h2>
<h2 className={styles.header}>{props.site && props.site.name}</h2>
{
<ButtonIcon className={styles.icon} size="lg">
{visible ? "arrow_drop_up" : "arrow_drop_down"}
Expand All @@ -93,7 +95,7 @@ const DashboardContainer: React.FunctionComponent<Props> = (props) => {
Refresh
</Button>
</Flex>
<Dashboard siteID={selectedSite.id} lastUpdated={lastUpdated} />
<Dashboard siteID={props.site.id} lastUpdated={lastUpdated} />
</MainLayout>
);
};
Expand Down
21 changes: 19 additions & 2 deletions src/core/client/admin/routes/Dashboard/DashboardRoute.tsx
Expand Up @@ -5,7 +5,7 @@ import { withRouteConfig } from "coral-framework/lib/router";

import { DashboardRouteQueryResponse } from "coral-admin/__generated__/DashboardRouteQuery.graphql";

import DashboardSiteSelectorContainer from "./DashboardContainer";
import DashboardContainer from "./DashboardContainer";

interface Props {
data: DashboardRouteQueryResponse | null;
Expand All @@ -15,12 +15,29 @@ const DashboardRoute: React.FunctionComponent<Props> = ({ data }) => {
return null;
}

return <DashboardSiteSelectorContainer query={data} />;
return (
<DashboardContainer
query={data}
site={
data.firstSite.edges && data.firstSite.edges.length > 0
? data.firstSite.edges[0].node
: null
}
/>
);
};

const enhanced = withRouteConfig<Props>({
query: graphql`
query DashboardRouteQuery {
firstSite: sites(first: 1) {
edges {
node {
id
name
}
}
}
...DashboardContainer_query
}
`,
Expand Down
9 changes: 2 additions & 7 deletions src/core/client/admin/routes/Dashboard/SiteDashboardRoute.tsx
Expand Up @@ -6,7 +6,7 @@ import { withRouteConfig } from "coral-framework/lib/router";

import { SiteDashboardRouteQueryResponse } from "coral-admin/__generated__/SiteDashboardRouteQuery.graphql";

import DashboardSiteSelectorContainer from "./DashboardContainer";
import DashboardContainer from "./DashboardContainer";

interface RouteParams {
siteID: string;
Expand All @@ -20,12 +20,7 @@ interface Props {
const SiteDashboardRoute: React.FunctionComponent<Props> = (props) => {
const { data } = props;
if (data && data.site) {
return (
<DashboardSiteSelectorContainer
query={data}
selectedSiteID={props.match.params.siteID}
/>
);
return <DashboardContainer query={data} site={data.site} />;
}
return null;
};
Expand Down

0 comments on commit cdcc991

Please sign in to comment.