From c85743d520b04a3c3abe0f67a9805d1c5eefb523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=87=E8=94=BA?= Date: Wed, 19 Jun 2019 19:56:18 +0800 Subject: [PATCH 1/4] fix(module:table): fix sortChange with dynamic columns (#3603) (#3605) close #3603 --- components/table/nz-thead.component.ts | 4 ++-- components/table/nz-thead.spec.ts | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/components/table/nz-thead.component.ts b/components/table/nz-thead.component.ts index 198d8001e77..9e549eccaf9 100644 --- a/components/table/nz-thead.component.ts +++ b/components/table/nz-thead.component.ts @@ -26,7 +26,7 @@ import { ViewEncapsulation } from '@angular/core'; import { merge, Subject } from 'rxjs'; -import { flatMap, startWith, takeUntil } from 'rxjs/operators'; +import { startWith, switchMap, takeUntil } from 'rxjs/operators'; import { InputBoolean } from 'ng-zorro-antd/core'; @@ -62,7 +62,7 @@ export class NzTheadComponent implements AfterContentInit, OnDestroy, AfterViewI this.listOfNzThComponent.changes .pipe( startWith(true), - flatMap(() => + switchMap(() => merge<{ key: string; value: string }>(...this.listOfNzThComponent.map(th => th.nzSortChangeWithKey)) ), takeUntil(this.destroy$) diff --git a/components/table/nz-thead.spec.ts b/components/table/nz-thead.spec.ts index 202bc874966..f8e53c38566 100644 --- a/components/table/nz-thead.spec.ts +++ b/components/table/nz-thead.spec.ts @@ -54,6 +54,27 @@ describe('nz-thead', () => { expect(upButtons[1].querySelector('.ant-table-column-sorter-down').classList).toContain('on'); expect(testComponent.sortChange).toHaveBeenCalledTimes(2); }); + + // Test for #3603 + it('should support dynamic headers', () => { + testComponent.singleSort = true; + fixture.detectChanges(); + expect(testComponent.sortChange).toHaveBeenCalledTimes(0); + let upButtons = table.nativeElement.querySelectorAll('.ant-table-column-sorters'); + upButtons[2].click(); + fixture.detectChanges(); + expect(testComponent.sortChange).toHaveBeenCalledTimes(1); + upButtons[3].click(); + fixture.detectChanges(); + expect(testComponent.sortChange).toHaveBeenCalledTimes(2); + + testComponent.columns = testComponent.columns.slice(0, 1); + fixture.detectChanges(); + upButtons = table.nativeElement.querySelectorAll('.ant-table-column-sorters'); + expect(upButtons.length).toBe(3); + upButtons[2].click(); + expect(testComponent.sortChange).toHaveBeenCalledTimes(3); + }); }); }); @@ -64,6 +85,7 @@ describe('nz-thead', () => { + ` @@ -71,4 +93,5 @@ describe('nz-thead', () => { export class NzTheadTestNzTableComponent { singleSort = false; sortChange = jasmine.createSpy('sort change'); + columns = ['third', 'fourth']; } From 9522658918e90ca2f01b4ebca565a280cc424354 Mon Sep 17 00:00:00 2001 From: Hsuan Lee Date: Wed, 19 Jun 2019 21:15:47 +0800 Subject: [PATCH 2/4] chore: sync with antd 3.19 (#3590) * chore: sync with antd 3.19 * test(module:page-header): fix test --- .../page-header/nz-page-header.component.html | 8 +++++--- components/page-header/nz-page-header.component.ts | 13 ++++++++++++- components/page-header/nz-page-header.spec.ts | 6 +++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/components/page-header/nz-page-header.component.html b/components/page-header/nz-page-header.component.html index 0556d96660d..055fb049486 100644 --- a/components/page-header/nz-page-header.component.html +++ b/components/page-header/nz-page-header.component.html @@ -1,8 +1,10 @@ -
- - +
+
+ + +
diff --git a/components/page-header/nz-page-header.component.ts b/components/page-header/nz-page-header.component.ts index a168c6b6b54..ed7150df0ea 100644 --- a/components/page-header/nz-page-header.component.ts +++ b/components/page-header/nz-page-header.component.ts @@ -32,7 +32,18 @@ import { NzPageHeaderFooterDirective } from './nz-page-header-cells'; host: { class: 'ant-page-header', '[class.ant-page-header-has-footer]': 'nzPageHeaderFooter' - } + }, + styles: [ + ` + .ant-page-header-back-button { + border: 0px; + background: transparent; + padding: 0px; + line-height: inherit; + display: inline-block; + } + ` + ] }) export class NzPageHeaderComponent implements OnInit, OnChanges { isTemplateRefBackIcon = false; diff --git a/components/page-header/nz-page-header.spec.ts b/components/page-header/nz-page-header.spec.ts index e57dbd21fd7..fccd1e64beb 100644 --- a/components/page-header/nz-page-header.spec.ts +++ b/components/page-header/nz-page-header.spec.ts @@ -65,14 +65,14 @@ describe('NzPageHeaderComponent', () => { const fixture = TestBed.createComponent(NzDemoPageHeaderBasicComponent); const pageHeader = fixture.debugElement.query(By.directive(NzPageHeaderComponent)); fixture.detectChanges(); - expect(pageHeader.nativeElement.querySelector('.ant-page-header-back-icon > i.anticon-arrow-left')).toBeTruthy(); + expect(pageHeader.nativeElement.querySelector('.ant-page-header-back i.anticon-arrow-left')).toBeTruthy(); }); it('should does not have an default back icon', () => { const fixture = TestBed.createComponent(NzDemoPageHeaderContentComponent); const pageHeader = fixture.debugElement.query(By.directive(NzPageHeaderComponent)); fixture.detectChanges(); - expect(pageHeader.nativeElement.querySelector('.ant-page-header-back-icon')).toBeFalsy(); + expect(pageHeader.nativeElement.querySelector('.ant-page-header-back')).toBeFalsy(); }); it('should nzBack work', () => { @@ -82,7 +82,7 @@ describe('NzPageHeaderComponent', () => { spyOn(context, 'onBack'); fixture.detectChanges(); expect(context.onBack).not.toHaveBeenCalled(); - const back = pageHeader.nativeElement.querySelector('.ant-page-header-back-icon'); + const back = pageHeader.nativeElement.querySelector('.ant-page-header-back'); (back as HTMLElement).click(); fixture.detectChanges(); expect(context.onBack).toHaveBeenCalled(); From 1b17110821f15870e2cec4d6ae331ed91eef87a2 Mon Sep 17 00:00:00 2001 From: Hsuan Lee Date: Thu, 20 Jun 2019 16:49:18 +0800 Subject: [PATCH 3/4] chore: refactor commit hook (#3610) * chore: refactor commit hook * chore(packaging): clean dependencie * chore(packaging): clean dev dependencie --- commitlint.config.js | 60 +++++++++++++++++++++ package.json | 4 +- scripts/git/commit-message.json | 24 --------- scripts/git/commit-msg.js | 21 -------- scripts/git/validate-commit-message.js | 73 -------------------------- 5 files changed, 63 insertions(+), 119 deletions(-) create mode 100644 commitlint.config.js delete mode 100644 scripts/git/commit-message.json delete mode 100755 scripts/git/commit-msg.js delete mode 100644 scripts/git/validate-commit-message.js diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 00000000000..e5762bf6286 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,60 @@ +'use strict'; +const message = process.env['HUSKY_GIT_PARAMS']; +const fs = require('fs'); + +const types = [ + 'build', + "chore", + 'ci', + 'docs', + 'feat', + 'fix', + 'perf', + 'refactor', + "release", + 'revert', + 'style', + 'test' +]; + +const scopes = [ + "showcase", + "packaging", + "changelog", + "schematics", + "module:*" +]; + +function parseMessage(message) { + const PATTERN = /^(\w+)(?:\(([^)]+)\))?\: (.+)$/; + const match = PATTERN.exec(message); + if (!match) { + return null; + } + return { + type: match[1] || null, + scope: match[2] || null, + } +} + +function getScopesRule() { + const messages = fs.readFileSync(message, {encoding: 'utf-8'}); + const parsed = parseMessage(messages.split('\n')[0]); + if (!parsed) { + return [2, 'always', scopes] + } + const { scope, type } = parsed; + if (scope && !scopes.includes(scope) && type !== 'release' && !/module:.+/.test(scope)) { + return [2, 'always', scopes] + } else { + return [2, 'always', []] + } +} + +module.exports = { + extends: ['@commitlint/config-angular'], + rules: { + 'type-enum': [2, 'always', types], + 'scope-enum': getScopesRule + } +}; diff --git a/package.json b/package.json index cc1ac75123a..0d1d012556c 100644 --- a/package.json +++ b/package.json @@ -64,6 +64,8 @@ "@angular/pwa": "^0.800.1", "@angular/router": "~8.0.0", "@angular/service-worker": "~8.0.0", + "@commitlint/cli": "^8.0.0", + "@commitlint/config-angular": "^8.0.0", "@nguniversal/module-map-ngfactory-loader": "^7.1.1", "@schematics/angular": "~8.0.1", "@stackblitz/sdk": "^1.1.1", @@ -123,7 +125,7 @@ }, "husky": { "hooks": { - "commit-msg": "node ./scripts/git/commit-msg.js -E HUSKY_GIT_PARAMS", + "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", "pre-commit": "lint-staged" } } diff --git a/scripts/git/commit-message.json b/scripts/git/commit-message.json deleted file mode 100644 index 3f9c6885b81..00000000000 --- a/scripts/git/commit-message.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "maxLength": 100, - "types": [ - "build", - "ci", - "docs", - "feat", - "fix", - "perf", - "refactor", - "release", - "style", - "test", - "chore", - "revert" - ], - "scopes": [ - "showcase", - "packaging", - "changelog", - "schematics", - "module:*" - ] -} diff --git a/scripts/git/commit-msg.js b/scripts/git/commit-msg.js deleted file mode 100755 index 1c8079e8e96..00000000000 --- a/scripts/git/commit-msg.js +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env node - -// from https://github.com/angular/angular/blob/master/scripts/git/commit-msg.js - -'use strict'; - -const fs = require('fs'); -const checkMsg = require('./validate-commit-message'); -const msgFile = process.env['HUSKY_GIT_PARAMS']; - -let isValid = true; -if (msgFile || true) { - const commitMsg = fs.readFileSync(msgFile, {encoding: 'utf-8'}); - const firstLine = commitMsg.split('\n')[0]; - isValid = checkMsg(firstLine); - if (!isValid) { - console.error('\x1b[36mCheck CONTRIBUTING.md at the root of the repo for more information.(请查看根目录下的 CONTRIBUTING.md 获取更多信息)\x1b[0m\n'); - } -} - -process.exit(isValid ? 0 : 1); diff --git a/scripts/git/validate-commit-message.js b/scripts/git/validate-commit-message.js deleted file mode 100644 index 26dfd200adb..00000000000 --- a/scripts/git/validate-commit-message.js +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env node - -// from https://github.com/angular/angular/blob/master/tools/validate-commit-message/validate-commit-message.js - -'use strict'; - -const fs = require('fs'); -const path = require('path'); -const configPath = path.resolve(__dirname, './commit-message.json'); -const config = JSON.parse(fs.readFileSync(configPath, 'utf8')); -const PATTERN = /^(\w+)(?:\(([^)]+)\))?\: (.+)$/; -const FIXUP_SQUASH = /^(fixup|squash)\! /i; -const REVERT = /^revert:? /i; - -module.exports = function (commitSubject) { - - const subject = commitSubject.replace(FIXUP_SQUASH, ''); - - if (subject.match(REVERT)) { - return true; - } - - if (subject.length > config['maxLength']) { - error(`The commit message is longer than ${config['maxLength']} characters`, commitSubject); - error(`commit 信息不能超过 ${config['maxLength']} 字符`, commitSubject, 'zh'); - return false; - } - - const match = PATTERN.exec(subject); - if (!match) { - error(`The commit message does not match the format of '(): ' OR ': '`, commitSubject); - error(`这条 commit 信息格式不正确 '(): ' 或 ': `, commitSubject, 'zh'); - return false; - } - - const type = match[1]; - - if (type.toLowerCase() === 'wip') { - error(`wip are not allowed in a commit, you can change this PR title`, commitSubject); - error(`wip 不允许出现在 commit 中,你可以在 PR 中修改它的标题`, commitSubject, 'zh'); - return false; - } - - if (config['types'].indexOf(type) === -1) { - error( - `${type} is not an allowed type.\n => TYPES: ${config['types'].join(', ')}`, commitSubject); - error( - `${type} 是不允许的 type.\n => TYPES: ${config['types'].join(', ')}`, commitSubject, 'zh'); - return false; - } - - const scope = match[2]; - - if (scope && !config['scopes'].includes(scope) && type !== 'release' && !/module:.+/.test(scope)) { - error( - `"${scope}" is not an allowed scope.\n => SCOPES: ${config['scopes'].join(', ')}`, commitSubject); - error( - `"${scope}" 是不允许的 scope.\n => SCOPES: ${config['scopes'].join(', ')}`, commitSubject, 'zh'); - return false; - } - - return true; -}; - -function error(errorMessage, commitMessage, lang) { - if (lang === 'zh') { - console.error(`\x1b[33m无效的 COMMIT 信息: "${commitMessage}"\x1b[0m\n\x1b[31m => 错误: ${errorMessage}\x1b[0m\n`); - } else { - console.error(`\x1b[33mINVALID COMMIT MSG: "${commitMessage}"\x1b[0m\n\x1b[31m => ERROR: ${errorMessage}\x1b[0m\n`); - } -} - -module.exports.config = config; From 2ff9b4d109f800d94a5103a34216207186389725 Mon Sep 17 00:00:00 2001 From: Hsuan Lee Date: Thu, 20 Jun 2019 16:53:35 +0800 Subject: [PATCH 4/4] chore: refactor commit hook (#3610) * chore: refactor commit hook * chore(packaging): clean dependencie * chore(packaging): clean dev dependencie