You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An npm library for Control Systems web applications
2
+
cs-web-lib is a React component library for EPICS Control Systems web applications, based off CSStudio Phoebus.
3
3
4
-
## Installation
5
-
6
-
:warning: cs-web-lib is **NOT** compatible with projects using create-react-app. Vite should be used instead.
7
-
8
-
Install via npm:
9
-
`npm install @diamondlightsource/cs-web-lib`
10
-
11
-
We use React 18. cs-web-lib requires several environment variables to be set in order to connect to PVWS and fetch PV value updates.
12
-
13
-
-`VITE_PVWS_SOCKET` - point to the server hosting the PVWS application.
14
-
-`VITE_PVWS_SSL` - set this to false if running a local PVWS instance e.g. localhost:8080 without SSL, otherwise true
15
-
16
-
These should be provided in a .env file at the root of your project.
17
-
18
-
Inside your application, create a screen by passing a .opi, .bob or .json file to the EmbeddedDisplay widget.
19
-
20
-
## Legacy Installation
21
-
22
-
PVWS was introduced in version 0.4.0. Versions prior to this used [Coniql](https://github.com/DiamondLightSource/coniql), and the .env variables used were `VITE_CONIQL_SOCKET` and `VITE_CONIQL_SSL`.
cs-web-lib does not contain the full suite of features and widgets provided by Phoebus. The tables below describes which features are currently included, are planned to be added, and which will not be added.
| Actions |✅| Some actions may not be supported. Please open an issue for any issues noticed. |
81
-
| Formulas |❌|`sim://` PVs are supported, but not `eq://`. This will be added in future. |
82
-
| Rules |✅| Partial support. x, y and Font rules are currently not supported. This will be added in future. Please open an issue for any issues noticed.|
83
-
| Scripts |❌| The use of scripting is recommended against in general by CS Studio Developers. Formulae should be able to handle most use cases. |
63
+
| Formulas |✅|`sim://`, `eq://` and `loc://` PVs are supported. |
64
+
| Rules |✅| Partial support. Please open an issue for any issues noticed.|
65
+
| Scripts |❌| Basic PoC for scripting is currently implemented, which works for background colour and position ONLY. |
66
+
67
+
## Installation
68
+
69
+
Install via npm:
70
+
71
+
`npm install @diamondlightsource/cs-web-lib`
72
+
73
+
To use cs-web-lib in a client project, you will need:
74
+
- React 18
75
+
- Vite
76
+
- A separate running instance of [PVWS](https://github.com/ornl-epics/pvws)
77
+
78
+
**Configuring PVWS**
79
+
80
+
To make use of PVs in cs-web-lib widgets, you need to connect to PVWS. The basic configuration parameters for this will be loaded at runtime from a JSON file. This should be located somewhere accessible at runtime such as `/public` directory. The schema/structure of the configuration file is:
81
+
82
+
```
83
+
{
84
+
PVWS_SOCKET: string
85
+
PVWS_SSL: boolean,
86
+
THROTTLE_PERIOD: integer
87
+
}
88
+
```
89
+
90
+
The configuration parameters are:
91
+
92
+
| Parameter | type | Description |
93
+
|- | -| - |
94
+
| PVWS_SOCKET | string | The fully qualified hostname and port of the instance of the PVWS web service |
95
+
| PVWS_SSL | boolean | If true use https, if false use http for connecting to the PVWS web service |
96
+
| THROTTLE_PERIOD | integer | The period in milliseconds between updates of the PV state variables |
97
+
98
+
At the root of your client app, create a `config.ts` file to load the config from this file.
99
+
100
+
```
101
+
import { CsWebLibConfig } from "@diamondlightsource/cs-web-lib";
console.warn("Configuration not found falling back to defaults", error);
114
+
// Set defaults here if necessary
115
+
config = {
116
+
PVWS_SOCKET: undefined,
117
+
PVWS_SSL: undefined,
118
+
THROTTLE_PERIOD: undefined
119
+
};
120
+
}
121
+
122
+
return config as CsWebLibConfig;
123
+
};
124
+
```
125
+
126
+
The final step is to wrap your application in a Redux Provider and pass in the loaded config and cs-web-lib PV store. This allows your application to access the store which handles subscribing to PVs and storing updates to values.
127
+
128
+
```
129
+
import { store, CsWebLibConfig } from "@diamondlightsource/cs-web-lib";
This component allows dynamic loading of different files, using a FileContext to store which file is currently displayed. The application must be wrapped in the FileProvider to access this context. The executeAction function can be called to trigger changes in displayed files.
174
+
```
175
+
import { FileProvider } from "@diamondlightsource/cs-web-lib";
cs-web-lib widgets can also be used independently of an Embedded Display or Dynamic Page widget, simply by treating them as any other React component. These must be initialised with a position, using either an `AbsolutePosition` or a `RelativePosition` object, and can be passed other properties.
84
229
85
230
## Development
86
-
To develop on the library code first clone this repo, install the npm package dependencies and then make changes:
87
231
88
-
cd cs-web-lib/
89
-
npm install
232
+
**Install Node**
233
+
234
+
Install Node.js version 22+, if it is not already installed on your machine.
A GitHub workflow has been setup to automatically publish a new package version to the NPM registry on the push of a new tag. This should be used as the preferred method of release a new package.
106
-
1. Update/increase the package version in package.json (see https://docs.npmjs.com/cli/v8/commands/npm-version for further details on this npm command):
270
+
1. Increment the package version in package.json
271
+
`npm version <major|minor|patch> -no-git-tag-version`
107
272
108
-
npm version <major|minor|patch> -no-git-tag-version
109
273
2. Commit and push this to GitHub:
274
+
```
275
+
git add package.json
276
+
git commit -m "..." package.json
277
+
git push <remote> <branch>
278
+
```
110
279
111
-
git add package.json
112
-
git commit -m "..." package.json
113
-
git push <remote> <branch>
114
280
3. Create a new tag and push to GitHub
115
-
116
-
git tag -a vX.XX.xx -m "..."
117
-
git push <remote> vX.XX.xx
281
+
```
282
+
git tag -a vX.XX.xx -m "..."
283
+
git push tag <remote> vX.XX.xx
284
+
```
118
285
This will trigger a job on GitHub to publish a new version of the cs-web-lib to NPM. Check that this job passes.
119
286
120
-
### Publishing to NPM locally
287
+
**Locally**
121
288
To publish a new version of the @diamondlightsource/cs-web-lib package you must first have an npm account and be a member of the DiamondLightSource organisation. Then:
122
289
1. Update the package version in package.json (follow the major.minor.patch versioning terminology).
123
290
2. Run the rollup command to package the library: `npm run rollup`.
0 commit comments