@redocly/theme 0.25.0 → 0.25.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.
@@ -29,7 +29,7 @@ function CodeBlockControls({ children, className, title, controls, }) {
29
29
  collapse && !((_c = codeSnippet === null || codeSnippet === void 0 ? void 0 : codeSnippet.collapse) === null || _c === void 0 ? void 0 : _c.hide) ? (react_1.default.createElement(CodeBlock_1.CodeBlockControlButton, { "data-cy": "collapse-all", "data-testid": "collapse-all", asIcon: controlsType === 'icon', onClick: collapse === null || collapse === void 0 ? void 0 : collapse.onClick, title: (collapse === null || collapse === void 0 ? void 0 : collapse.tooltipText) || 'Collapse all' }, controlsType === 'icon' ? (react_1.default.createElement(icons_1.CollapseIcon, null)) : (collapse === null || collapse === void 0 ? void 0 : collapse.label) ? (collapse.label) : ('Collapse all'))) : null,
30
30
  select ? (react_1.default.createElement(CodeBlock_1.CodeBlockControlButton, { "data-cy": "select-all", "data-testid": "select-all", asIcon: controlsType === 'icon', onClick: select === null || select === void 0 ? void 0 : select.onClick, title: select === null || select === void 0 ? void 0 : select.tooltipText }, controlsType === 'icon' ? react_1.default.createElement(icons_1.SelectIcon, null) : (select === null || select === void 0 ? void 0 : select.label) ? select.label : 'Select all')) : null,
31
31
  deselect ? (react_1.default.createElement(CodeBlock_1.CodeBlockControlButton, { "data-cy": "clear-all", "data-testid": "clear-all", asIcon: controlsType === 'icon', onClick: deselect === null || deselect === void 0 ? void 0 : deselect.onClick, title: deselect === null || deselect === void 0 ? void 0 : deselect.tooltipText }, controlsType === 'icon' ? (react_1.default.createElement(icons_1.DeselectIcon, null)) : (deselect === null || deselect === void 0 ? void 0 : deselect.label) ? (deselect.label) : ('Clear all'))) : null,
32
- report && ((_d = report === null || report === void 0 ? void 0 : report.props) === null || _d === void 0 ? void 0 : _d.visible) ? (react_1.default.createElement(CodeBlock_1.CodeBlockControlButton, Object.assign({ "data-cy": "report-button", "data-testid": "report-button", asIcon: controlsType === 'icon', title: report.tooltipText }, report.props, { onClick: () => telemetry_1.telemetry.send('code_snippet_reported', {}) }), controlsType === 'icon' ? react_1.default.createElement(icons_1.ReportIcon, null) : ((_e = report.props) === null || _e === void 0 ? void 0 : _e.buttonText) || 'Report')) : null))) : null;
32
+ report && ((_d = report === null || report === void 0 ? void 0 : report.props) === null || _d === void 0 ? void 0 : _d.visible) ? (react_1.default.createElement(CodeBlock_1.CodeBlockControlButton, Object.assign({ "data-cy": "report-button", "data-testid": "report-button", asIcon: controlsType === 'icon', title: report.tooltipText }, report.props), controlsType === 'icon' ? react_1.default.createElement(icons_1.ReportIcon, null) : ((_e = report.props) === null || _e === void 0 ? void 0 : _e.buttonText) || 'Report')) : null))) : null;
33
33
  return children || controls ? (react_1.default.createElement(ContainerWraper, { "data-component-name": "CodeBlock/CodeBlockControls", className: className }, children ? children : defaultControls)) : null;
34
34
  }
35
35
  exports.CodeBlockControls = CodeBlockControls;
@@ -40,6 +40,7 @@ const Feedback = (props) => {
40
40
  const { feedback: themeFeedbackConf } = (0, hooks_1.useThemeConfig)();
41
41
  const feedbackConf = Object.assign(Object.assign({}, themeFeedbackConf), props);
42
42
  const renderFeedbackComponent = () => {
43
+ const { type, settings, path } = feedbackConf;
43
44
  switch (type) {
44
45
  case 'rating':
45
46
  return (React.createElement(Wrapper, null,
@@ -70,7 +71,6 @@ const Feedback = (props) => {
70
71
  break;
71
72
  }
72
73
  };
73
- const { type, settings, path } = feedbackConf;
74
74
  return React.createElement(React.Fragment, { key: pathname }, renderFeedbackComponent());
75
75
  };
76
76
  exports.Feedback = Feedback;
@@ -41,6 +41,7 @@ var MOOD_STATES;
41
41
  const Mood = ({ settings, onSubmit, className }) => {
42
42
  const { label, submitText, comment: commentSettings, reasons: reasonsSettings } = settings || {};
43
43
  const [score, setScore] = React.useState('');
44
+ const [isSubmitted, setIsSubmitted] = React.useState(false);
44
45
  const [comment, setComment] = React.useState('');
45
46
  const [reasons, setReasons] = React.useState([]);
46
47
  const { translate } = (0, hooks_1.useTranslate)();
@@ -72,11 +73,14 @@ const Mood = ({ settings, onSubmit, className }) => {
72
73
  return (React.createElement(Feedback_1.Comment, { onSubmit: ({ comment }) => setComment(comment), settings: { label: renderCommentLabel(score) } }));
73
74
  }
74
75
  if (score) {
75
- onSubmit({
76
- score,
77
- comment,
78
- reasons,
79
- });
76
+ if (!isSubmitted) {
77
+ onSubmit({
78
+ score,
79
+ comment,
80
+ reasons,
81
+ });
82
+ setIsSubmitted(true);
83
+ }
80
84
  return (React.createElement(Wrapper, null,
81
85
  React.createElement(Label, { "data-translation-key": translationKeys.submitText }, translate(translationKeys.submitText, submitText || 'Thank you for your feedback!'))));
82
86
  }
@@ -33,6 +33,7 @@ const Feedback_1 = require("../../components/Feedback");
33
33
  const hooks_1 = require("../../mocks/hooks");
34
34
  const Rating = ({ settings, onSubmit, className }) => {
35
35
  const { label, max, submitText, comment: commentSettings, reasons: reasonsSettings, } = settings || {};
36
+ const [isSubmitted, setIsSubmitted] = React.useState(false);
36
37
  const [score, setScore] = React.useState(0);
37
38
  const [comment, setComment] = React.useState('');
38
39
  const [reasons, setReasons] = React.useState([]);
@@ -51,12 +52,15 @@ const Rating = ({ settings, onSubmit, className }) => {
51
52
  return (React.createElement(Feedback_1.Comment, { onSubmit: ({ comment }) => setComment(comment), settings: { label: commentSettings.label } }));
52
53
  }
53
54
  if (score) {
54
- onSubmit({
55
- score,
56
- comment,
57
- reasons,
58
- max: maxRating,
59
- });
55
+ if (!isSubmitted) {
56
+ onSubmit({
57
+ score,
58
+ comment,
59
+ reasons,
60
+ max: maxRating,
61
+ });
62
+ setIsSubmitted(true);
63
+ }
60
64
  return (React.createElement(Wrapper, null,
61
65
  React.createElement(Label, { "data-translation-key": translationKeys.submitText }, translate(translationKeys.submitText, submitText || 'Thank you for helping improve our documentation!'))));
62
66
  }
@@ -22,6 +22,15 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
25
34
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
36
  };
@@ -29,14 +38,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
38
  exports.ReportDialog = void 0;
30
39
  const React = __importStar(require("react"));
31
40
  const styled_components_1 = __importDefault(require("styled-components"));
41
+ const react_router_dom_1 = require("react-router-dom");
42
+ const telemetry_1 = require("../../mocks/telemetry");
32
43
  const Comment_1 = require("../../components/Feedback/Comment");
33
44
  const ReportDialog = ({ location, settings, onSubmit, onCancel, submitFeedback, }) => {
34
45
  const { label } = settings;
46
+ const { pathname } = (0, react_router_dom_1.useLocation)();
35
47
  return (React.createElement(Wrapper, { className: "modal" },
36
- React.createElement(Comment_1.Comment, { settings: { label }, onSubmit: (value) => {
37
- submitFeedback({ type: 'problem', values: value, path: location });
48
+ React.createElement(Comment_1.Comment, { settings: { label }, onSubmit: (value) => __awaiter(void 0, void 0, void 0, function* () {
49
+ yield submitFeedback({ type: 'problem', values: value, location, path: pathname });
50
+ telemetry_1.telemetry.send('code_snippet_reported', {});
38
51
  onSubmit();
39
- }, onCancel: onCancel })));
52
+ }), onCancel: onCancel })));
40
53
  };
41
54
  exports.ReportDialog = ReportDialog;
42
55
  const Wrapper = styled_components_1.default.div `
@@ -34,6 +34,7 @@ const Thumbs_1 = require("../../components/Feedback/Thumbs");
34
34
  const hooks_1 = require("../../mocks/hooks");
35
35
  const Sentiment = ({ settings, onSubmit, className }) => {
36
36
  const { label, submitText, comment: commentSettings, reasons: reasonsSettings } = settings || {};
37
+ const [isSubmitted, setIsSubmitted] = React.useState(false);
37
38
  const [score, setScore] = React.useState(0);
38
39
  const [comment, setComment] = React.useState('');
39
40
  const [reasons, setReasons] = React.useState([]);
@@ -56,11 +57,14 @@ const Sentiment = ({ settings, onSubmit, className }) => {
56
57
  return (React.createElement(Feedback_1.Comment, { onSubmit: ({ comment }) => setComment(comment), settings: { label: commentLabel } }));
57
58
  }
58
59
  if (score) {
59
- onSubmit({
60
- score,
61
- comment,
62
- reasons,
63
- });
60
+ if (!isSubmitted) {
61
+ onSubmit({
62
+ score,
63
+ comment,
64
+ reasons,
65
+ });
66
+ setIsSubmitted(true);
67
+ }
64
68
  return (React.createElement(Wrapper, null,
65
69
  React.createElement(Label, { "data-translation-key": translationKeys.submitText }, translate(translationKeys.submitText, submitText || 'Thank you for helping improve our documentation!'))));
66
70
  }
@@ -101,6 +101,6 @@ export type ReportDialogProps = {
101
101
  settings: {
102
102
  label?: string;
103
103
  };
104
- submitFeedback: ({ type, values, path }: SubmitFeedbackParams) => Promise<void>;
104
+ submitFeedback: ({ type, values, path, location }: SubmitFeedbackParams) => Promise<void>;
105
105
  className?: string;
106
106
  };
@@ -4,11 +4,13 @@ exports.useReportDialog = void 0;
4
4
  const react_1 = require("react");
5
5
  const hooks_1 = require("../../mocks/hooks");
6
6
  const hooks_2 = require("../../hooks");
7
+ const useSubmitFeedback_1 = require("../../mocks/Feedback/useSubmitFeedback");
7
8
  function useReportDialog() {
8
9
  const { codeSnippet: { report = {} } = {} } = (0, hooks_2.useThemeConfig)();
9
10
  const [isReportDialogShown, setIsReportDialogShown] = (0, react_1.useState)(false);
10
11
  const isReportButtonShown = (report === null || report === void 0 ? void 0 : report.hide) === false; // TODO: report temporary disabled by default
11
12
  const { translate } = (0, hooks_1.useTranslate)();
13
+ const { submitFeedback } = (0, useSubmitFeedback_1.useSubmitFeedback)();
12
14
  const translationKeys = {
13
15
  buttonText: 'theme.codeSnippet.report.buttonText',
14
16
  tooltipText: 'theme.codeSnippet.report.tooltipText',
@@ -32,6 +34,7 @@ function useReportDialog() {
32
34
  },
33
35
  onSubmit: hideReportDialog,
34
36
  onCancel: hideReportDialog,
37
+ submitFeedback,
35
38
  };
36
39
  return {
37
40
  reportDialog: { visible: isReportDialogShown, props: reportDialogProps },
@@ -4,6 +4,7 @@ export type SubmitFeedbackParams = {
4
4
  type: string;
5
5
  values: Record<string, unknown>;
6
6
  path?: string;
7
+ location?: string;
7
8
  };
8
9
  export type FeedbackProps = {
9
10
  type: FEEDBACK_TYPES;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/theme",
3
- "version": "0.25.0",
3
+ "version": "0.25.1",
4
4
  "description": "Shared UI components lib",
5
5
  "keywords": [
6
6
  "theme",
@@ -142,7 +142,6 @@ export function CodeBlockControls({
142
142
  asIcon={controlsType === 'icon'}
143
143
  title={report.tooltipText}
144
144
  {...report.props}
145
- onClick={() => telemetry.send('code_snippet_reported', {})}
146
145
  >
147
146
  {controlsType === 'icon' ? <ReportIcon /> : report.props?.buttonText || 'Report'}
148
147
  </CodeBlockControlButton>
@@ -15,6 +15,8 @@ export const Feedback = (props: FeedbackProps & { path?: string }) => {
15
15
  const feedbackConf = { ...themeFeedbackConf, ...props };
16
16
 
17
17
  const renderFeedbackComponent = () => {
18
+ const { type, settings, path } = feedbackConf;
19
+
18
20
  switch (type) {
19
21
  case 'rating':
20
22
  return (
@@ -70,8 +72,6 @@ export const Feedback = (props: FeedbackProps & { path?: string }) => {
70
72
  }
71
73
  };
72
74
 
73
- const { type, settings, path } = feedbackConf;
74
-
75
75
  return <React.Fragment key={pathname}>{renderFeedbackComponent()}</React.Fragment>;
76
76
  };
77
77
 
@@ -15,6 +15,7 @@ export enum MOOD_STATES {
15
15
  export const Mood = ({ settings, onSubmit, className }: MoodProps): JSX.Element => {
16
16
  const { label, submitText, comment: commentSettings, reasons: reasonsSettings } = settings || {};
17
17
  const [score, setScore] = React.useState('');
18
+ const [isSubmitted, setIsSubmitted] = React.useState(false);
18
19
  const [comment, setComment] = React.useState('');
19
20
  const [reasons, setReasons] = React.useState([] as ReasonsProps['settings']['items']);
20
21
  const { translate } = useTranslate();
@@ -68,11 +69,16 @@ export const Mood = ({ settings, onSubmit, className }: MoodProps): JSX.Element
68
69
  }
69
70
 
70
71
  if (score) {
71
- onSubmit({
72
- score,
73
- comment,
74
- reasons,
75
- });
72
+ if (!isSubmitted) {
73
+ onSubmit({
74
+ score,
75
+ comment,
76
+ reasons,
77
+ });
78
+
79
+ setIsSubmitted(true);
80
+ }
81
+
76
82
  return (
77
83
  <Wrapper>
78
84
  <Label data-translation-key={translationKeys.submitText}>
@@ -18,6 +18,7 @@ export const Rating = ({ settings, onSubmit, className }: RatingProps): JSX.Elem
18
18
  comment: commentSettings,
19
19
  reasons: reasonsSettings,
20
20
  } = settings || {};
21
+ const [isSubmitted, setIsSubmitted] = React.useState(false);
21
22
  const [score, setScore] = React.useState(0);
22
23
  const [comment, setComment] = React.useState('');
23
24
  const [reasons, setReasons] = React.useState([] as ReasonsProps['settings']['items']);
@@ -49,12 +50,16 @@ export const Rating = ({ settings, onSubmit, className }: RatingProps): JSX.Elem
49
50
  }
50
51
 
51
52
  if (score) {
52
- onSubmit({
53
- score,
54
- comment,
55
- reasons,
56
- max: maxRating,
57
- });
53
+ if (!isSubmitted) {
54
+ onSubmit({
55
+ score,
56
+ comment,
57
+ reasons,
58
+ max: maxRating,
59
+ });
60
+ setIsSubmitted(true);
61
+ }
62
+
58
63
  return (
59
64
  <Wrapper>
60
65
  <Label data-translation-key={translationKeys.submitText}>
@@ -1,6 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import styled from 'styled-components';
3
+ import { useLocation } from 'react-router-dom';
3
4
 
5
+ import { telemetry } from '@portal/telemetry';
4
6
  import { Comment } from '@theme/components/Feedback/Comment';
5
7
  import type { ReportDialogProps } from '@theme/components/Feedback';
6
8
 
@@ -12,13 +14,15 @@ export const ReportDialog = ({
12
14
  submitFeedback,
13
15
  }: ReportDialogProps): JSX.Element => {
14
16
  const { label } = settings;
17
+ const { pathname } = useLocation();
15
18
 
16
19
  return (
17
20
  <Wrapper className="modal">
18
21
  <Comment
19
22
  settings={{ label }}
20
- onSubmit={(value) => {
21
- submitFeedback({ type: 'problem', values: value, path: location });
23
+ onSubmit={async (value) => {
24
+ await submitFeedback({ type: 'problem', values: value, location, path: pathname });
25
+ telemetry.send('code_snippet_reported', {});
22
26
  onSubmit();
23
27
  }}
24
28
  onCancel={onCancel}
@@ -8,6 +8,7 @@ import { useTranslate } from '@portal/hooks';
8
8
 
9
9
  export const Sentiment = ({ settings, onSubmit, className }: SentimentProps): JSX.Element => {
10
10
  const { label, submitText, comment: commentSettings, reasons: reasonsSettings } = settings || {};
11
+ const [isSubmitted, setIsSubmitted] = React.useState(false);
11
12
  const [score, setScore] = React.useState(0);
12
13
  const [comment, setComment] = React.useState('');
13
14
  const [reasons, setReasons] = React.useState([] as ReasonsProps['settings']['items']);
@@ -47,11 +48,14 @@ export const Sentiment = ({ settings, onSubmit, className }: SentimentProps): JS
47
48
  }
48
49
 
49
50
  if (score) {
50
- onSubmit({
51
- score,
52
- comment,
53
- reasons,
54
- });
51
+ if (!isSubmitted) {
52
+ onSubmit({
53
+ score,
54
+ comment,
55
+ reasons,
56
+ });
57
+ setIsSubmitted(true);
58
+ }
55
59
  return (
56
60
  <Wrapper>
57
61
  <Label data-translation-key={translationKeys.submitText}>
@@ -90,6 +90,6 @@ export type ReportDialogProps = {
90
90
  settings: {
91
91
  label?: string;
92
92
  };
93
- submitFeedback: ({ type, values, path }: SubmitFeedbackParams) => Promise<void>;
93
+ submitFeedback: ({ type, values, path, location }: SubmitFeedbackParams) => Promise<void>;
94
94
  className?: string;
95
95
  };
@@ -3,6 +3,7 @@ import { useState } from 'react';
3
3
  import type { ReportDialogProps } from '@theme/components/Feedback/types';
4
4
  import { useTranslate } from '@portal/hooks';
5
5
  import { useThemeConfig } from '@theme/hooks';
6
+ import { useSubmitFeedback } from '@portal/Feedback/useSubmitFeedback';
6
7
 
7
8
  export interface ReportButtonProps {
8
9
  onClick: () => void;
@@ -20,6 +21,7 @@ export function useReportDialog(): Record<string, ReportComponentsProps> {
20
21
  const [isReportDialogShown, setIsReportDialogShown] = useState(false);
21
22
  const isReportButtonShown = report?.hide === false; // TODO: report temporary disabled by default
22
23
  const { translate } = useTranslate();
24
+ const { submitFeedback } = useSubmitFeedback();
23
25
  const translationKeys = {
24
26
  buttonText: 'theme.codeSnippet.report.buttonText',
25
27
  tooltipText: 'theme.codeSnippet.report.tooltipText',
@@ -44,6 +46,7 @@ export function useReportDialog(): Record<string, ReportComponentsProps> {
44
46
  },
45
47
  onSubmit: hideReportDialog,
46
48
  onCancel: hideReportDialog,
49
+ submitFeedback,
47
50
  };
48
51
 
49
52
  return {
@@ -6,6 +6,7 @@ export type SubmitFeedbackParams = {
6
6
  type: string;
7
7
  values: Record<string, unknown>;
8
8
  path?: string;
9
+ location?: string;
9
10
  };
10
11
 
11
12
  export type FeedbackProps = {