Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Release PR #3098

Merged
merged 32 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f9d463f
feat: introduce Discussion model and store for persisting data
thisislawatts Dec 22, 2023
75d510a
test: add coverage for edit comment method
thisislawatts Dec 22, 2023
a7b565f
fix: add tests around fetch discussion behaviour
thisislawatts Dec 22, 2023
491d8a0
chore: remove debug console
thisislawatts Dec 22, 2023
4a1eb41
chore: extend test coverage to include error path
thisislawatts Dec 22, 2023
b2a8693
fix: tighten up validation for sourceType
thisislawatts Dec 22, 2023
a3275d5
chore: drop formatting method
thisislawatts Dec 22, 2023
3c5a6e8
chore: refactor to avoid instantation of unused var
thisislawatts Dec 22, 2023
4cdffbb
chore: drop unused UI prop
thisislawatts Dec 22, 2023
2417d37
chore: add reference to sourceType
thisislawatts Dec 22, 2023
f65a348
feat: load discussion store as part of state init
thisislawatts Dec 22, 2023
fd41225
chore: rename method to better reflect behaviour
thisislawatts Dec 22, 2023
55f21ce
test: switch to Discussion specific comments
thisislawatts Dec 23, 2023
e06b3ef
Merge pull request #3092 from ONEARMY/feat/new-discussion-model
thisislawatts Dec 23, 2023
b79a1b7
refactor: remove unused file upload
mariojsnunes Dec 23, 2023
bfeeb49
Merge pull request #3097 from mariojsnunes/refactor/remove-unused-fil…
thisislawatts Dec 24, 2023
26a27c8
chore: reduce log output
thisislawatts Dec 24, 2023
4726d13
test(components): add some assertations around CommentList
thisislawatts Dec 25, 2023
7edf5cd
refactor: settings class components to hooks
mariojsnunes Dec 26, 2023
63782a6
Merge pull request #3099 from mariojsnunes/refactor/user-settings-hooks
thisislawatts Dec 26, 2023
8a0a184
test: refactor to match React naming conventions
thisislawatts Dec 26, 2023
556861d
refactor: header class components to hooks
mariojsnunes Dec 26, 2023
f11bbc0
fix(components): correct deps for all useEffect instances
thisislawatts Dec 26, 2023
83a37ef
Merge pull request #3107 from mariojsnunes/refactor/header-component-…
thisislawatts Dec 26, 2023
dcf4ce6
chore: align with standards for naming custom React Hook function
thisislawatts Dec 26, 2023
b99bda7
Merge pull request #3109 from ONEARMY/chore/refactor-align-with-react…
thisislawatts Dec 26, 2023
07dcbc2
Merge pull request #3106 from ONEARMY/chore/refactor-tests-to-match-R…
thisislawatts Dec 26, 2023
9bb9dff
Merge pull request #3104 from ONEARMY/chore/components-correct-deps-i…
thisislawatts Dec 26, 2023
b9944e6
refactor: remove (not used) resend signup message component
mariojsnunes Dec 26, 2023
4c53014
Merge pull request #3110 from mariojsnunes/refactor/remove-unused-com…
thisislawatts Dec 26, 2023
16098ca
Merge pull request #3101 from ONEARMY/chore/reduce-log-output
thisislawatts Dec 26, 2023
b23a89b
Merge pull request #3103 from ONEARMY/chore/introduce-tests-to-commen…
thisislawatts Dec 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
"react-dropzone": "^10.1.10",
"react-final-form": "6.5.3",
"react-final-form-arrays": "^3.1.3",
"react-firebase-file-uploader": "2.4.4",
"react-foco": "^1.3.1",
"react-ga4": "^1.4.1",
"react-hamburger-menu": "^1.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/CommentItem/CommentItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const CommentItem = (props: CommentItemProps) => {
if (textRef.current) {
setTextHeight(textRef.current.scrollHeight)
}
}, [text])
}, [textRef])

