Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: shows argument list and highlights changed and invalid fields in menu #1059

Merged
merged 12 commits into from
Apr 30, 2021
39 changes: 33 additions & 6 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@
"framework": "express"
},
"@nrwl/angular:application": {
"style": "scss",
"linter": "eslint",
"unitTestRunner": "jest",
"e2eTestRunner": "cypress"
},
"@nrwl/angular:library": {
"unitTestRunner": "none"
"style": "scss",
"linter": "eslint",
"unitTestRunner": "jest"
},
"@nrwl/angular:component": {
"style": "scss"
}
},
"projects": {
Expand Down Expand Up @@ -272,6 +279,31 @@
},
"schematics": {}
},
"vscode-ui-argument-list": {
"projectType": "library",
"root": "libs/vscode-ui/argument-list",
"sourceRoot": "libs/vscode-ui/argument-list/src",
"prefix": "nx-console",
"architect": {
"lint": {
"builder": "@nrwl/linter:eslint",
"options": {
"lintFilePatterns": [
"libs/vscode-ui/argument-list/src/**/*.ts",
"libs/vscode-ui/argument-list/src/**/*.html"
]
}
},
"test": {
"builder": "@nrwl/jest:jest",
"outputs": ["coverage/libs/vscode-ui/argument-list"],
"options": {
"jestConfig": "libs/vscode-ui/argument-list/jest.config.js",
"passWithNoTests": true
}
}
}
},
"vscode-ui-components": {
"projectType": "library",
"root": "libs/vscode-ui/components",
Expand All @@ -294,11 +326,6 @@
},
"outputs": ["coverage/libs/vscode-ui/components"]
}
},
"schematics": {
"@nrwl/angular:component": {
"styleext": "scss"
}
}
},
"vscode-ui-styles": {
Expand Down
1 change: 1 addition & 0 deletions apps/vscode-ui/src/styles.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@import 'flex';
@import 'variables';
@import '~vscode-codicons/dist/codicon';

html,
body {
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports = {
projects: [
'<rootDir>/apps/vscode-ui',
'<rootDir>/libs/server',
'<rootDir>/libs/vscode-ui/argument-list',
'<rootDir>/libs/vscode-ui/components',
'<rootDir>/libs/vscode-ui/feature-task-execution-form',
'<rootDir>/libs/vscode/nx-project-view',
Expand Down
31 changes: 31 additions & 0 deletions libs/vscode-ui/argument-list/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"extends": ["../../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts"],
"extends": [
"plugin:@nrwl/nx/angular",
"plugin:@angular-eslint/template/process-inline-templates"
],
"parserOptions": {
"project": ["libs/vscode-ui/argument-list/tsconfig.*?.json"]
},
"rules": {
"@angular-eslint/directive-selector": [
"error",
{ "type": "attribute", "prefix": "nx-console", "style": "camelCase" }
],
"@angular-eslint/component-selector": [
"error",
{ "type": "element", "prefix": "nx-console", "style": "kebab-case" }
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@nrwl/nx/angular-template"],
"rules": {}
}
]
}
23 changes: 23 additions & 0 deletions libs/vscode-ui/argument-list/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = {
displayName: 'vscode-ui-argument-list',
preset: '../../../jest.preset.js',
setupFilesAfterEnv: ['<rootDir>/src/test-setup.ts'],
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.(html|svg)$',
astTransformers: {
before: [
'jest-preset-angular/build/InlineFilesTransformer',
'jest-preset-angular/build/StripStylesTransformer',
],
},
},
},
coverageDirectory: '../../../coverage/libs/vscode-ui/argument-list',
snapshotSerializers: [
'jest-preset-angular/build/AngularNoNgAttributesSnapshotSerializer.js',
'jest-preset-angular/build/AngularSnapshotSerializer.js',
'jest-preset-angular/build/HTMLCommentSerializer.js',
],
};
1 change: 1 addition & 0 deletions libs/vscode-ui/argument-list/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './lib/argument-list.module';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div *ngFor="let arg of args" [innerHtml]="arg"></div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
div {
overflow-wrap: break-word;
margin-left: 1em;
text-indent: -1em;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ArgumentListComponent } from './argument-list.component';

describe('ArgumentListComponent', () => {
let component: ArgumentListComponent;
let fixture: ComponentFixture<ArgumentListComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ArgumentListComponent],
}).compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(ArgumentListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

it('should format arguments for multiline break-word', () => {
component.args = [
'--some-arg=withalistofoptions,that-may-not-fit-on-a-single-line',
];
fixture.detectChanges();
expect(component.args).toEqual([
'--some-arg=<wbr>withalistofoptions,that-may-not-fit-on-a-single-line',
]);
});
});
36 changes: 36 additions & 0 deletions libs/vscode-ui/argument-list/src/lib/argument-list.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
Component,
Input,
ChangeDetectionStrategy,
SecurityContext,
} from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';

@Component({
selector: 'nx-console-argument-list',
templateUrl: './argument-list.component.html',
styleUrls: ['./argument-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class ArgumentListComponent {
private _formattedArgs: string[];
@Input()
get args(): string[] {
return this._formattedArgs;
}
set args(values: string[]) {
this._formattedArgs =
values &&
values.map(
(value) =>
this.domSanitizer.sanitize(
SecurityContext.HTML,
this.domSanitizer.bypassSecurityTrustHtml(
value.replace('=', '=<wbr>')
)
) || ''
);
}

constructor(private readonly domSanitizer: DomSanitizer) {}
}
11 changes: 11 additions & 0 deletions libs/vscode-ui/argument-list/src/lib/argument-list.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

import { ArgumentListComponent } from './argument-list.component';

@NgModule({
imports: [CommonModule],
declarations: [ArgumentListComponent],
exports: [ArgumentListComponent],
})
export class ArgumentListModule {}
1 change: 1 addition & 0 deletions libs/vscode-ui/argument-list/src/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import 'jest-preset-angular';
13 changes: 13 additions & 0 deletions libs/vscode-ui/argument-list/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
}
]
}
19 changes: 19 additions & 0 deletions libs/vscode-ui/argument-list/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"target": "es2015",
"declaration": true,
"declarationMap": true,
"inlineSources": true,
"types": [],
"lib": ["dom", "es2018"]
},
"angularCompilerOptions": {
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"enableResourceInlining": true
},
"exclude": ["src/test-setup.ts", "**/*.spec.ts"],
"include": ["**/*.ts"]
}
10 changes: 10 additions & 0 deletions libs/vscode-ui/argument-list/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"files": ["src/test-setup.ts"],
"include": ["**/*.spec.ts", "**/*.d.ts"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*ngFor="let field of fields"
(click)="scrollToField(field.name)"
[class.active]="activeFieldName === field.name"
[class.valid]="isFieldValid(field.name)"
[class.error]="isFieldInvalid(field.name)"
[id]="field.name + '-field-tree-item'"
[style.display]="filteredFields.has(field.name) ? 'block' : 'none'"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@
font-weight: 700;
opacity: 1;
}

&.valid {
color: $modified-text-color;
}
&.error {
color: $error-text-color;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class FieldTreeComponent implements OnChanges {
@Input() fields: Array<Option>;
@Input() activeFieldName: string;
@Input() filteredFields: Set<string>;
@Input() validFields: {[name: string]: string[] | string | number | boolean};
@Input() invalidFields: {[name: string]: string[] | string | number | boolean};

userSelectedField?: string;

Expand Down Expand Up @@ -73,4 +75,12 @@ export class FieldTreeComponent implements OnChanges {
});
}
}

isFieldValid(fieldName: string): boolean {
return this.validFields && !!this.validFields[fieldName];
}

isFieldInvalid(fieldName: string): boolean {
return this.invalidFields && this.invalidFields[fieldName] !== undefined;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:host {
display: block;
position: relative;
margin-bottom: 1.5rem;
margin-bottom: 1rem;
white-space: normal;

.field-title {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { CheckboxComponent } from './checkbox/checkbox.component';
import { FieldComponent } from './field/field.component';
import { FieldTreeComponent } from './field-tree/field-tree.component';
import { MultipleSelectComponent } from './multiple-select/multiple-select.component';
import { FormatTaskPipe } from './format-task/format-task.pipe';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pipe is used over in the parent form, and it needs to call the formatTask function directly now as well for the copy to clipboard functionality, so I moved it into that lib.

import { FieldItemsPipe } from './field-items/field-items.pipe';

@NgModule({
Expand All @@ -21,7 +20,6 @@ import { FieldItemsPipe } from './field-items/field-items.pipe';
FieldComponent,
FieldTreeComponent,
MultipleSelectComponent,
FormatTaskPipe,
FieldItemsPipe,
],
exports: [
Expand All @@ -32,7 +30,6 @@ import { FieldItemsPipe } from './field-items/field-items.pipe';
FieldComponent,
FieldTreeComponent,
MultipleSelectComponent,
FormatTaskPipe,
],
})
export class VscodeUiComponentsModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { FormatTaskPipe } from './format-task.pipe';

describe('FormatTaskPipe', () => {
const pipe = new FormatTaskPipe();

it('should reformat workspace generator commands', () => {
expect(
pipe.transform({
name: '',
cliName: 'ng',
description: '',
options: [],
command: 'generate',
positional: 'workspace-schematic:xyz-name',
})
).toEqual('nx workspace-schematic xyz-name');
expect(
pipe.transform({
name: '',
cliName: 'ng',
description: '',
options: [],
command: 'generate',
positional: 'workspace-generator:xyz-name',
})
).toEqual('nx workspace-generator xyz-name');
expect(
pipe.transform({
name: '',
cliName: 'ng',
description: '',
options: [],
command: 'generate',
positional: '@nrwl/angular:library',
})
).toEqual('ng generate @nrwl/angular:library');
});
});
Loading