2022-02-18 09:38:17 -08:00
|
|
|
import React, { useState } from 'react';
|
2021-05-11 15:41:42 -07:00
|
|
|
import styled from 'styled-components';
|
2022-02-18 09:38:17 -08:00
|
|
|
import { Alert, Divider, Input, Select } from 'antd';
|
|
|
|
|
import { SearchOutlined } from '@ant-design/icons';
|
2021-05-11 15:41:42 -07:00
|
|
|
|
|
|
|
|
import { SearchablePage } from '../../search/SearchablePage';
|
|
|
|
|
import { ChartGroup } from './ChartGroup';
|
2022-02-18 09:38:17 -08:00
|
|
|
import { useGetAnalyticsChartsQuery, useGetMetadataAnalyticsChartsQuery } from '../../../graphql/analytics.generated';
|
2021-05-11 15:41:42 -07:00
|
|
|
import { useGetHighlightsQuery } from '../../../graphql/highlights.generated';
|
|
|
|
|
import { Highlight } from './Highlight';
|
|
|
|
|
import { Message } from '../../shared/Message';
|
2022-02-18 09:38:17 -08:00
|
|
|
import { useListDomainsQuery } from '../../../graphql/domain.generated';
|
|
|
|
|
import filterSearchQuery from '../../search/utils/filterSearchQuery';
|
|
|
|
|
import { ANTD_GRAY } from '../../entity/shared/constants';
|
2021-05-11 15:41:42 -07:00
|
|
|
|
|
|
|
|
const HighlightGroup = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: space-between;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
padding-top: 20px;
|
2022-02-18 09:38:17 -08:00
|
|
|
margin-bottom: 10px;
|
2021-05-11 15:41:42 -07:00
|
|
|
`;
|
|
|
|
|
|
2022-02-18 09:38:17 -08:00
|
|
|
const MetadataAnalyticsInput = styled.div`
|
|
|
|
|
display: flex;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const MetadataAnalyticsPlaceholder = styled.span`
|
|
|
|
|
margin: 25px;
|
|
|
|
|
margin-bottom: 50px;
|
|
|
|
|
font-size: 18px;
|
|
|
|
|
color: ${ANTD_GRAY[7]};
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const DomainSelect = styled(Select)`
|
|
|
|
|
margin-left: 25px;
|
|
|
|
|
width: 200px;
|
|
|
|
|
display: inline-block;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
const StyledSearchBar = styled(Input)`
|
|
|
|
|
&&& {
|
|
|
|
|
margin-left: 10px;
|
|
|
|
|
border-radius: 70px;
|
|
|
|
|
color: ${ANTD_GRAY[7]};
|
|
|
|
|
width: 250px;
|
|
|
|
|
}
|
|
|
|
|
`;
|
2021-05-11 15:41:42 -07:00
|
|
|
|
|
|
|
|
export const AnalyticsPage = () => {
|
|
|
|
|
const { data: chartData, loading: chartLoading, error: chartError } = useGetAnalyticsChartsQuery();
|
|
|
|
|
const { data: highlightData, loading: highlightLoading, error: highlightError } = useGetHighlightsQuery();
|
2022-02-18 09:38:17 -08:00
|
|
|
const {
|
|
|
|
|
loading: domainLoading,
|
|
|
|
|
error: domainError,
|
|
|
|
|
data: domainData,
|
|
|
|
|
} = useListDomainsQuery({
|
|
|
|
|
variables: {
|
|
|
|
|
input: {
|
|
|
|
|
start: 0,
|
|
|
|
|
count: 1000,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
fetchPolicy: 'no-cache',
|
|
|
|
|
});
|
|
|
|
|
const [domain, setDomain] = useState('');
|
|
|
|
|
const [stagedQuery, setStagedQuery] = useState('');
|
|
|
|
|
const [query, setQuery] = useState('');
|
|
|
|
|
|
|
|
|
|
const onDomainChange = (inputDomain) => setDomain(inputDomain);
|
|
|
|
|
const onStagedQueryChange = (inputQuery) => setStagedQuery(inputQuery);
|
|
|
|
|
const {
|
|
|
|
|
loading: metadataAnalyticsLoading,
|
|
|
|
|
error: metadataAnalyticsError,
|
|
|
|
|
data: metadataAnalyticsData,
|
|
|
|
|
} = useGetMetadataAnalyticsChartsQuery({
|
|
|
|
|
variables: {
|
|
|
|
|
input: {
|
|
|
|
|
entityType: null,
|
|
|
|
|
domain,
|
|
|
|
|
query,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
skip: domain === '' && query === '',
|
|
|
|
|
});
|
2021-05-11 15:41:42 -07:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<SearchablePage>
|
|
|
|
|
<HighlightGroup>
|
|
|
|
|
{highlightLoading && (
|
|
|
|
|
<Message type="loading" content="Loading Highlights..." style={{ marginTop: '10%' }} />
|
|
|
|
|
)}
|
|
|
|
|
{highlightError && (
|
|
|
|
|
<Alert type="error" message={highlightError?.message || 'Highlights failed to load'} />
|
|
|
|
|
)}
|
2022-02-18 09:38:17 -08:00
|
|
|
{highlightData?.getHighlights?.map((highlight) => (
|
2021-07-30 17:41:03 -07:00
|
|
|
<Highlight highlight={highlight} shortenValue />
|
2021-05-11 15:41:42 -07:00
|
|
|
))}
|
|
|
|
|
</HighlightGroup>
|
2022-02-18 09:38:17 -08:00
|
|
|
<>
|
|
|
|
|
{chartLoading && <Message type="loading" content="Loading Charts..." style={{ marginTop: '10%' }} />}
|
|
|
|
|
{chartError && (
|
|
|
|
|
<Alert type="error" message={metadataAnalyticsError?.message || 'Charts failed to load'} />
|
|
|
|
|
)}
|
|
|
|
|
{chartData?.getAnalyticsCharts
|
|
|
|
|
?.filter((chartGroup) => chartGroup.groupId === 'GlobalMetadataAnalytics')
|
|
|
|
|
.map((chartGroup) => (
|
|
|
|
|
<ChartGroup chartGroup={chartGroup} />
|
|
|
|
|
))}
|
|
|
|
|
</>
|
|
|
|
|
<>
|
|
|
|
|
{domainLoading && <Message type="loading" content="Loading Domains..." style={{ marginTop: '10%' }} />}
|
|
|
|
|
{domainError && (
|
|
|
|
|
<Alert type="error" message={metadataAnalyticsError?.message || 'Domains failed to load'} />
|
|
|
|
|
)}
|
|
|
|
|
{!chartLoading && (
|
|
|
|
|
<>
|
|
|
|
|
<Divider />
|
|
|
|
|
<MetadataAnalyticsInput>
|
|
|
|
|
<DomainSelect
|
|
|
|
|
showSearch
|
|
|
|
|
placeholder="Select a domain"
|
|
|
|
|
onChange={onDomainChange}
|
|
|
|
|
filterOption={(input, option) =>
|
|
|
|
|
option?.children.toLowerCase().indexOf(input.toLowerCase()) >= 0
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<Select.Option value="ALL">All</Select.Option>
|
|
|
|
|
{domainData?.listDomains?.domains.map((domainChoice) => (
|
|
|
|
|
<Select.Option value={domainChoice.urn}>
|
|
|
|
|
{domainChoice?.properties?.name}
|
|
|
|
|
</Select.Option>
|
|
|
|
|
))}
|
|
|
|
|
</DomainSelect>
|
|
|
|
|
<StyledSearchBar
|
|
|
|
|
placeholder="Search"
|
|
|
|
|
onPressEnter={(e) => {
|
|
|
|
|
e.stopPropagation();
|
|
|
|
|
setQuery(filterSearchQuery(stagedQuery || ''));
|
|
|
|
|
}}
|
|
|
|
|
value={stagedQuery}
|
|
|
|
|
onChange={(e) => onStagedQueryChange(e.target.value)}
|
|
|
|
|
data-testid="analytics-search-input"
|
|
|
|
|
prefix={
|
|
|
|
|
<SearchOutlined onClick={() => setQuery(filterSearchQuery(stagedQuery || ''))} />
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
</MetadataAnalyticsInput>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</>
|
|
|
|
|
<>
|
|
|
|
|
{metadataAnalyticsLoading && (
|
|
|
|
|
<Message type="loading" content="Loading Charts..." style={{ marginTop: '10%' }} />
|
|
|
|
|
)}
|
|
|
|
|
{metadataAnalyticsError && (
|
|
|
|
|
<Alert type="error" message={metadataAnalyticsError?.message || 'Charts failed to load'} />
|
|
|
|
|
)}
|
|
|
|
|
{domain === '' && query === ''
|
|
|
|
|
? !chartLoading && (
|
|
|
|
|
<MetadataAnalyticsPlaceholder>
|
|
|
|
|
Please specify domain or query to get granular results
|
|
|
|
|
</MetadataAnalyticsPlaceholder>
|
|
|
|
|
)
|
|
|
|
|
: metadataAnalyticsData?.getMetadataAnalyticsCharts?.map((chartGroup) => (
|
|
|
|
|
<ChartGroup chartGroup={chartGroup} />
|
|
|
|
|
))}
|
|
|
|
|
</>
|
2021-05-11 15:41:42 -07:00
|
|
|
<>
|
|
|
|
|
{chartLoading && <Message type="loading" content="Loading Charts..." style={{ marginTop: '10%' }} />}
|
|
|
|
|
{chartError && <Alert type="error" message={chartError?.message || 'Charts failed to load'} />}
|
2022-02-18 09:38:17 -08:00
|
|
|
{!chartLoading &&
|
|
|
|
|
chartData?.getAnalyticsCharts
|
|
|
|
|
?.filter((chartGroup) => chartGroup.groupId === 'DataHubUsageAnalytics')
|
|
|
|
|
.map((chartGroup) => (
|
|
|
|
|
<>
|
|
|
|
|
<Divider />
|
|
|
|
|
<ChartGroup chartGroup={chartGroup} />
|
|
|
|
|
</>
|
|
|
|
|
))}
|
2021-05-11 15:41:42 -07:00
|
|
|
</>
|
|
|
|
|
</SearchablePage>
|
|
|
|
|
);
|
|
|
|
|
};
|