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

Merge branch '501456-polices-bug-complieance-framework-label' into 'master'

Add projects label for exceeding number per page

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/171342



Merged-by: default avatarAlexander Turinske <aturinske@gitlab.com>
Approved-by: default avatarAlexander Turinske <aturinske@gitlab.com>
Co-authored-by: default avatarArtur Fedorov <afedorov@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -4,6 +4,7 @@ import { sprintf, __ } from '~/locale'; ...@@ -4,6 +4,7 @@ import { sprintf, __ } from '~/locale';
import { import {
COMPLIANCE_FRAMEWORKS_DESCRIPTION, COMPLIANCE_FRAMEWORKS_DESCRIPTION,
COMPLIANCE_FRAMEWORKS_DESCRIPTION_NO_PROJECTS, COMPLIANCE_FRAMEWORKS_DESCRIPTION_NO_PROJECTS,
COMPLIANCE_FRAMEWORKS_DESCRIPTION_OVER_MAX_NUMBER_OF_PROJECTS,
} from 'ee/security_orchestration/components/policy_drawer/constants'; } from 'ee/security_orchestration/components/policy_drawer/constants';
export default { export default {
...@@ -22,6 +23,11 @@ export default { ...@@ -22,6 +23,11 @@ export default {
required: false, required: false,
default: 0, default: 0,
}, },
defaultProjectPageSize: {
type: Number,
required: false,
default: 100,
},
}, },
computed: { computed: {
hasHiddenLabels() { hasHiddenLabels() {
...@@ -51,8 +57,22 @@ export default { ...@@ -51,8 +57,22 @@ export default {
return COMPLIANCE_FRAMEWORKS_DESCRIPTION_NO_PROJECTS; return COMPLIANCE_FRAMEWORKS_DESCRIPTION_NO_PROJECTS;
} }
if (this.hasMoreProjects) {
return sprintf(COMPLIANCE_FRAMEWORKS_DESCRIPTION_OVER_MAX_NUMBER_OF_PROJECTS, {
pageSize: this.defaultProjectPageSize,
});
}
return COMPLIANCE_FRAMEWORKS_DESCRIPTION(this.projectsLength); return COMPLIANCE_FRAMEWORKS_DESCRIPTION(this.projectsLength);
}, },
hasMoreProjects() {
return this.projectsLength >= this.defaultProjectPageSize && this.hasNextPage;
},
hasNextPage() {
return this.complianceFrameworks.some(
(framework) => framework.projects.pageInfo?.hasNextPage,
);
},
projectsLength() { projectsLength() {
const allProjectsOfComplianceFrameworks = this.complianceFrameworks const allProjectsOfComplianceFrameworks = this.complianceFrameworks
?.flatMap(({ projects = {} }) => projects?.nodes?.map(({ id }) => id)) ?.flatMap(({ projects = {} }) => projects?.nodes?.map(({ id }) => id))
......
...@@ -23,6 +23,10 @@ export const COMPLIANCE_FRAMEWORKS_DESCRIPTION = (projectsCount) => ...@@ -23,6 +23,10 @@ export const COMPLIANCE_FRAMEWORKS_DESCRIPTION = (projectsCount) =>
projectsCount, projectsCount,
); );
export const COMPLIANCE_FRAMEWORKS_DESCRIPTION_OVER_MAX_NUMBER_OF_PROJECTS = s__(
`SecurityOrchestration|%{pageSize}+ projects which have compliance framework:`,
);
export const COMPLIANCE_FRAMEWORKS_DESCRIPTION_NO_PROJECTS = s__( export const COMPLIANCE_FRAMEWORKS_DESCRIPTION_NO_PROJECTS = s__(
'SecurityOrchestration|This applies to following compliance frameworks:', 'SecurityOrchestration|This applies to following compliance frameworks:',
); );
......
...@@ -11,6 +11,9 @@ fragment PolicyScope on PolicyScope { ...@@ -11,6 +11,9 @@ fragment PolicyScope on PolicyScope {
nodes { nodes {
id id
} }
pageInfo {
...PageInfo
}
} }
} }
pageInfo { pageInfo {
......
...@@ -35,6 +35,18 @@ describe('ComplianceFrameworksToggleList', () => { ...@@ -35,6 +35,18 @@ describe('ComplianceFrameworksToggleList', () => {
}); });
}); });
describe('projects exceed page size', () => {
it('renders correct label when project list is bigger then default page size', () => {
createComponent({
propsData: {
defaultProjectPageSize: 2,
},
});
expect(findHeader().text()).toBe('2+ projects which have compliance framework:');
});
});
describe('single framework', () => { describe('single framework', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
...@@ -55,8 +67,8 @@ describe('ComplianceFrameworksToggleList', () => { ...@@ -55,8 +67,8 @@ describe('ComplianceFrameworksToggleList', () => {
it.each` it.each`
labelsToShow | expectedLength | expectedText labelsToShow | expectedLength | expectedText
${2} | ${2} | ${'+ 1 more'} ${2} | ${2} | ${'+ 2 more'}
${1} | ${1} | ${'+ 2 more'} ${1} | ${1} | ${'+ 3 more'}
`('can show only partial list', ({ labelsToShow, expectedLength, expectedText }) => { `('can show only partial list', ({ labelsToShow, expectedLength, expectedText }) => {
createComponent({ createComponent({
propsData: { propsData: {
......
...@@ -128,6 +128,29 @@ export const complianceFrameworksResponse = [ ...@@ -128,6 +128,29 @@ export const complianceFrameworksResponse = [
], ],
}, },
}, },
{
id: convertToGraphQLId(TYPE_COMPLIANCE_FRAMEWORK, 4),
name: 'a4',
default: true,
description: 'description 4',
color: '#cd5b45',
pipelineConfigurationFullPath: 'path 4',
projects: {
nodes: [
{
id: '1',
name: 'project-1',
},
{
id: '2',
name: 'project-2',
},
],
pageInfo: {
hasNextPage: true,
},
},
},
]; ];
export const mockLinkedSppItemsResponse = ({ projects = [], namespaces = [], groups = [] } = {}) => export const mockLinkedSppItemsResponse = ({ projects = [], namespaces = [], groups = [] } = {}) =>
......
...@@ -49446,6 +49446,9 @@ msgstr "" ...@@ -49446,6 +49446,9 @@ msgstr ""
msgid "SecurityOrchestration|%{frameworkName} has %{projectLength} %{projects}" msgid "SecurityOrchestration|%{frameworkName} has %{projectLength} %{projects}"
msgstr "" msgstr ""
   
msgid "SecurityOrchestration|%{pageSize}+ projects which have compliance framework:"
msgstr ""
msgid "SecurityOrchestration|%{scanners}" msgid "SecurityOrchestration|%{scanners}"
msgstr "" msgstr ""
   
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册