Skip to content

Commit

Permalink
fix generate ui & generate ui e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKless committed Dec 12, 2024
1 parent 79ccb30 commit becb086
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 67 deletions.
6 changes: 2 additions & 4 deletions apps/generate-ui-v2-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"sourceMap": false,
"outDir": "../../dist/out-tsc",
"types": ["cypress", "node", "cypress-real-events"],
"moduleResolution": "node"
"outDir": "out-tsc/generate-ui-v2-e2e",
"types": ["cypress", "node", "cypress-real-events"]
},
"include": [
"src/**/*.ts",
Expand Down
2 changes: 1 addition & 1 deletion apps/generate-ui-v2/src/components/field-nav-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FieldValueConsumer } from './field-value-consumer-mixin';
@customElement('field-nav-item')
export class FieldNavItem extends FieldValueConsumer(LitElement) {
@property()
protected option: Option;
option: Option;

@property()
greyedOut = false;
Expand Down
28 changes: 14 additions & 14 deletions apps/generate-ui-v2/src/components/field-value-consumer-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ import { generatorContextContext } from '../contexts/generator-context-context';
type Constructor<T> = new (...args: any[]) => T;

export declare class FieldValueConsumerInterface {
protected option: Option;
protected validation: boolean | string | undefined;
protected touched: boolean;
protected isDefaultValue: boolean;
protected submitted: boolean;
protected generatorContext: GeneratorContext | undefined;
protected shouldRenderChanged(): boolean;
protected shouldRenderError(): boolean;
option: Option;
validation: boolean | string | undefined;
touched: boolean;
isDefaultValue: boolean;
submitted: boolean;
generatorContext: GeneratorContext | undefined;
shouldRenderChanged(): boolean;
shouldRenderError(): boolean;
}

export const FieldValueConsumer = <T extends Constructor<LitElement>>(
superClass: T
) => {
class FieldValueConsumerElement extends superClass {
protected option: Option;
option: Option;

@state()
private validation: string | boolean | undefined;
validation: string | boolean | undefined;

@state()
private touched = false;
touched = false;

@state()
private isDefaultValue = true;
isDefaultValue = true;

@state()
private submitted = false;
submitted = false;

@state() generatorContext: GeneratorContext | undefined;

Expand Down Expand Up @@ -85,7 +85,7 @@ export const FieldValueConsumer = <T extends Constructor<LitElement>>(
return this.touched && !this.isDefaultValue;
}

protected createRenderRoot(): Element | ShadowRoot {
createRenderRoot(): Element | ShadowRoot {
return this;
}
}
Expand Down
4 changes: 1 addition & 3 deletions apps/generate-ui-v2/src/components/fields/array-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,7 @@ export class ArrayField extends FieldWrapper(Field(LitElement)) {
this.dispatchValue(this.elements);
}

protected setFieldValue(
value: string | boolean | number | string[] | undefined
) {
setFieldValue(value: string | boolean | number | string[] | undefined) {
if (typeof value === 'string') {
this.elements = value.split(',');
} else if (Array.isArray(value)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Combobox, ComboboxAutocomplete } from '@microsoft/fast-foundation';

@customElement('autocomplete-field')
export class AutocompleteField extends FieldWrapper(Field(LitElement)) {
protected renderField(): TemplateResult {
renderField(): TemplateResult {
if (this.editor === 'vscode') {
return this.renderVSCode();
} else {
Expand Down Expand Up @@ -94,9 +94,7 @@ export class AutocompleteField extends FieldWrapper(Field(LitElement)) {
this.dispatchValue(value);
}

protected setFieldValue(
value: string | boolean | number | string[] | undefined
) {
setFieldValue(value: string | boolean | number | string[] | undefined) {
const selector =
this.editor === 'vscode' ? 'vscode-combobox' : 'intellij-combobox';
const autocompleteNode = this.renderRoot.querySelector(selector);
Expand Down
4 changes: 1 addition & 3 deletions apps/generate-ui-v2/src/components/fields/checkbox-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ export class CheckboxField extends CheckboxWrapper(Field(LitElement)) {
}
}

protected setFieldValue(
value: string | number | boolean | string[] | undefined
): void {
setFieldValue(value: string | number | boolean | string[] | undefined): void {
const inputElement = this.renderRoot.querySelector(
this.editor === 'intellij' ? 'input' : 'vscode-checkbox'
);
Expand Down
6 changes: 2 additions & 4 deletions apps/generate-ui-v2/src/components/fields/input-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { FieldWrapper } from './mixins/field-wrapper-mixin';

@customElement('input-field')
export class InputField extends FieldWrapper(Field(LitElement)) {
protected renderField(): TemplateResult {
renderField(): TemplateResult {
const error = this.shouldRenderError();
if (this.editor === 'intellij') {
return html`
Expand Down Expand Up @@ -44,9 +44,7 @@ export class InputField extends FieldWrapper(Field(LitElement)) {
this.dispatchValue(value);
}

protected setFieldValue(
value: string | boolean | number | string[] | undefined
) {
setFieldValue(value: string | boolean | number | string[] | undefined) {
const inputNode = this.renderRoot.querySelector(
this.editor === 'intellij' ? 'input' : 'vscode-text-field'
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const CheckboxWrapper = <
base: T
) => {
return class extends base {
protected render() {
render() {
return html`
<div
class="${this.shouldRenderError()
Expand Down
34 changes: 14 additions & 20 deletions apps/generate-ui-v2/src/components/fields/mixins/field-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,21 @@ export type OptionChangedDetails = {

export declare class FieldInterface {
option: Option;
protected renderField(): TemplateResult;
protected validation: boolean | string | undefined;
protected touched: boolean;
protected dispatchValue(
value: string | boolean | number | string[] | undefined
): void;
protected setFieldValue(
value: string | boolean | number | string[] | undefined
): void;
protected fieldId: string;
protected ariaAttributes: Record<string, string>;
renderField(): TemplateResult;
validation: boolean | string | undefined;
touched: boolean;
dispatchValue(value: string | boolean | number | string[] | undefined): void;
setFieldValue(value: string | boolean | number | string[] | undefined): void;
fieldId: string;
ariaAttributes: Record<string, string>;
}

export const Field = <T extends Constructor<LitElement>>(superClass: T) => {
class FieldElement extends FieldValueConsumer(EditorContext(superClass)) {
@property()
option: Option;

protected dispatchValue(
value: string | boolean | number | string[] | undefined
) {
dispatchValue(value: string | boolean | number | string[] | undefined) {
const defaultValue = extractDefaultValue(this.option);
const isDefaultValue = compareWithDefaultValue(value, defaultValue);

Expand All @@ -62,7 +56,7 @@ export const Field = <T extends Constructor<LitElement>>(superClass: T) => {
);
}

protected firstUpdated(
firstUpdated(
_changedProperties: PropertyValueMap<unknown> | Map<PropertyKey, unknown>
): void {
super.updated(_changedProperties);
Expand All @@ -87,11 +81,11 @@ export const Field = <T extends Constructor<LitElement>>(superClass: T) => {
this.dispatchValue(undefined);
}

protected get fieldId(): string {
get fieldId(): string {
return `${this.option.name}-field`;
}

protected get ariaAttributes(): Record<
get ariaAttributes(): Record<
'id' | 'aria-invalid' | 'aria-describedby',
string
> {
Expand All @@ -101,19 +95,19 @@ export const Field = <T extends Constructor<LitElement>>(superClass: T) => {
'aria-describedby': `${this.fieldId}-error`,
};
}
protected createRenderRoot(): Element | ShadowRoot {
createRenderRoot(): Element | ShadowRoot {
return this;
}

// placeholders for subclasses
protected setFieldValue(
setFieldValue(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
value: string | boolean | number | string[] | undefined
): void {
throw new Error('Not implemented');
}

protected renderField(): TemplateResult {
renderField(): TemplateResult {
throw new Error('Not implemented');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const FieldWrapper = <
base: T
) => {
return class extends base {
protected render() {
render() {
return html`
<div
class="${this.shouldRenderError()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ export class MultiselectField extends FieldWrapper(Field(LitElement)) {
this.dispatchValue(this.selectedElements);
}

protected setFieldValue(
value: string | number | boolean | string[] | undefined
): void {
setFieldValue(value: string | number | boolean | string[] | undefined): void {
let values: string[] = [];
if (typeof value === 'string') {
values = value.split(',');
Expand Down
6 changes: 2 additions & 4 deletions apps/generate-ui-v2/src/components/fields/select-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ export class SelectField extends FieldWrapper(Field(LitElement)) {
`;
}

protected setFieldValue(
value: string | number | boolean | string[] | undefined
): void {
setFieldValue(value: string | number | boolean | string[] | undefined): void {
const selectNode = this.renderRoot.querySelector(
this.editor === 'intellij' ? 'select' : 'vscode-dropdown'
);
Expand All @@ -83,7 +81,7 @@ export class SelectField extends FieldWrapper(Field(LitElement)) {
selectNode.value = value ? `${value}` : '';
}

private handleChange(e: Event) {
handleChange(e: Event) {
const value = (e.target as HTMLInputElement).value;
this.dispatchValue(value);
}
Expand Down
15 changes: 12 additions & 3 deletions apps/generate-ui-v2/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
{
"extends": "./tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"outDir": "out-tsc/generate-ui-v2",
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["node"],
"useDefineForClassFields": false
"useDefineForClassFields": false,
"lib": ["DOM", "esnext.asynciterable"],
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noImplicitOverride": false,
"noImplicitReturns": false,
"noUnusedLocals": false,
"isolatedModules": false,
"strict": false
},
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"],
"include": ["src/**/*.ts"],
Expand Down
10 changes: 8 additions & 2 deletions apps/generate-ui-v2/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
{
"extends": "./tsconfig.json",
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"outDir": "out-tsc/jest",
"module": "commonjs",
"moduleResolution": "node10",
"types": ["jest", "node"]
},
"include": [
"jest.config.ts",
"src/**/*.test.ts",
"src/**/*.spec.ts",
"src/**/*.d.ts"
],
"references": [
{
"path": "./tsconfig.app.json"
}
]
}

0 comments on commit becb086

Please sign in to comment.