codeforlife 2.6.10 → 2.6.12
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/.github/workflows/main.yml +7 -0
- package/CHANGELOG.md +15 -0
- package/package.json +2 -15
- package/src/components/DownloadFileButton.tsx +54 -0
- package/src/components/index.ts +2 -0
- package/src/settings/index.ts +6 -1
- package/src/vite.config.ts +49 -0
- package/vite.config.ts +2 -0
|
@@ -34,3 +34,10 @@ jobs:
|
|
|
34
34
|
with:
|
|
35
35
|
cfl-bot-gh-token: ${{ secrets.CFL_BOT_GH_TOKEN }}
|
|
36
36
|
npm-token: ${{ secrets.NPM_TOKEN }}
|
|
37
|
+
|
|
38
|
+
monitor:
|
|
39
|
+
uses: ocadotechnology/codeforlife-workspace/.github/workflows/monitor-javascript-release.yaml@main
|
|
40
|
+
secrets: inherit
|
|
41
|
+
needs: [release]
|
|
42
|
+
with:
|
|
43
|
+
node-version: 18
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [2.6.12](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.11...v2.6.12) (2025-03-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* monitor release ([4bb40e1](https://github.com/ocadotechnology/codeforlife-package-javascript/commit/4bb40e1c0021c5371c64b3fb894b4fddccf19374))
|
|
7
|
+
* Portal frontend 48 ([#82](https://github.com/ocadotechnology/codeforlife-package-javascript/issues/82)) ([b76b4b8](https://github.com/ocadotechnology/codeforlife-package-javascript/commit/b76b4b8dd4b5822820577a149d13992468c1cc0c))
|
|
8
|
+
|
|
9
|
+
## [2.6.11](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.10...v2.6.11) (2025-02-25)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* Portal frontend 40 ([#78](https://github.com/ocadotechnology/codeforlife-package-javascript/issues/78)) ([18082bb](https://github.com/ocadotechnology/codeforlife-package-javascript/commit/18082bbd60e2ec52dfaf072ca092c3812a25fab0))
|
|
15
|
+
|
|
1
16
|
## [2.6.10](https://github.com/ocadotechnology/codeforlife-package-javascript/compare/v2.6.9...v2.6.10) (2025-02-25)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
|
@@ -2,22 +2,10 @@
|
|
|
2
2
|
"name": "codeforlife",
|
|
3
3
|
"description": "Common frontend code",
|
|
4
4
|
"private": false,
|
|
5
|
-
"version": "2.6.
|
|
5
|
+
"version": "2.6.12",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"
|
|
9
|
-
"start": "serve -s dist",
|
|
10
|
-
"build": "tsc && vite build",
|
|
11
|
-
"preview": "vite preview",
|
|
12
|
-
"test": "vitest run",
|
|
13
|
-
"test:coverage": "vitest run --coverage",
|
|
14
|
-
"test:verbose": "vitest run --reporter=verbose --coverage.thresholds.lines=90 --coverage.thresholds.functions=90 --coverage.thresholds.branches=90 --coverage.thresholds.statements=90",
|
|
15
|
-
"test:ui": "vitest --ui",
|
|
16
|
-
"format": "prettier --write .",
|
|
17
|
-
"format:check": "prettier --check --write=false .",
|
|
18
|
-
"lint": "eslint --max-warnings=0 .",
|
|
19
|
-
"lint:fix": "eslint --fix .",
|
|
20
|
-
"type-check": "tsc --noEmit"
|
|
8
|
+
"cli": "VITE_CONFIG=./vite.config.ts ../scripts/frontend/cli $@"
|
|
21
9
|
},
|
|
22
10
|
"repository": {
|
|
23
11
|
"type": "git",
|
|
@@ -47,7 +35,6 @@
|
|
|
47
35
|
"react-dom": "^18.2.0",
|
|
48
36
|
"react-redux": "^9.1.0",
|
|
49
37
|
"react-router-dom": "^6.23.1",
|
|
50
|
-
"serve": "^14.2.3",
|
|
51
38
|
"sirv": "^3.0.0",
|
|
52
39
|
"yup": "^1.1.1"
|
|
53
40
|
},
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Button, type ButtonProps } from "@mui/material"
|
|
2
|
+
import { type FC, useEffect } from "react"
|
|
3
|
+
import { Download as DownloadIcon } from "@mui/icons-material"
|
|
4
|
+
|
|
5
|
+
export type DownloadFileButtonProps = ButtonProps & {
|
|
6
|
+
file:
|
|
7
|
+
| Blob
|
|
8
|
+
| MediaSource
|
|
9
|
+
| {
|
|
10
|
+
text: string
|
|
11
|
+
mimeType: "plain" | "csv"
|
|
12
|
+
name: string
|
|
13
|
+
charset?: string
|
|
14
|
+
extension?: string
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const DownloadFileButton: FC<DownloadFileButtonProps> = ({
|
|
19
|
+
children = "Download",
|
|
20
|
+
endIcon = <DownloadIcon />,
|
|
21
|
+
file,
|
|
22
|
+
...otherButtonProps
|
|
23
|
+
}) => {
|
|
24
|
+
let url: undefined | string = undefined
|
|
25
|
+
let anchorProps: undefined | { download?: string; href: string } = undefined
|
|
26
|
+
if ("mimeType" in file) {
|
|
27
|
+
let { text, mimeType, name, charset = "utf-8", extension } = file
|
|
28
|
+
|
|
29
|
+
if (!extension) extension = "." + { plain: "txt", csv: "csv" }[mimeType]
|
|
30
|
+
|
|
31
|
+
anchorProps = {
|
|
32
|
+
download: name + extension,
|
|
33
|
+
href: `data:text/${mimeType};charset=${charset},${encodeURIComponent(text)}`,
|
|
34
|
+
}
|
|
35
|
+
} else {
|
|
36
|
+
url = URL.createObjectURL(file)
|
|
37
|
+
|
|
38
|
+
anchorProps = { href: url }
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
return () => {
|
|
43
|
+
if (url) URL.revokeObjectURL(url)
|
|
44
|
+
}
|
|
45
|
+
}, [url])
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<Button endIcon={endIcon} {...otherButtonProps} {...anchorProps}>
|
|
49
|
+
{children}
|
|
50
|
+
</Button>
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default DownloadFileButton
|
package/src/components/index.ts
CHANGED
|
@@ -6,6 +6,8 @@ export * from "./CopyIconButton"
|
|
|
6
6
|
export { default as CopyIconButton } from "./CopyIconButton"
|
|
7
7
|
export * from "./Countdown"
|
|
8
8
|
export { default as Countdown } from "./Countdown"
|
|
9
|
+
export * from "./DownloadFileButton"
|
|
10
|
+
export { default as DownloadFileButton } from "./DownloadFileButton"
|
|
9
11
|
export * from "./ElevatedAppBar"
|
|
10
12
|
export { default as ElevatedAppBar } from "./ElevatedAppBar"
|
|
11
13
|
export * from "./Image"
|
package/src/settings/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// Shorthand to access environment variables.
|
|
2
|
-
export default import.meta.env
|
|
2
|
+
export default Object.defineProperty(import.meta.env, "vite", {
|
|
3
|
+
writable: false,
|
|
4
|
+
value: new Proxy(import.meta.env, {
|
|
5
|
+
get: (target, name: string) => target[`VITE_${name}`],
|
|
6
|
+
}),
|
|
7
|
+
}) as ImportMetaEnv & { vite: Record<string, string> }
|
|
3
8
|
|
|
4
9
|
export * from "./custom"
|
|
5
10
|
export * from "./vite"
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared Vite configuration for all frontend services.
|
|
3
|
+
*
|
|
4
|
+
* Vite: https://vitest.dev/config/
|
|
5
|
+
* Vitest: https://vitest.dev/config/
|
|
6
|
+
*
|
|
7
|
+
* NOTE: This doesn't belong in codeforlife-workspace/configs/frontend as it's
|
|
8
|
+
* still and a script which needs to be included in a Node.js runtime.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { defineConfig } from "vitest/config"
|
|
12
|
+
import react from "@vitejs/plugin-react"
|
|
13
|
+
|
|
14
|
+
export default defineConfig({
|
|
15
|
+
plugins: [react()],
|
|
16
|
+
resolve: {
|
|
17
|
+
alias: {
|
|
18
|
+
codeforlife: "codeforlife/src",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
envDir: "env",
|
|
22
|
+
server: {
|
|
23
|
+
open: true,
|
|
24
|
+
host: true,
|
|
25
|
+
},
|
|
26
|
+
test: {
|
|
27
|
+
globals: true,
|
|
28
|
+
environment: "jsdom",
|
|
29
|
+
setupFiles: "src/setupTests",
|
|
30
|
+
mockReset: true,
|
|
31
|
+
coverage: {
|
|
32
|
+
enabled: true,
|
|
33
|
+
provider: "istanbul",
|
|
34
|
+
reporter: ["html", "cobertura"],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
optimizeDeps: {
|
|
38
|
+
// TODO: investigate which of these are needed
|
|
39
|
+
include: [
|
|
40
|
+
"@mui/x-date-pickers",
|
|
41
|
+
"@mui/x-date-pickers/AdapterDayjs",
|
|
42
|
+
"dayjs",
|
|
43
|
+
"dayjs/locale/en-gb",
|
|
44
|
+
"@mui/icons-material",
|
|
45
|
+
"yup",
|
|
46
|
+
"formik",
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
})
|
package/vite.config.ts
CHANGED
|
@@ -2,6 +2,8 @@ import react from "@vitejs/plugin-react"
|
|
|
2
2
|
import { defineConfig } from "vitest/config"
|
|
3
3
|
|
|
4
4
|
// https://vitejs.dev/config/
|
|
5
|
+
// TODO: https://vite.dev/guide/build.html#library-mode
|
|
6
|
+
// TODO: import common configs from src/vite.config.ts
|
|
5
7
|
export default defineConfig({
|
|
6
8
|
plugins: [react()],
|
|
7
9
|
server: {
|