const showMore = () => {
setShowMore(!isShowMore)
Expand Down
15 changes: 1 addition & 14 deletions packages/components/src/CommentList/CommentList.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import type { StoryFn, Meta } from '@storybook/react'
import { CommentList } from './CommentList'
import { faker } from '@faker-js/faker'
import { createComments } from './createComments'

export default {
title: 'Components/CommentList',
component: CommentList,
} as Meta<typeof CommentList>

const createComments = (numberOfComments = 2, commentOverloads = {}) =>
[...Array(numberOfComments).keys()].slice(0).map(() => ({
_created: faker.date.past().toString(),
creatorCountry: faker.address.countryCode().toLowerCase(),
_creatorId: faker.internet.userName(),
_id: faker.database.mongodbObjectId(),
creatorName: faker.internet.userName(),
isUserVerified: faker.datatype.boolean(),
text: faker.lorem.text(),
isEditable: faker.datatype.boolean(),
...commentOverloads,
}))

export const Default: StoryFn<typeof CommentList> = () => (
<CommentList
comments={createComments(2)}
Expand Down
69 changes: 69 additions & 0 deletions packages/components/src/CommentList/CommentList.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { fireEvent } from '@testing-library/react'
import { vi } from 'vitest'
import { render } from '../tests/utils'
import { CommentList } from './CommentList'
import type { CommentItemProps as Comment } from '../CommentItem/CommentItem'
import { createComments } from './createComments'

const mockHandleEdit = vi.fn()
const mockHandleEditRequest = vi.fn()
const mockHandleDelete = vi.fn()
const mockTrackEvent = vi.fn()

describe('CommentList', () => {
it('renders the correct number of comments initially', () => {
const mockComments: Comment[] = createComments(2)
const screen = render(
<CommentList
comments={mockComments}
handleEdit={mockHandleEdit}
handleEditRequest={mockHandleEditRequest}
handleDelete={mockHandleDelete}
trackEvent={mockTrackEvent}
/>,
)
expect(screen.getAllByTestId('CommentList: item')).toHaveLength(
mockComments.length,
)
})

it('loads more comments when show more button is clicked', () => {
const mockComments: Comment[] = createComments(20)
const screen = render(
<CommentList
comments={mockComments}
handleEdit={mockHandleEdit}
handleEditRequest={mockHandleEditRequest}
handleDelete={mockHandleDelete}
trackEvent={mockTrackEvent}
/>,
)
fireEvent.click(screen.getByText('show more comments'))
expect(screen.getAllByTestId('CommentList: item').length).toBeGreaterThan(5)
expect(mockTrackEvent).toHaveBeenCalledWith({
category: 'Comments',
action: 'Show more',
label: undefined, // Replace with expected article title if available
})
})

it('highlights the correct comment when highlightedCommentId is provided', () => {
const mockComments: Comment[] = createComments(10)
const highComm = mockComments[1]
const highlightedCommentId = highComm._id // Replace with an actual ID from mockComments
highComm.text = 'Highlighted comment text'
const screen = render(
<CommentList
comments={mockComments}
highlightedCommentId={highlightedCommentId}
handleEdit={mockHandleEdit}
handleEditRequest={mockHandleEditRequest}
handleDelete={mockHandleDelete}
trackEvent={mockTrackEvent}
/>,
)
expect(screen.getAllByTestId('CommentList: item')[1]).toHaveStyle(
'border: 2px dashed black',
)
})
})
5 changes: 3 additions & 2 deletions packages/components/src/CommentList/CommentList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button, CommentItem } from '../'
import type { CommentItemProps as Comment } from '../CommentItem/CommentItem'
const MAX_COMMENTS = 5

type CommentListProps = {
export type CommentListProps = {
comments: Comment[]
handleEdit: (_id: string, comment: string) => Promise<void>
handleEditRequest: () => Promise<void>
Expand Down Expand Up @@ -48,7 +48,7 @@ export const CommentList = ({
setMoreComments(Math.floor(i / MAX_COMMENTS) + 1)
scrollIntoRelevantComment(highlightedCommentId)
}
}, [highlightedCommentId])
}, [highlightedCommentId, comments])

