@drodil/backstage-plugin-qeta-react 2.14.0 → 3.0.0
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/dist/api.esm.js +8 -0
- package/dist/api.esm.js.map +1 -0
- package/dist/components/AnswerCard/AnswerCard.esm.js +113 -0
- package/dist/components/AnswerCard/AnswerCard.esm.js.map +1 -0
- package/dist/components/AnswerForm/AnswerForm.esm.js +153 -0
- package/dist/components/AnswerForm/AnswerForm.esm.js.map +1 -0
- package/dist/components/AnswersContainer/AnswerList.esm.js +100 -0
- package/dist/components/AnswersContainer/AnswerList.esm.js.map +1 -0
- package/dist/components/AnswersContainer/AnswerListItem.esm.js +90 -0
- package/dist/components/AnswersContainer/AnswerListItem.esm.js.map +1 -0
- package/dist/components/AnswersContainer/AnswersContainer.esm.js +210 -0
- package/dist/components/AnswersContainer/AnswersContainer.esm.js.map +1 -0
- package/dist/components/ArticleContent/ArticleButtons.esm.js +90 -0
- package/dist/components/ArticleContent/ArticleButtons.esm.js.map +1 -0
- package/dist/components/ArticleContent/ArticleContent.esm.js +78 -0
- package/dist/components/ArticleContent/ArticleContent.esm.js.map +1 -0
- package/dist/components/AuthorBox/AuthorBox.esm.js +25 -0
- package/dist/components/AuthorBox/AuthorBox.esm.js.map +1 -0
- package/dist/components/Buttons/AddToCollectionButton.esm.js +68 -0
- package/dist/components/Buttons/AddToCollectionButton.esm.js.map +1 -0
- package/dist/components/Buttons/AskQuestionButton.esm.js +40 -0
- package/dist/components/Buttons/AskQuestionButton.esm.js.map +1 -0
- package/dist/components/Buttons/BackToArticlesButton.esm.js +40 -0
- package/dist/components/Buttons/BackToArticlesButton.esm.js.map +1 -0
- package/dist/components/Buttons/BackToCollectionsButton.esm.js +25 -0
- package/dist/components/Buttons/BackToCollectionsButton.esm.js.map +1 -0
- package/dist/components/Buttons/BackToQuestionsButton.esm.js +40 -0
- package/dist/components/Buttons/BackToQuestionsButton.esm.js.map +1 -0
- package/dist/components/Buttons/CreateCollectionButton.esm.js +29 -0
- package/dist/components/Buttons/CreateCollectionButton.esm.js.map +1 -0
- package/dist/components/Buttons/EntityFollowButton.esm.js +34 -0
- package/dist/components/Buttons/EntityFollowButton.esm.js.map +1 -0
- package/dist/components/Buttons/FavoriteButton.esm.js +45 -0
- package/dist/components/Buttons/FavoriteButton.esm.js.map +1 -0
- package/dist/components/Buttons/LinkButton.esm.js +28 -0
- package/dist/components/Buttons/LinkButton.esm.js.map +1 -0
- package/dist/components/Buttons/TagFollowButton.esm.js +34 -0
- package/dist/components/Buttons/TagFollowButton.esm.js.map +1 -0
- package/dist/components/Buttons/VoteButtons.esm.js +75 -0
- package/dist/components/Buttons/VoteButtons.esm.js.map +1 -0
- package/dist/components/Buttons/WriteArticleButton.esm.js +40 -0
- package/dist/components/Buttons/WriteArticleButton.esm.js.map +1 -0
- package/dist/components/CollectionCard/CollectionCard.esm.js +63 -0
- package/dist/components/CollectionCard/CollectionCard.esm.js.map +1 -0
- package/dist/components/CollectionForm/CollectionForm.esm.js +251 -0
- package/dist/components/CollectionForm/CollectionForm.esm.js.map +1 -0
- package/dist/components/CollectionsGrid/CollectionsGrid.esm.js +40 -0
- package/dist/components/CollectionsGrid/CollectionsGrid.esm.js.map +1 -0
- package/dist/components/CollectionsGrid/CollectionsGridContent.esm.js +67 -0
- package/dist/components/CollectionsGrid/CollectionsGridContent.esm.js.map +1 -0
- package/dist/components/CollectionsGrid/CollectionsGridItem.esm.js +48 -0
- package/dist/components/CollectionsGrid/CollectionsGridItem.esm.js.map +1 -0
- package/dist/components/CommentSection/CommentList.esm.js +47 -0
- package/dist/components/CommentSection/CommentList.esm.js.map +1 -0
- package/dist/components/CommentSection/CommentSection.esm.js +126 -0
- package/dist/components/CommentSection/CommentSection.esm.js.map +1 -0
- package/dist/components/DeleteModal/DeleteModal.esm.js +88 -0
- package/dist/components/DeleteModal/DeleteModal.esm.js.map +1 -0
- package/dist/components/EntitiesGrid/EntitiesGrid.esm.js +45 -0
- package/dist/components/EntitiesGrid/EntitiesGrid.esm.js.map +1 -0
- package/dist/components/EntitiesGrid/EntitiesGridItem.esm.js +61 -0
- package/dist/components/EntitiesGrid/EntitiesGridItem.esm.js.map +1 -0
- package/dist/components/FilterPanel/DateRangeFilter.esm.js +110 -0
- package/dist/components/FilterPanel/DateRangeFilter.esm.js.map +1 -0
- package/dist/components/FilterPanel/FilterPanel.esm.js +238 -0
- package/dist/components/FilterPanel/FilterPanel.esm.js.map +1 -0
- package/dist/components/FollowedLists/FollowedEntitiesList.esm.js +43 -0
- package/dist/components/FollowedLists/FollowedEntitiesList.esm.js.map +1 -0
- package/dist/components/FollowedLists/FollowedTagsList.esm.js +43 -0
- package/dist/components/FollowedLists/FollowedTagsList.esm.js.map +1 -0
- package/dist/components/HomePageCards/ImpactCard.esm.js +22 -0
- package/dist/components/HomePageCards/ImpactCard.esm.js.map +1 -0
- package/dist/components/HomePageCards/PostsCard.esm.js +42 -0
- package/dist/components/HomePageCards/PostsCard.esm.js.map +1 -0
- package/dist/components/Links/Links.esm.js +33 -0
- package/dist/components/Links/Links.esm.js.map +1 -0
- package/dist/components/MarkdownEditor/MarkdownEditor.esm.js +63 -0
- package/dist/components/MarkdownEditor/MarkdownEditor.esm.js.map +1 -0
- package/dist/components/MarkdownRenderer/MarkdownRenderer.esm.js +97 -0
- package/dist/components/MarkdownRenderer/MarkdownRenderer.esm.js.map +1 -0
- package/dist/components/PostAnonymouslyCheckbox/PostAnonymouslyCheckbox.esm.js +34 -0
- package/dist/components/PostAnonymouslyCheckbox/PostAnonymouslyCheckbox.esm.js.map +1 -0
- package/dist/components/PostForm/EntitiesInput.esm.js +100 -0
- package/dist/components/PostForm/EntitiesInput.esm.js.map +1 -0
- package/dist/components/PostForm/PostForm.esm.js +283 -0
- package/dist/components/PostForm/PostForm.esm.js.map +1 -0
- package/dist/components/PostForm/TagInput.esm.js +81 -0
- package/dist/components/PostForm/TagInput.esm.js.map +1 -0
- package/dist/components/PostHighlightList/PostHighlightList.esm.js +72 -0
- package/dist/components/PostHighlightList/PostHighlightList.esm.js.map +1 -0
- package/dist/components/PostsContainer/NoPostsCard.esm.js +50 -0
- package/dist/components/PostsContainer/NoPostsCard.esm.js.map +1 -0
- package/dist/components/PostsContainer/PostList.esm.js +113 -0
- package/dist/components/PostsContainer/PostList.esm.js.map +1 -0
- package/dist/components/PostsContainer/PostListItem.esm.js +138 -0
- package/dist/components/PostsContainer/PostListItem.esm.js.map +1 -0
- package/dist/components/PostsContainer/PostsContainer.esm.js +152 -0
- package/dist/components/PostsContainer/PostsContainer.esm.js.map +1 -0
- package/dist/components/PostsGrid/PostsGrid.esm.js +146 -0
- package/dist/components/PostsGrid/PostsGrid.esm.js.map +1 -0
- package/dist/components/PostsGrid/PostsGridContent.esm.js +90 -0
- package/dist/components/PostsGrid/PostsGridContent.esm.js.map +1 -0
- package/dist/components/PostsGrid/PostsGridItem.esm.js +57 -0
- package/dist/components/PostsGrid/PostsGridItem.esm.js.map +1 -0
- package/dist/components/QuestionCard/QuestionCard.esm.js +107 -0
- package/dist/components/QuestionCard/QuestionCard.esm.js.map +1 -0
- package/dist/components/QuestionsTable/QuestionTableRow.esm.js +21 -0
- package/dist/components/QuestionsTable/QuestionTableRow.esm.js.map +1 -0
- package/dist/components/QuestionsTable/QuestionsTable.esm.js +131 -0
- package/dist/components/QuestionsTable/QuestionsTable.esm.js.map +1 -0
- package/dist/components/RelativeTimeWithTooltip/RelativeTimeWithTooltip.esm.js +22 -0
- package/dist/components/RelativeTimeWithTooltip/RelativeTimeWithTooltip.esm.js.map +1 -0
- package/dist/components/StatsChart/StatsChart.esm.js +245 -0
- package/dist/components/StatsChart/StatsChart.esm.js.map +1 -0
- package/dist/components/SummaryStatsGrid/SummaryStatsGrid.esm.js +53 -0
- package/dist/components/SummaryStatsGrid/SummaryStatsGrid.esm.js.map +1 -0
- package/dist/components/TagsAndEntities/EntityChip.esm.js +80 -0
- package/dist/components/TagsAndEntities/EntityChip.esm.js.map +1 -0
- package/dist/components/TagsAndEntities/TagChip.esm.js +78 -0
- package/dist/components/TagsAndEntities/TagChip.esm.js.map +1 -0
- package/dist/components/TagsAndEntities/TagsAndEntities.esm.js +32 -0
- package/dist/components/TagsAndEntities/TagsAndEntities.esm.js.map +1 -0
- package/dist/components/TagsGrid/EditTagModal.esm.js +73 -0
- package/dist/components/TagsGrid/EditTagModal.esm.js.map +1 -0
- package/dist/components/TagsGrid/TagGridItem.esm.js +56 -0
- package/dist/components/TagsGrid/TagGridItem.esm.js.map +1 -0
- package/dist/components/TagsGrid/TagsGrid.esm.js +45 -0
- package/dist/components/TagsGrid/TagsGrid.esm.js.map +1 -0
- package/dist/components/TopRankingUsersCard/TopRankingUsersCard.esm.js +161 -0
- package/dist/components/TopRankingUsersCard/TopRankingUsersCard.esm.js.map +1 -0
- package/dist/components/TopRankingUsersCard/TrophyIcon.esm.js +19 -0
- package/dist/components/TopRankingUsersCard/TrophyIcon.esm.js.map +1 -0
- package/dist/components/TopRankingUsersCard/styles.esm.js +23 -0
- package/dist/components/TopRankingUsersCard/styles.esm.js.map +1 -0
- package/dist/components/UsersGrid/UsersGrid.esm.js +43 -0
- package/dist/components/UsersGrid/UsersGrid.esm.js.map +1 -0
- package/dist/components/UsersGrid/UsersGridItem.esm.js +66 -0
- package/dist/components/UsersGrid/UsersGridItem.esm.js.map +1 -0
- package/dist/index.d.ts +568 -1
- package/dist/index.esm.js +45 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/routes.esm.js +56 -1
- package/dist/routes.esm.js.map +1 -1
- package/dist/translation.esm.js +470 -0
- package/dist/translation.esm.js.map +1 -0
- package/dist/utils/hooks.esm.js +734 -0
- package/dist/utils/hooks.esm.js.map +1 -0
- package/dist/utils/utils.esm.js +93 -0
- package/dist/utils/utils.esm.js.map +1 -0
- package/package.json +32 -5
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { useRouteRef, useAnalytics, useApi, configApiRef, errorApiRef } from '@backstage/core-plugin-api';
|
|
2
|
+
import { Button, TextField, Grid, FormControl, FormHelperText, Select, MenuItem } from '@material-ui/core';
|
|
3
|
+
import { Alert } from '@material-ui/lab';
|
|
4
|
+
import React, { useEffect, useCallback } from 'react';
|
|
5
|
+
import { useForm, Controller } from 'react-hook-form';
|
|
6
|
+
import { useNavigate } from 'react-router-dom';
|
|
7
|
+
import { useTranslation, useStyles } from '../../utils/hooks.esm.js';
|
|
8
|
+
import { MarkdownEditor } from '../MarkdownEditor/MarkdownEditor.esm.js';
|
|
9
|
+
import { collectionRouteRef } from '../../routes.esm.js';
|
|
10
|
+
import { confirmNavigationIfEdited, imageUpload } from '../../utils/utils.esm.js';
|
|
11
|
+
import { qetaApiRef } from '../../api.esm.js';
|
|
12
|
+
|
|
13
|
+
const formToRequest = (form, images, headerImage) => {
|
|
14
|
+
return {
|
|
15
|
+
...form,
|
|
16
|
+
images,
|
|
17
|
+
headerImage
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const getDefaultValues = () => {
|
|
21
|
+
return {
|
|
22
|
+
title: "",
|
|
23
|
+
readAccess: "private",
|
|
24
|
+
editAccess: "private"
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const getValues = async (api, id) => {
|
|
28
|
+
if (!id) {
|
|
29
|
+
return { form: getDefaultValues() };
|
|
30
|
+
}
|
|
31
|
+
const collection = await api.getCollection(id);
|
|
32
|
+
return {
|
|
33
|
+
form: {
|
|
34
|
+
title: collection.title,
|
|
35
|
+
description: collection.description,
|
|
36
|
+
editAccess: collection.editAccess,
|
|
37
|
+
readAccess: collection.readAccess,
|
|
38
|
+
headerImage: collection.headerImage
|
|
39
|
+
},
|
|
40
|
+
collection
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const CollectionForm = (props) => {
|
|
44
|
+
const { id, onPost } = props;
|
|
45
|
+
const collectionRoute = useRouteRef(collectionRouteRef);
|
|
46
|
+
const navigate = useNavigate();
|
|
47
|
+
const analytics = useAnalytics();
|
|
48
|
+
const [posting, setPosting] = React.useState(false);
|
|
49
|
+
const [values, setValues] = React.useState(getDefaultValues());
|
|
50
|
+
const [error, setError] = React.useState(false);
|
|
51
|
+
const [edited, setEdited] = React.useState(false);
|
|
52
|
+
const [headerImage, setHeaderImage] = React.useState();
|
|
53
|
+
const [canModifyAccess, setCanModifyAccess] = React.useState(true);
|
|
54
|
+
const [images, setImages] = React.useState([]);
|
|
55
|
+
const { t } = useTranslation();
|
|
56
|
+
const qetaApi = useApi(qetaApiRef);
|
|
57
|
+
const configApi = useApi(configApiRef);
|
|
58
|
+
const errorApi = useApi(errorApiRef);
|
|
59
|
+
const styles = useStyles();
|
|
60
|
+
const isUploadDisabled = configApi.getOptionalBoolean("qeta.storage.disabled") || false;
|
|
61
|
+
const {
|
|
62
|
+
register,
|
|
63
|
+
handleSubmit,
|
|
64
|
+
control,
|
|
65
|
+
reset,
|
|
66
|
+
formState: { errors }
|
|
67
|
+
} = useForm({
|
|
68
|
+
values,
|
|
69
|
+
defaultValues: getDefaultValues()
|
|
70
|
+
});
|
|
71
|
+
const postQuestion = (data) => {
|
|
72
|
+
setPosting(true);
|
|
73
|
+
if (id) {
|
|
74
|
+
qetaApi.updateCollection(Number(id), formToRequest(data, images, headerImage)).then((q) => {
|
|
75
|
+
if (!q || !q.id) {
|
|
76
|
+
setError(true);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
setEdited(false);
|
|
80
|
+
reset();
|
|
81
|
+
analytics.captureEvent("edit", "collection");
|
|
82
|
+
if (onPost) {
|
|
83
|
+
onPost(q);
|
|
84
|
+
} else {
|
|
85
|
+
navigate(collectionRoute({ id: q.id.toString(10) }));
|
|
86
|
+
}
|
|
87
|
+
}).catch((_e) => {
|
|
88
|
+
setError(true);
|
|
89
|
+
setPosting(false);
|
|
90
|
+
});
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
qetaApi.createCollection(formToRequest(data, images, headerImage)).then((q) => {
|
|
94
|
+
if (!q || !q.id) {
|
|
95
|
+
setError(true);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
setEdited(false);
|
|
99
|
+
analytics.captureEvent("post", "collection");
|
|
100
|
+
reset();
|
|
101
|
+
navigate(collectionRoute({ id: q.id.toString(10) }));
|
|
102
|
+
}).catch((_e) => {
|
|
103
|
+
setError(true);
|
|
104
|
+
setPosting(false);
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (id) {
|
|
109
|
+
getValues(qetaApi, id).then((data) => {
|
|
110
|
+
setValues(data.form);
|
|
111
|
+
setHeaderImage(data.form.headerImage);
|
|
112
|
+
setCanModifyAccess(data.collection?.canDelete ?? false);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}, [qetaApi, id]);
|
|
116
|
+
useEffect(() => {
|
|
117
|
+
reset(values);
|
|
118
|
+
}, [values, reset]);
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
return confirmNavigationIfEdited(edited);
|
|
121
|
+
}, [edited]);
|
|
122
|
+
const onImageUpload = useCallback(
|
|
123
|
+
(imageId) => {
|
|
124
|
+
setImages((prevImages) => [...prevImages, imageId]);
|
|
125
|
+
},
|
|
126
|
+
[setImages]
|
|
127
|
+
);
|
|
128
|
+
return /* @__PURE__ */ React.createElement(
|
|
129
|
+
"form",
|
|
130
|
+
{
|
|
131
|
+
onSubmit: handleSubmit(postQuestion),
|
|
132
|
+
onChange: () => {
|
|
133
|
+
setEdited(true);
|
|
134
|
+
},
|
|
135
|
+
className: "qetaAskForm"
|
|
136
|
+
},
|
|
137
|
+
error && /* @__PURE__ */ React.createElement(Alert, { severity: "error" }, t("collectionForm.errorPosting")),
|
|
138
|
+
!isUploadDisabled && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(
|
|
139
|
+
"input",
|
|
140
|
+
{
|
|
141
|
+
accept: "image/*",
|
|
142
|
+
style: { display: "none" },
|
|
143
|
+
id: "headerImage",
|
|
144
|
+
type: "file",
|
|
145
|
+
onChange: async (event) => {
|
|
146
|
+
if (!event.target.files || event.target.files.length === 0) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const buffer = await event.target.files[0].arrayBuffer();
|
|
150
|
+
const uri = await imageUpload({
|
|
151
|
+
qetaApi,
|
|
152
|
+
errorApi,
|
|
153
|
+
onImageUpload
|
|
154
|
+
})(buffer).next();
|
|
155
|
+
if (typeof uri.value === "string") {
|
|
156
|
+
setHeaderImage(uri.value);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
), /* @__PURE__ */ React.createElement("label", { htmlFor: "headerImage" }, /* @__PURE__ */ React.createElement(Button, { variant: "contained", color: "primary", component: "span" }, t("collectionForm.uploadHeaderImage")))),
|
|
161
|
+
headerImage && /* @__PURE__ */ React.createElement("img", { className: styles.headerImage, src: headerImage, alt: "header" }),
|
|
162
|
+
/* @__PURE__ */ React.createElement(
|
|
163
|
+
TextField,
|
|
164
|
+
{
|
|
165
|
+
label: "Title",
|
|
166
|
+
className: "qetaCollectionFormTitle",
|
|
167
|
+
required: true,
|
|
168
|
+
fullWidth: true,
|
|
169
|
+
error: "title" in errors,
|
|
170
|
+
margin: "normal",
|
|
171
|
+
variant: "outlined",
|
|
172
|
+
helperText: t("collectionForm.titleInput.helperText"),
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
...register("title", { required: true, maxLength: 255 })
|
|
175
|
+
}
|
|
176
|
+
),
|
|
177
|
+
/* @__PURE__ */ React.createElement(
|
|
178
|
+
Controller,
|
|
179
|
+
{
|
|
180
|
+
control,
|
|
181
|
+
rules: {
|
|
182
|
+
required: false
|
|
183
|
+
},
|
|
184
|
+
render: ({ field: { onChange, value } }) => /* @__PURE__ */ React.createElement(
|
|
185
|
+
MarkdownEditor,
|
|
186
|
+
{
|
|
187
|
+
value: value ?? "",
|
|
188
|
+
onChange,
|
|
189
|
+
height: 400,
|
|
190
|
+
error: "content" in errors,
|
|
191
|
+
placeholder: t("collectionForm.descriptionInput.placeholder"),
|
|
192
|
+
config: configApi,
|
|
193
|
+
onImageUpload
|
|
194
|
+
}
|
|
195
|
+
),
|
|
196
|
+
name: "description"
|
|
197
|
+
}
|
|
198
|
+
),
|
|
199
|
+
/* @__PURE__ */ React.createElement(Grid, { container: true, style: { marginTop: "1rem", marginBottom: "1rem" } }, /* @__PURE__ */ React.createElement(Grid, { item: true }, /* @__PURE__ */ React.createElement(
|
|
200
|
+
Controller,
|
|
201
|
+
{
|
|
202
|
+
control,
|
|
203
|
+
rules: { required: true },
|
|
204
|
+
render: ({ field: { onChange, value } }) => /* @__PURE__ */ React.createElement(FormControl, null, /* @__PURE__ */ React.createElement(FormHelperText, null, "Read access"), /* @__PURE__ */ React.createElement(
|
|
205
|
+
Select,
|
|
206
|
+
{
|
|
207
|
+
variant: "outlined",
|
|
208
|
+
onChange,
|
|
209
|
+
value,
|
|
210
|
+
disabled: !canModifyAccess
|
|
211
|
+
},
|
|
212
|
+
/* @__PURE__ */ React.createElement(MenuItem, { value: "private" }, "Only you"),
|
|
213
|
+
/* @__PURE__ */ React.createElement(MenuItem, { value: "public" }, "Anyone")
|
|
214
|
+
)),
|
|
215
|
+
name: "readAccess"
|
|
216
|
+
}
|
|
217
|
+
)), /* @__PURE__ */ React.createElement(Grid, { item: true }, /* @__PURE__ */ React.createElement(
|
|
218
|
+
Controller,
|
|
219
|
+
{
|
|
220
|
+
control,
|
|
221
|
+
rules: { required: true },
|
|
222
|
+
render: ({ field: { onChange, value } }) => /* @__PURE__ */ React.createElement(FormControl, null, /* @__PURE__ */ React.createElement(FormHelperText, null, "Edit access"), /* @__PURE__ */ React.createElement(
|
|
223
|
+
Select,
|
|
224
|
+
{
|
|
225
|
+
variant: "outlined",
|
|
226
|
+
onChange,
|
|
227
|
+
value,
|
|
228
|
+
disabled: !canModifyAccess
|
|
229
|
+
},
|
|
230
|
+
/* @__PURE__ */ React.createElement(MenuItem, { value: "private" }, "Only you"),
|
|
231
|
+
/* @__PURE__ */ React.createElement(MenuItem, { value: "public" }, "Anyone")
|
|
232
|
+
)),
|
|
233
|
+
name: "editAccess"
|
|
234
|
+
}
|
|
235
|
+
))),
|
|
236
|
+
/* @__PURE__ */ React.createElement(
|
|
237
|
+
Button,
|
|
238
|
+
{
|
|
239
|
+
color: "primary",
|
|
240
|
+
type: "submit",
|
|
241
|
+
variant: "contained",
|
|
242
|
+
disabled: posting,
|
|
243
|
+
className: `qetaCollectionFormSubmitBtn ${styles.postButton}`
|
|
244
|
+
},
|
|
245
|
+
id ? t("collectionForm.submit.existingCollection") : t("collectionForm.submit.newCollection")
|
|
246
|
+
)
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export { CollectionForm };
|
|
251
|
+
//# sourceMappingURL=CollectionForm.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CollectionForm.esm.js","sources":["../../../src/components/CollectionForm/CollectionForm.tsx"],"sourcesContent":["import {\n configApiRef,\n errorApiRef,\n useAnalytics,\n useApi,\n useRouteRef,\n} from '@backstage/core-plugin-api';\nimport {\n Button,\n FormControl,\n FormHelperText,\n Grid,\n MenuItem,\n Select,\n TextField,\n} from '@material-ui/core';\nimport { Alert } from '@material-ui/lab';\nimport React, { useCallback, useEffect } from 'react';\nimport { Controller, useForm } from 'react-hook-form';\nimport { useNavigate } from 'react-router-dom';\nimport {\n CollectionRequest,\n CollectionResponse,\n QetaApi,\n} from '@drodil/backstage-plugin-qeta-common';\nimport { useStyles, useTranslation } from '../../utils';\nimport { MarkdownEditor } from '../MarkdownEditor/MarkdownEditor';\nimport { collectionRouteRef } from '../../routes';\nimport { confirmNavigationIfEdited, imageUpload } from '../../utils/utils';\nimport { qetaApiRef } from '../../api';\nimport { CollectionFormData } from './types';\n\nconst formToRequest = (\n form: CollectionFormData,\n images: number[],\n headerImage?: string,\n): CollectionRequest => {\n return {\n ...form,\n images,\n headerImage,\n };\n};\n\nexport type CollectionFormProps = {\n id?: string;\n onPost?: (collection: CollectionResponse) => void;\n};\n\nconst getDefaultValues = (): CollectionFormData => {\n return {\n title: '',\n readAccess: 'private',\n editAccess: 'private',\n };\n};\n\nconst getValues = async (\n api: QetaApi,\n id?: string,\n): Promise<{ form: CollectionFormData; collection?: CollectionResponse }> => {\n if (!id) {\n return { form: getDefaultValues() };\n }\n\n const collection = await api.getCollection(id);\n return {\n form: {\n title: collection.title,\n description: collection.description,\n editAccess: collection.editAccess,\n readAccess: collection.readAccess,\n headerImage: collection.headerImage,\n },\n collection,\n };\n};\n\nexport const CollectionForm = (props: CollectionFormProps) => {\n const { id, onPost } = props;\n const collectionRoute = useRouteRef(collectionRouteRef);\n const navigate = useNavigate();\n const analytics = useAnalytics();\n const [posting, setPosting] = React.useState(false);\n const [values, setValues] = React.useState(getDefaultValues());\n const [error, setError] = React.useState(false);\n const [edited, setEdited] = React.useState(false);\n const [headerImage, setHeaderImage] = React.useState<string | undefined>();\n const [canModifyAccess, setCanModifyAccess] = React.useState(true);\n\n const [images, setImages] = React.useState<number[]>([]);\n const { t } = useTranslation();\n\n const qetaApi = useApi(qetaApiRef);\n const configApi = useApi(configApiRef);\n const errorApi = useApi(errorApiRef);\n const styles = useStyles();\n const isUploadDisabled =\n configApi.getOptionalBoolean('qeta.storage.disabled') || false;\n const {\n register,\n handleSubmit,\n control,\n reset,\n formState: { errors },\n } = useForm<CollectionFormData>({\n values,\n defaultValues: getDefaultValues(),\n });\n\n const postQuestion = (data: CollectionFormData) => {\n setPosting(true);\n\n if (id) {\n qetaApi\n .updateCollection(Number(id), formToRequest(data, images, headerImage))\n .then(q => {\n if (!q || !q.id) {\n setError(true);\n return;\n }\n setEdited(false);\n reset();\n analytics.captureEvent('edit', 'collection');\n if (onPost) {\n onPost(q);\n } else {\n navigate(collectionRoute({ id: q.id.toString(10) }));\n }\n })\n .catch(_e => {\n setError(true);\n setPosting(false);\n });\n return;\n }\n qetaApi\n .createCollection(formToRequest(data, images, headerImage))\n .then(q => {\n if (!q || !q.id) {\n setError(true);\n return;\n }\n setEdited(false);\n analytics.captureEvent('post', 'collection');\n reset();\n navigate(collectionRoute({ id: q.id.toString(10) }));\n })\n .catch(_e => {\n setError(true);\n setPosting(false);\n });\n };\n\n useEffect(() => {\n if (id) {\n getValues(qetaApi, id).then(data => {\n setValues(data.form);\n setHeaderImage(data.form.headerImage);\n setCanModifyAccess(data.collection?.canDelete ?? false);\n });\n }\n }, [qetaApi, id]);\n\n useEffect(() => {\n reset(values);\n }, [values, reset]);\n\n useEffect(() => {\n return confirmNavigationIfEdited(edited);\n }, [edited]);\n\n const onImageUpload = useCallback(\n (imageId: number) => {\n setImages(prevImages => [...prevImages, imageId]);\n },\n [setImages],\n );\n\n return (\n <form\n onSubmit={handleSubmit(postQuestion)}\n onChange={() => {\n setEdited(true);\n }}\n className=\"qetaAskForm\"\n >\n {error && (\n <Alert severity=\"error\">{t('collectionForm.errorPosting')}</Alert>\n )}\n {!isUploadDisabled && (\n <>\n <input\n accept=\"image/*\"\n style={{ display: 'none' }}\n id=\"headerImage\"\n type=\"file\"\n onChange={async event => {\n if (!event.target.files || event.target.files.length === 0) {\n return;\n }\n const buffer = await event.target.files[0].arrayBuffer();\n\n const uri = await imageUpload({\n qetaApi,\n errorApi,\n onImageUpload,\n })(buffer).next();\n if (typeof uri.value === 'string') {\n setHeaderImage(uri.value);\n }\n }}\n />\n <label htmlFor=\"headerImage\">\n <Button variant=\"contained\" color=\"primary\" component=\"span\">\n {t('collectionForm.uploadHeaderImage')}\n </Button>\n </label>\n </>\n )}\n {headerImage && (\n <img className={styles.headerImage} src={headerImage} alt=\"header\" />\n )}\n <TextField\n label=\"Title\"\n className=\"qetaCollectionFormTitle\"\n required\n fullWidth\n error={'title' in errors}\n margin=\"normal\"\n variant=\"outlined\"\n helperText={t('collectionForm.titleInput.helperText')}\n {\n // @ts-ignore\n ...register('title', { required: true, maxLength: 255 })\n }\n />\n\n <Controller\n control={control}\n rules={{\n required: false,\n }}\n render={({ field: { onChange, value } }) => (\n <MarkdownEditor\n value={value ?? ''}\n onChange={onChange}\n height={400}\n error={'content' in errors}\n placeholder={t('collectionForm.descriptionInput.placeholder')}\n config={configApi}\n onImageUpload={onImageUpload}\n />\n )}\n name=\"description\"\n />\n <Grid container style={{ marginTop: '1rem', marginBottom: '1rem' }}>\n <Grid item>\n <Controller\n control={control}\n rules={{ required: true }}\n render={({ field: { onChange, value } }) => (\n <FormControl>\n <FormHelperText>Read access</FormHelperText>\n <Select\n variant=\"outlined\"\n onChange={onChange}\n value={value}\n disabled={!canModifyAccess}\n >\n <MenuItem value=\"private\">Only you</MenuItem>\n <MenuItem value=\"public\">Anyone</MenuItem>\n </Select>\n </FormControl>\n )}\n name=\"readAccess\"\n />\n </Grid>\n <Grid item>\n <Controller\n control={control}\n rules={{ required: true }}\n render={({ field: { onChange, value } }) => (\n <FormControl>\n <FormHelperText>Edit access</FormHelperText>\n <Select\n variant=\"outlined\"\n onChange={onChange}\n value={value}\n disabled={!canModifyAccess}\n >\n <MenuItem value=\"private\">Only you</MenuItem>\n <MenuItem value=\"public\">Anyone</MenuItem>\n </Select>\n </FormControl>\n )}\n name=\"editAccess\"\n />\n </Grid>\n </Grid>\n <Button\n color=\"primary\"\n type=\"submit\"\n variant=\"contained\"\n disabled={posting}\n className={`qetaCollectionFormSubmitBtn ${styles.postButton}`}\n >\n {id\n ? t('collectionForm.submit.existingCollection')\n : t('collectionForm.submit.newCollection')}\n </Button>\n </form>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AAgCA,MAAM,aAAgB,GAAA,CACpB,IACA,EAAA,MAAA,EACA,WACsB,KAAA;AACtB,EAAO,OAAA;AAAA,IACL,GAAG,IAAA;AAAA,IACH,MAAA;AAAA,IACA,WAAA;AAAA,GACF,CAAA;AACF,CAAA,CAAA;AAOA,MAAM,mBAAmB,MAA0B;AACjD,EAAO,OAAA;AAAA,IACL,KAAO,EAAA,EAAA;AAAA,IACP,UAAY,EAAA,SAAA;AAA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,eAAA;AAAA,WAAA;AAAA,0BAEV,KAAA,CAAA,aAAA,CAAA,QAAA,EAAA,EAAS,KAAM,EAAA,SAAA,EAAA,EAAU,UAAQ,CAAA;AAAA,0BACjC,KAAA,CAAA,aAAA,CAAA,QAAA,EAAA,EAAS,KAAM,EAAA,QAAA,EAAA,EAAS,QAAM,CAAA;AAAA,SAEnC,CAAA;AAAA,QAEF,IAAK,EAAA,YAAA;AAAA,OAAA;AAAA,KAET,CACF,CAAA;AAAA,oBACA,KAAA,CAAA,aAAA;AAAA,MAAC,MAAA;AAAA,MAAA;AAAA,QACC,KAAM,EAAA,SAAA;AAAA,QACN,IAAK,EAAA,QAAA;AAAA,QACL,OAAQ,EAAA,WAAA;AAAA,QACR,QAAU,EAAA,OAAA;AAAA,QACV,SAAA,EAAW,CAA+B,4BAAA,EAAA,MAAA,CAAO,UAAU,CAAA,CAAA;AAAA,OAAA;AAAA,MAE1D,EACG,GAAA,CAAA,CAAE,0CAA0C,CAAA,GAC5C,EAAE,qCAAqC,CAAA;AAAA,KAC7C;AAAA,GACF,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React, { useEffect } from 'react';
|
|
2
|
+
import { useTranslation, useQetaApi } from '../../utils/hooks.esm.js';
|
|
3
|
+
import { Box, Grid, Typography } from '@material-ui/core';
|
|
4
|
+
import { CollectionsGridContent } from './CollectionsGridContent.esm.js';
|
|
5
|
+
|
|
6
|
+
const CollectionsGrid = () => {
|
|
7
|
+
const { t } = useTranslation();
|
|
8
|
+
const [page, setPage] = React.useState(1);
|
|
9
|
+
const [pageCount, setPageCount] = React.useState(1);
|
|
10
|
+
const collectionsPerPage = 20;
|
|
11
|
+
const {
|
|
12
|
+
value: response,
|
|
13
|
+
loading,
|
|
14
|
+
error
|
|
15
|
+
} = useQetaApi((api) => {
|
|
16
|
+
return api.getCollections({
|
|
17
|
+
limit: collectionsPerPage,
|
|
18
|
+
offset: (page - 1) * collectionsPerPage
|
|
19
|
+
});
|
|
20
|
+
}, []);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (response) {
|
|
23
|
+
setPageCount(Math.ceil(response.total / collectionsPerPage));
|
|
24
|
+
}
|
|
25
|
+
}, [response, collectionsPerPage]);
|
|
26
|
+
return /* @__PURE__ */ React.createElement(Box, { className: "qetaCollectionsGrid" }, /* @__PURE__ */ React.createElement(Grid, { container: true, justifyContent: "space-between" }), /* @__PURE__ */ React.createElement(Grid, { container: true, justifyContent: "space-between" }, /* @__PURE__ */ React.createElement(Grid, { item: true }, /* @__PURE__ */ React.createElement(Typography, { variant: "h6", className: "qetaPostsContainerQuestionCount" }, t("common.collections", { count: response?.total ?? 0 })))), /* @__PURE__ */ React.createElement(
|
|
27
|
+
CollectionsGridContent,
|
|
28
|
+
{
|
|
29
|
+
loading,
|
|
30
|
+
error,
|
|
31
|
+
response,
|
|
32
|
+
page,
|
|
33
|
+
pageCount,
|
|
34
|
+
onPageChange: setPage
|
|
35
|
+
}
|
|
36
|
+
));
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { CollectionsGrid };
|
|
40
|
+
//# sourceMappingURL=CollectionsGrid.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CollectionsGrid.esm.js","sources":["../../../src/components/CollectionsGrid/CollectionsGrid.tsx"],"sourcesContent":["import React, { useEffect } from 'react';\nimport { useQetaApi, useTranslation } from '../../utils';\nimport { Box, Grid, Typography } from '@material-ui/core';\nimport { CollectionsGridContent } from './CollectionsGridContent';\n\nexport const CollectionsGrid = () => {\n const { t } = useTranslation();\n const [page, setPage] = React.useState(1);\n const [pageCount, setPageCount] = React.useState(1);\n const collectionsPerPage = 20;\n\n const {\n value: response,\n loading,\n error,\n } = useQetaApi(api => {\n return api.getCollections({\n limit: collectionsPerPage,\n offset: (page - 1) * collectionsPerPage,\n });\n }, []);\n\n useEffect(() => {\n if (response) {\n setPageCount(Math.ceil(response.total / collectionsPerPage));\n }\n }, [response, collectionsPerPage]);\n\n return (\n <Box className=\"qetaCollectionsGrid\">\n <Grid container justifyContent=\"space-between\" />\n <Grid container justifyContent=\"space-between\">\n <Grid item>\n <Typography variant=\"h6\" className=\"qetaPostsContainerQuestionCount\">\n {t('common.collections', { count: response?.total ?? 0 })}\n </Typography>\n </Grid>\n </Grid>\n <CollectionsGridContent\n loading={loading}\n error={error}\n response={response}\n page={page}\n pageCount={pageCount}\n onPageChange={setPage}\n />\n </Box>\n );\n};\n"],"names":[],"mappings":";;;;;AAKO,MAAM,kBAAkB,MAAM;AACnC,EAAM,MAAA,EAAE,CAAE,EAAA,GAAI,cAAe,EAAA,CAAA;AAC7B,EAAA,MAAM,CAAC,IAAM,EAAA,OAAO,CAAI,GAAA,KAAA,CAAM,SAAS,CAAC,CAAA,CAAA;AACxC,EAAA,MAAM,CAAC,SAAW,EAAA,YAAY,CAAI,GAAA,KAAA,CAAM,SAAS,CAAC,CAAA,CAAA;AAClD,EAAA,MAAM,kBAAqB,GAAA,EAAA,CAAA;AAE3B,EAAM,MAAA;AAAA,IACJ,KAAO,EAAA,QAAA;AAAA,IACP,OAAA;AAAA,IACA,KAAA;AAAA,GACF,GAAI,WAAW,CAAO,GAAA,KAAA;AACpB,IAAA,OAAO,IAAI,cAAe,CAAA;AAAA,MACxB,KAAO,EAAA,kBAAA;AAAA,MACP,MAAA,EAAA,CAAS,OAAO,CAAK,IAAA,kBAAA;AAAA,KACtB,CAAA,CAAA;AAAA,GACH,EAAG,EAAE,CAAA,CAAA;AAEL,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,QAAU,EAAA;AACZ,MAAA,YAAA,CAAa,IAAK,CAAA,IAAA,CAAK,QAAS,CAAA,KAAA,GAAQ,kBAAkB,CAAC,CAAA,CAAA;AAAA,KAC7D;AAAA,GACC,EAAA,CAAC,QAAU,EAAA,kBAAkB,CAAC,CAAA,CAAA;AAEjC,EAAA,2CACG,GAAI,EAAA,EAAA,SAAA,EAAU,qBACb,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,QAAK,SAAS,EAAA,IAAA,EAAC,cAAe,EAAA,eAAA,EAAgB,mBAC9C,KAAA,CAAA,aAAA,CAAA,IAAA,EAAA,EAAK,WAAS,IAAC,EAAA,cAAA,EAAe,mCAC5B,KAAA,CAAA,aAAA,CAAA,IAAA,EAAA,EAAK,IAAI,EAAA,IAAA,EAAA,sCACP,UAAW,EAAA,EAAA,OAAA,EAAQ,IAAK,EAAA,SAAA,EAAU,qCAChC,CAAE,CAAA,oBAAA,EAAsB,EAAE,KAAA,EAAO,UAAU,KAAS,IAAA,CAAA,EAAG,CAC1D,CACF,CACF,CACA,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,sBAAA;AAAA,IAAA;AAAA,MACC,OAAA;AAAA,MACA,KAAA;AAAA,MACA,QAAA;AAAA,MACA,IAAA;AAAA,MACA,SAAA;AAAA,MACA,YAAc,EAAA,OAAA;AAAA,KAAA;AAAA,GAElB,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import React, { useState, useRef, useEffect } from 'react';
|
|
2
|
+
import { useTranslation } from '../../utils/hooks.esm.js';
|
|
3
|
+
import { Progress, WarningPanel } from '@backstage/core-components';
|
|
4
|
+
import { Box, Grid } from '@material-ui/core';
|
|
5
|
+
import { Pagination } from '@material-ui/lab';
|
|
6
|
+
import { CollectionsGridItem } from './CollectionsGridItem.esm.js';
|
|
7
|
+
|
|
8
|
+
const CollectionsGridContent = (props) => {
|
|
9
|
+
const { loading, error, response, onPageChange, page, pageCount } = props;
|
|
10
|
+
const [initialLoad, setInitialLoad] = useState(true);
|
|
11
|
+
const { t } = useTranslation();
|
|
12
|
+
const gridRef = useRef(null);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
if (!initialLoad) {
|
|
15
|
+
setInitialLoad(false);
|
|
16
|
+
}
|
|
17
|
+
}, [initialLoad, loading]);
|
|
18
|
+
const handlePageChange = (_event, value) => {
|
|
19
|
+
if (gridRef.current) {
|
|
20
|
+
gridRef.current.scrollIntoView();
|
|
21
|
+
}
|
|
22
|
+
onPageChange(value);
|
|
23
|
+
};
|
|
24
|
+
if (loading && initialLoad) {
|
|
25
|
+
return /* @__PURE__ */ React.createElement(Progress, null);
|
|
26
|
+
}
|
|
27
|
+
if (error || response === void 0) {
|
|
28
|
+
return /* @__PURE__ */ React.createElement(
|
|
29
|
+
WarningPanel,
|
|
30
|
+
{
|
|
31
|
+
severity: "error",
|
|
32
|
+
title: t("postsList.errorLoading", { itemType: "collections" })
|
|
33
|
+
},
|
|
34
|
+
error?.message
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
if (initialLoad && (!response.collections || response.collections.length === 0)) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
return /* @__PURE__ */ React.createElement("div", { ref: gridRef }, /* @__PURE__ */ React.createElement(Box, { sx: { mt: 2 }, className: "qetaCollectionsGrid" }, /* @__PURE__ */ React.createElement(
|
|
41
|
+
Grid,
|
|
42
|
+
{
|
|
43
|
+
container: true,
|
|
44
|
+
direction: "row",
|
|
45
|
+
alignItems: "stretch",
|
|
46
|
+
style: { marginTop: "1rem" }
|
|
47
|
+
},
|
|
48
|
+
response.collections.map((p) => {
|
|
49
|
+
return /* @__PURE__ */ React.createElement(Grid, { item: true, xs: 12, md: 4, lg: 3, key: p.id }, /* @__PURE__ */ React.createElement(CollectionsGridItem, { collection: p }));
|
|
50
|
+
})
|
|
51
|
+
), /* @__PURE__ */ React.createElement(Grid, { container: true, justifyContent: "center", style: { marginTop: "2rem" } }, /* @__PURE__ */ React.createElement(
|
|
52
|
+
Pagination,
|
|
53
|
+
{
|
|
54
|
+
page,
|
|
55
|
+
onChange: handlePageChange,
|
|
56
|
+
count: pageCount,
|
|
57
|
+
size: "large",
|
|
58
|
+
variant: "outlined",
|
|
59
|
+
className: "qetaPostListPagination",
|
|
60
|
+
showFirstButton: true,
|
|
61
|
+
showLastButton: true
|
|
62
|
+
}
|
|
63
|
+
))));
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export { CollectionsGridContent };
|
|
67
|
+
//# sourceMappingURL=CollectionsGridContent.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CollectionsGridContent.esm.js","sources":["../../../src/components/CollectionsGrid/CollectionsGridContent.tsx"],"sourcesContent":["import { CollectionsResponse } from '@drodil/backstage-plugin-qeta-common';\nimport React, { useEffect, useRef, useState } from 'react';\nimport { useTranslation } from '../../utils';\nimport { Progress, WarningPanel } from '@backstage/core-components';\nimport { Box, Grid } from '@material-ui/core';\nimport { Pagination } from '@material-ui/lab';\nimport { CollectionsGridItem } from './CollectionsGridItem';\n\nexport const CollectionsGridContent = (props: {\n loading: boolean;\n error: any;\n response?: CollectionsResponse;\n onPageChange: (page: number) => void;\n page: number;\n pageCount: number;\n}) => {\n const { loading, error, response, onPageChange, page, pageCount } = props;\n const [initialLoad, setInitialLoad] = useState(true);\n const { t } = useTranslation();\n const gridRef = useRef<HTMLDivElement | null>(null);\n\n useEffect(() => {\n if (!initialLoad) {\n setInitialLoad(false);\n }\n }, [initialLoad, loading]);\n\n const handlePageChange = (\n _event: React.ChangeEvent<unknown>,\n value: number,\n ) => {\n if (gridRef.current) {\n gridRef.current.scrollIntoView();\n }\n onPageChange(value);\n };\n\n if (loading && initialLoad) {\n return <Progress />;\n }\n\n if (error || response === undefined) {\n return (\n <WarningPanel\n severity=\"error\"\n title={t('postsList.errorLoading', { itemType: 'collections' })}\n >\n {error?.message}\n </WarningPanel>\n );\n }\n\n if (\n initialLoad &&\n (!response.collections || response.collections.length === 0)\n ) {\n return null;\n }\n\n return (\n <div ref={gridRef}>\n <Box sx={{ mt: 2 }} className=\"qetaCollectionsGrid\">\n <Grid\n container\n direction=\"row\"\n alignItems=\"stretch\"\n style={{ marginTop: '1rem' }}\n >\n {response.collections.map(p => {\n return (\n <Grid item xs={12} md={4} lg={3} key={p.id}>\n <CollectionsGridItem collection={p} />\n </Grid>\n );\n })}\n </Grid>\n <Grid container justifyContent=\"center\" style={{ marginTop: '2rem' }}>\n <Pagination\n page={page}\n onChange={handlePageChange}\n count={pageCount}\n size=\"large\"\n variant=\"outlined\"\n className=\"qetaPostListPagination\"\n showFirstButton\n showLastButton\n />\n </Grid>\n </Box>\n </div>\n );\n};\n"],"names":[],"mappings":";;;;;;;AAQa,MAAA,sBAAA,GAAyB,CAAC,KAOjC,KAAA;AACJ,EAAA,MAAM,EAAE,OAAS,EAAA,KAAA,EAAO,UAAU,YAAc,EAAA,IAAA,EAAM,WAAc,GAAA,KAAA,CAAA;AACpE,EAAA,MAAM,CAAC,WAAA,EAAa,cAAc,CAAA,GAAI,SAAS,IAAI,CAAA,CAAA;AACnD,EAAM,MAAA,EAAE,CAAE,EAAA,GAAI,cAAe,EAAA,CAAA;AAC7B,EAAM,MAAA,OAAA,GAAU,OAA8B,IAAI,CAAA,CAAA;AAElD,EAAA,SAAA,CAAU,MAAM;AACd,IAAA,IAAI,CAAC,WAAa,EAAA;AAChB,MAAA,cAAA,CAAe,KAAK,CAAA,CAAA;AAAA,KACtB;AAAA,GACC,EAAA,CAAC,WAAa,EAAA,OAAO,CAAC,CAAA,CAAA;AAEzB,EAAM,MAAA,gBAAA,GAAmB,CACvB,MAAA,EACA,KACG,KAAA;AACH,IAAA,IAAI,QAAQ,OAAS,EAAA;AACnB,MAAA,OAAA,CAAQ,QAAQ,cAAe,EAAA,CAAA;AAAA,KACjC;AACA,IAAA,YAAA,CAAa,KAAK,CAAA,CAAA;AAAA,GACpB,CAAA;AAEA,EAAA,IAAI,WAAW,WAAa,EAAA;AAC1B,IAAA,2CAAQ,QAAS,EAAA,IAAA,CAAA,CAAA;AAAA,GACnB;AAEA,EAAI,IAAA,KAAA,IAAS,aAAa,KAAW,CAAA,EAAA;AACnC,IACE,uBAAA,KAAA,CAAA,aAAA;AAAA,MAAC,YAAA;AAAA,MAAA;AAAA,QACC,QAAS,EAAA,OAAA;AA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AA,MACA,QAAU,EAAA,gBAAA;AAAA,MACV,KAAO,EAAA,SAAA;AAAA,MACP,IAAK,EAAA,OAAA;AAAA,MACL,OAAQ,EAAA,UAAA;AAAA,MACR,SAAU,EAAA,wBAAA;AAAA,MACV,eAAe,EAAA,IAAA;AAAA,MACf,cAAc,EAAA,IAAA;AAAA,KAAA;AAAA,GAElB,CACF,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { truncate, removeMarkdownFormatting } from '@drodil/backstage-plugin-qeta-common';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useTranslation, useStyles, useEntityAuthor } from '../../utils/hooks.esm.js';
|
|
4
|
+
import { useRouteRef } from '@backstage/core-plugin-api';
|
|
5
|
+
import { collectionRouteRef, userRouteRef } from '../../routes.esm.js';
|
|
6
|
+
import { Card, CardActionArea, CardMedia, CardContent, Typography, Box, Avatar } from '@material-ui/core';
|
|
7
|
+
import DOMPurify from 'dompurify';
|
|
8
|
+
import { useNavigate } from 'react-router-dom';
|
|
9
|
+
import { TagsAndEntities } from '../TagsAndEntities/TagsAndEntities.esm.js';
|
|
10
|
+
import { Link } from '@backstage/core-components';
|
|
11
|
+
import { RelativeTimeWithTooltip } from '../RelativeTimeWithTooltip/RelativeTimeWithTooltip.esm.js';
|
|
12
|
+
|
|
13
|
+
const CollectionsGridItem = (props) => {
|
|
14
|
+
const { collection } = props;
|
|
15
|
+
const { t } = useTranslation();
|
|
16
|
+
const collectionRoute = useRouteRef(collectionRouteRef);
|
|
17
|
+
const userRoute = useRouteRef(userRouteRef);
|
|
18
|
+
const styles = useStyles();
|
|
19
|
+
const { name, initials, user } = useEntityAuthor(collection);
|
|
20
|
+
const navigate = useNavigate();
|
|
21
|
+
const href = collectionRoute({ id: collection.id.toString(10) });
|
|
22
|
+
return /* @__PURE__ */ React.createElement(Card, { style: { height: "100%", display: "flex", flexDirection: "column" } }, /* @__PURE__ */ React.createElement(CardActionArea, { onClick: () => navigate(href) }, collection.headerImage && /* @__PURE__ */ React.createElement(
|
|
23
|
+
CardMedia,
|
|
24
|
+
{
|
|
25
|
+
component: "img",
|
|
26
|
+
height: "140",
|
|
27
|
+
image: collection.headerImage,
|
|
28
|
+
alt: collection.title
|
|
29
|
+
}
|
|
30
|
+
), /* @__PURE__ */ React.createElement(CardContent, { style: { paddingBottom: "0.5rem" } }, /* @__PURE__ */ React.createElement(Typography, { gutterBottom: true, variant: "h6", component: "div" }, collection.title), collection.description && /* @__PURE__ */ React.createElement(Typography, { variant: "body2", color: "textSecondary", gutterBottom: true }, DOMPurify.sanitize(
|
|
31
|
+
truncate(removeMarkdownFormatting(collection.description), 200)
|
|
32
|
+
)))), /* @__PURE__ */ React.createElement(CardContent, { style: { paddingTop: "0.5rem", marginTop: "auto" } }, /* @__PURE__ */ React.createElement(TagsAndEntities, { entity: collection }), /* @__PURE__ */ React.createElement(Box, { style: { paddingLeft: "0.2rem", paddingTop: "0.5rem" } }, /* @__PURE__ */ React.createElement(Typography, { variant: "caption" }, /* @__PURE__ */ React.createElement(
|
|
33
|
+
Avatar,
|
|
34
|
+
{
|
|
35
|
+
src: user?.spec?.profile?.picture,
|
|
36
|
+
className: styles.questionListItemAvatar,
|
|
37
|
+
alt: name,
|
|
38
|
+
variant: "rounded"
|
|
39
|
+
},
|
|
40
|
+
initials
|
|
41
|
+
), collection.owner === "anonymous" ? t("common.anonymousAuthor") : /* @__PURE__ */ React.createElement(Link, { to: `${userRoute()}/${collection.owner}` }, name), " ", /* @__PURE__ */ React.createElement(Link, { to: href, className: "qetaPostListItemQuestionBtn" }, /* @__PURE__ */ React.createElement(RelativeTimeWithTooltip, { value: collection.created })), " \xB7 ", t("common.posts", {
|
|
42
|
+
count: collection.posts?.length ?? 0,
|
|
43
|
+
itemType: "post"
|
|
44
|
+
})))));
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export { CollectionsGridItem };
|
|
48
|
+
//# sourceMappingURL=CollectionsGridItem.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CollectionsGridItem.esm.js","sources":["../../../src/components/CollectionsGrid/CollectionsGridItem.tsx"],"sourcesContent":["import {\n Collection,\n removeMarkdownFormatting,\n truncate,\n} from '@drodil/backstage-plugin-qeta-common';\nimport React from 'react';\nimport { useStyles, useTranslation } from '../../utils';\nimport { useRouteRef } from '@backstage/core-plugin-api';\nimport { collectionRouteRef, userRouteRef } from '../../routes';\nimport {\n Avatar,\n Box,\n Card,\n CardActionArea,\n CardContent,\n CardMedia,\n Typography,\n} from '@material-ui/core';\nimport { useEntityAuthor } from '../../utils/hooks';\nimport DOMPurify from 'dompurify';\nimport { useNavigate } from 'react-router-dom';\nimport { TagsAndEntities } from '../TagsAndEntities/TagsAndEntities';\nimport { Link } from '@backstage/core-components';\nimport { RelativeTimeWithTooltip } from '../RelativeTimeWithTooltip';\n\nexport interface PostsGridItemProps {\n collection: Collection;\n}\n\nexport const CollectionsGridItem = (props: PostsGridItemProps) => {\n const { collection } = props;\n const { t } = useTranslation();\n\n const collectionRoute = useRouteRef(collectionRouteRef);\n const userRoute = useRouteRef(userRouteRef);\n const styles = useStyles();\n const { name, initials, user } = useEntityAuthor(collection);\n const navigate = useNavigate();\n const href = collectionRoute({ id: collection.id.toString(10) });\n\n return (\n <Card style={{ height: '100%', display: 'flex', flexDirection: 'column' }}>\n <CardActionArea onClick={() => navigate(href)}>\n {collection.headerImage && (\n <CardMedia\n component=\"img\"\n height=\"140\"\n image={collection.headerImage}\n alt={collection.title}\n />\n )}\n <CardContent style={{ paddingBottom: '0.5rem' }}>\n <Typography gutterBottom variant=\"h6\" component=\"div\">\n {collection.title}\n </Typography>\n {collection.description && (\n <Typography variant=\"body2\" color=\"textSecondary\" gutterBottom>\n {DOMPurify.sanitize(\n truncate(removeMarkdownFormatting(collection.description), 200),\n )}\n </Typography>\n )}\n </CardContent>\n </CardActionArea>\n <CardContent style={{ paddingTop: '0.5rem', marginTop: 'auto' }}>\n <TagsAndEntities entity={collection} />\n <Box style={{ paddingLeft: '0.2rem', paddingTop: '0.5rem' }}>\n <Typography variant=\"caption\">\n <Avatar\n src={user?.spec?.profile?.picture}\n className={styles.questionListItemAvatar}\n alt={name}\n variant=\"rounded\"\n >\n {initials}\n </Avatar>\n {collection.owner === 'anonymous' ? (\n t('common.anonymousAuthor')\n ) : (\n <Link to={`${userRoute()}/${collection.owner}`}>{name}</Link>\n )}{' '}\n <Link to={href} className=\"qetaPostListItemQuestionBtn\">\n <RelativeTimeWithTooltip value={collection.created} />\n </Link>\n {' · '}\n {t('common.posts', {\n count: collection.posts?.length ?? 0,\n itemType: 'post',\n })}\n </Typography>\n </Box>\n </CardContent>\n </Card>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;;;AA6Ba,MAAA,mBAAA,GAAsB,CAAC,KAA8B,KAAA;AAChE,EAAM,MAAA,EAAE,YAAe,GAAA,KAAA,CAAA;AACvB,EAAM,MAAA,EAAE,CAAE,EAAA,GAAI,cAAe,EAAA,CAAA;AAE7B,EAAM,MAAA,eAAA,GAAkB,YAAY,kBAAkB,CAAA,CAAA;AACtD,EAAM,MAAA,SAAA,GAAY,YAAY,YAAY,CAAA,CAAA;AAC1C,EAAA,MAAM,SAAS,SAAU,EAAA,CAAA;AACzB,EAAA,MAAM,EAAE,IAAM,EAAA,QAAA,EAAU,IAAK,EAAA,GAAI,gBAAgB,UAAU,CAAA,CAAA;AAC3D,EAAA,MAAM,WAAW,WAAY,EAAA,CAAA;AAC7B,EAAM,MAAA,IAAA,GAAO,gBAAgB,EAAE,EAAA,EAAI,WAAW,EAAG,CAAA,QAAA,CAAS,EAAE,CAAA,EAAG,CAAA,CAAA;AAE/D,EAAA,2CACG,IAAK,EAAA,EAAA,KAAA,EAAO,EAAE,MAAQ,EAAA,MAAA,EAAQ,SAAS,MAAQ,EAAA,aAAA,EAAe,UAC7D,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,kBAAe,OAAS,EAAA,MAAM,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AA,IAAA,EAAM,OAAS,EAAA,OAAA;AAAA,MAC1B,WAAW,MAAO,CAAA,sBAAA;AAAA,MAClB,GAAK,EAAA,IAAA;AAAA,MACL,OAAQ,EAAA,SAAA;AAAA,KAAA;AAAA,IAEP,QAAA;AAAA,GAEF,EAAA,UAAA,CAAW,KAAU,KAAA,WAAA,GACpB,EAAE,wBAAwB,CAAA,mBAEzB,KAAA,CAAA,aAAA,CAAA,IAAA,EAAA,EAAK,IAAI,CAAG,EAAA,SAAA,EAAW,CAAA,CAAA,EAAI,WAAW,KAAK,CAAA,CAAA,EAAA,EAAK,IAAK,CAAA,EACrD,qBACF,KAAA,CAAA,aAAA,CAAA,IAAA,EAAA,EAAK,EAAI,EAAA,IAAA,EAAM,WAAU,6BACxB,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,uBAAwB,EAAA,EAAA,KAAA,EAAO,WAAW,OAAS,EAAA,CACtD,CACC,EAAA,QAAA,EACA,EAAE,cAAgB,EAAA;AAAA,IACjB,KAAA,EAAO,UAAW,CAAA,KAAA,EAAO,MAAU,IAAA,CAAA;AAAA,IACnC,QAAU,EAAA,MAAA;AAAA,GACX,CACH,CACF,CACF,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Box, Typography, Divider } from '@material-ui/core';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Link } from '@backstage/core-components';
|
|
4
|
+
import { useStyles, useTranslation } from '../../utils/hooks.esm.js';
|
|
5
|
+
import { useApi } from '@backstage/core-plugin-api';
|
|
6
|
+
import { RelativeTimeWithTooltip } from '../RelativeTimeWithTooltip/RelativeTimeWithTooltip.esm.js';
|
|
7
|
+
import { AuthorLink } from '../Links/Links.esm.js';
|
|
8
|
+
import { MarkdownRenderer } from '../MarkdownRenderer/MarkdownRenderer.esm.js';
|
|
9
|
+
import { qetaApiRef } from '../../api.esm.js';
|
|
10
|
+
|
|
11
|
+
const CommentList = (props) => {
|
|
12
|
+
const { question, answer, onCommentDelete } = props;
|
|
13
|
+
const entity = answer ?? question;
|
|
14
|
+
const styles = useStyles();
|
|
15
|
+
const qetaApi = useApi(qetaApiRef);
|
|
16
|
+
const { t } = useTranslation();
|
|
17
|
+
const deleteComment = (id) => {
|
|
18
|
+
if (answer) {
|
|
19
|
+
qetaApi.deleteAnswerComment(question.id, answer.id, id).then((a) => {
|
|
20
|
+
onCommentDelete(question, a);
|
|
21
|
+
return;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
qetaApi.deletePostComment(question.id, id).then((q) => onCommentDelete(q));
|
|
25
|
+
};
|
|
26
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, entity.comments?.map((c) => {
|
|
27
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Box, { key: c.id, className: "qetaCommentBox" }, /* @__PURE__ */ React.createElement(
|
|
28
|
+
MarkdownRenderer,
|
|
29
|
+
{
|
|
30
|
+
content: c.content,
|
|
31
|
+
className: `${styles.markdownContent} inline`
|
|
32
|
+
}
|
|
33
|
+
), " \u2013 ", /* @__PURE__ */ React.createElement(AuthorLink, { entity: c }), " ", /* @__PURE__ */ React.createElement(Typography, { variant: "caption", className: "qetaCommentTime" }, /* @__PURE__ */ React.createElement(RelativeTimeWithTooltip, { value: c.created })), (c.own || c.canDelete) && /* @__PURE__ */ React.createElement(React.Fragment, null, " / ", /* @__PURE__ */ React.createElement(
|
|
34
|
+
Link,
|
|
35
|
+
{
|
|
36
|
+
underline: "none",
|
|
37
|
+
to: "#",
|
|
38
|
+
className: "qetaCommentDeleteBtn",
|
|
39
|
+
onClick: () => deleteComment(c.id)
|
|
40
|
+
},
|
|
41
|
+
t("commentList.deleteLink")
|
|
42
|
+
))), /* @__PURE__ */ React.createElement(Divider, null));
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export { CommentList };
|
|
47
|
+
//# sourceMappingURL=CommentList.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommentList.esm.js","sources":["../../../src/components/CommentSection/CommentList.tsx"],"sourcesContent":["import {\n AnswerResponse,\n PostResponse,\n} from '@drodil/backstage-plugin-qeta-common';\nimport { Box, Divider, Typography } from '@material-ui/core';\nimport React from 'react';\nimport { Link } from '@backstage/core-components';\nimport { useStyles, useTranslation } from '../../utils/hooks';\nimport { useApi } from '@backstage/core-plugin-api';\nimport { RelativeTimeWithTooltip } from '../RelativeTimeWithTooltip/RelativeTimeWithTooltip';\nimport { AuthorLink } from '../Links/Links';\nimport { MarkdownRenderer } from '../MarkdownRenderer/MarkdownRenderer';\nimport { qetaApiRef } from '../../api';\n\nexport const CommentList = (props: {\n onCommentDelete: (question: PostResponse, answer?: AnswerResponse) => void;\n question: PostResponse;\n answer?: AnswerResponse;\n}) => {\n const { question, answer, onCommentDelete } = props;\n const entity = answer ?? question;\n const styles = useStyles();\n const qetaApi = useApi(qetaApiRef);\n const { t } = useTranslation();\n\n const deleteComment = (id: number) => {\n if (answer) {\n qetaApi.deleteAnswerComment(question.id, answer.id, id).then(a => {\n onCommentDelete(question, a);\n return;\n });\n }\n qetaApi.deletePostComment(question.id, id).then(q => onCommentDelete(q));\n };\n\n return (\n <>\n {entity.comments?.map(c => {\n return (\n <>\n <Box key={c.id} className=\"qetaCommentBox\">\n <MarkdownRenderer\n content={c.content}\n className={`${styles.markdownContent} inline`}\n />\n {' – '}\n <AuthorLink entity={c} />{' '}\n <Typography variant=\"caption\" className=\"qetaCommentTime\">\n <RelativeTimeWithTooltip value={c.created} />\n </Typography>\n {(c.own || c.canDelete) && (\n <>\n {' / '}\n <Link\n underline=\"none\"\n to=\"#\"\n className=\"qetaCommentDeleteBtn\"\n onClick={() => deleteComment(c.id)}\n >\n {t('commentList.deleteLink')}\n </Link>\n </>\n )}\n </Box>\n <Divider />\n </>\n );\n })}\n </>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;AAca,MAAA,WAAA,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