Skip to content

[#603][3.3] Add various improvements to the existing new gui code - #613

Merged
zuozhiw merged 10 commits into
masterfrom
new-gui-improve
May 7, 2018
Merged

zuozhiw merged 10 commits into
masterfrom
new-gui-improve

Conversation

@zuozhiw

@zuozhiw zuozhiw commented Apr 29, 2018 •

Copy link
Copy Markdown
Contributor

This PR includes various small but important improvements to the existing code. It prepares for the usage of all these improvements for later PRs.

  1. Introduce --strict mode for TypeScript compiler. (important)
  2. Uniform all test case names to be should do something. (important)
  3. Update some dependency versions. (minor)
  4. Change all global testing constants to a function that returns a copy of the data. This is to avoid a test case modify the object and affect all other test cases.

1. Introduce --strict mode from TypeScript compiler.

TypeScript --strict compiler option enables all options that are related to strict type checking. Important ones are:

--strictNullChecks:

By default all variables can implicitly be null or undefined. undefined is the root of all evils, similar to Java's worst mistake NullPointerException.

With this option on, we must explicitly check for null and undefined, for example, the following function gets a number value from a map:

// this compiles normally, but doesn't compile with --strictNullChecks
// value is possibly undefined if the map doesn't contain the key
public getValue(key: string): number {
  const value = this.map.get(key);
  return value;
}

We must handle undefined explicitly. Typescript uses local control flow type analysis to help us do this.

public getValue(key: string): number {
  // value is of type number or undefined
  const value: number | undefined  = this.map.get(key);
  if (value === undefined) {
    throw new Error('cannot find key');
  }
  // value is now only type number (not null or undefined)
  return value;
}

--strictPropertyInitialization:

With this option on, we must initialize a class variable when we declare it or in the constructor.

In our codebase, we have a class variable jointjsPaper, which won't be initialized after ngAfterViewInit because we need to wait for the HTML rendering to complete. With this option on, we must declare it as:

private jointjsPaper: joint.dia.Paper | undefined

There are some other options to help do type checking. In general, with all these options on, TypeScript compiler forces us to write better and safer code.

2. Uniform all test case names to be should do something.

In the default test template generated by angular, all test cases starts with should do something. We didn't strictly follow that convention.

After more experience in writing test cases, this convention offers multiple benefits and should be strictly followed:

  • test case names are now English and much more readable
  • easy to identify the test scenarios in the test report (instead of finding them in the hundred lines codebase)
  • generates a clean and easy to read test report
  • helps know what is wrong more easily when a test case fails
  • a shift of mindset from testing a specific function to testing a behavior: the BDD revolution (Behavior Driven Development)

Frontend Test Report of a module's behaviors
screen shot 2018-04-29 at 3 26 59 pm

Backend Test Report of a module's test function names:
screen shot 2018-04-29 at 3 38 14 pm


export const MOCK_OPERATOR_SCHEMA_LIST: OperatorSchema[] = [
export const getMockOperatorSchemaList: () => OperatorSchema[] =
() => cloneDeep([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why the change to cloneDeep?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To avoid a test case changing the global constant variable and affect the all other test cases. In this way, test cases only get a copy of the data. It won't have any effect even if they modified the data.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have added the reason to the PR description.

return operatorStyleAttrs;
}


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please remove these lines. Unnecessary changes to whitespace makes Git think that something has changed and basically two big block of functions show up on deleted and added side.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me try to do that, hopefully git can be smarter to pick up the difference. The cause might not be the empty lines though. Originally these functions are just functions, they are outside of the class. Now these functions are static class functions, and they are inside the class. That should be the main reason.

@zuozhiw

zuozhiw commented May 1, 2018 •

Copy link
Copy Markdown
Contributor Author

Changes related to joint-ui.service.ts:

  1. Constants variables (such as deleteButtonPath, deleteButtonSVG) has been moved outside of the class. They were declared as public readonly. They are now not part of the class and declared as export const. This is for better reflect their nature of constants and not bind to an instance of a class.

  2. Changes to some helper functions original declared outside of the class (declared as export function) (such as getCustomPortStyleAttrs, getCustomOperatorStyleAttrs), and some functions originally declared as public inside the the class (getJointjsLinkElement, getDefaultLinkElement). They are now uniformly changed to public static. This is to reflect that they are part of the class, but they are static and not bind to an instance.

  3. The return type signature of some functions are improved. For example, return type of getCustomPortStyleAttrs is changed from a general Object to a more specific joint.attributes.SVGAttributes

  4. setupCustomJointjsModel is changed. Original implementation is to use JointJS's own extend function joint.shapes.devs['TexeraOperatorShape'] = joint.shapes.devs.Model.extend. In the old JavaScript versions, there were no concept of class, and that's the old way of extending a class. After we enable the --strict option, this method is no longer considered type safe. It has been changed it to use the new way: class TexeraCustomJointElement extends joint.shapes.devs.Model.

Comment thread core/new-gui/tslint.json
"static-method",
"instance-method"
]
"order": "instance-sandwich"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what does instance-sandwich do?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

tslint is responsible for checking coding styles.
the default class member is something like:
static field
instance field
static method
instance method

And I don't like that ordering, sandwich is:
static field
instance field
instance method
static method

so static method is in the end. Most of the static methods are just helper functions, so it makes sense to put them in the end.

}

/**
* OperatorUIElementService controls the shape of an operator

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Change name in comment

@avinash0161 avinash0161 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few questions. Please reply to them. Otherwise it's fine.

@zuozhiw
zuozhiw merged commit 88ed8e5 into master May 7, 2018
@zuozhiw
zuozhiw deleted the new-gui-improve branch May 7, 2018 05:25
Yicong-Huang added a commit that referenced this pull request Jul 5, 2026
### What changes were proposed in this PR?

Patch-level alignment of all Angular packages in `frontend/`, across the
two Angular release lines:

| Line | Packages | Before | After |
| --- | --- | --- | --- |
| CLI toolchain | `@angular/cli`, `@angular-devkit/build-angular`,
`@angular-devkit/core`, `@angular-devkit/schematics`,
`@schematics/angular` | 21.2.8 | 21.2.18 |
| Framework | `@angular/{core,common,compiler,compiler-cli,localize}` |
21.2.17 | 21.2.17 (unchanged) |
| Framework |
`@angular/{animations,forms,router,platform-browser,platform-browser-dynamic}`
| 21.2.10 | 21.2.17 |
| CDK | `@angular/cdk` | 21.2.8 | 21.2.14 |

(The framework line has no 21.2.18 — 21.2.17 is its latest; CLI and
framework version independently.)

The toolchain bump is security-motivated: 21.2.8 exact-pins several
build-time dependencies with open advisories, which a plain lockfile
refresh cannot move. 21.2.18 re-pins them all to patched versions:

| Pinned dep | Before | After | Dependabot alerts resolved |
| --- | --- | --- | --- |
| undici | 7.24.4 | 7.28.0 |
[#617](https://github.com/apache/texera/security/dependabot/617) (high),
[#614](https://github.com/apache/texera/security/dependabot/614) (high),
[#621](https://github.com/apache/texera/security/dependabot/621),
[#613](https://github.com/apache/texera/security/dependabot/613),
[#623](https://github.com/apache/texera/security/dependabot/623),
[#616](https://github.com/apache/texera/security/dependabot/616) |
| vite | 7.3.2 | 7.3.6 |
[#591](https://github.com/apache/texera/security/dependabot/591) (high),
[#594](https://github.com/apache/texera/security/dependabot/594) |
| piscina | 5.1.4 | 5.2.0 |
[#610](https://github.com/apache/texera/security/dependabot/610) (high)
|
| webpack-dev-server | 5.2.3 | 5.2.5 |
[#609](https://github.com/apache/texera/security/dependabot/609),
[#518](https://github.com/apache/texera/security/dependabot/518) |
| esbuild | 0.27.3 | 0.28.1 |
[#555](https://github.com/apache/texera/security/dependabot/555) |
| postcss | 8.5.6 | 8.5.12 |
[#474](https://github.com/apache/texera/security/dependabot/474) |

13 alerts total (4 high). Not covered here (separate lockfile copies of
the same packages, planned as a follow-up refresh): undici `^6.25.0`
([#622](https://github.com/apache/texera/security/dependabot/622),
[#620](https://github.com/apache/texera/security/dependabot/620),
[#615](https://github.com/apache/texera/security/dependabot/615)) and
vite 8.x
([#593](https://github.com/apache/texera/security/dependabot/593),
[#590](https://github.com/apache/texera/security/dependabot/590)).

The framework/CDK alignment additionally clears the `YN0060`
incorrect-peer-dependency warnings printed on every `yarn install` (the
tree previously mixed 21.2.10 and 21.2.17).

Diff is `frontend/package.json` + the corresponding `yarn.lock`
re-resolution; no config or code changes.

### Any related issues, documentation, discussions?

Closes #6154

### How was this PR tested?

Existing test cases; no behavior change expected.

- `yarn build` (production `ng build`) — succeeds, only pre-existing
CommonJS warnings.
- `yarn test:ci` — all suites pass (`NX Successfully ran target test for
project gui`).

Both were run after each of the two commits (toolchain bump;
framework/CDK alignment).

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Fable 5)

---------

(backported from commit fd79073)

Co-authored-by: Claude Fable 5 <[email protected]>
aglinxinyuan pushed a commit to aglinxinyuan/texera that referenced this pull request Jul 5, 2026
…#6155)

### What changes were proposed in this PR?

Patch-level alignment of all Angular packages in `frontend/`, across the
two Angular release lines:

| Line | Packages | Before | After |
| --- | --- | --- | --- |
| CLI toolchain | `@angular/cli`, `@angular-devkit/build-angular`,
`@angular-devkit/core`, `@angular-devkit/schematics`,
`@schematics/angular` | 21.2.8 | 21.2.18 |
| Framework | `@angular/{core,common,compiler,compiler-cli,localize}` |
21.2.17 | 21.2.17 (unchanged) |
| Framework |
`@angular/{animations,forms,router,platform-browser,platform-browser-dynamic}`
| 21.2.10 | 21.2.17 |
| CDK | `@angular/cdk` | 21.2.8 | 21.2.14 |

(The framework line has no 21.2.18 — 21.2.17 is its latest; CLI and
framework version independently.)

The toolchain bump is security-motivated: 21.2.8 exact-pins several
build-time dependencies with open advisories, which a plain lockfile
refresh cannot move. 21.2.18 re-pins them all to patched versions:

| Pinned dep | Before | After | Dependabot alerts resolved |
| --- | --- | --- | --- |
| undici | 7.24.4 | 7.28.0 |
[apache#617](https://github.com/apache/texera/security/dependabot/617) (high),
[apache#614](https://github.com/apache/texera/security/dependabot/614) (high),
[apache#621](https://github.com/apache/texera/security/dependabot/621),
[apache#613](https://github.com/apache/texera/security/dependabot/613),
[apache#623](https://github.com/apache/texera/security/dependabot/623),
[apache#616](https://github.com/apache/texera/security/dependabot/616) |
| vite | 7.3.2 | 7.3.6 |
[apache#591](https://github.com/apache/texera/security/dependabot/591) (high),
[apache#594](https://github.com/apache/texera/security/dependabot/594) |
| piscina | 5.1.4 | 5.2.0 |
[apache#610](https://github.com/apache/texera/security/dependabot/610) (high)
|
| webpack-dev-server | 5.2.3 | 5.2.5 |
[apache#609](https://github.com/apache/texera/security/dependabot/609),
[apache#518](https://github.com/apache/texera/security/dependabot/518) |
| esbuild | 0.27.3 | 0.28.1 |
[apache#555](https://github.com/apache/texera/security/dependabot/555) |
| postcss | 8.5.6 | 8.5.12 |
[apache#474](https://github.com/apache/texera/security/dependabot/474) |

13 alerts total (4 high). Not covered here (separate lockfile copies of
the same packages, planned as a follow-up refresh): undici `^6.25.0`
([apache#622](https://github.com/apache/texera/security/dependabot/622),
[apache#620](https://github.com/apache/texera/security/dependabot/620),
[apache#615](https://github.com/apache/texera/security/dependabot/615)) and
vite 8.x
([apache#593](https://github.com/apache/texera/security/dependabot/593),
[apache#590](https://github.com/apache/texera/security/dependabot/590)).

The framework/CDK alignment additionally clears the `YN0060`
incorrect-peer-dependency warnings printed on every `yarn install` (the
tree previously mixed 21.2.10 and 21.2.17).

Diff is `frontend/package.json` + the corresponding `yarn.lock`
re-resolution; no config or code changes.

### Any related issues, documentation, discussions?

Closes apache#6154

### How was this PR tested?

Existing test cases; no behavior change expected.

- `yarn build` (production `ng build`) — succeeds, only pre-existing
CommonJS warnings.
- `yarn test:ci` — all suites pass (`NX Successfully ran target test for
project gui`).

Both were run after each of the two commits (toolchain bump;
framework/CDK alignment).

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Fable 5)

---------

Co-authored-by: Claude Fable 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants