@jetbrains/ring-ui 8.0.0-beta.4 → 8.0.0-beta.5

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.
Files changed (51) hide show
  1. package/components/alert/alert-actions.d.ts +4 -0
  2. package/components/alert/alert-actions.js +5 -0
  3. package/components/alert/alert-heading.d.ts +4 -0
  4. package/components/alert/alert-heading.js +6 -0
  5. package/components/alert/alert.css +63 -22
  6. package/components/alert/alert.d.ts +14 -1
  7. package/components/alert/alert.js +34 -19
  8. package/components/alert/container.css +1 -2
  9. package/components/alert-service/alert-service.d.ts +2 -1
  10. package/components/alert-service/alert-service.js +8 -4
  11. package/components/auth/auth-core.d.ts +5 -9
  12. package/components/auth/auth-core.js +56 -15
  13. package/components/button-group/button-group.css +5 -5
  14. package/components/date-picker/consts.d.ts +1 -0
  15. package/components/date-picker/date-input.js +6 -2
  16. package/components/header/header.css +3 -3
  17. package/components/http/http.d.ts +2 -2
  18. package/components/http/http.js +2 -2
  19. package/components/i18n/i18n.d.ts +1 -0
  20. package/components/i18n/messages.json +1 -0
  21. package/components/table/default-item-renderer.d.ts +7 -1
  22. package/components/table/default-item-renderer.js +18 -5
  23. package/components/table/internal/reorder-animation-context.d.ts +21 -0
  24. package/components/table/internal/reorder-animation-context.js +60 -0
  25. package/components/table/internal/reorder-handle.d.ts +9 -0
  26. package/components/table/internal/reorder-handle.js +334 -0
  27. package/components/table/internal/reorder-layout-context.d.ts +16 -0
  28. package/components/table/internal/reorder-layout-context.js +69 -0
  29. package/components/table/internal/table-header.d.ts +1 -4
  30. package/components/table/internal/table-header.js +32 -246
  31. package/components/table/internal/{virtual-items.d.ts → virtualization.d.ts} +10 -3
  32. package/components/table/internal/{virtual-items.js → virtualization.js} +8 -6
  33. package/components/table/item-virtualization.d.ts +5 -3
  34. package/components/table/item-virtualization.js +4 -6
  35. package/components/table/reorder-animation.d.ts +37 -0
  36. package/components/table/reorder-animation.js +11 -0
  37. package/components/table/reorder-item-layout.d.ts +32 -0
  38. package/components/table/reorder-item-layout.js +23 -0
  39. package/components/table/table-const.d.ts +0 -32
  40. package/components/table/table-const.js +0 -7
  41. package/components/table/table-primitives.d.ts +43 -0
  42. package/components/table/table-primitives.js +9 -0
  43. package/components/table/table-props.d.ts +29 -5
  44. package/components/table/table.css +17 -10
  45. package/components/table/table.d.ts +31 -5
  46. package/components/table/table.js +64 -35
  47. package/components/user-card/smart-user-card-tooltip.d.ts +1 -1
  48. package/components/util-stories.d.ts +2 -2
  49. package/package.json +12 -12
  50. package/components/table/internal/column-animation.d.ts +0 -16
  51. package/components/table/internal/column-animation.js +0 -45
@@ -0,0 +1,4 @@
1
+ import { type HTMLAttributes } from 'react';
2
+ export interface AlertActionsProps extends HTMLAttributes<HTMLDivElement> {
3
+ }
4
+ export default function AlertActions({ className, ...restProps }: AlertActionsProps): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import classNames from 'classnames';
2
+ import styles from './alert.css';
3
+ export default function AlertActions({ className, ...restProps }) {
4
+ return <div className={classNames(styles.actions, className)} {...restProps}/>;
5
+ }
@@ -0,0 +1,4 @@
1
+ import { type HeadingProps } from '../heading/heading';
2
+ export interface AlertHeadingProps extends HeadingProps {
3
+ }
4
+ export default function AlertHeading({ level, className, ...restProps }: AlertHeadingProps): import("react").JSX.Element;
@@ -0,0 +1,6 @@
1
+ import classNames from 'classnames';
2
+ import Heading, { Levels } from '../heading/heading';
3
+ import styles from './alert.css';
4
+ export default function AlertHeading({ level = Levels.H3, className, ...restProps }) {
5
+ return <Heading level={level} className={classNames(styles.heading, className)} {...restProps}/>;
6
+ }
@@ -8,11 +8,14 @@
8
8
 
