Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Dschoordsch committed Dec 11, 2024
1 parent f401e81 commit acdc5ed
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 102 deletions.
28 changes: 13 additions & 15 deletions packages/mattermost-plugin/AtmosphereProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import {Client4} from 'mattermost-redux/client'
import {ReactNode, useCallback, useEffect} from 'react'
import {useSelector} from 'react-redux'
import {RelayEnvironmentProvider} from 'react-relay'
import {Atmosphere} from './Atmosphere'
import {getPluginServerRoute} from './selectors'
import {Client4} from 'mattermost-redux/client'
import {useSelector} from 'react-redux'

type Props = {
environment: Atmosphere
children: ReactNode
}

export default function AtmosphereProvider({ environment, children }: Props) {
export default function AtmosphereProvider({environment, children}: Props) {
const pluginServerRoute = useSelector(getPluginServerRoute)
const serverUrl = `${pluginServerRoute}/login`
const login = useCallback(async () => {
const response = await fetch(serverUrl, Client4.getOptions({
method: "POST",
headers: {
"Content-Type": "application/json",
},
}));
const response = await fetch(
serverUrl,
Client4.getOptions({
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
})
)
const body = await response.json()
console.log('GEORG response', body)
environment.state.authToken = body.authToken

}, [serverUrl])

useEffect(() => {
Expand All @@ -36,9 +38,5 @@ export default function AtmosphereProvider({ environment, children }: Props) {
return null
}

return (
<RelayEnvironmentProvider environment={environment}>
{children}
</RelayEnvironmentProvider>
)
return <RelayEnvironmentProvider environment={environment}>{children}</RelayEnvironmentProvider>
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const LinkTeamModalRoot = () => {

return (
<Suspense fallback={null}>
<LinkTeamModal/>
<LinkTeamModal />
</Suspense>
)
}
Expand Down
4 changes: 1 addition & 3 deletions packages/mattermost-plugin/components/LoadingSpinner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ const LoadingSpinner = ({text, style}: Props) => {
style={style}
data-testid='loadingSpinner'
>
<span
className='fa fa-spinner fa-fw fa-pulse spinner'
/>
<span className='fa fa-spinner fa-fw fa-pulse spinner' />
{text}
</span>
)
Expand Down
8 changes: 3 additions & 5 deletions packages/mattermost-plugin/components/Menu.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {DotsVerticalIcon} from '@mattermost/compass-icons/components'
import {IconButton, Menu, MenuItem} from '@mui/material'
import {
DotsVerticalIcon,
} from '@mattermost/compass-icons/components'
import React from 'react'

type MenuOption = {
Expand Down Expand Up @@ -32,12 +30,12 @@ const MoreMenu = ({options}: Props) => {
aria-haspopup='true'
onClick={handleOpen}
>
<DotsVerticalIcon/>
<DotsVerticalIcon />
</IconButton>
<Menu
id='long-menu'
MenuListProps={{
'aria-labelledby': 'long-button',
'aria-labelledby': 'long-button'
}}
anchorEl={anchorEl}
open={open}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import React, {useEffect, useMemo} from 'react'
import graphql from 'babel-plugin-relay/macro'
import {markdownToDraft} from 'markdown-draft-js'
import React, {useEffect, useMemo} from 'react'
import {Modal} from 'react-bootstrap'
import {useDispatch, useSelector} from 'react-redux'
import {markdownToDraft} from 'markdown-draft-js'

import {getPost} from 'mattermost-redux/selectors/entities/posts'

import {GlobalState} from 'mattermost-redux/types/store'

import {useLazyLoadQuery, useMutation} from 'react-relay'
import {PushReflectionModalMutation} from '../../__generated__/PushReflectionModalMutation.graphql'
import {PushReflectionModalQuery} from '../../__generated__/PushReflectionModalQuery.graphql'
import {closePushPostAsReflection} from '../../reducers'
import {getAssetsUrl, getPostURL, pushPostAsReflection} from '../../selectors'
import Select from '../Select'
import {useLazyLoadQuery, useMutation} from 'react-relay'
import {PushReflectionModalQuery} from '../../__generated__/PushReflectionModalQuery.graphql'
import {PushReflectionModalMutation} from '../../__generated__/PushReflectionModalMutation.graphql'

const PostUtils = (window as any).PostUtils

Expand All @@ -22,47 +22,63 @@ const PushReflectionModal = () => {
const post = useSelector((state: GlobalState) => getPost(state, postId!))
const postUrl = useSelector((state: GlobalState) => getPostURL(state, postId!))

const data = useLazyLoadQuery<PushReflectionModalQuery>(graphql`
query PushReflectionModalQuery {
viewer {
teams {
id
activeMeetings {
const data = useLazyLoadQuery<PushReflectionModalQuery>(
graphql`
query PushReflectionModalQuery {
viewer {
teams {
id
name
meetingType
... on RetrospectiveMeeting {
phases {
... on ReflectPhase {
reflectPrompts {
id
question
description
}
stages {
isComplete
activeMeetings {
id
name
meetingType
... on RetrospectiveMeeting {
phases {
... on ReflectPhase {
reflectPrompts {
id
question
description
}
stages {
isComplete
}
}
}
templateId
}
templateId
}
}
}
}
}
`, {})
`,
{}
)
const {viewer} = data
const {teams} = viewer
const retroMeetings = useMemo(() => teams.flatMap(({activeMeetings}) => activeMeetings).filter(({meetingType}) => meetingType === 'retrospective'), [teams])
const [selectedMeeting, setSelectedMeeting] = React.useState<typeof retroMeetings[number]>()
const [selectedPrompt, setSelectedPrompt] = React.useState<{id: string, question: string, description: string}>()
const retroMeetings = useMemo(
() =>
teams
.flatMap(({activeMeetings}) => activeMeetings)
.filter(({meetingType}) => meetingType === 'retrospective'),
[teams]
)
const [selectedMeeting, setSelectedMeeting] = React.useState<(typeof retroMeetings)[number]>()
const [selectedPrompt, setSelectedPrompt] = React.useState<{
id: string
question: string
description: string
}>()

const [comment, setComment] = React.useState('')
const formattedPost = useMemo(() => {
if (!post) {
return null
}
const quotedMessage = post.message.split('\n').map((line) => `> ${line}`).join('\n')
const quotedMessage = post.message
.split('\n')
.map((line) => `> ${line}`)
.join('\n')
return `${quotedMessage}\n\n[See comment in Mattermost](${postUrl})`
}, [post])

Expand All @@ -84,7 +100,10 @@ const PushReflectionModal = () => {
}
}, [data, selectedMeeting])

const reflectPhase = useMemo(() => selectedMeeting?.phases?.find((phase: any) => 'reflectPrompts' in phase), [selectedMeeting])
const reflectPhase = useMemo(
() => selectedMeeting?.phases?.find((phase: any) => 'reflectPrompts' in phase),
[selectedMeeting]
)

useEffect(() => {
setSelectedPrompt(reflectPhase?.reflectPrompts?.[0])
Expand All @@ -102,7 +121,6 @@ const PushReflectionModal = () => {
return
}


const markdown = `${comment}\n\n${formattedPost}`
const rawObject = markdownToDraft(markdown)
const content = JSON.stringify(rawObject)
Expand All @@ -113,9 +131,9 @@ const PushReflectionModal = () => {
meetingId: selectedMeeting.id,
promptId: selectedPrompt.id,
content,
sortOrder: 0,
},
},
sortOrder: 0
}
}
})

handleClose()
Expand All @@ -138,35 +156,33 @@ const PushReflectionModal = () => {
>
<Modal.Header closeButton={true}>
<Modal.Title>
<img
width={36}
height={36}
src={`${assetsPath}/parabol.png`}
/>
<img width={36} height={36} src={`${assetsPath}/parabol.png`} />
{' Add Comment to Parabol Activity'}
</Modal.Title>
</Modal.Header>
<Modal.Body>
<div>
<p>Choose an open Retro activity and the Prompt where you want to send the Mattermost comment. A reference link back to Mattermost will be inlcuded in the reflection.</p>
<p>
Choose an open Retro activity and the Prompt where you want to send the Mattermost
comment. A reference link back to Mattermost will be inlcuded in the reflection.
</p>
</div>
{post && (
<div className='form-group'>
<label
className='control-label'
htmlFor='comment'
>Add a Comment<span className='error-text'> *</span></label>
<label className='control-label' htmlFor='comment'>
Add a Comment<span className='error-text'> *</span>
</label>
<div
className='form-control'
style={{
resize: 'none',
height: 'auto',
height: 'auto'
}}
>
<textarea
style={{
border: 'none',
width: '100%',
width: '100%'
}}
id='comment'
value={comment}
Expand All @@ -180,32 +196,39 @@ const PushReflectionModal = () => {
</div>
</div>
)}
{data && (<>
<Select
label='Choose Activity'
required={true}
value={selectedMeeting}
options={retroMeetings ?? []}
onChange={setSelectedMeeting}
/>
<Select
label='Choose Prompt'
required={true}
value={selectedPrompt && {id: selectedPrompt.id, name: selectedPrompt.question}}
options={reflectPhase?.reflectPrompts?.map(({id, question}) => ({id, name: question})) ?? []}
onChange={(selected) => selected && setSelectedPrompt(reflectPhase?.reflectPrompts?.find((prompt) => prompt.id === selected.id))}
/>
</>)}
{data && (
<>
<Select
label='Choose Activity'
required={true}
value={selectedMeeting}
options={retroMeetings ?? []}
onChange={setSelectedMeeting}
/>
<Select
label='Choose Prompt'
required={true}
value={selectedPrompt && {id: selectedPrompt.id, name: selectedPrompt.question}}
options={
reflectPhase?.reflectPrompts?.map(({id, question}) => ({id, name: question})) ?? []
}
onChange={(selected) =>
selected &&
setSelectedPrompt(
reflectPhase?.reflectPrompts?.find((prompt) => prompt.id === selected.id)
)
}
/>
</>
)}
</Modal.Body>
<Modal.Footer>
<button
className='btn btn-tertiary cancel-button'
onClick={handleClose}
>Cancel</button>
<button
className='btn btn-primary save-button'
onClick={handlePush}
>Add Comment</button>
<button className='btn btn-tertiary cancel-button' onClick={handleClose}>
Cancel
</button>
<button className='btn btn-primary save-button' onClick={handlePush}>
Add Comment
</button>
</Modal.Footer>
</Modal>
)
Expand Down
4 changes: 2 additions & 2 deletions packages/mattermost-plugin/hooks/useCurrentChannel.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useSelector } from 'react-redux'
import { getCurrentChannel } from 'mattermost-redux/selectors/entities/channels'
import {getCurrentChannel} from 'mattermost-redux/selectors/entities/channels'
import {useSelector} from 'react-redux'

export const useCurrentChannel = () => {
const channel = useSelector(getCurrentChannel)
Expand Down
12 changes: 7 additions & 5 deletions packages/mattermost-plugin/types/mattermost-webapp/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import React from 'react'

export type ContextArgs = {channel_id: string};
export type ContextArgs = {channel_id: string}

type FormatTextOptions = {
atMentions?: boolean;
markdown?: boolean;
atMentions?: boolean
markdown?: boolean
}

type MessageHtmlToComponentOptions = {
mentionHighlight: boolean;
mentionHighlight: boolean
}

export interface PluginRegistry {
registerReducer(reducer)
registerChannelHeaderButtonAction(icon: Reast.ReactNode, action: () => void, tooltipText: string)
registerPostTypeComponent(typeName: string, component: React.ElementType)
registerRightHandSidebarComponent(component: React.ReactNode, title: string | JSX.Element)
registerSlashCommandWillBePostedHook(hook: (rawMessage: string, contextArgs: ContextArgs) => Promise<{}>)
registerSlashCommandWillBePostedHook(
hook: (rawMessage: string, contextArgs: ContextArgs) => Promise<{}>
)
registerWebSocketEventHandler(event: string, handler: (msg: any) => void)
registerAppBarComponent(iconUrl: string, action: () => void, tooltipText: string)
registerLeftSidebarHeaderComponent(component: React.ReactNode)
Expand Down

0 comments on commit acdc5ed

Please sign in to comment.