@opengeoweb/sigmet-airmet 4.13.0 → 4.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +164 -2
- package/index.esm.js +492 -146
- package/index.umd.js +503 -156
- package/lib/AirmetDemo.stories.d.ts +2 -0
- package/lib/SigmetDemo.stories.d.ts +2 -0
- package/lib/components/MetInfoWrapper/utils.d.ts +14 -0
- package/lib/components/MetInfoWrapper/utils.spec.d.ts +1 -0
- package/lib/components/ProductList/ProductList.stories.d.ts +8 -2
- package/lib/types.d.ts +26 -23
- package/lib/utils/config/config.d.ts +7 -0
- package/lib/utils/config/config.spec.d.ts +1 -0
- package/lib/utils/config/index.d.ts +4 -0
- package/lib/utils/testUtils.d.ts +1 -1
- package/package.json +10 -8
- package/lib/utils/config.d.ts +0 -3
package/README.md
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|

|
|
2
2
|

|
|
3
3
|
|
|
4
|
+
# Content
|
|
5
|
+
|
|
6
|
+
- [Installation](#installation)
|
|
7
|
+
- [Use](#use)
|
|
8
|
+
- [API](#api)
|
|
9
|
+
- [Configuration](#configuration)
|
|
10
|
+
- [Configuration file location](#configuration-file-location)
|
|
11
|
+
- [Configuration schema location](#configuration-schema-location)
|
|
12
|
+
- [Configuration typescript types](#configuration-typescript-types)
|
|
13
|
+
- [Add a new configuration key](#add-a-new-configuration-key)
|
|
14
|
+
- [Using a new configuration key](#using-a-new-configuration-key)
|
|
15
|
+
- [Documentation](#documentation)
|
|
16
|
+
|
|
17
|
+
<small><i><a href='http://ecotrust-canada.github.io/markdown-toc/'>Table of contents generated with markdown-toc</a></i></small>
|
|
18
|
+
|
|
4
19
|
# sigmet-airmet
|
|
5
20
|
|
|
6
21
|
React component library with Sigmet and Airmet components for the opengeoweb project.
|
|
@@ -23,7 +38,6 @@ import { MetInfoWrapper } from '@opengeoweb/sigmet-airmet'
|
|
|
23
38
|
### API
|
|
24
39
|
|
|
25
40
|
Documentation of the API can be found on Swagger (make sure you're connected to the KNMI network).
|
|
26
|
-
ADD API DOCUMENTATION
|
|
27
41
|
|
|
28
42
|
The front-end uses the [axios](https://github.com/axios/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:
|
|
29
43
|
|
|
@@ -31,6 +45,36 @@ The front-end uses the [axios](https://github.com/axios/axios) library to fetch
|
|
|
31
45
|
import { ApiProvider } from '@opengeoweb/api';
|
|
32
46
|
import { MetInfoWrapper } from '@opengeoweb/sigmet-airmet';
|
|
33
47
|
|
|
48
|
+
const sigmetProductConfig = {
|
|
49
|
+
location_indicator_mwo: 'EHDB',
|
|
50
|
+
fir_areas: {
|
|
51
|
+
EHAA: {
|
|
52
|
+
fir_name: 'AMSTERDAM FIR',
|
|
53
|
+
location_indicator_atsr: 'EHAA',
|
|
54
|
+
location_indicator_atsu: 'EHAA',
|
|
55
|
+
area_preset: 'NL_FIR',
|
|
56
|
+
max_hours_of_validity: 4,
|
|
57
|
+
hours_before_validity: 4,
|
|
58
|
+
tc_max_hours_of_validity: 6,
|
|
59
|
+
tc_hours_before_validity: 12,
|
|
60
|
+
va_max_hours_of_validity: 6,
|
|
61
|
+
va_hours_before_validity: 12,
|
|
62
|
+
adjacent_firs: ['EKDK', 'EDWW', 'EDGG', 'EBBU', 'EGTT', 'EGPX'],
|
|
63
|
+
units: [
|
|
64
|
+
{
|
|
65
|
+
unit_type: 'level_unit',
|
|
66
|
+
allowed_units: ['FT', 'FL'],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
unit_type: 'movement_unit',
|
|
70
|
+
allowed_units: ['KT'],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
active_firs: ['EHAA'],
|
|
76
|
+
};
|
|
77
|
+
|
|
34
78
|
const myAuth = {
|
|
35
79
|
username: 'string',
|
|
36
80
|
token: 'string',
|
|
@@ -49,11 +93,129 @@ const Component = () => {
|
|
|
49
93
|
createApi={createApi}
|
|
50
94
|
authTokenURL="url/tokenrefresh"
|
|
51
95
|
>
|
|
52
|
-
<MetInfoWrapper productType='sigmet' />
|
|
96
|
+
<MetInfoWrapper productType='sigmet' productConfig={sigmetProductConfig} />
|
|
53
97
|
</ApiProvider>
|
|
54
98
|
)}
|
|
55
99
|
```
|
|
56
100
|
|
|
101
|
+
### Configuration
|
|
102
|
+
|
|
103
|
+
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.
|
|
104
|
+
|
|
105
|
+
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.
|
|
106
|
+
|
|
107
|
+
#### Configuration file location
|
|
108
|
+
|
|
109
|
+
These are the default configuration files for both products. They are being used in the stories and snapshots.
|
|
110
|
+
|
|
111
|
+
- airmet: `libs/sigmet-airmet/src/lib/utils/config/airmet.config.json`
|
|
112
|
+
- sigmet: `libs/sigmet-airmet/src/lib/utils/config/sigmet.config.json`
|
|
113
|
+
|
|
114
|
+
#### Configuration schema location
|
|
115
|
+
|
|
116
|
+
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`.
|
|
117
|
+
|
|
118
|
+
- firArea.schema: `libs/sigmet-airmet/src/lib/utils/config/firArea.schema.json`
|
|
119
|
+
Defines the shared properties and validations of sigmet and airmet.
|
|
120
|
+
- airmet.schema: `libs/sigmet-airmet/src/lib/utils/config/airmet.schema.json`
|
|
121
|
+
Defines the airmet config validations. Since airmet currently has no unique properties it inherits the firArea scheme via the ref prop: `"$ref": "firArea.schema.json"`
|
|
122
|
+
- sigmet.schema: `libs/sigmet-airmet/src/lib/utils/config/sigmet.schema.json`
|
|
123
|
+
Defines the sigmet config validations. Sigmet is using the firArea scheme but has some unique properties so it's using the scheme via the $merge prop: ```"$merge": {
|
|
124
|
+
"source": { "$ref": "firArea.schema.json" } ```
|
|
125
|
+
|
|
126
|
+
#### Configuration typescript types
|
|
127
|
+
|
|
128
|
+
The `SigmetConfig` and `AirmetConfig` types can be found in `libs/sigmet-airmet/src/lib/types.ts` and are leading in defining the configuration files.
|
|
129
|
+
|
|
130
|
+
#### Add a new configuration key
|
|
131
|
+
|
|
132
|
+
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. 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.
|
|
133
|
+
|
|
134
|
+
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:
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
export type FIRArea = {
|
|
138
|
+
// ...rest of props
|
|
139
|
+
units: AllowedUnits[];
|
|
140
|
+
my_new_config: string[];
|
|
141
|
+
};
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
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
|
|
145
|
+
|
|
146
|
+
2. 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 `libs/sigmet-airmet/src/lib/utils/config/firArea.schema.json` under `properties` register the new prop `my_new_config` property.
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
"my_new_config": {
|
|
150
|
+
"type": "array",
|
|
151
|
+
"items": {
|
|
152
|
+
"type": "string"
|
|
153
|
+
},
|
|
154
|
+
"minItems": 1
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
2.1. Make the `my_new_config` prop also required by adding it to the `required` list:
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
"required": [
|
|
162
|
+
// ...other,
|
|
163
|
+
"units",
|
|
164
|
+
"my_new_config"
|
|
165
|
+
],
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
2.2 Time to test out the validations. First airmet, go to http://localhost:4400/?path=/story/demo-airmet--airmet-dialog-demo you see an error about a missing key. If we go to test out sigmet on http://localhost:4400/?path=/story/demo-sigmet--sigmet-dialog-demo, we can see there's no error while we would expect one. This is because sigmet is merging the firArea scheme, but overwrites the required list. To fix this, open `libs/sigmet-airmet/src/lib/utils/config/sigmet.schema.json` and add `my_new_config` to the required prop. Afterwards an error should show for sigmet.
|
|
169
|
+
|
|
170
|
+
```
|
|
171
|
+
"required": [
|
|
172
|
+
// ...other,
|
|
173
|
+
"units",
|
|
174
|
+
"my_new_config"
|
|
175
|
+
],
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
3. 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:
|
|
179
|
+
|
|
180
|
+
- inside `libs/sigmet-airmet/src/lib/utils/config/sigmet.config.json` add `"my_new_config": ["test"]`
|
|
181
|
+
- inside `libs/sigmet-airmet/src/lib/utils/config/airmet.config.json` add `"my_new_config": ["test"]`
|
|
182
|
+
|
|
183
|
+
4. 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.
|
|
184
|
+
5. 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`.
|
|
185
|
+
6. 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`
|
|
186
|
+
|
|
187
|
+
#### Using a new configuration key
|
|
188
|
+
|
|
189
|
+
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.
|
|
190
|
+
|
|
191
|
+
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`.
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
export const getMyNewConfigTest = (
|
|
195
|
+
fir: string,
|
|
196
|
+
config: ProductConfig,
|
|
197
|
+
): string[] => {
|
|
198
|
+
const {
|
|
199
|
+
my_new_config,
|
|
200
|
+
} = config.fir_areas[fir];
|
|
201
|
+
|
|
202
|
+
return my_new_config;
|
|
203
|
+
};
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
2. 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
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
const StartGeometry: React.FC<StartGeometryProps> = ({
|
|
210
|
+
// other props
|
|
211
|
+
setDrawModeType,
|
|
212
|
+
productConfig
|
|
213
|
+
}: StartGeometryProps) => {
|
|
214
|
+
const myConfigValues = getMyNewConfigTest(productConfig)
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
3. 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.
|
|
218
|
+
|
|
57
219
|
## Documentation
|
|
58
220
|
|
|
59
221
|
https://opengeoweb.gitlab.io/opengeoweb/docs/sigmet-airmet/
|