9.16.0 • Published 7 days ago

@opengeoweb/sigmet-airmet v9.16.0

Weekly downloads
-
License
Apache-2.0
Repository
gitlab
Last release
7 days ago

current version coverage

Content

Table of contents generated with markdown-toc

sigmet-airmet

React component library with Sigmet and Airmet components for the opengeoweb project. This library was generated with Nx.

Installation

npm install @opengeoweb/sigmet-airmet

Use

You can use any component exported from sigmet-airmet by importing them, for example:

import { MetInfoWrapper } from '@opengeoweb/sigmet-airmet'

API

Documentation of the API can be found on Swagger (make sure you're connected to the KNMI network).

The front-end uses the axios library to fetch data from the api. Importing components from the sigmet-airmet lib should be wrapped by the ApiProvider component with a specified baseURL. Example:

import { ApiProvider } from '@opengeoweb/api';
import { MetInfoWrapper } from '@opengeoweb/sigmet-airmet';

const sigmetProductConfig = {
  location_indicator_mwo: 'EHDB',
  fir_areas: {
    EHAA: {
      fir_name: 'AMSTERDAM FIR',
      location_indicator_atsr: 'EHAA',
      location_indicator_atsu: 'EHAA',
      area_preset: 'NL_FIR',
      max_hours_of_validity: 4,
      hours_before_validity: 4,
      tc_max_hours_of_validity: 6,
      tc_hours_before_validity: 12,
      va_max_hours_of_validity: 6,
      va_hours_before_validity: 12,
      adjacent_firs: ['EKDK', 'EDWW', 'EDGG', 'EBBU', 'EGTT', 'EGPX'],
      units: [
        {
          unit_type: 'level_unit',
          allowed_units: ['FT', 'FL'],
        },
        {
          unit_type: 'movement_unit',
          allowed_units: ['KT'],
        },
      ],
    },
  },
  active_firs: ['EHAA'],
};

const myAuth = {
  username: 'string',
  token: 'string',
  refresh_token: 'string',
};

const Component = () => {
  const [auth, onSetAuth] = React.useState(myAuth);

  return (
      <ApiProvider
        baseURL="http://test.com"
        appURL="http://app.com"
        auth={auth}
        onSetAuth={onSetAuth}
        createApi={createApi}
        authTokenURL="url/tokenrefresh"
      >
        <MetInfoWrapper productType='sigmet' productConfig={sigmetProductConfig} />
      </ApiProvider>
  )}

Configuration

Every country has different rules for aviation so a configuration file is required to let the module work correctly. Airmet uses basic configuration which has been expanded for sigmet to contain more custom properties. The validation rules are stored in schema files following the conventions of https://json-schema.org/. The npm packages ajv and ajv-merge-patch (to extend validation by using the merge prop) have been used to validate the configuration files against the schemas. The configurations are passed by the productConfig prop of the MetInfoWrapper component. When the module is rendered, it will first validate the given configuration. When that's valid, it will continue with fetching some requests to the backend and start the module.

Currently the validation is strict meaning that every missing or wrongly typed prop results in an error. All errors should be readable and give hints to the developer.

Configuration file location

These are the default configuration files for both products. They are being used in the stories and snapshots.

  • airmet: libs/sigmet-airmet/src/lib/utils/config/airmet.config.json
  • sigmet: libs/sigmet-airmet/src/lib/utils/config/sigmet.config.json

Configuration schema location

Schema files define all required properties and types for the configuration files. Sigmet and airmet share some properties, these can be found in firArea.schema.json.

  • firArea.schema: tools/build-static-schemas/firArea.schema.json Defines the shared properties and validations of sigmet and airmet.
  • airmet.schema: tools/build-static-schemas/airmet.schema.json Defines the airmet config validations. Airmet uses the firArea scheme and adds unique properties via the $merge prop: "$merge": { "source": { "$ref": "firArea.schema.json" }
  • sigmet.schema: tools/build-static-schemas/sigmet.schema.json Defines the sigmet config validations. Sigmet uses the firArea scheme and adds unique properties via the $merge prop: "$merge": { "source": { "$ref": "firArea.schema.json" }

These schema files are build using the schema building tool in tools/build-static-schemas/generateStaticSchemas.js, see tools/build-static-schemas/Readme.md

Configuration typescript types

The SigmetConfig and AirmetConfig types can be found in libs/sigmet-airmet/src/lib/types.ts and are leading in defining the configuration files.

Add a new configuration key

Follow these steps to add a new key to the configuration file. Make sure to run storybook by nx storybook sigmet-airmet to test the validations.

Note: Before being able to see your changes to the validation in storybook, ensure you compile the validation schemas as described in [tools/build-static-schemas/Readme.md](https://gitlab.com/opengeoweb/opengeoweb/-/tree/master/tools/build-static-schemas)

In this example, we're going to add a new property called my_new_config: an array with strings that is used by sigmet and airmet.

  1. Since the new prop is used by both sigmet and airmet, we want to add it to the FIRArea typescript type. Inside libs/sigmet-airmet/src/lib/types.ts add the following:
export type FIRArea = {
  // ...rest of props
  units: AllowedUnits[];
  my_new_config: string[];
};

If you now run nx typecheck sigmet-airmet it will fail, and that's expected as we added a new required prop but we have not added it to our configs. We will fix this later

  1. Add the new validation to the schema. This validation should check for an empty array and if the array is filled with a string. Inside tools/build-static-schemas/firArea.schema.json under properties register the new prop my_new_config property.
"my_new_config": {
  "type": "array",
  "items": {
    "type": "string"
  },
  "minItems": 1
}

2.1. Make the my_new_config prop also required by adding it to the required list:

"required": [
    // ...other,
    "units",
    "my_new_config"
  ],

2.2 Time to test out the validations. First airmet, go to http://localhost:4400/?path=/story/demo-airmet--airmet-dialog-demo. We expect there to be an error since you added a new required property but the story is still working. The same goes for sigmet http://localhost:4400/?path=/story/demo-sigmet--sigmet-dialog-demo. This is because we are merging the firArea scheme, but this overwrites the required list. To fix this, open tools/build-static-schemas/sigmet.schema.json and add my_new_config to the required prop in the fir_areas key. Do the same in tools/build-static-schemas/airmet.schema.json Afterwards an error should show for both.

"required": [
    // ...other,
    "units",
    "my_new_config"
  ],
  1. Now we know the validations are working, it's time to add my_new_config to the configuration files. After this both stories of sigmet and airmet should work again without errors:
  • inside libs/sigmet-airmet/src/lib/utils/config/sigmet.config.json add "my_new_config": ["test"]
  • inside libs/sigmet-airmet/src/lib/utils/config/airmet.config.json add "my_new_config": ["test"]
  1. Next fix the typescript errors. When running nx typecheck sigmet-airmet it will complain on missing props inside the libs/sigmet-airmet/src/lib/components/ProductForms/utils.spec.tsx test. Add the new config keys to config examples. After this typescript should be fixed. We will add tests later for this file when we want to use the new property.
  2. In general we should test that the property is passed in, has the correct type and the correct minimum number of items. These tests should be added for both sigmet and airmet ensuring we don't break either of the modules in future. Add these tests in libs/sigmet-airmet/src/lib/utils/config/config.spec.ts.
  3. Last but not least, don't forget to add the new keys in the config on the place where sigmet/airmet is used. In the case of opengeoweb, the config files are currently located in the assets folder in apps/geoweb/src/assets

Using a new configuration key

Every config key can be used throughout the aviationmodule. If you followed the previous steps we have a new property that is validated and can be used, but does not have any logic yet.

  1. Create a new method inside libs/sigmet-airmet/src/lib/components/ProductForms/utils.tsx. This method should have the config as param to extract the value to use inside the code. Afterwards add the tests in libs/sigmet-airmet/src/lib/components/ProductForms/utils.spec.tsx.
export const getMyNewConfigTest = (
fir: string,
config: ProductConfig,
): string[] => {
const {
  my_new_config,
} = config.fir_areas[fir];

return my_new_config;
};
  1. Decide on which component the configuration should be used. Let's take StartGeometry as example. This component needs a productConfig prop. Open the component and extend the props of the component with ConfigurableFormFieldProps like interface StartGeometryProps extends ConfigurableFormFieldProps and remove unneeded double props. The StartGeometry component is imported in [Sigmet/Airmet]Form, in these files pass the productConfig key. Afterwards you can use the prop inside StartGeometry like
const StartGeometry: React.FC<StartGeometryProps> = ({
  // other props
  setDrawModeType,
  productConfig
}: StartGeometryProps) => {
  const myConfigValues  = getMyNewConfigTest(productConfig)
  1. After all is working add the unit tests and make sure typescript linting will pass again, as ConfigurableFormFieldProps makes sure you're not forgetting to pass the config.

Documentation

https://opengeoweb.gitlab.io/opengeoweb/docs/sigmet-airmet/

9.16.0

7 days ago

9.15.0

21 days ago

9.14.0

1 month ago

9.13.0

1 month ago

9.12.0

2 months ago

9.11.0

2 months ago

9.10.2

2 months ago

9.10.0

2 months ago

9.10.1

2 months ago

9.9.0

3 months ago

9.8.0

3 months ago

9.7.0

3 months ago

9.6.0

3 months ago

9.5.0

4 months ago

9.4.1

4 months ago

9.4.0

4 months ago

9.3.1

5 months ago

9.3.0

5 months ago

9.2.0

5 months ago

5.1.1

10 months ago

5.1.0

10 months ago

6.1.0

8 months ago

6.1.1

8 months ago

8.4.1

6 months ago

8.4.0

6 months ago

8.1.0

7 months ago

8.3.0

7 months ago

9.1.0

5 months ago

5.2.1

9 months ago

5.2.0

9 months ago

5.0.1

10 months ago

5.0.0

10 months ago

6.0.1

9 months ago

6.0.0

9 months ago

6.0.3

9 months ago

6.0.2

9 months ago

6.0.4

8 months ago

8.3.1

7 months ago

7.0.0

8 months ago

4.22.0

10 months ago

4.22.1

10 months ago

8.0.0

8 months ago

8.2.0

7 months ago

9.0.0

6 months ago

4.14.1

1 year ago

4.16.0

1 year ago

4.18.0

1 year ago

4.21.0

11 months ago

4.19.0

1 year ago

4.19.1

1 year ago

4.15.0

1 year ago

4.15.1

1 year ago

4.17.0

1 year ago

4.20.0

11 months ago

4.12.0

1 year ago

4.11.0

1 year ago

4.13.0

1 year ago

4.13.1

1 year ago

4.7.1

1 year ago

4.9.1

1 year ago

4.6.1

1 year ago

4.10.0

1 year ago

4.8.0

1 year ago

4.7.0

1 year ago

4.5.0

1 year ago

4.6.0

1 year ago

4.4.0

2 years ago

4.3.0

2 years ago

4.2.0

2 years ago

3.0.0

2 years ago

2.15.0

2 years ago

4.1.0

2 years ago

4.0.0

2 years ago

2.12.0

2 years ago

2.10.0

2 years ago

2.7.0

2 years ago

2.9.0

2 years ago

2.8.0

2 years ago

2.13.0

2 years ago

2.14.0

2 years ago

2.5.0

2 years ago

2.6.0

2 years ago

2.3.0

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.2.1

2 years ago

2.1.2

2 years ago

2.2.0

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

1.3.0

2 years ago

2.1.1

2 years ago

2.1.0

2 years ago

1.2.5

3 years ago

1.2.3

3 years ago

1.2.2

3 years ago

1.2.0

3 years ago

1.1.6

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.0

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.21

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.19

3 years ago