Skip to content

Commit

Permalink
fix some types
Browse files Browse the repository at this point in the history
  • Loading branch information
Cammisuli committed Dec 9, 2021
1 parent 6b77797 commit 0f46f3b
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 57 deletions.
5 changes: 2 additions & 3 deletions libs/schema/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ export type OptionPropertyDescription = Schema['properties'][number];

export type CliOption = {
name: string;
required?: boolean;
positional?: number;
alias?: string;
hidden?: boolean;
deprecated?: boolean | string;
} & OptionPropertyDescription;

export interface Option extends Omit<CliOption, 'default'> {
export interface Option extends CliOption {
tooltip?: string;
itemTooltips?: ItemTooltips;
items?: string[] | ItemsWithEnum;
aliases: string[];
default?: string[] | string | number | boolean | undefined;
isRequired: boolean;
}

export interface ItemTooltips {
Expand Down
43 changes: 23 additions & 20 deletions libs/server/src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export async function normalizeSchema(

const nxOption: Option = {
...option,
required: isFieldRequired(requiredFields, option, xPrompt, $default),
isRequired: isFieldRequired(requiredFields, option, xPrompt, $default),
aliases: option.alias ? [option.alias] : [],
...(workspaceDefault !== undefined && { default: workspaceDefault }),
...($default && { $default }),
Expand Down Expand Up @@ -374,24 +374,27 @@ export function toWorkspaceFormat(w: any): WorkspaceJsonConfiguration {
}

function schemaToOptions(schema: Schema): CliOption[] {
return Object.keys(schema.properties).reduce<CliOption[]>((acc, curr) => {
const currentProperties = schema.properties[curr];
const $default = currentProperties.$default;
const $defaultIndex =
$default?.['$source'] === 'argv' ? $default['index'] : undefined;
const positional: number | undefined =
typeof $defaultIndex === 'number' ? $defaultIndex : undefined;

const visible = currentProperties.visible ?? true;
if (!visible || (currentProperties as any).hidden) {
return acc;
}
return Object.keys(schema.properties).reduce<CliOption[]>(
(cliOptions, option) => {
const currentProperties = schema.properties[option];
const $default = currentProperties.$default;
const $defaultIndex =
$default?.['$source'] === 'argv' ? $default['index'] : undefined;
const positional: number | undefined =
typeof $defaultIndex === 'number' ? $defaultIndex : undefined;

const visible = currentProperties.visible ?? true;
if (!visible || (currentProperties as any).hidden) {
return cliOptions;
}

acc.push({
name: curr,
positional,
...currentProperties,
});
return acc;
}, []);
cliOptions.push({
name: option,
positional,
...currentProperties,
});
return cliOptions;
},
[]
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
[style.display]="filteredFields.has(field.name) ? 'block' : 'none'"
>
{{ camelToTitle(field.name) }}
<ng-container *ngIf="field.required">*</ng-container>
<ng-container *ngIf="field.isRequired">*</ng-container>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ import { Option } from '@nx-console/schema';
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class FieldTreeComponent implements OnChanges {
@Input() fields: Array<Option>;
@Input() fields: Option[];
@Input() activeFieldName: string;
@Input() filteredFields: Set<string>;
@Input() validFields: {[name: string]: string[] | string | number | boolean};
@Input() invalidFields: {[name: string]: string[] | string | number | boolean};
@Input() validFields: {
[name: string]: string[] | string | number | boolean;
};
@Input() invalidFields: {
[name: string]: string[] | string | number | boolean;
};

userSelectedField?: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="field-title" [attr.title]="field.tooltip ? field.tooltip : null">
{{ field.name }}
<ng-container *ngIf="field.required">*</ng-container>
<ng-container *ngIf="field.isRequired">*</ng-container>
<span class="deprecated-warning" *ngIf="field.deprecated">(deprecated)</span>
</div>

Expand Down
2 changes: 1 addition & 1 deletion libs/vscode-ui/components/src/lib/field/field.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class FieldComponent implements ControlValueAccessor, OnDestroy {
return Object.keys(this.control.errors ?? {})
.map((key) => {
if (this.control.errors) {
if (key === 'required') {
if (key === 'isRequired') {
return `${fieldName
.slice(0, 1)
.toLocaleUpperCase()}${fieldName.slice(1)} is required`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class="text-input"
[type]="field.type === 'number' ? 'number' : 'text'"
role="textbox"
[required]="field.required"
[required]="field.isRequired"
[formControlName]="field.name"
/>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
multiple
role="combobox"
[id]="field.name"
[required]="field.required"
[required]="field.isRequired"
[formControlName]="field.name"
>
<option *ngIf="!field.default" value="" [selected]="!value"></option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class MultipleSelectComponent implements OnInit, OnDestroy {
private readonly subscriptions = new Subscription();

ngOnInit(): void {
this.subscriptions.add(
this.field.this.subscriptions.add(
this.selectControl.valueChanges.subscribe((value) =>
this.valueChange.emit(value)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
(change)="updateValue($event.target.value)"
role="combobox"
[id]="field.name"
[required]="field.required"
[required]="field.isRequired"
[formControlName]="field.name"
>
<option *ngIf="!field.default" value="" [selected]="!value"></option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,9 @@ export class TaskExecutionFormComponent implements OnInit, AfterViewChecked {

readonly filterFieldsControl = new FormControl('');

private readonly filterValue$ = (this.filterFieldsControl
.valueChanges as Observable<string>).pipe(
private readonly filterValue$ = (
this.filterFieldsControl.valueChanges as Observable<string>
).pipe(
startWith(''),
map((filterValue) => filterValue.toLowerCase()),
distinctUntilChanged()
Expand Down Expand Up @@ -284,7 +285,7 @@ export class TaskExecutionFormComponent implements OnInit, AfterViewChecked {

architect.options.forEach((schema) => {
const validators: Array<ValidatorFn> = [];
if (schema.required) {
if (schema.isRequired) {
validators.push(Validators.required);
}
if (schema.enum || schema.items) {
Expand Down Expand Up @@ -356,7 +357,8 @@ export class TaskExecutionFormComponent implements OnInit, AfterViewChecked {
defaultValues[field.name] = field.default.map((item) => String(item));
} else {
defaultValues[field.name] =
String(field.default) || (field.type === OptionType.Boolean ? 'false' : '');
String(field.default) ||
(field.type === OptionType.Boolean ? 'false' : '');
}
});

Expand Down Expand Up @@ -386,10 +388,7 @@ export class TaskExecutionFormComponent implements OnInit, AfterViewChecked {
const configuration = form.get('configuration')?.value;
const args = this.serializeArgs(form.value, architect, configuration);
const flags = configuration
? [
getConfigurationFlag(configuration),
...args,
]
? [getConfigurationFlag(configuration), ...args]
: args;
if (architect.command === 'generate') {
flags.push('--no-interactive');
Expand Down Expand Up @@ -429,21 +428,26 @@ export class TaskExecutionFormComponent implements OnInit, AfterViewChecked {
control.valid &&
// touched is not working with checkbox, so ignore touched and just check !== defaultValue
// control.touched &&
((option.type !== OptionType.Array && control.value !== defaultValues[option.name]) ||
((option.type !== OptionType.Array &&
control.value !== defaultValues[option.name]) ||
(option.type === OptionType.Array &&
control.value &&
control.value.join(',') !== ((defaultValues[option.name] || []) as string[]).join(',')
)
)) ||
control.value.join(',') !==
((defaultValues[option.name] || []) as string[]).join(
','
)))) ||
// ** INVALID fields **
// invalid and touched (checkbox is always valid as true/false)
(!valid && control.touched && control.invalid)
);
})
.reduce((options, option) => ({
...options,
[option.name]: form.controls[option.name].value,
}), {});
.reduce(
(options, option) => ({
...options,
[option.name]: form.controls[option.name].value,
}),
{}
);
})
);
}
Expand All @@ -466,7 +470,8 @@ export class TaskExecutionFormComponent implements OnInit, AfterViewChecked {
if (!defaultValues[f.name] && !value[f.name]) return;
if (
Array.isArray(defaultValues[f.name]) &&
(defaultValues[f.name] as string[]).join(',') === value[f.name].join(',')
(defaultValues[f.name] as string[]).join(',') ===
value[f.name].join(',')
)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const initialSchema: TaskExecutionSchema = {
description: 'Application that the new domain libraries will belong to',
type: OptionType.String,
default: 'nxConsole',
required: true,
isRequired: true,
aliases: ['a'],
hidden: false,
tooltip: 'What application will the new domain libraries be under?',
Expand All @@ -70,7 +70,7 @@ const initialSchema: TaskExecutionSchema = {
name: 'libraries',
description: 'The library types that will be generated',
type: OptionType.Array,
required: true,
isRequired: true,
default: ['data-access', 'feature'],
items: {
enum: ['data-access', 'feature', 'shell', 'ui', 'util'],
Expand All @@ -85,16 +85,15 @@ const initialSchema: TaskExecutionSchema = {
shell:
'shell - for wrapping different libraries and exposing them as a single library. Also, for routing.',
ui: 'ui - for dumb components',
util:
'util - for model files, constants, validators, pipes and any other miscellaneous items, e.g. shared functions.',
util: 'util - for model files, constants, validators, pipes and any other miscellaneous items, e.g. shared functions.',
},
},
{
name: 'style',
description: 'The file extension to be used for style files.',
type: OptionType.String,
default: 'scss',
required: false,
isRequired: false,
aliases: ['s'],
hidden: false,
tooltip: 'Which stylesheet format would you like to use?',
Expand All @@ -110,7 +109,7 @@ const initialSchema: TaskExecutionSchema = {
description: 'Add a e2e cypress project',
type: OptionType.Boolean,
default: true,
required: false,
isRequired: false,
aliases: [],
hidden: false,
tooltip: 'Add a cypress e2e app?',
Expand All @@ -120,7 +119,7 @@ const initialSchema: TaskExecutionSchema = {
name: 'color',
description: 'Which color should be used?',
type: OptionType.String,
required: false,
isRequired: false,
default: cssColorNames[5],
aliases: [],
hidden: false,
Expand Down

0 comments on commit 0f46f3b

Please sign in to comment.