Skip to content

Commit 5ecbb03

Browse files
Ahtesham QuraishAhtesham Quraish
authored andcommitted
chatgpt modal review
1 parent 5e29ed5 commit 5ecbb03

3 files changed

Lines changed: 59 additions & 57 deletions

File tree

frontends/main/src/app-pages/WebsiteContent/WebsiteContentDraftListingPage.tsx

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const PageHeader = styled.div`
4646
margin-bottom: 40px;
4747
`
4848

49-
const DraftArticleCard = styled(Card)`
49+
const DraftContentCard = styled(Card)`
5050
display: flex;
5151
flex-direction: column;
5252
height: 100%;
@@ -84,35 +84,35 @@ const CONTENT_TYPE_LABELS: Record<string, string> = {
8484
news: "News",
8585
}
8686

87-
const DraftItem: React.FC<{ article: WebsiteContent; type: string }> = ({
88-
article,
87+
const DraftItem: React.FC<{ contentItem: WebsiteContent; type: string }> = ({
88+
contentItem,
8989
type,
9090
}) => {
91-
const itemUrl = article.is_published
92-
? `/${type === "article" ? "articles" : type}/${article.slug || article.id}`
93-
: websiteContentEditView(type, article.id)
91+
const itemUrl = contentItem.is_published
92+
? `/${type === "article" ? "articles" : type}/${contentItem.slug || contentItem.id}`
93+
: websiteContentEditView(type, contentItem.id)
9494

95-
const imageUrl = extractFirstImage(article.content)
95+
const imageUrl = extractFirstImage(contentItem.content)
9696

9797
return (
98-
<DraftArticleCard forwardClicksToLink>
98+
<DraftContentCard forwardClicksToLink>
9999
<Card.Image
100100
src={imageUrl || DEFAULT_BACKGROUND_IMAGE_URL}
101-
alt={article.title}
101+
alt={contentItem.title}
102102
/>
103103
<Card.Title href={itemUrl} lines={2} style={{ marginBottom: "-13px" }}>
104-
{article.title}
104+
{contentItem.title}
105105
</Card.Title>
106106
<Card.Footer>
107-
<LocalDate date={article.created_on} />
108-
{!article.is_published && (
107+
<LocalDate date={contentItem.created_on} />
108+
{!contentItem.is_published && (
109109
<>
110110
{" • "}
111111
<DraftBadge>Draft</DraftBadge>
112112
</>
113113
)}
114114
</Card.Footer>
115-
</DraftArticleCard>
115+
</DraftContentCard>
116116
)
117117
}
118118

@@ -143,7 +143,7 @@ const WebsiteContentDraftListingPage: React.FC<
143143
: {}),
144144
}
145145

146-
const { data: articles, isLoading: isLoadingArticles } =
146+
const { data: contentItems, isLoading: isLoadingContentItems } =
147147
useWebsiteContentList(listParams)
148148

149149
useEffect(() => {
@@ -152,11 +152,13 @@ const WebsiteContentDraftListingPage: React.FC<
152152
}
153153
}, [page])
154154

155-
const draftArticles = articles?.results
156-
const totalPages = articles?.count ? Math.ceil(articles.count / PAGE_SIZE) : 0
155+
const draftItems = contentItems?.results
156+
const totalPages = contentItems?.count
157+
? Math.ceil(contentItems.count / PAGE_SIZE)
158+
: 0
157159

158-
if (isLoadingArticles) {
159-
return <LoadingSpinner loading={isLoadingArticles} />
160+
if (isLoadingContentItems) {
161+
return <LoadingSpinner loading={isLoadingContentItems} />
160162
}
161163

162164
return (
@@ -174,19 +176,19 @@ const WebsiteContentDraftListingPage: React.FC<
174176
</ButtonLink>
175177
</PageHeader>
176178

177-
{isLoadingArticles ? (
179+
{isLoadingContentItems ? (
178180
<LoadingContainer>
179181
<LoadingSpinner loading size={48} />
180182
</LoadingContainer>
181-
) : draftArticles && draftArticles.length > 0 ? (
183+
) : draftItems && draftItems.length > 0 ? (
182184
<>
183185
<Grid2 container columnSpacing="24px" rowSpacing="28px">
184-
{draftArticles.map((article) => (
186+
{draftItems.map((contentItem) => (
185187
<Grid2
186-
key={article.id}
188+
key={contentItem.id}
187189
size={{ xs: 12, sm: 6, md: 4, lg: 3, xl: 3 }}
188190
>
189-
<DraftItem article={article} type={type} />
191+
<DraftItem contentItem={contentItem} type={type} />
190192
</Grid2>
191193
))}
192194
</Grid2>

frontends/main/src/page-components/TiptapEditor/NewsViewer.test.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe("NewsViewer", () => {
1111
})
1212
setMockResponse.get(urls.userMe.get(), user)
1313

14-
const article = factories.websiteContent.websiteContent({
14+
const newsItem = factories.websiteContent.websiteContent({
1515
content: {
1616
type: "doc",
1717
content: [
@@ -64,7 +64,7 @@ describe("NewsViewer", () => {
6464
},
6565
})
6666

67-
renderWithProviders(<NewsEditor article={article} readOnly />)
67+
renderWithProviders(<NewsEditor article={newsItem} readOnly />)
6868

6969
await screen.findByRole("heading", { name: "Test Title", level: 1 })
7070
await screen.findByText("Test subheading")
@@ -78,12 +78,12 @@ describe("NewsViewer", () => {
7878
})
7979
setMockResponse.get(urls.userMe.get(), user)
8080
const authorName = `${user.first_name} ${user.last_name}`
81-
const article = factories.websiteContent.websiteContent({
81+
const newsItem = factories.websiteContent.websiteContent({
8282
user,
8383
author_name: authorName,
8484
})
8585

86-
renderWithProviders(<NewsEditor article={article} readOnly />)
86+
renderWithProviders(<NewsEditor article={newsItem} readOnly />)
8787

8888
await screen.findByText(`By ${authorName}`)
8989
})
@@ -95,7 +95,7 @@ describe("NewsViewer", () => {
9595
})
9696
setMockResponse.get(urls.userMe.get(), user)
9797

98-
const article = factories.websiteContent.websiteContent({
98+
const newsItem = factories.websiteContent.websiteContent({
9999
content: {
100100
type: "doc",
101101
content: [
@@ -202,7 +202,7 @@ describe("NewsViewer", () => {
202202
},
203203
})
204204

205-
renderWithProviders(<NewsEditor article={article} readOnly />)
205+
renderWithProviders(<NewsEditor article={newsItem} readOnly />)
206206

207207
await screen.findByRole("heading", { level: 1, name: "Heading Level 1" })
208208
await screen.findByRole("heading", { level: 2, name: "Heading Level 2" })
@@ -219,7 +219,7 @@ describe("NewsViewer", () => {
219219
})
220220
setMockResponse.get(urls.userMe.get(), user)
221221

222-
const article = factories.websiteContent.websiteContent({
222+
const newsItem = factories.websiteContent.websiteContent({
223223
content: {
224224
type: "doc",
225225
content: [
@@ -294,7 +294,7 @@ describe("NewsViewer", () => {
294294
},
295295
})
296296

297-
renderWithProviders(<NewsEditor article={article} readOnly />)
297+
renderWithProviders(<NewsEditor article={newsItem} readOnly />)
298298

299299
const firstUnordered = await screen.findByText("First unordered item")
300300
const secondUnordered = await screen.findByText("Second unordered item")
@@ -321,7 +321,7 @@ describe("NewsViewer", () => {
321321
})
322322
setMockResponse.get(urls.userMe.get(), user)
323323

324-
const article = factories.websiteContent.websiteContent({
324+
const newsItem = factories.websiteContent.websiteContent({
325325
content: {
326326
type: "doc",
327327
content: [
@@ -398,7 +398,7 @@ describe("NewsViewer", () => {
398398
},
399399
})
400400

401-
renderWithProviders(<NewsEditor article={article} readOnly />)
401+
renderWithProviders(<NewsEditor article={newsItem} readOnly />)
402402

403403
const boldText = await screen.findByText("bold text")
404404
expect(boldText).toBeInTheDocument()
@@ -428,7 +428,7 @@ describe("NewsViewer", () => {
428428
})
429429
setMockResponse.get(urls.userMe.get(), user)
430430

431-
const article = factories.websiteContent.websiteContent({
431+
const newsItem = factories.websiteContent.websiteContent({
432432
content: {
433433
type: "doc",
434434
content: [
@@ -486,7 +486,7 @@ describe("NewsViewer", () => {
486486
},
487487
})
488488

489-
renderWithProviders(<NewsEditor article={article} readOnly />)
489+
renderWithProviders(<NewsEditor article={newsItem} readOnly />)
490490

491491
const link = await screen.findByRole("link", { name: "example.com" })
492492
expect(link).toBeInTheDocument()
@@ -500,8 +500,8 @@ describe("NewsViewer", () => {
500500
is_article_editor: true,
501501
})
502502
setMockResponse.get(urls.userMe.get(), user)
503-
const article = factories.websiteContent.websiteContent()
504-
renderWithProviders(<NewsEditor article={article} readOnly />)
503+
const newsItem = factories.websiteContent.websiteContent()
504+
renderWithProviders(<NewsEditor article={newsItem} readOnly />)
505505

506506
await screen.findByRole("link", { name: "Edit" })
507507
})

frontends/main/src/page-components/TiptapEditor/contentTypes/news/NewsEditor.happydom.test.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ describe("NewsEditor - Content Editing and Saving", () => {
3636
})
3737
setMockResponse.get(urls.userMe.get(), user)
3838

39-
const article = factories.websiteContent.websiteContent({
39+
const newsItem = factories.websiteContent.websiteContent({
4040
id: articleId,
4141
title,
4242
content,
4343
is_published: false,
4444
})
45-
setMockResponse.get(urls.websiteContent.details(articleId), article)
45+
setMockResponse.get(urls.websiteContent.details(articleId), newsItem)
4646

47-
renderWithProviders(<NewsEditor article={article} onSave={mockOnSave} />, {
47+
renderWithProviders(<NewsEditor article={newsItem} onSave={mockOnSave} />, {
4848
user,
4949
})
5050

5151
await screen.findByTestId("editor")
52-
return article
52+
return newsItem
5353
}
5454

5555
describe("Editing title in banner heading", () => {
@@ -376,7 +376,7 @@ describe("NewsEditor - Content Editing and Saving", () => {
376376
})
377377

378378
describe("Save as Draft functionality", () => {
379-
test("can save article as draft", async () => {
379+
test("can save news as draft", async () => {
380380
const initialContent: JSONContent = {
381381
type: "doc",
382382
content: [
@@ -404,23 +404,23 @@ describe("NewsEditor - Content Editing and Saving", () => {
404404
],
405405
}
406406

407-
const article = await setupEditor(initialContent, 208, "Title")
407+
const newsItem = await setupEditor(initialContent, 208, "Title")
408408

409409
const paragraph = screen.getByText("Content")
410410
await userEvent.click(paragraph)
411411
await userEvent.keyboard("{Control>}a{/Control}")
412412
await userEvent.type(paragraph, "Updated content")
413413

414-
const updatedArticle = {
415-
...article,
414+
const updatedNewsItem = {
415+
...newsItem,
416416
content: expect.objectContaining({
417417
type: "doc",
418418
}),
419419
is_published: false,
420420
}
421421
setMockResponse.patch(
422-
urls.websiteContent.details(article.id),
423-
updatedArticle,
422+
urls.websiteContent.details(newsItem.id),
423+
updatedNewsItem,
424424
)
425425

426426
const saveDraftButton = await screen.findByRole("button", {
@@ -433,7 +433,7 @@ describe("NewsEditor - Content Editing and Saving", () => {
433433

434434
expect(makeRequest).toHaveBeenCalledWith(
435435
"patch",
436-
urls.websiteContent.details(article.id),
436+
urls.websiteContent.details(newsItem.id),
437437
expect.objectContaining({
438438
is_published: false,
439439
author_name: "",
@@ -505,20 +505,20 @@ describe("NewsEditor - Content Editing and Saving", () => {
505505
})
506506
})
507507

508-
describe("Creating new articles", () => {
509-
test("submits article successfully", async () => {
508+
describe("Creating news", () => {
509+
test("submits news successfully", async () => {
510510
const user = factories.user.user({
511511
is_authenticated: true,
512512
is_article_editor: true,
513513
})
514514
setMockResponse.get(urls.userMe.get(), user)
515515

516-
const createdArticle = factories.websiteContent.websiteContent({
516+
const createdNewsItem = factories.websiteContent.websiteContent({
517517
id: 101,
518518
title: "My Article",
519519
is_published: true,
520520
})
521-
setMockResponse.post(urls.websiteContent.list(), createdArticle)
521+
setMockResponse.post(urls.websiteContent.list(), createdNewsItem)
522522

523523
renderWithProviders(<NewsEditor onSave={mockOnSave} />, { user })
524524

@@ -598,7 +598,7 @@ describe("NewsEditor - Content Editing and Saving", () => {
598598

599599
expect(savedData).toBeDefined()
600600
expect(savedData).toMatchObject({
601-
id: createdArticle.id,
601+
id: createdNewsItem.id,
602602
title: "My Article",
603603
is_published: true,
604604
})
@@ -638,20 +638,20 @@ describe("NewsEditor - Document Rendering", () => {
638638
})
639639
setMockResponse.get(urls.userMe.get(), user)
640640

641-
const article = factories.websiteContent.websiteContent({
641+
const newsItem = factories.websiteContent.websiteContent({
642642
id: 1,
643643
title: "Test Article",
644644
content,
645645
})
646-
setMockResponse.get(urls.websiteContent.details(articleId), article)
646+
setMockResponse.get(urls.websiteContent.details(articleId), newsItem)
647647

648648
renderWithProviders(
649-
<NewsEditor article={article} onSave={mockOnSave} readOnly />,
649+
<NewsEditor article={newsItem} onSave={mockOnSave} readOnly />,
650650
{ user },
651651
)
652652

653653
await screen.findByTestId("editor")
654-
return article
654+
return newsItem
655655
}
656656

657657
test("renders editor when user has ArticleEditor permission", async () => {

0 commit comments

Comments
 (0)