Skip to content

Commit

Permalink
Merge branch 'master' into 3135-fix-sort-by-comment
Browse files Browse the repository at this point in the history
  • Loading branch information
goratt12 authored Jan 2, 2024
2 parents 47aef52 + 6b3e60b commit c541a67
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 99 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,15 @@
"contributions": [
"code"
]
},
{
"login": "darigovresearch",
"name": "Darigov Research",
"avatar_url": "https://avatars.githubusercontent.com/u/30328618?v=4",
"profile": "https://www.darigovresearch.com/",
"contributions": [
"doc"
]
}
],
"projectName": "community-platform",
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Thanks go to these wonderful people ([emoji key](https://allcontributors.org/doc
<td align="center" valign="top" width="14.28%"><a href="http://ignasplace.com"><img src="https://avatars.githubusercontent.com/u/76262712?v=4?s=60" width="60px;" alt="Ignas"/><br /><sub><b>Ignas</b></sub></a><br /><a href="https://github.com/ONEARMY/community-platform/commits?author=IgnasPlace" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mariojsnunes"><img src="https://avatars.githubusercontent.com/u/8073622?v=4?s=60" width="60px;" alt="Mário Nunes"/><br /><sub><b>Mário Nunes</b></sub></a><br /><a href="https://github.com/ONEARMY/community-platform/commits?author=mariojsnunes" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/oktomus"><img src="https://avatars.githubusercontent.com/u/4656466?v=4?s=60" width="60px;" alt="Kevin Masson"/><br /><sub><b>Kevin Masson</b></sub></a><br /><a href="https://github.com/ONEARMY/community-platform/commits?author=oktomus" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://www.darigovresearch.com/"><img src="https://avatars.githubusercontent.com/u/30328618?v=4?s=60" width="60px;" alt="Darigov Research"/><br /><sub><b>Darigov Research</b></sub></a><br /><a href="https://github.com/ONEARMY/community-platform/commits?author=darigovresearch" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
Expand Down
70 changes: 35 additions & 35 deletions packages/documentation/docs/Contributing/start-contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,46 @@ title: Start Contributing

## What is my role?

By default we consider everyone that submits a PR a contributor. People that contribute regularly and want to get more involved can become maintainers to help new contributors. People here for the long term are core maintainers and work on the core of the platform. Here is an overview of the roles
By default we consider everyone that submits a pull request (PR) to be a contributor. People that contribute regularly and want to get more involved can become maintainers to help new contributors. People here for the long term are core maintainers and work on the core of the platform. Here is an overview of the roles

| Role | Payment | Requirements | Tasks |
| --------------------- | ------------- | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| **🤙 Contributor** | Bounty System | Submit a PR | Resolves issues by submitting Pull Requests |
| **⚡️ Maintainer** | Bounty System | Minimum 3 merged PR's + chat with core maintainer | Review basic PR's, help contributors, improve documentation |
| **🪛 Core Maintainer** | Hourly scale | Minimum 3 months maintainer | Review complex PR's, Improve code quality, Devops, optimisations, Security, general updates, Documentation |
| Role | Payment | Requirements | Tasks |
| ---------------------- | ------------- | ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------- |
| **🤙 Contributor** | Bounty System | Submit a PR | Resolves issues by submitting pull requests |
| **⚡️ Maintainer** | Bounty System | Minimum 3 merged PR's + chat with core maintainer | Review basic PR's, help contributors & improve documentation |
| **🔧 Core Maintainer** | Hourly scale | Minimum 3 months maintainer | Review complex PR's, improve code quality, devops, optimisations, security, general updates & documentation |

### 🤙 Contributors to do:
### 🤙 Things that Contributors do:

#### Pick up issues

1. Check our [documentation](/) to run it locally.
2. Pick an open [issue](https://github.com/ONEARMY/community-platform/issues).
3. If there is a [bounty](/Contributing/bounties) label on it you can claim a reward.
4. Read our [contribution guidelines](https://github.com/ONEARMY/community-platform/blob/master/CONTRIBUTING.md)
4. Read our [contribution guidelines](https://github.com/ONEARMY/community-platform/blob/master/CONTRIBUTING.md).
5. Bonus: Add [tests](/Testing/end-to-end).

### ⚡️ Maintainers to do:
### ⚡️ Things that Maintainers do:

#### Review incoming code from Contributors

1. Validate if code is clean
2. Validate if the [project structure](https://github.com/ONEARMY/community-platform/blob/master/CONTRIBUTING.md#--project-structure) is correct
3. Check out user profile to see who is behind the commit
4. Add them to our [contributors list](#recognising-contributors)
5. Make sure [Lint commit](https://github.com/ONEARMY/community-platform/blob/master/CONTRIBUTING.md#--commit-style-guide) message is correct
1. Validate if code is clean.
2. Validate if the [project structure](https://github.com/ONEARMY/community-platform/blob/master/CONTRIBUTING.md#--project-structure) is correct.
3. Check out user profile to see who is behind the commit.
4. Add them to our [contributors list](#recognising-contributors).
5. Make sure [Lint commit](https://github.com/ONEARMY/community-platform/blob/master/CONTRIBUTING.md#--commit-style-guide) message is correct.
6. Make sure all checks are passed and help to resolve errors.
7. If there is a [bounty](/Contributing/bounties) label on the PR you can get it for reviewing.
8. Bonus: Ask for integrating tests
8. Bonus: Ask for integrating tests.

### 🪛 Core Maintainer to do:
### 🔧 Things that Core Maintainers do:

#### Review complex PRs & Releasing Changes
#### Review complex PRs & release changes

The workflow for deploying code changes from development to production environments. It ensures proper review, testing, and versioning before reaching production sites.
There is a workflow for deploying code changes from development to production environments. It ensures proper review, testing, and versioning before reaching production sites.

The steps are as follows:

- Pull Request (PR) is merged into the `master` branch.
- The PR is merged into the `master` branch.
- `master` branch triggers an automated build and deployment to development environments.
- A Release PR is automatically raised to merge `master` into the `production` branch.
- Manual approval is required by a maintainer, then merge Release PR into `production`.
Expand All @@ -58,25 +58,25 @@ We have adopted [all contributors](https://allcontributors.org/) and their tooli

After merging a new contributors PR:

1. Add a comment to the merged PR mentioning the bot, contributor and their contribution [type](https://allcontributors.org/docs/en/emoji-key), for example: `@all-contributors add @username for code`
2. A PR will be automatically raised, [example](https://github.com/ONEARMY/community-platform/pull/1952)
3. The PR raised by the All Contributors bot will need to be merged with admin privileges as the required CI skips are deliberately skipped.
1. Add a comment to the merged PR mentioning the bot, contributor and their contribution [type](https://allcontributors.org/docs/en/emoji-key), for example: `@all-contributors add @username for code`.
2. A PR will be automatically raised, [example](https://github.com/ONEARMY/community-platform/pull/1952).
3. The PR raised by the `All Contributors` bot will need to be merged with admin privileges as the required CI skips are deliberately skipped.

### Payment

Each role get paid a bit differently. Contributors and maintainers get paid according to the [Bounty system](/Contributing/bounties). For core maintainers there is a separate hourly pay scale. Aimed at developers who help a bit more consistently at around 2-3h per week. If you're interested in these roles then feel free to reach out on [Discord](https://discord.gg/gJ7Yyk4).
Each role gets paid a bit differently. Contributors and maintainers get paid according to the [Bounty system](/Contributing/bounties). For core maintainers there is a separate hourly pay scale. Aimed at developers who help a bit more consistently at around 2-3 hours per week. If you're interested in these roles then feel free to reach out on [Discord](https://discord.gg/gJ7Yyk4).

## Onboarding checklist

| Tasks | 🤙 Contributor | ⚡️ Maintainer | 🪛 Core Maintainer |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | -------------- | ----------------- |
| Invite to [Discord](https://discord.gg/gJ7Yyk4) #development | ☑️ | ☑️ | ☑️ |
| Send link to [bounty](/Contributing/bounties) system | ☑️ | ☑️ | ☑️ |
| Add GitHub [maintainer permissions](https://github.com/ONEARMY/community-platform/settings/access) | | ☑️ | ☑️ |
| Add maintainer status using [All contributors ](#recognising-contributors) | | ☑️ | ☑️ |
| Get on a video call | | ☑️ | ☑️ |
| Explain hourly rate vs bounty system | | ☑️ | ☑️ |
| Add GitHub [core maintainer permissions](https://github.com/ONEARMY/community-platform/settings/access) | | | ☑️ |
| Add core-maintainer status using [All contributors ](#recognising-contributors) | | | ☑️ |
| Invite to Google Analytics | | | ☑️ |
| Invite to **Firebase** projects: Precious Plastic PROD, Precious Plastic DEV, Project Kamp PROD, Project Kamp DEV, Fixing Fashion PROD, Fixing Fashion DEV | | | ☑️ |
| Tasks | 🤙 Contributor | ⚡️ Maintainer | 🔧 Core Maintainer |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | -------------- | ------------------ |
| Invite to [Discord](https://discord.gg/gJ7Yyk4) #development | ☑️ | ☑️ | ☑️ |
| Send link to [bounty](/Contributing/bounties) system | ☑️ | ☑️ | ☑️ |
| Add GitHub [maintainer permissions](https://github.com/ONEARMY/community-platform/settings/access) | | ☑️ | ☑️ |
| Add maintainer status using [All contributors ](#recognising-contributors) | | ☑️ | ☑️ |
| Get on a video call | | ☑️ | ☑️ |
| Explain hourly rate vs bounty system | | ☑️ | ☑️ |
| Add GitHub [core maintainer permissions](https://github.com/ONEARMY/community-platform/settings/access) | | | ☑️ |
| Add core-maintainer status using [All contributors ](#recognising-contributors) | | | ☑️ |
| Invite to Google Analytics | | | ☑️ |
| Invite to **Firebase** projects: Precious Plastic PROD, Precious Plastic DEV, Project Kamp PROD, Project Kamp DEV, Fixing Fashion PROD, Fixing Fashion DEV | | | ☑️ |
41 changes: 35 additions & 6 deletions src/pages/Question/QuestionPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { Loader, ModerationStatus, UsefulStatsButton } from 'oa-components'
import {
Loader,
ModerationStatus,
UsefulStatsButton,
FollowButton,
} from 'oa-components'
import { useState, useEffect } from 'react'
import { Link, useParams } from 'react-router-dom'
import type { IQuestion } from 'src/models'
Expand All @@ -13,20 +18,27 @@ export const QuestionPage = () => {
const [isLoading, setIsLoading] = useState(true)
const [question, setQuestion] = useState<IQuestion.Item | undefined>()
const [isEditable, setIsEditable] = useState(false)
const [hasUserSubscribed, setHasUserSubscribed] = useState(false)

useEffect(() => {
const fetchQuestions = async () => {
if (slug) {
const question: any = await store.fetchQuestionBySlug(slug)
store.activeQuestionItem = question || null
const foundQuestion: any = await store.fetchQuestionBySlug(slug)
store.activeQuestionItem = foundQuestion || null

if (isLoading) {
setQuestion(question || null)
setQuestion(foundQuestion || null)

if (store.activeUser) {
setIsEditable(isAllowedToEditContent(question, store.activeUser))
setIsEditable(
isAllowedToEditContent(foundQuestion, store.activeUser),
)
}
}

setHasUserSubscribed(
foundQuestion?.subscribers?.includes(store.activeUser?.userName),
)
}

setIsLoading(false)
Expand All @@ -52,19 +64,36 @@ export const QuestionPage = () => {
}
}

const isLoggedIn = store.activeUser ? true : false
const onFollowClick = () => {
if (question) {
store.toggleSubscriberStatusByUserName(
question._id,
store.activeUser?.userName,
)
setHasUserSubscribed(!hasUserSubscribed)
}
return null
}

return (
<Box sx={{ p: 7 }}>
{isLoading ? (
<Loader />
) : question ? (
<Card sx={{ mt: 4, p: 4, position: 'relative' }}>
<Flex sx={{ flexWrap: 'wrap', gap: '10px' }}>
<Flex sx={{ flexWrap: 'wrap', gap: 2 }}>
<UsefulStatsButton
votedUsefulCount={store.votedUsefulCount}
hasUserVotedUseful={store.userVotedActiveQuestionUseful}
isLoggedIn={store.activeUser ? true : false}
onUsefulClick={onUsefulClick}
/>
<FollowButton
hasUserSubscribed={hasUserSubscribed}
isLoggedIn={isLoggedIn ? true : false}
onFollowClick={onFollowClick}
/>
</Flex>
<ModerationStatus
status={question.moderation}
Expand Down
40 changes: 40 additions & 0 deletions src/pages/Question/question.routes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,46 @@ describe('question.routes', () => {
})
})

describe('Follow', () => {
it('displays following status', async () => {
let wrapper
const user = FactoryUser()
const question = FactoryQuestionItem({
subscribers: [user.userName],
})
const mockFetchQuestionBySlug = jest.fn().mockResolvedValue(question)
useQuestionStore.mockReturnValue({
...mockQuestionStore,
activeUser: user,
fetchQuestionBySlug: mockFetchQuestionBySlug,
})

await act(async () => {
wrapper = (await renderFn(`/questions/${question.slug}`)).wrapper
})

await waitFor(() => {
expect(wrapper.getByText('Following')).toBeInTheDocument()
})
})

it('supports follow behaviour', async () => {
let wrapper
const question = FactoryQuestionItem()
const mockFetchQuestionBySlug = jest.fn().mockResolvedValue(question)
useQuestionStore.mockReturnValue({
...mockQuestionStore,
fetchQuestionBySlug: mockFetchQuestionBySlug,
})

await act(async () => {
wrapper = (await renderFn(`/questions/${question.slug}`)).wrapper
})

expect(wrapper.getByText('Follow')).toBeInTheDocument()
})
})

it('does not show Edit call to action', async () => {
let wrapper
mockActiveUser = FactoryUser()
Expand Down
29 changes: 29 additions & 0 deletions src/stores/Question/question.store.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const factory = async () => {
return newValue
})

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
store.db.update.mockImplementation((newValue) => {
return newValue
})

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
store.db.getWhere.mockImplementation(async () => {})
Expand All @@ -28,6 +34,9 @@ const factory = async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
getWhereFn: store.db.getWhere,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
updateFn: store.db.update,
}
}

Expand Down Expand Up @@ -158,4 +167,24 @@ describe('question.store', () => {
expect(questionDoc).toStrictEqual(newQuestion)
})
})

describe('toggleSubscriberStatusByUserName', () => {
it('adds user to subscribers list', async () => {
const { store, updateFn } = await factory()
const newQuestion = FactoryQuestionItem({
title: 'Question title',
subscribers: [],
})

// Act
await store.toggleSubscriberStatusByUserName(newQuestion._id, 'user1')

expect(updateFn).toBeCalledWith(
expect.objectContaining({
_id: newQuestion._id,
subscribers: ['user1'],
}),
)
})
})
})
Loading

0 comments on commit c541a67

Please sign in to comment.