return (
<Box
Expand All @@ -62,6 +62,7 @@ export const CommentList = ({
comments.slice(0, shownComments).map((comment: Comment) => (
<Box
key={comment._id}
data-testid="CommentList: item"
sx={{
marginBottom: 4,
border: `${
Expand Down
18 changes: 18 additions & 0 deletions packages/components/src/CommentList/createComments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { CommentItemProps as Comment } from '../CommentItem/CommentItem'
import { faker } from '@faker-js/faker'

export const createComments = (
numberOfComments = 2,
commentOverloads = {},
): Comment[] =>
[...Array(numberOfComments).keys()].slice(0).map(() => ({
_created: faker.date.past().toString(),
creatorCountry: faker.address.countryCode().toLowerCase(),
_creatorId: faker.internet.userName(),
_id: faker.database.mongodbObjectId(),
creatorName: faker.internet.userName(),
isUserVerified: faker.datatype.boolean(),
text: faker.lorem.text(),
isEditable: faker.datatype.boolean(),
...commentOverloads,
}))
6 changes: 3 additions & 3 deletions packages/components/src/ImageGallery/ImageGallery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export const ImageGallery = (props: ImageGalleryProps) => {

useEffect(() => {
const images = (props.images || []).filter((img) => img !== null)
setState({
setState((state) => ({
...state,
activeImageIndex: 0,
images: images,
})
}))

// Initializes the Photoswipe lightbox to use the provided images
lightbox.current = new PhotoSwipeLightbox({
Expand Down Expand Up @@ -103,7 +103,7 @@ export const ImageGallery = (props: ImageGalleryProps) => {
lightbox.current?.destroy()
lightbox.current = undefined
}
}, [props.images])
}, [props.images, props.photoSwipeOptions])

const setActive = (imageIndex: number) => {
setState({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const NotificationList = (props: Props) => {
const sx = props.sx || {}
useEffect(() => {
notifications.length && markAllNotified && markAllNotified()
}, [])
}, [notifications, markAllNotified])

return (
<Card sx={{ padding: 2, maxHeight: 310, overflowY: 'auto', ...sx }}>
Expand Down
3 changes: 2 additions & 1 deletion packages/components/src/OsmGeocoding/OsmGeocoding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const OsmGeocoding = ({
}

const showResultsListing = !!results.length && showResults && !showLoader

const dcb = useDebouncedCallback(
(search: string) => getGeocoding(search),
debounceMs,
Expand All @@ -83,7 +84,7 @@ export const OsmGeocoding = ({
if (queryLocationService) {
dcb(searchValue)
}
}, [searchValue, queryLocationService])
}, [searchValue, queryLocationService, dcb])

return (
<div
Expand Down
1 change: 1 addition & 0 deletions shared/models/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const generateDBEndpoints = (DB_PREFIX = '') => ({
questions: `${DB_PREFIX}questions_rev20230926`,
questionCategories: `${DB_PREFIX}question_categories_rev20231130`,
user_integrations: `${DB_PREFIX}user_integrations`,
discussions: `${DB_PREFIX}discussions_rev20231022`,
})

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'
import { useCommonStores } from '../../index'
import type { AggregationsStore } from 'src/stores/Aggregations/aggregations.store'

export const userStats = (userId: string) => {
export const useMemberStatistics = (userId: string) => {
const { aggregationsStore } = useCommonStores().stores
const [totalUseful, setTotalUseful] = useState<number>(0)
const [verified, setVerified] = useState<boolean>(false)
Expand Down
12 changes: 12 additions & 0 deletions src/models/discussion.models.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { IComment } from './comment.model'

export type IDiscussionComment = IComment & {
parentCommentId: string | null
}

export type IDiscussion = {
_id: string
sourceId: string
sourceType: 'question'
comments: IDiscussionComment[]
}
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export * from './user.models'
export * from './userPreciousPlastic.models'
export * from './notifications.models'
export * from './question.models'
export * from './discussion.models'
export interface UserComment extends IComment {
isEditable: boolean
}
12 changes: 6 additions & 6 deletions src/pages/Howto/Content/Common/Howto.form.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('Howto form', () => {
// Act
let wrapper
await act(async () => {
wrapper = await getWrapper(formValues, 'edit', {})
wrapper = await Wrapper(formValues, 'edit', {})
})

// Assert
Expand All @@ -66,7 +66,7 @@ describe('Howto form', () => {
// Act
let wrapper
await act(async () => {
wrapper = await getWrapper(formValues, 'edit', {})
wrapper = await Wrapper(formValues, 'edit', {})
})

// Assert
Expand All @@ -88,7 +88,7 @@ describe('Howto form', () => {
// Act
let wrapper
await act(async () => {
wrapper = await getWrapper(formValues, 'edit', {})
wrapper = await Wrapper(formValues, 'edit', {})
})

// Assert
Expand All @@ -111,7 +111,7 @@ describe('Howto form', () => {
// Act
let wrapper
await act(async () => {
wrapper = await getWrapper(formValues, 'edit', {})
wrapper = await Wrapper(formValues, 'edit', {})
})

// Assert
Expand All @@ -131,7 +131,7 @@ describe('Howto form', () => {
// Act
let wrapper
await act(async () => {
wrapper = await getWrapper(formValues, 'edit', {})
wrapper = await Wrapper(formValues, 'edit', {})

// clear files
const reuploadFilesButton = wrapper.getByTestId('re-upload-files')
Expand All @@ -157,7 +157,7 @@ describe('Howto form', () => {
})
})

const getWrapper = async (formValues, parentType, navProps) => {
const Wrapper = async (formValues, parentType, navProps) => {
return render(
<Provider {...useCommonStores().stores}>
<ThemeProvider theme={Theme}>
Expand Down
2 changes: 0 additions & 2 deletions src/pages/Howto/Content/Common/Howto.form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import {
} from '.'

import type { IHowtoFormInput } from 'src/models/howto.models'
import type { UploadedFile } from 'src/pages/common/UploadedFile/UploadedFile'
import type { HowtoStore } from 'src/stores/Howto/howto.store'
export type ParentType = 'create' | 'edit'

Expand All @@ -62,7 +61,6 @@ const FormContainer = styled.form`
@inject('howtoStore')
@observer
export class HowtoForm extends React.PureComponent<IProps, IState> {
uploadRefs: { [key: string]: UploadedFile | null } = {}
formContainerRef = React.createRef<HTMLElement>()
public checkFilesValid = (formValues: IHowtoFormInput) => {
if (
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Maps/Maps.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('Maps', () => {
},
})

await getWrapper()
await Wrapper()

expect(global.navigator.geolocation.getCurrentPosition).toBeCalled()
})
Expand Down Expand Up @@ -99,7 +99,7 @@ describe('Maps', () => {
let wrapper

await act(async () => {
wrapper = await getWrapper('/map#abc')
wrapper = await Wrapper('/map#abc')
})

await waitFor(async () => {
Expand All @@ -109,7 +109,7 @@ describe('Maps', () => {
})
})

const getWrapper = async (path = '/map') => {
const Wrapper = async (path = '/map') => {
const router = createMemoryRouter(
createRoutesFromElements(<Route path="/map" element={<Maps />} />),
{
Expand Down
16 changes: 0 additions & 16 deletions src/pages/PageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ const SignUpMessagePage = lazy(
() =>
import(/* webpackChunkName: "SignUpMessage" */ './SignUp/SignUpMessage'),
)
const ResendSignUpMessagePage = lazy(
() =>
import(
/* webpackChunkName: "ResendSignUpMessage" */ './SignUp/ResendSignUpMessage'
),
)
const SignUpPage = lazy(
() => import(/* webpackChunkName: "SignUp" */ './SignUp/SignUp'),
)
Expand Down Expand Up @@ -147,15 +141,6 @@ const signupmessage = {
description: '',
}

const resendsignupmessage = {
moduleName: MODULE.USER,
path: '/resend-sign-up-message',
exact: true,
component: <ResendSignUpMessagePage />,
title: 'Resend Sign Up Message',
description: '',
}

const privacyPolicy = {
moduleName: MODULE.CORE,
path: '/privacy',
Expand Down Expand Up @@ -203,7 +188,6 @@ export const NO_HEADER_PAGES: IPageMeta[] = [
user,
signup,
signupmessage,
resendsignupmessage,
signin,
ResearchModule, // CC 2021-06-24 - Temporary - make research module accessible to all in production but hide from nav
unsubscribe,
Expand Down
Loading
Loading