9
9
  display: flex;
10
10
  align-items: baseline;
11
+ gap: var(--ring-unit);
11
12
 
12
13
  box-sizing: border-box;
13
- min-height: calc(var(--ring-unit) * 5);
14
+ width: calc(var(--ring-unit) * 45);
15
+ max-width: 100%;
16
+ min-height: calc(var(--ring-unit) * 5.5);
14
17
  margin: var(--ring-unit) auto;
15
- padding: 0 calc(var(--ring-unit) * 2);
18
+ padding: calc(var(--ring-unit) * 1.5);
16
19
 
17
20
  transition:
18
21
  transform var(--ring-alert-animation-duration) var(--ring-alert-animation-easing),
@@ -21,16 +24,18 @@
21
24
  white-space: nowrap;
22
25
  pointer-events: auto;
23
26
 
24
- border-radius: var(--ring-border-radius);
27
+ border-radius: var(--ring-border-radius-large);
25
28
  background-color: var(--ring-popup-background-color);
26
29
  box-shadow: var(--ring-popup-shadow);
27
30
 
28
31
  font-size: var(--ring-font-size);
29
- line-height: calc(var(--ring-unit) * 5);
32
+ line-height: 20px;
30
33
  }
31
34
 
32
35
  .alertInline {
33
36
  margin: var(--ring-unit);
37
+ /* Keep the margin box within narrow parents despite the fixed width */
38
+ max-width: calc(100% - var(--ring-unit) * 2);
34
39
  }
35
40
 
36
41
  .error {
@@ -39,26 +44,42 @@
39
44
  color: var(--ring-error-color);
40
45
  }
41
46
 
