@linagora/twake-react-new-version 1.1.2 → 1.2.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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## @linagora/twake-react-new-version [1.2.1](https://github.com/linagora/twake-libs/compare/@linagora/twake-react-new-version@1.2.0...@linagora/twake-react-new-version@1.2.1) (2026-11-21)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **twake-react-new-version:** Centre the text between the title and the buttons ([#74](https://github.com/linagora/twake-libs/issues/74)) ([d0dfacd](https://github.com/linagora/twake-libs/commit/d0dfacd19ffaa55b04d21529f6f4a326c9bde476))
7
+
8
+ # @linagora/twake-react-new-version [1.2.0](https://github.com/linagora/twake-libs/compare/@linagora/twake-react-new-version@1.1.2...@linagora/twake-react-new-version@1.2.0) (2026-11-18)
9
+
10
+
11
+ ### Features
12
+
13
+ * **twake-react-new-version:** Show patch notes by language, Not now as a text button ([a805947](https://github.com/linagora/twake-libs/commit/a8059479cb2e14c30227046fb6796f76b2aec6f0))
14
+
1
15
  ## @linagora/twake-react-new-version [1.1.2](https://github.com/linagora/twake-libs/compare/@linagora/twake-react-new-version@1.1.1...@linagora/twake-react-new-version@1.1.2) (2026-11-18)
2
16
 
3
17
 
package/README.md CHANGED
@@ -19,7 +19,8 @@ npm install @linagora/twake-react-new-version
19
19
  Each build has its own id (the commit in CI, for instance). The app:
20
20
 
21
21
  - writes it in the bundle, so the running tab knows its own build;
22
- - serves it at `/version.json` as `{ "build": "<id>" }`, with `Cache-Control: no-store`.
22
+ - serves it at `/version.json` as `{ "build": "<id>" }`, with `Cache-Control: no-store`;
23
+ - optionally adds patch notes: `{ "build": "<id>", "notes": { "en": "- Faster search\n- Dark mode", "fr": "…" } }`, one text per language code. Entries that are not non-empty strings are ignored, and `notes` is ignored when it is not an object or has no usable entry.
23
24
 
24
25
  The id must be in the bundle, not read at runtime from a file served next to it: during a rollout a tab may get the bundle of the old server and that file from the new one, and would never be offered a reload.
25
26
 
@@ -54,13 +55,17 @@ Every 10 minutes, when the tab gets the focus, becomes visible again or comes ba
54
55
 
55
56
  ### What the user sees
56
57
 
57
- A dialog titled « What's new in <appName> », with the text « An update just arrived. Reload to get it. », centred, and « Not now » and « Reload » side by side, centred. With `image`, a banner above the title shows the illustration. « Not now », Escape or a click outside decline that build for the life of the tab: the dialog comes back only for a build not declined yet, so a rollback to a declined build is not offered again.
58
+ A dialog titled « What's new in <appName> », with the text « An update just arrived. Reload to get it. », centred, and « Not now » (a text button) and « Reload » side by side, centred. With `image`, a banner above the title shows the illustration. « Not now », Escape or a click outside decline that build for the life of the tab: the dialog comes back only for a build not declined yet, so a rollback to a declined build is not offered again.
59
+
60
+ ### Patch notes
61
+
62
+ When `/version.json` has notes for the app language (else `en`), the dialog shows them instead of the usual text. Consecutive lines starting with `- ` are drawn as a list, any other line as text. The zone scrolls (`max-height` 60vh, `overflow-y: auto`) when the notes are long. Without usable notes, the usual text shows.
58
63
 
59
64
  ### Props
60
65
 
61
66
  - `running`: the build id of this bundle
62
67
  - `appName`: the name shown in the text, such as `Twake Mail`
63
- - `fetchServed()`: reads the served build id, `fetchServedBuild` by default
68
+ - `fetchServed()`: reads the served version, `fetchServedVersion` by default. It may answer a `ServedVersion` (`{ build, notes }`), a bare build id string (no notes) or null
64
69
  - `reload()`: `window.location.reload` by default
65
70
  - `intervalMs`: time between two checks, 10 minutes by default
66
71
  - `image`: URL of a decorative illustration (`alt=""`), drawn centred in a full-width banner about 130 px high at the top of the dialog, `object-fit: contain`, cut at the bottom of the banner if taller; no banner without it
@@ -72,4 +77,4 @@ A dialog titled « What's new in <appName> », with the text « An update just a
72
77
 
73
78
  ### Detection alone
74
79
 
75
- `fetchServedBuild(url = '/version.json')` and `isNewBuild(running, served)` are exported for an app that wants another surface than the dialog.
80
+ `fetchServedVersion(url = '/version.json')` (`{ build, notes } | null`, notes null when absent or unusable), `fetchServedBuild(url = '/version.json')` (the build id only), `notesFor(notes, lang)` (the notes in `lang`, else `en`, else null) and `isNewBuild(running, served)` are exported, with the `ServedVersion` type, for an app that wants another surface than the dialog.
@@ -1,10 +1,12 @@
1
1
  import React from 'react';
2
+ import { type ServedVersion } from './version';
2
3
  export interface NewVersionDialogProps {
3
4
  /** The build id of this bundle, the one `/version.json` names once served */
4
5
  running: string;
5
6
  /** The name shown in the text, such as `Twake Mail` */
6
7
  appName: string;
7
- fetchServed?: () => Promise<string | null>;
8
+ /** Reads the served version; a bare string is a build without notes. `fetchServedVersion` by default */
9
+ fetchServed?: () => Promise<string | ServedVersion | null>;
8
10
  reload?: () => void;
9
11
  intervalMs?: number;
10
12
  /** URL of a decorative illustration, drawn in a banner at the top */
@@ -1,6 +1,7 @@
1
1
  import React, { useEffect, useId, useRef, useState } from 'react';
2
- import { Box, Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle } from '@linagora/twake-mui';
2
+ import { Box, Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, dialogTitleClasses } from '@linagora/twake-mui';
3
3
  import { useExtendI18n, useI18n } from 'twake-i18n';
4
+ import { PatchNotes } from './PatchNotes';
4
5
  import de from './locales/de.json';
5
6
  import en from './locales/en.json';
6
7
  import es from './locales/es.json';
@@ -8,7 +9,7 @@ import fr from './locales/fr.json';
8
9
  import it from './locales/it.json';
9
10
  import ru from './locales/ru.json';
10
11
  import vi from './locales/vi.json';
11
- import { CHECK_VERSION_EVENT, fetchServedBuild, isNewBuild } from './version';
12
+ import { CHECK_VERSION_EVENT, fetchServedVersion, isNewBuild, notesFor } from './version';
12
13
  const locales = { de, en, es, fr, it, ru, vi };
13
14
  const MINUTE = 60000;
14
15
  const MIN_GAP_MS = 30000;
@@ -94,7 +95,7 @@ const Banner = ({ image, background }) => (React.createElement(Box, { sx: theme
94
95
  * that build for the life of the tab: the dialog comes back only for a build
95
96
  * not declined yet. Mount it once, under the app's `I18n` and twake-mui theme
96
97
  */
97
- export const NewVersionDialog = ({ running, appName, fetchServed = fetchServedBuild, reload = () => window.location.reload(), intervalMs = 10 * MINUTE, image, imageBackground }) => {
98
+ export const NewVersionDialog = ({ running, appName, fetchServed = fetchServedVersion, reload = () => window.location.reload(), intervalMs = 10 * MINUTE, image, imageBackground }) => {
98
99
  const { t, lang } = useI18n();
99
100
  useExtendI18n({ [lang]: locales[lang] ?? locales.en });
100
101
  const titleId = useId();
@@ -104,22 +105,29 @@ export const NewVersionDialog = ({ running, appName, fetchServed = fetchServedBu
104
105
  useVersionChecks(async () => {
105
106
  if (offered !== null)
106
107
  return;
107
- const served = await fetchServed().catch(() => null);
108
- if (isNewBuild(running, served) && !declined.current.has(served)) {
108
+ const answer = await fetchServed().catch(() => null);
109
+ const served = typeof answer === 'string' ? { build: answer, notes: null } : answer;
110
+ if (served !== null &&
111
+ isNewBuild(running, served.build) &&
112
+ !declined.current.has(served.build)) {
109
113
  setOffered(served);
110
114
  }
111
115
  }, intervalMs);
116
+ const notes = notesFor(offered?.notes ?? null, lang);
112
117
  const notNow = () => {
113
118
  if (offered !== null)
114
- declined.current.add(offered);
119
+ declined.current.add(offered.build);
115
120
  setOffered(null);
116
121
  };
117
122
  return (React.createElement(Dialog, { open: offered !== null, onClose: notNow, size: "small", "aria-labelledby": titleId, "data-testid": "new-version-dialog" },
118
123
  image !== undefined && (React.createElement(Banner, { image: image, background: imageBackground })),
119
124
  React.createElement(DialogTitle, { id: titleId, sx: { textAlign: 'center' } }, t('twakeNewVersion.title').replace('%{appName}', appName)),
120
- React.createElement(DialogContent, null,
121
- React.createElement(DialogContentText, { sx: { textAlign: 'center' } }, t('twakeNewVersion.body').replace('%{appName}', appName))),
125
+ React.createElement(DialogContent, { sx: {
126
+ [`.${dialogTitleClasses.root} + &`]: { pt: 1 },
127
+ pb: { xs: 1, md: 1.5 },
128
+ ...(notes !== null && { overflowY: 'visible' })
129
+ } }, notes !== null ? (React.createElement(PatchNotes, { notes: notes, titleId: titleId })) : (React.createElement(DialogContentText, { sx: { textAlign: 'center' } }, t('twakeNewVersion.body').replace('%{appName}', appName)))),
122
130
  React.createElement(DialogActions, { sx: { justifyContent: 'center' } },
123
- React.createElement(Button, { variant: "outlined", "data-testid": "new-version-not-now", onClick: notNow }, t('twakeNewVersion.notNow')),
131
+ React.createElement(Button, { variant: "text", "data-testid": "new-version-not-now", onClick: notNow }, t('twakeNewVersion.notNow')),
124
132
  React.createElement(Button, { variant: "contained", color: "primary", "data-testid": "new-version-reload", onClick: reload }, t('twakeNewVersion.reload')))));
125
133
  };
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ type Block = {
3
+ list: string[];
4
+ } | {
5
+ text: string;
6
+ };
7
+ /**
8
+ * Splits notes into blocks: consecutive `- ` lines make one list, any other
9
+ * non-empty line is a text block
10
+ */
11
+ export declare const parseNotes: (notes: string) => Block[];
12
+ /**
13
+ * The patch notes of the offered build, in the one scrolling zone of the
14
+ * dialog (past 60vh). It takes the focus with Tab so the keyboard can scroll
15
+ * it, and is named by the dialog title.
16
+ * Used by: NewVersionDialog
17
+ */
18
+ export declare const PatchNotes: ({ notes, titleId }: {
19
+ notes: string;
20
+ titleId: string;
21
+ }) => React.ReactElement;
22
+ export {};
@@ -0,0 +1,30 @@
1
+ import React from 'react';
2
+ import { Box, Typography } from '@linagora/twake-mui';
3
+ /**
4
+ * Splits notes into blocks: consecutive `- ` lines make one list, any other
5
+ * non-empty line is a text block
6
+ */
7
+ export const parseNotes = (notes) => {
8
+ const blocks = [];
9
+ for (const line of notes.split('\n')) {
10
+ const last = blocks[blocks.length - 1];
11
+ if (line.startsWith('- ')) {
12
+ if (last !== undefined && 'list' in last)
13
+ last.list.push(line.slice(2));
14
+ else
15
+ blocks.push({ list: [line.slice(2)] });
16
+ }
17
+ else if (line.trim() !== '') {
18
+ blocks.push({ text: line });
19
+ }
20
+ }
21
+ return blocks;
22
+ };
23
+ /**
24
+ * The patch notes of the offered build, in the one scrolling zone of the
25
+ * dialog (past 60vh). It takes the focus with Tab so the keyboard can scroll
26
+ * it, and is named by the dialog title.
27
+ * Used by: NewVersionDialog
28
+ */
29
+ export const PatchNotes = ({ notes, titleId }) => (React.createElement(Box, { role: "region", "aria-labelledby": titleId, tabIndex: 0, sx: { maxHeight: '60vh', overflowY: 'auto' } }, parseNotes(notes).map((block, i) => 'list' in block ? (React.createElement(Box, { component: "ul", key: i, sx: { my: 1, pl: 3 } }, block.list.map((item, j) => (React.createElement("li", { key: j },
30
+ React.createElement(Typography, { variant: "body1", component: "span" }, item)))))) : (React.createElement(Typography, { key: i, variant: "body1" }, block.text)))));
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { NewVersionDialog, type NewVersionDialogProps } from './NewVersionDialog';
2
- export { CHECK_VERSION_EVENT, fetchServedBuild, isNewBuild, requestVersionCheck } from './version';
2
+ export { CHECK_VERSION_EVENT, fetchServedBuild, fetchServedVersion, isNewBuild, notesFor, requestVersionCheck, type ServedVersion } from './version';
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export { NewVersionDialog } from './NewVersionDialog';
2
- export { CHECK_VERSION_EVENT, fetchServedBuild, isNewBuild, requestVersionCheck } from './version';
2
+ export { CHECK_VERSION_EVENT, fetchServedBuild, fetchServedVersion, isNewBuild, notesFor, requestVersionCheck } from './version';
package/dist/version.d.ts CHANGED
@@ -5,11 +5,22 @@ export declare const CHECK_VERSION_EVENT = "twake:check-version";
5
5
  * sign of a tab running an older build than the served one
6
6
  */
7
7
  export declare const requestVersionCheck: () => void;
8
+ /** What `/version.json` says: the build id and, optionally, patch notes by language */
9
+ export interface ServedVersion {
10
+ build: string;
11
+ /** Notes by language code, null when absent or without a usable entry */
12
+ notes: Record<string, string> | null;
13
+ }
8
14
  /**
9
- * The id of the build the server serves now, read in `{ "build": "…" }`.
10
- * Null when it cannot tell: an error, the network, or a page that is not that
11
- * JSON (a dev server answers index.html for any path)
15
+ * Reads `{ "build": "…", "notes": { "en": "…" } }` at `url`. Null when it
16
+ * cannot tell: an error, the network, or a page that is not that JSON (a dev
17
+ * server answers index.html for any path). Unusable notes are dropped, the
18
+ * build is kept
12
19
  */
20
+ export declare const fetchServedVersion: (url?: string, fetchFn?: typeof fetch) => Promise<ServedVersion | null>;
21
+ /** The id of the build the server serves now, null when it cannot tell */
13
22
  export declare const fetchServedBuild: (url?: string, fetchFn?: typeof fetch) => Promise<string | null>;
23
+ /** The notes in `lang`, else in English, else null */
24
+ export declare const notesFor: (notes: Record<string, string> | null, lang: string) => string | null;
14
25
  /** True when the server serves a build other than the one running here */
15
26
  export declare const isNewBuild: (running: string, served: string | null) => served is string;
package/dist/version.js CHANGED
@@ -7,23 +7,37 @@ export const CHECK_VERSION_EVENT = 'twake:check-version';
7
7
  export const requestVersionCheck = () => {
8
8
  window.dispatchEvent(new Event(CHECK_VERSION_EVENT));
9
9
  };
10
+ const usableNotes = (value) => {
11
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
12
+ return null;
13
+ }
14
+ const entries = Object.entries(value).filter((entry) => typeof entry[1] === 'string' && entry[1] !== '');
15
+ return entries.length > 0 ? Object.fromEntries(entries) : null;
16
+ };
10
17
  /**
11
- * The id of the build the server serves now, read in `{ "build": "…" }`.
12
- * Null when it cannot tell: an error, the network, or a page that is not that
13
- * JSON (a dev server answers index.html for any path)
18
+ * Reads `{ "build": "…", "notes": { "en": "…" } }` at `url`. Null when it
19
+ * cannot tell: an error, the network, or a page that is not that JSON (a dev
20
+ * server answers index.html for any path). Unusable notes are dropped, the
21
+ * build is kept
14
22
  */
15
- export const fetchServedBuild = async (url = '/version.json', fetchFn = fetch) => {
23
+ export const fetchServedVersion = async (url = '/version.json', fetchFn = fetch) => {
16
24
  try {
17
25
  const response = await fetchFn(url, { cache: 'no-store' });
18
26
  if (!response.ok)
19
27
  return null;
20
- const body = await response.json();
28
+ const body = (await response.json());
21
29
  const build = body?.build;
22
- return typeof build === 'string' && build !== '' ? build : null;
30
+ if (typeof build !== 'string' || build === '')
31
+ return null;
32
+ return { build, notes: usableNotes(body?.notes) };
23
33
  }
24
34
  catch {
25
35
  return null;
26
36
  }
27
37
  };
38
+ /** The id of the build the server serves now, null when it cannot tell */
39
+ export const fetchServedBuild = async (url = '/version.json', fetchFn = fetch) => (await fetchServedVersion(url, fetchFn))?.build ?? null;
40
+ /** The notes in `lang`, else in English, else null */
41
+ export const notesFor = (notes, lang) => notes?.[lang] ?? notes?.en ?? null;
28
42
  /** True when the server serves a build other than the one running here */
29
43
  export const isNewBuild = (running, served) => served !== null && served !== '' && served !== running;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@linagora/twake-react-new-version",
3
3
  "type": "module",
4
- "version": "1.1.2",
4
+ "version": "1.2.1",
5
5
  "description": "Tells the user of a Twake application that a new version is served, and offers a reload in a dialog with an optional illustration",
6
6
  "author": "Twake",
7
7
  "license": "MIT",