Skip to content

[Discuss] Code alignment between master and 7.x branches #78923

@sebelga

Description

@sebelga

In the ES UI team, we have several places (upgrade assistant, mappings and now the upcoming #78331) where the code between master and 7.x diverges.

Those differences are a problem for

We could try to remember all the little nuances between the branches, but we know we will forget them as we keep adding functionalities and plugins. We can try to keep a document up to date with the differences but I think it will get quickly obsolete and hard to parse to get a full picture of the differences.

The best place to indicate the difference IMO is in the code itself.

if (BRANCH === '7.x') {
  ...
}

We can't get much clearer than that, and this can be backported without any problem.

In master, the above example will be evaluated to

if (false) {
  // this dead code will be removed by the JS minimizer and not part of the bundle
}

Dynamic imports

When possible, the code that will be deprecated (e.g. a component rendering a deprecated mapping field), should be exported from a barrel file following the convention: index_<branch>.ts.

As an example, the boost parameter is removed from the mappings in 8.x. We should remove its export from the current index.ts file and export it from a index_7x.ts file.
Then its import can be conditional, according to the branch we are on

let BoostParameter: React.FunctionComponent<any>;

if (BRANCH === '7.x') {
  import('../../field_parameters/index_7x').then((parameters) => {
    BoostParameter = parameters.BoostParameter;
  });
}

...and then in the JSX

{BRANCH === '7.x' && (
  <BoostParameter defaultToggleValue={getDefaultToggleValue('boost', field.source)} />
)}

Tests

As a side benefit, when the code is self-explanatory, then there is little risk to forget to add a test for that code branch.

if (BRANCH === '7.x') {
  test('it should have the boost parameter', () => { ... });
}

For now, I am only seeing the need of knowing the branch (the major version) the code will be run from. But this would leave the door open for feature flags in case there is a switch of priorities during a release cycle (which hasn't happened yet but we almost got into the situation in the last release).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions