Skip to content
代码片段 群组 项目
未验证 提交 1e1a7706 编辑于 作者: Payton Burdette's avatar Payton Burdette 提交者: GitLab
浏览文件

Merge branch '386842-fix-usage-overview-title' into 'master'

No related branches found
No related tags found
无相关合并请求
...@@ -77,22 +77,17 @@ export const prepareQuery = (queryKeysToInclude = []) => { ...@@ -77,22 +77,17 @@ export const prepareQuery = (queryKeysToInclude = []) => {
return Object.fromEntries(queryIncludeVariables); return Object.fromEntries(queryIncludeVariables);
}; };
const extractRootGroup = (requestPath = '') => {
const [rootGroup] = requestPath.split('/');
return rootGroup;
};
/** /**
* Fetch usage overview metrics, making sure to only query * Fetch usage overview metrics, making sure to only query
* the top most group from the namespace. * the top most group from the namespace.
*/ */
export const fetch = async ({ namespace, query: { include = [] } }) => { export const fetch = async ({
rootNamespace: { requestPath: fullPath },
query: { include = [] },
}) => {
const variableOverrides = prepareQuery(include); const variableOverrides = prepareQuery(include);
const { startDate, endDate } = USAGE_OVERVIEW_DEFAULT_DATE_RANGE; const { startDate, endDate } = USAGE_OVERVIEW_DEFAULT_DATE_RANGE;
const fullPath = extractRootGroup(namespace.requestPath);
if (!fullPath.length) return usageOverviewNoData;
try { try {
const { data = {} } = await defaultClient.query({ const { data = {} } = await defaultClient.query({
query: getUsageOverviewQuery, query: getUsageOverviewQuery,
......
...@@ -40,6 +40,8 @@ export default () => { ...@@ -40,6 +40,8 @@ export default () => {
routerBase, routerBase,
features, features,
availableVisualizations = '', availableVisualizations = '',
rootNamespaceName,
rootNamespaceFullPath,
} = el.dataset; } = el.dataset;
const analyticsDashboardPointer = buildAnalyticsDashboardPointer(analyticsDashboardPointerJSON); const analyticsDashboardPointer = buildAnalyticsDashboardPointer(analyticsDashboardPointerJSON);
...@@ -112,6 +114,8 @@ export default () => { ...@@ -112,6 +114,8 @@ export default () => {
analyticsSettingsPath, analyticsSettingsPath,
features: convertArrayToCamelCase(JSON.parse(features)), features: convertArrayToCamelCase(JSON.parse(features)),
vsdAvailableVisualizations, vsdAvailableVisualizations,
rootNamespaceName,
rootNamespaceFullPath,
}, },
render(h) { render(h) {
return h(DashboardsApp); return h(DashboardsApp);
......
...@@ -49,7 +49,14 @@ export default { ...@@ -49,7 +49,14 @@ export default {
UsageOverview: () => UsageOverview: () =>
import('ee/analytics/analytics_dashboards/components/visualizations/usage_overview.vue'), import('ee/analytics/analytics_dashboards/components/visualizations/usage_overview.vue'),
}, },
inject: ['namespaceId', 'namespaceFullPath', 'namespaceName', 'isProject'], inject: [
'namespaceId',
'namespaceFullPath',
'namespaceName',
'isProject',
'rootNamespaceName',
'rootNamespaceFullPath',
],
props: { props: {
visualization: { visualization: {
type: Object, type: Object,
...@@ -119,6 +126,13 @@ export default { ...@@ -119,6 +126,13 @@ export default {
'Analytics|Something went wrong while connecting to your data source. See %{linkStart}troubleshooting documentation%{linkEnd}.', 'Analytics|Something went wrong while connecting to your data source. See %{linkStart}troubleshooting documentation%{linkEnd}.',
); );
}, },
rootNamespace() {
return {
name: this.rootNamespaceName,
requestPath: this.rootNamespaceFullPath,
isProject: false,
};
},
namespace() { namespace() {
return { return {
name: this.namespaceName, name: this.namespaceName,
...@@ -128,7 +142,7 @@ export default { ...@@ -128,7 +142,7 @@ export default {
}, },
panelTitle() { panelTitle() {
return convertToSnakeCase(this.visualization.type) === VISUALIZATION_USAGE_OVERVIEW return convertToSnakeCase(this.visualization.type) === VISUALIZATION_USAGE_OVERVIEW
? sprintf(VISUALIZATION_USAGE_TITLE, { namespaceName: this.namespace.name }) ? sprintf(VISUALIZATION_USAGE_TITLE, { namespaceName: this.rootNamespace.name })
: this.title; : this.title;
}, },
}, },
...@@ -157,6 +171,7 @@ export default { ...@@ -157,6 +171,7 @@ export default {
title: this.title, title: this.title,
projectId: this.namespaceId, projectId: this.namespaceId,
namespace: this.namespace, namespace: this.namespace,
rootNamespace: this.rootNamespace,
query, query,
queryOverrides, queryOverrides,
visualizationType: this.visualization.type, visualizationType: this.visualization.type,
......
...@@ -21,7 +21,9 @@ def analytics_dashboards_list_app_data(namespace) ...@@ -21,7 +21,9 @@ def analytics_dashboards_list_app_data(namespace)
namespace_name: namespace.name, namespace_name: namespace.name,
namespace_full_path: namespace.full_path, namespace_full_path: namespace.full_path,
features: is_project ? enabled_analytics_features(namespace).to_json : [].to_json, features: is_project ? enabled_analytics_features(namespace).to_json : [].to_json,
router_base: router_base(namespace) router_base: router_base(namespace),
root_namespace_name: namespace.root_ancestor.name,
root_namespace_full_path: namespace.root_ancestor.full_path
} }
end end
......
...@@ -21,7 +21,7 @@ import { ...@@ -21,7 +21,7 @@ import {
describe('Usage overview Data Source', () => { describe('Usage overview Data Source', () => {
let obj; let obj;
const namespace = { name: 'cool namespace', requestPath: 'some-group-path' }; const rootNamespace = { name: 'cool namespace', requestPath: 'some-group-path' };
const queryKeys = [USAGE_OVERVIEW_IDENTIFIER_GROUPS, USAGE_OVERVIEW_IDENTIFIER_MERGE_REQUESTS]; const queryKeys = [USAGE_OVERVIEW_IDENTIFIER_GROUPS, USAGE_OVERVIEW_IDENTIFIER_MERGE_REQUESTS];
const mockQuery = { include: queryKeys }; const mockQuery = { include: queryKeys };
const { group: mockGroupUsageMetricsQueryResponse } = mockUsageMetricsQueryResponse; const { group: mockGroupUsageMetricsQueryResponse } = mockUsageMetricsQueryResponse;
...@@ -84,19 +84,19 @@ describe('Usage overview Data Source', () => { ...@@ -84,19 +84,19 @@ describe('Usage overview Data Source', () => {
describe('fetch', () => { describe('fetch', () => {
it.each` it.each`
label | namespaceParam label | namespace
${'with a project'} | ${{ requestPath: 'some-group/some-project' }} ${'with a project'} | ${{ requestPath: 'some-group/some-project' }}
${'with a sub group'} | ${{ requestPath: 'some-group/some-subgroup' }} ${'with a sub group'} | ${{ requestPath: 'some-group/some-subgroup' }}
${'with a group'} | ${{ requestPath: 'some-group' }} ${'with a group'} | ${{ requestPath: 'some-group' }}
`('$label queries the top level group', async ({ namespaceParam }) => { `('$label queries the top level group', async ({ namespace }) => {
jest.spyOn(defaultClient, 'query').mockResolvedValue({ data: {} }); jest.spyOn(defaultClient, 'query').mockResolvedValue({ data: {} });
obj = await fetch({ namespace: namespaceParam, query: mockQuery }); obj = await fetch({ rootNamespace, namespace, query: mockQuery });
expect(defaultClient.query).toHaveBeenCalledWith( expect(defaultClient.query).toHaveBeenCalledWith(
expect.objectContaining({ expect.objectContaining({
variables: { variables: {
fullPath: 'some-group', fullPath: rootNamespace.requestPath,
startDate: expect.anything(), startDate: expect.anything(),
endDate: expect.anything(), endDate: expect.anything(),
includeGroups: true, includeGroups: true,
...@@ -113,7 +113,7 @@ describe('Usage overview Data Source', () => { ...@@ -113,7 +113,7 @@ describe('Usage overview Data Source', () => {
jest.spyOn(defaultClient, 'query').mockResolvedValue({ data: {} }); jest.spyOn(defaultClient, 'query').mockResolvedValue({ data: {} });
obj = await fetch({ obj = await fetch({
namespace, rootNamespace,
query: { include: [USAGE_OVERVIEW_IDENTIFIER_MERGE_REQUESTS] }, query: { include: [USAGE_OVERVIEW_IDENTIFIER_MERGE_REQUESTS] },
}); });
...@@ -135,8 +135,8 @@ describe('Usage overview Data Source', () => { ...@@ -135,8 +135,8 @@ describe('Usage overview Data Source', () => {
it.each` it.each`
label | data | params label | data | params
${'with no data'} | ${{}} | ${{ namespace, query: mockQuery }} ${'with no data'} | ${{}} | ${{ rootNamespace, query: mockQuery }}
${'with no namespace.requestPath'} | ${mockUsageMetricsQueryResponse} | ${{ namespace: {}, query: mockQuery }} ${'with no namespace.requestPath'} | ${mockUsageMetricsQueryResponse} | ${{ rootNamespace: {}, query: mockQuery }}
`('$label returns the no data object', async ({ params }) => { `('$label returns the no data object', async ({ params }) => {
jest.spyOn(defaultClient, 'query').mockResolvedValue({ data: {} }); jest.spyOn(defaultClient, 'query').mockResolvedValue({ data: {} });
...@@ -149,7 +149,7 @@ describe('Usage overview Data Source', () => { ...@@ -149,7 +149,7 @@ describe('Usage overview Data Source', () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(defaultClient, 'query').mockRejectedValue(); jest.spyOn(defaultClient, 'query').mockRejectedValue();
obj = fetch({ namespace, query: mockQuery }); obj = fetch({ rootNamespace, query: mockQuery });
}); });
it('returns the no data object', async () => { it('returns the no data object', async () => {
...@@ -163,7 +163,7 @@ describe('Usage overview Data Source', () => { ...@@ -163,7 +163,7 @@ describe('Usage overview Data Source', () => {
.spyOn(defaultClient, 'query') .spyOn(defaultClient, 'query')
.mockResolvedValue({ data: mockUsageMetricsQueryResponse }); .mockResolvedValue({ data: mockUsageMetricsQueryResponse });
obj = await fetch({ namespace, query: mockQuery }); obj = await fetch({ rootNamespace, query: mockQuery });
}); });
it('will fetch the usage metrics', () => { it('will fetch the usage metrics', () => {
......
...@@ -34,6 +34,8 @@ describe('PanelsBase', () => { ...@@ -34,6 +34,8 @@ describe('PanelsBase', () => {
namespaceId: '1', namespaceId: '1',
namespaceName: 'Namespace name', namespaceName: 'Namespace name',
namespaceFullPath: 'namespace/full/path', namespaceFullPath: 'namespace/full/path',
rootNamespaceName: 'Root namespace name',
rootNamespaceFullPath: 'namespace',
isProject: true, isProject: true,
}, },
propsData: { propsData: {
......
...@@ -75,6 +75,8 @@ def expected_data(has_permission) ...@@ -75,6 +75,8 @@ def expected_data(has_permission)
analytics_settings_path: "/#{project.full_path}/-/settings/analytics#js-analytics-dashboards-settings", analytics_settings_path: "/#{project.full_path}/-/settings/analytics#js-analytics-dashboards-settings",
namespace_name: project.name, namespace_name: project.name,
namespace_full_path: project.full_path, namespace_full_path: project.full_path,
root_namespace_full_path: group.name,
root_namespace_name: group.full_path,
features: (enabled && has_permission ? [:product_analytics] : []).to_json, features: (enabled && has_permission ? [:product_analytics] : []).to_json,
router_base: '/-/analytics/dashboards' router_base: '/-/analytics/dashboards'
} }
...@@ -111,6 +113,8 @@ def expected_data(collector_host) ...@@ -111,6 +113,8 @@ def expected_data(collector_host)
analytics_settings_path: "/groups/#{sub_group.full_path}/-/edit#js-analytics-dashboards-settings", analytics_settings_path: "/groups/#{sub_group.full_path}/-/edit#js-analytics-dashboards-settings",
namespace_name: sub_group.name, namespace_name: sub_group.name,
namespace_full_path: sub_group.full_path, namespace_full_path: sub_group.full_path,
root_namespace_full_path: group.name,
root_namespace_name: group.full_path,
features: [].to_json, features: [].to_json,
router_base: "/groups/#{sub_group.full_path}/-/analytics/dashboards" router_base: "/groups/#{sub_group.full_path}/-/analytics/dashboards"
} }
...@@ -158,6 +162,8 @@ def expected_data(collector_host) ...@@ -158,6 +162,8 @@ def expected_data(collector_host)
analytics_settings_path: "/groups/#{group.full_path}/-/edit#js-analytics-dashboards-settings", analytics_settings_path: "/groups/#{group.full_path}/-/edit#js-analytics-dashboards-settings",
namespace_name: group.name, namespace_name: group.name,
namespace_full_path: group.full_path, namespace_full_path: group.full_path,
root_namespace_full_path: group.name,
root_namespace_name: group.full_path,
features: [].to_json, features: [].to_json,
router_base: "/groups/#{group.full_path}/-/analytics/dashboards" router_base: "/groups/#{group.full_path}/-/analytics/dashboards"
} }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册