42
- .icon {
43
- margin-right: var(--ring-unit);
47
+ .error .icon {
48
+ color: var(--ring-icon-error-color);
49
+ }
50
+
51
+ .success .icon {
52
+ color: var(--ring-icon-success-color);
53
+ }
54
+
55
+ .warning .icon {
56
+ color: var(--ring-icon-warning-color);
57
+ }
58
+
59
+ .info .icon {
60
+ color: var(--ring-link-color);
44
61
  }
45
62
 
46
63
  .caption {
47
64
  overflow: hidden;
48
65
 
49
- max-width: calc(100% - calc(var(--ring-unit) * 5));
66
+ flex-grow: 1;
50
67
 
51
- margin: 12px 0;
68
+ min-width: 0;
52
69
 
53
70
  white-space: normal;
54
71
 
55
72
  color: var(--ring-active-text-color);
73
+ }
56
74
 
57
- line-height: 20px;
75
+ .afterMessage {
76
+ overflow: hidden;
58
77
 
59
- &.withCloseButton {
60
- margin-right: calc(var(--ring-unit) * 5);
61
- }
78
+ min-width: 0;
79
+
80
+ white-space: normal;
81
+
82
+ color: var(--ring-active-text-color);
62
83
  }
63
84
 
64
85
  .badge {
@@ -68,21 +89,17 @@
68
89
  }
69
90
 
70
91
  .loader {
71
- top: 2px;
92
+ top: 3px;
72
93
 
73
- margin-right: var(--ring-unit);
94
+ margin-top: -1px;
74
95
  }
75
96
 
97
+ /* Padding restores a comfortable hit target around the bare 16px glyph
98
+ of the inline icon-only Button; negative margin keeps the glyph where
99
+ the flex layout would put it without the padding */
76
100
  .close.close {
77
- position: absolute;
78
- top: 2px;
79
- right: 0;
80
-
81
- margin: calc(var(--ring-unit) / 2);
101
+ margin: calc(var(--ring-unit) * -1);
82
102
  padding: var(--ring-unit);
83
-
84
- font-size: 0;
85
- line-height: 0;
86
103
  }
87
104
 
88
105
  @keyframes show {
@@ -135,5 +152,29 @@
135
152
 
136
153
  .animationShaking {
137
154
  animation-name: shaking;
155
+
138
156
  animation-duration: 500ms;
139
157
  }
158
+
159
+ /* Doubled to override the Heading component's level-based styles, so the
160
+ level prop stays semantic and doesn't change the alert design: Heading's
161
+ :is(hN) selectors have higher specificity than a single class */
162
+ .heading.heading {
163
+ margin: 0 0 calc(var(--ring-unit) / 2);
164
+
165
+ letter-spacing: normal;
166
+ text-transform: none;
167
+
168
+ color: inherit;
169
+
170
+ font-size: var(--ring-font-size);
171
+ font-weight: var(--ring-font-weight-bold);
172
+ line-height: var(--ring-line-height);
173
+ }
174
+
175
+ .actions {
176
+ display: flex;
177
+ gap: calc(var(--ring-unit)*2);
178
+
179
+ margin: calc(var(--ring-unit) * 2) 0 calc(var(--ring-unit) / 2);
180
+ }
@@ -1,6 +1,8 @@
1
1
  import { PureComponent, type ReactNode } from 'react';
2
2
  import * as React from 'react';
3
3
  import Theme from '../global/theme';
4
+ import AlertHeading from './alert-heading';
5
+ import AlertActions from './alert-actions';
4
6
  export declare const ANIMATION_TIME = 500;
5
7
  /**
6
8
  * @name Alert
@@ -14,8 +16,16 @@ export declare enum AlertType {
14
16
  MESSAGE = "message",
15
17
  SUCCESS = "success",
16
18
  WARNING = "warning",
17
- LOADING = "loading"
19
+ LOADING = "loading",
20
+ INFO = "info"
18
21
  }
22
+ /**
23
+ * Maps the values React renders as nothing (except empty arrays/fragments,
24
+ * which are not worth chasing here) to undefined, so that they neither create
25
+ * the afterMessage wrapper nor distinguish alerts in the alert-service
26
+ * duplicate check
27
+ */
28
+ export declare function normalizeAfterMessage(afterMessage: ReactNode): ReactNode;
19
29
  export interface AlertProps {
20
30
  theme: Theme;
21
31
  timeout: number;
@@ -39,6 +49,7 @@ export interface AlertProps {
39
49
  captionClassName?: string | null | undefined;
40
50
  closeButtonClassName?: string | null | undefined;
41
51
  'data-test'?: string | null | undefined;
52
+ afterMessage?: ReactNode;
42
53
  }
43
54
  interface State {
44
55
  height: number | null;
@@ -74,6 +85,8 @@ export default class Alert extends PureComponent<AlertProps, State> {
74
85
  node?: HTMLDivElement | null;
75
86
  hideTimeout?: number;
76
87
  static Type: typeof AlertType;
88
+ static Heading: typeof AlertHeading;
89
+ static Actions: typeof AlertActions;
77
90
  closeRequest: (event: React.MouseEvent<HTMLElement>) => void;
78
91
  startCloseAnimation: () => void;
79
92
  private _close;
@@ -2,15 +2,18 @@ import { PureComponent } from 'react';
2
2
  import * as React from 'react';
3
3
  import classNames from 'classnames';
4
4
  import exceptionIcon from '@jetbrains/icons/exception';
5
- import checkmarkIcon from '@jetbrains/icons/checkmark';
5
+ import successIcon from '@jetbrains/icons/success';
6
6
  import warningIcon from '@jetbrains/icons/warning';
7
+ import infoIcon from '@jetbrains/icons/info-filled';
7
8
  import closeIcon from '@jetbrains/icons/close';
8
- import Icon, { Color } from '../icon/icon';
9
+ import Icon from '../icon/icon';
9
10
  import Loader from '../loader-inline/loader-inline';
10
11
  import { getRect } from '../global/dom';
11
12
  import dataTests from '../global/data-tests';
12
13
  import Button from '../button/button';
13
14
  import Theme, { ThemeProvider } from '../global/theme';
15
+ import AlertHeading from './alert-heading';
16
+ import AlertActions from './alert-actions';
14
17
  import styles from './alert.css';
15
18
  export const ANIMATION_TIME = 500;
16
19
  /**
@@ -27,6 +30,7 @@ export var AlertType;
27
30
  AlertType["SUCCESS"] = "success";
28
31
  AlertType["WARNING"] = "warning";
29
32
  AlertType["LOADING"] = "loading";
33
+ AlertType["INFO"] = "info";
30
34
  })(AlertType || (AlertType = {}));
31
35
  /**
32
36
  * Lookup table of alert type to icon modifier.
@@ -34,18 +38,19 @@ export var AlertType;
34
38
  */
35
39
  const TypeToIcon = {
36
40
  [AlertType.ERROR]: exceptionIcon,
37
- [AlertType.SUCCESS]: checkmarkIcon,
41
+ [AlertType.SUCCESS]: successIcon,
38
42
  [AlertType.WARNING]: warningIcon,
43
+ [AlertType.INFO]: infoIcon,
39
44
  };
40
45
  /**
41
- * Lookup table of alert type to icon color.
42
- * @type {Object.<AlertType, Icon.Color>}
46
+ * Maps the values React renders as nothing (except empty arrays/fragments,
47
+ * which are not worth chasing here) to undefined, so that they neither create
48
+ * the afterMessage wrapper nor distinguish alerts in the alert-service
49
+ * duplicate check
43
50
  */
44
- const TypeToIconColor = {
45
- [AlertType.ERROR]: Color.RED,
46
- [AlertType.SUCCESS]: Color.GREEN,
47
- [AlertType.WARNING]: Color.WHITE,
48
- };
51
+ export function normalizeAfterMessage(afterMessage) {
52
+ return afterMessage == null || typeof afterMessage === 'boolean' || afterMessage === '' ? undefined : afterMessage;
53
+ }
49
54
  /**
50
55
  * @constructor
51
56
  * @name Alert
@@ -87,6 +92,8 @@ export default class Alert extends PureComponent {
87
92
  node;
88
93
  hideTimeout;
89
94
  static Type = AlertType;
95
+ static Heading = AlertHeading;
96
+ static Actions = AlertActions;
90
97
  closeRequest = (event) => {
91
98
  this.startCloseAnimation();
92
99
  return this.props.onCloseRequest(event);
@@ -106,7 +113,8 @@ export default class Alert extends PureComponent {
106
113
  * @private
107
114
  */
108
115
  _handleCaptionsLinksClick = (evt) => {
109
- if (evt.target instanceof Element && evt.target.matches('a')) {
116
+ const link = evt.target instanceof Element ? evt.target.closest('a') : null;
117
+ if (link != null && evt.currentTarget.contains(link)) {
110
118
  this.closeRequest(evt);
111
119
  }
112
120
  };
@@ -114,13 +122,11 @@ export default class Alert extends PureComponent {
114
122
  * @private
115
123
  */
116
124
  _getCaption() {
117
- return (<span className={classNames(styles.caption, this.props.captionClassName, {
118
- [styles.withCloseButton]: this.props.closeable,
119
- })} onClick={this._handleCaptionsLinksClick}
125
+ return (<div className={classNames(styles.caption, this.props.captionClassName)} onClick={this._handleCaptionsLinksClick}
120
126
  // We only process clicks on `a` elements, see above
121
127
  role='presentation'>
122
128
  {this.props.children}
123
- </span>);
129
+ </div>);
124
130
  }
125
131
  /**
126
132
  * @private
@@ -129,7 +135,7 @@ export default class Alert extends PureComponent {
129
135
  _getIcon() {
130
136
  const glyph = TypeToIcon[this.props.type];
131
137
  if (glyph) {
132
- return <Icon glyph={glyph} className={styles.icon} color={TypeToIconColor[this.props.type] || Color.DEFAULT}/>;
138
+ return <Icon glyph={glyph} className={styles.icon}/>;
133
139
  }
134
140
  if (this.props.type === AlertType.LOADING) {
135
141
  return <Loader className={styles.loader}/>;
@@ -140,21 +146,30 @@ export default class Alert extends PureComponent {
140
146
  this.node = node;
141
147
  };
142
148
  render() {
143
- const { type, inline, isClosing, isShaking, closeButtonClassName, showWithAnimation, className, 'data-test': dataTest, theme, } = this.props;
149
+ const { type, inline, isClosing, isShaking, closeButtonClassName, showWithAnimation, className, 'data-test': dataTest, theme, afterMessage, } = this.props;
144
150
  const classes = classNames(className, {
145
151
  [styles.alert]: true,
146
152
  [styles.animationOpen]: showWithAnimation,
147
- [styles.error]: type === 'error',
153
+ [styles.error]: type === AlertType.ERROR,
154
+ [styles.success]: type === AlertType.SUCCESS,
155
+ [styles.warning]: type === AlertType.WARNING,
156
+ [styles.info]: type === AlertType.INFO,
148
157
  [styles.alertInline]: inline,
149
158
  [styles.animationClosing]: isClosing,
150
159
  [styles.animationShaking]: isShaking,
151
160
  });
152
161
  const height = this.state.height;
153
162
  const style = height ? { marginBottom: -height } : undefined;
163
+ const shownAfterMessage = normalizeAfterMessage(afterMessage);
154
164
  return (<ThemeProvider theme={theme} className={classes} data-test={dataTests('alert', dataTest)} data-test-type={type} style={style} ref={this.storeAlertRef}>
155
165
  {this._getIcon()}
156
166
  {this._getCaption()}
157
- {this.props.closeable ? (<Button icon={closeIcon} className={classNames(styles.close, closeButtonClassName)} data-test='alert-close' aria-label='close alert' onClick={this.closeRequest}/>) : ('')}
167
+ {shownAfterMessage != null && (<div className={styles.afterMessage} onClick={this._handleCaptionsLinksClick}
168
+ // We only process clicks on `a` elements, see above
169
+ role='presentation'>
170
+ {shownAfterMessage}
171
+ </div>)}
172
+ {this.props.closeable ? (<Button icon={closeIcon} className={classNames(styles.close, closeButtonClassName)} data-test='alert-close' aria-label='close alert' onClick={this.closeRequest}/>) : null}
158
173
  </ThemeProvider>);
159
174
  }
160
175
  }
@@ -11,6 +11,7 @@
11
11
  align-items: flex-end;
12
12
  flex-direction: column;
13
13
 
14
+ max-width: calc(100vw - var(--ring-unit) * 4);
14
15
  max-height: calc(100vh - 2 * var(--ring-unit));
15
16
 
16
17
  pointer-events: none;
@@ -24,7 +25,5 @@
24
25
 
25
26
  overflow-y: auto;
26
27
 
27
- min-width: calc(var(--ring-unit) * 30);
28
- max-width: calc(var(--ring-unit) * 50);
29
28
  margin-top: 0;
30
29
  }
@@ -20,7 +20,7 @@ export declare class AlertService {
20
20
  * Renders alert container into virtual node to skip maintaining container
21
21
  */
22
22
  renderAlerts(): void;
23
- findSameAlert(message: ReactNode, type: AlertType | undefined): AlertItem;
23
+ findSameAlert(message: ReactNode, type: AlertType | undefined, afterMessage?: ReactNode): AlertItem | undefined;
24
24
  startAlertClosing(alert: AlertItem): void;
25
25
  remove(key: string | number | null | undefined): void;
26
26
  removeWithoutAnimation(key: string | number): void;
@@ -31,6 +31,7 @@ export declare class AlertService {
31
31
  message(message: ReactNode, timeout?: number): string | number;
32
32
  warning(message: ReactNode, timeout?: number): string | number;
33
33
  successMessage(message: ReactNode, timeout?: number): string | number;
34
+ infoMessage(message: ReactNode, timeout?: number): string | number;
34
35
  loadingMessage(message: ReactNode, timeout?: number): string | number;
35
36
  }
36
37
  declare const alertService: AlertService;
@@ -1,6 +1,6 @@
1
1
  import { createRoot } from 'react-dom/client';
2
2
  import getUID from '../global/get-uid';
3
- import Alert, { ANIMATION_TIME, Container as AlertContainer } from '../alert/alert';
3
+ import Alert, { ANIMATION_TIME, Container as AlertContainer, normalizeAfterMessage, } from '../alert/alert';
4
4
  export const DEFAULT_ALERT_TIMEOUT = 10000; // 10 seconds
5
5
  /**
6
6
  * @name Alert Service
@@ -33,8 +33,9 @@ export class AlertService {
33
33
  renderAlerts() {
34
34
  this.reactRoot.render(this.renderAlertContainer(this.showingAlerts));
35
35
  }
36
- findSameAlert(message, type) {
37
- return this.showingAlerts.filter(it => it.type === type && it.message === message)[0];
36
+ findSameAlert(message, type, afterMessage) {
37
+ const normalizedAfterMessage = normalizeAfterMessage(afterMessage);
38
+ return this.showingAlerts.find(it => it.type === type && it.message === message && normalizeAfterMessage(it.afterMessage) === normalizedAfterMessage);
38
39
  }
39
40
  startAlertClosing(alert) {
40
41
  alert.isClosing = true;
@@ -60,7 +61,7 @@ export class AlertService {
60
61
  }
61
62
  addAlert(message, type, timeout = this.defaultTimeout, options = {}) {
62
63
  const { onCloseRequest, onClose, ...restOptions } = options;
63
- const sameAlert = this.findSameAlert(message, type);
64
+ const sameAlert = this.findSameAlert(message, type, options.afterMessage);
64
65
  if (sameAlert) {
65
66
  sameAlert.isShaking = true;
66
67
  this.renderAlerts();
@@ -102,6 +103,9 @@ export class AlertService {
102
103
  successMessage(message, timeout) {
103
104
  return this.addAlert(message, Alert.Type.SUCCESS, timeout);
104
105
  }
106
+ infoMessage(message, timeout) {
107
+ return this.addAlert(message, Alert.Type.INFO, timeout);
108
+ }
105
109
  loadingMessage(message, timeout) {
106
110
  return this.addAlert(message, Alert.Type.LOADING, timeout);
107
111
  }
@@ -171,18 +171,13 @@ declare class Auth implements HTTPAuth {
171
171
  requestToken(): Promise<string | null>;
172
172
  /**
173
173
  * Get new token in the background or redirect to the login page.
174
- *
175
- * Retries background token refresh with delays from {@link AuthConfig.tokenRefreshRetryDelays}
176
- * with increasing delays before showing the auth dialog.
177
- * This handles transient failures that commonly occur after network
178
- * recovery (e.g. waking from sleep, switching networks) where the first
179
- * iframe-based auth attempt fails but a subsequent one succeeds once
180
- * the Hub session is re-established.
181
- *
182
174
  * @return {Promise.<string | null>}
183
175
  */
184
- forceTokenUpdate(): Promise<string | null>;
176
+ forceTokenUpdate(failedToken?: string | null): Promise<string | null>;
185
177
  private _doForceTokenUpdate;
178
+ private _refreshTokenUnderWebLock;
179
+ private _refreshTokenOrReuseChanged;
180
+ private _handleTokenRefreshFailure;
186
181
  loadCurrentService(): Promise<void>;
187
182
  getAPIPath(): string;
188
183
  /**
@@ -195,6 +190,7 @@ declare class Auth implements HTTPAuth {
195
190
  requestUser(): Promise<any>;
196
191
  updateUser(): Promise<void>;
197
192
  _detectUserChange(accessToken: string): Promise<void>;
193
+ private _getUserWithTokenRefresh;
198
194
  _beforeLogout(params?: AuthDialogParams): void;
199
195
  _showAuthDialog({ nonInteractive, error, canCancel, onTryAgain }?: AuthDialogParams): void;
200
196
  _showUserChangedDialog({ newUser, onApply, onPostpone }: UserChangedDialogParams): void;
@@ -1,7 +1,7 @@
1
1
  /* eslint-disable no-underscore-dangle,max-lines */
2
2
  import { fixUrl, getAbsoluteBaseURL } from '../global/url';
3
3
  import Listeners from '../global/listeners';
4
- import HTTP from '../http/http';
4
+ import HTTP, { CODE, HTTPError } from '../http/http';
5
5
  import promiseWithTimeout from '../global/promise-with-timeout';
6
6
  import { getTranslations, getTranslationsWithFallback, translate } from '../i18n/i18n';
7
7
  import AuthStorage from './storage';
@@ -16,6 +16,7 @@ const DEFAULT_BACKEND_CHECK_TIMEOUT = 10 * 1000;
16
16
  const BACKGROUND_REDIRECT_TIMEOUT = 20 * 1000;
17
17
  const DEFAULT_WAIT_FOR_REDIRECT_TIMEOUT = 5 * 1000;
18
18
  export const TOKEN_REFRESH_RETRY_DELAYS = [0, 2000, 5000];
19
+ const TOKEN_REFRESH_LOCK_TIMEOUT = 15 * 1000;
19
20
  export const USER_CHANGED_EVENT = 'userChange';
20
21
  export const DOMAIN_USER_CHANGED_EVENT = 'domainUser';
21
22
  export const LOGOUT_EVENT = 'logout';
@@ -346,26 +347,19 @@ class Auth {
346
347
  }
347
348
  /**
348
349
  * Get new token in the background or redirect to the login page.
349
- *
350
- * Retries background token refresh with delays from {@link AuthConfig.tokenRefreshRetryDelays}
351
- * with increasing delays before showing the auth dialog.
352
- * This handles transient failures that commonly occur after network
353
- * recovery (e.g. waking from sleep, switching networks) where the first
354
- * iframe-based auth attempt fails but a subsequent one succeeds once
355
- * the Hub session is re-established.
356
- *
357
350
  * @return {Promise.<string | null>}
358
351
  */
359
- forceTokenUpdate() {
352
+ forceTokenUpdate(failedToken) {
360
353
  if (this._forceTokenUpdatePromise) {
361
354
  return this._forceTokenUpdatePromise;
362
355
  }
363
- this._forceTokenUpdatePromise = this._doForceTokenUpdate().finally(() => {
356
+ this._forceTokenUpdatePromise = this._doForceTokenUpdate(failedToken).finally(() => {
364
357
  this._forceTokenUpdatePromise = null;
365
358
  });
366
359
  return this._forceTokenUpdatePromise;
367
360
  }
368
- async _doForceTokenUpdate() {
361
+ async _doForceTokenUpdate(failedToken) {
362
+ const previousToken = failedToken ?? (await this._storage?.getToken())?.accessToken ?? null;
369
363
  try {
370
364
  if (!this._backendCheckPromise) {
371
365
  this._backendCheckPromise = this._checkBackendsStatusesIfEnabled();
@@ -378,18 +372,50 @@ class Auth {
378
372
  finally {
379
373
  this._backendCheckPromise = null;
380
374
  }
375
+ const attempt = await this._refreshTokenUnderWebLock(previousToken);
376
+ if ('token' in attempt) {
377
+ return attempt.token;
378
+ }
379
+ return this._handleTokenRefreshFailure(attempt.error);
380
+ }
381
+ async _refreshTokenUnderWebLock(previousToken) {
382
+ if (navigator.locks == null) {
383
+ return this._refreshTokenOrReuseChanged(previousToken);
384
+ }
385
+ const lockName = `ring-ui-token-refresh-${this.config.clientId}`;
386
+ try {
387
+ return await navigator.locks.request(lockName, { signal: AbortSignal.timeout(TOKEN_REFRESH_LOCK_TIMEOUT) }, () => this._refreshTokenOrReuseChanged(previousToken));
388
+ }
389
+ catch {
390
+ return this._refreshTokenOrReuseChanged(previousToken);
391
+ }
392
+ }
393
+ async _refreshTokenOrReuseChanged(previousToken) {
394
+ let storedToken = null;
395
+ try {
396
+ storedToken = (await this._tokenValidator?.validateTokenLocally()) ?? null;
397
+ }
398
+ catch {
399
+ // No valid local token — fall through to refresh.
400
+ }
401
+ if (storedToken != null && storedToken !== previousToken) {
402
+ return { token: storedToken };
403
+ }
381
404
  let lastError = null;
382
405
  for (const delay of this.config.tokenRefreshRetryDelays) {
383
406
  if (delay > 0) {
384
407
  await new Promise(resolve => setTimeout(resolve, delay));
385
408
  }
386
409
  try {
387
- return (await this._backgroundFlow?.authorize()) ?? null;
410
+ return { token: (await this._backgroundFlow?.authorize()) ?? null };
388
411
  }
389
412
  catch (error) {
390
413
  lastError = error instanceof Error ? error : new Error(String(error));
391
414
  }
392
415
  }
416
+ return { error: lastError ?? new Error('Failed to refresh token') };
417
+ }
418
+ async _handleTokenRefreshFailure(lastError) {
393
419
  if (this._canShowDialogs()) {
394
420
  return new Promise(resolve => {
395
421
  const onTryAgain = async () => {
@@ -419,7 +445,7 @@ class Auth {
419
445
  if (authRequest) {
420
446
  this._redirectCurrentPage(authRequest.url);
421
447
  }
422
- throw new TokenValidator.TokenValidationError(lastError?.message ?? 'Failed to refresh token');
448
+ throw new TokenValidator.TokenValidationError(lastError.message);
423
449
  }
424
450
  async loadCurrentService() {
425
451
  if (this._service.serviceName) {
@@ -471,7 +497,7 @@ class Auth {
471
497
  }
472
498
  async _detectUserChange(accessToken) {
473
499
  const windowWasOpen = this._isLoginWindowOpen;
474
- const user = await this.getUser(accessToken);
500
+ const user = await this._getUserWithTokenRefresh(accessToken);
475
501
  const onApply = () => {
476
502
  this.user = user;
477
503
  this.listeners.trigger(USER_CHANGED_EVENT, user);
@@ -495,6 +521,21 @@ class Auth {
495
521
  });
496
522
  }
497
523
  }
524
+ async _getUserWithTokenRefresh(accessToken) {
525
+ try {
526
+ return await this.getUser(accessToken);
527
+ }
528
+ catch (error) {
529
+ if (!(error instanceof HTTPError) || error.status !== CODE.UNAUTHORIZED) {
530
+ throw error;
531
+ }
532
+ const attempt = await this._refreshTokenUnderWebLock(accessToken);
533
+ if ('error' in attempt) {
534
+ throw error;
535
+ }
536
+ return this.getUser(attempt.token);
537
+ }
538
+ }
498
539
  _beforeLogout(params) {
499
540
  if (this._canShowDialogs()) {
500
541
  const onTryAgain = async () => {
@@ -1,6 +1,6 @@
1
1
  @import '../global/variables.css';
2
2
 
3
- @value button, active, flat from '../button/button.css';
3
+ @value button, active as buttonActive, flat from '../button/button.css';
4
4
 
5
5
  :root,
6
6
  :host {
@@ -133,14 +133,14 @@
133
133
  0 0 0 1px var(--ring-border-hover-color);
134
134
  }
135
135
 
136
- .buttonGroup .button.button.active {
136
+ .buttonGroup .button.button.buttonActive {
137
137
  --ring-button-border-radius-left: var(--ring-border-radius);
138
138
  --ring-button-border-radius-right: var(--ring-border-radius);
139
139
 
140
140
  box-shadow: var(--ring-button-shadow) var(--ring-button-border-color);
141
141
  }
142
142
 
143
- .buttonGroup .button:focus-visible.active {
143
+ .buttonGroup .button:focus-visible.buttonActive {
144
144
  --ring-button-border-radius-left: var(--ring-border-radius);
145
145
  --ring-button-border-radius-right: var(--ring-border-radius);
146
146
 
@@ -149,7 +149,7 @@
149
149
  0 0 0 1px var(--ring-border-hover-color);
150
150
  }
151
151
 
152
- .buttonGroup .button.active[disabled] {
152
+ .buttonGroup .button.buttonActive[disabled] {
153
153
  box-shadow: var(--ring-button-shadow) var(--ring-border-hover-color);
154
154
  }
155
155
  /* stylelint-enable */
@@ -240,7 +240,7 @@
240
240
  }
241
241
  }
242
242
 
243
- & .active {
243
+ & .buttonActive {
244
244
  z-index: var(--ring-button-group-active-z-index);
245
245
 
246
246
  &[disabled] {
@@ -34,6 +34,7 @@ export interface DateInputTranslations {
34
34
  addSecondDate?: string;
35
35
  addTime?: string;
36
36
  selectName?: string;
37
+ selectDate?: string;
37
38
  }
38
39
  export interface DateSpecificPopupProps {
39
40
  withTime?: false | undefined;
@@ -47,7 +47,7 @@ export default class DateInput extends React.PureComponent {
47
47
  };
48
48
  render() {
49
49
  const { active, divider, text, time, name, hoverDate, date, displayFormat, translations, onActivate, onClear, fromPlaceholder, toPlaceholder, timePlaceholder, locale, } = this.props;
50
- const { translate } = this.context;
50
+ const { messages, translate } = this.context;
51
51
  let displayText = '';
52
52
  if (active && hoverDate) {
53
53
  displayText = displayFormat(hoverDate, locale);
@@ -70,7 +70,11 @@ export default class DateInput extends React.PureComponent {
70
70
  case 'time':
71
71
  return timePlaceholder || (translations?.addTime ?? translate('addTime'));
72
72
  default:
73
- return (translations?.selectName ?? translate('selectName'))
73
+ return (translations?.selectDate ??
74
+ translations?.selectName ??
75
+ messages.selectDate ??
76
+ messages.selectName ??
77
+ translate('selectDate'))
74
78
  .replace('%name%', name)
75
79
  .replace('{{name}}', name);
76
80
  }