Skip to content

Commit

Permalink
fix(analytics): skip ListDomains if user cannot manage domains and ha…
Browse files Browse the repository at this point in the history
…ve only one loading message (#6624)
  • Loading branch information
aditya-radhakrishnan authored Dec 3, 2022
1 parent c8d943a commit 5e971ce
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Message } from '../../shared/Message';
import { useListDomainsQuery } from '../../../graphql/domain.generated';
import filterSearchQuery from '../../search/utils/filterSearchQuery';
import { ANTD_GRAY } from '../../entity/shared/constants';
import { useGetAuthenticatedUser } from '../../useGetAuthenticatedUser';

const HighlightGroup = styled.div`
display: flex;
Expand Down Expand Up @@ -46,13 +47,16 @@ const StyledSearchBar = styled(Input)`
`;

export const AnalyticsPage = () => {
const me = useGetAuthenticatedUser();
const canManageDomains = me?.platformPrivileges?.createDomains;
const { data: chartData, loading: chartLoading, error: chartError } = useGetAnalyticsChartsQuery();
const { data: highlightData, loading: highlightLoading, error: highlightError } = useGetHighlightsQuery();
const {
loading: domainLoading,
error: domainError,
data: domainData,
} = useListDomainsQuery({
skip: !canManageDomains,
variables: {
input: {
start: 0,
Expand Down Expand Up @@ -82,12 +86,11 @@ export const AnalyticsPage = () => {
skip: domain === '' && query === '',
});

const isLoading = highlightLoading || chartLoading || domainLoading || metadataAnalyticsLoading;
return (
<>
{isLoading && <Message type="loading" content="Loading..." style={{ marginTop: '10%' }} />}
<HighlightGroup>
{highlightLoading && (
<Message type="loading" content="Loading Highlights..." style={{ marginTop: '10%' }} />
)}
{highlightError && (
<Alert type="error" message={highlightError?.message || 'Highlights failed to load'} />
)}
Expand All @@ -96,7 +99,6 @@ export const AnalyticsPage = () => {
))}
</HighlightGroup>
<>
{chartLoading && <Message type="loading" content="Loading Charts..." style={{ marginTop: '10%' }} />}
{chartError && (
<Alert type="error" message={metadataAnalyticsError?.message || 'Charts failed to load'} />
)}
Expand All @@ -107,7 +109,6 @@ export const AnalyticsPage = () => {
))}
</>
<>
{domainLoading && <Message type="loading" content="Loading Domains..." style={{ marginTop: '10%' }} />}
{domainError && (
<Alert type="error" message={metadataAnalyticsError?.message || 'Domains failed to load'} />
)}
Expand Down Expand Up @@ -148,9 +149,6 @@ export const AnalyticsPage = () => {
)}
</>
<>
{metadataAnalyticsLoading && (
<Message type="loading" content="Loading Charts..." style={{ marginTop: '10%' }} />
)}
{metadataAnalyticsError && (
<Alert type="error" message={metadataAnalyticsError?.message || 'Charts failed to load'} />
)}
Expand All @@ -165,7 +163,6 @@ export const AnalyticsPage = () => {
))}
</>
<>
{chartLoading && <Message type="loading" content="Loading Charts..." style={{ marginTop: '10%' }} />}
{chartError && <Alert type="error" message={chartError?.message || 'Charts failed to load'} />}
{!chartLoading &&
chartData?.getAnalyticsCharts
Expand Down

0 comments on commit 5e971ce

Please sign in to comment.