Skip to content

Commit

Permalink
porgress
Browse files Browse the repository at this point in the history
  • Loading branch information
IanMayo committed Nov 25, 2021
1 parent 72b0b19 commit 20df71b
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 163 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import React from 'react'
import { MessageCustom, ForceData, ForceRole, TemplateBodysByKey, ChannelData, ChannelCollab } from '@serge/custom-types'
import { MessageCustom, ForceData, ForceRole, TemplateBodysByKey, ChannelCollab } from '@serge/custom-types'
import { isMessageReaded, setMessageState } from '@serge/helpers'
import { ForceColor } from '..'
import ChannelCoaMessageDetail2 from '../../molecules/channel-coa-message-detail-2'
import { Badge } from '../../atoms/badge'
import { CollaborativeMessageStates, CollaborativePermission, SpecialChannelColumns } from '@serge/config'
import getAssignees from './assignees'
import getKey from './get-key'
import { faEnvelope, faEnvelopeOpen } from '@fortawesome/free-solid-svg-icons'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'

Expand Down Expand Up @@ -45,20 +44,15 @@ export const genData2 = (
currentWargame: string,
templates: TemplateBodysByKey,
isUmpire: boolean,
channel: ChannelData,
channelColb: ChannelCollab,
permission: CollaborativePermission,
canCollaborate: boolean,
canReleaseMessages: boolean,
canUnClaimMessages: boolean,
gameDate: string,
isCollaborating: boolean,
isObserver: boolean,
onChange: (msg: MessageCustom) => void
): GenData2 => {
let unreadMessagesCount = 0

const assignees: ForceRole[] = getAssignees(channelColb.participants, forces)
const isCollaborating = permission > CollaborativePermission.CannotCollaborate

const sortCol = (str1: string, str2: string): number => {
const a = str1.toLowerCase()
Expand Down Expand Up @@ -157,12 +151,7 @@ export const genData2 = (
const lastUpdated = collab ? collab.lastUpdated : 'Pending'
const status = collab ? collab.status : 'Unallocated'

// flag for if we tell original sender of RFI that it has been responded to
const isFinalised = status === CollaborativeMessageStates.Closed ||
status === CollaborativeMessageStates.Finalized ||
status === CollaborativeMessageStates.Released

const messageStateKey = getKey(message, canCollaborate, canReleaseMessages, canUnClaimMessages, isFinalised, isObserver)
const messageStateKey = message._id
const isReaded = isMessageReaded(currentWargame, role.forceName, role.roleName, messageStateKey)

if (!isReaded) unreadMessagesCount++
Expand All @@ -182,12 +171,8 @@ export const genData2 = (
message={message}
role={role}
isUmpire={isUmpire}
channel={channel}
channelColb={channelColb}
permission={permission}
canCollaborate={canCollaborate}
canReleaseMessages={canReleaseMessages}
canUnClaimMessages={canUnClaimMessages}
assignees={assignees}
onChange={(newMeesage: MessageCustom): void => {
onChange && onChange(newMeesage)
Expand Down
31 changes: 2 additions & 29 deletions packages/components/src/local/coa-status-board-2/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import React from 'react'
import renderer from 'react-test-renderer'
import { ForceRole, MessageCustom, Role, ChannelData, ChannelCollab } from '@serge/custom-types'
import { CUSTOM_MESSAGE, CollaborativeMessageStates, SpecialChannelTypes, CHANNEL_COLLAB, InitialStates, CollaborativePermission, CollaborativeMessageStates2 } from '@serge/config'
import { ForceRole, MessageCustom, Role, ChannelCollab } from '@serge/custom-types'
import { CUSTOM_MESSAGE, CollaborativeMessageStates, CHANNEL_COLLAB, InitialStates, CollaborativePermission, CollaborativeMessageStates2 } from '@serge/config'
import { forces, MessageTemplatesMockByKey, WargameMock } from '@serge/mocks'
import CoaStatusBoard2 from './index'
import moment from 'moment'
Expand All @@ -15,32 +15,6 @@ const whiteGC: Role = forces[0].roles[0]
const blueCO: Role = forces[1].roles[0]
const redCO: Role = forces[2].roles[0]

/* test data */
const testChannel: ChannelData = {
collabOptions: {
extraColumns: [],
mode: 'edit',
returnVerbs: ['Endorse', 'Request Changes'],
startWithReview: true
},
format: SpecialChannelTypes.CHANNEL_COLLAB_EDIT,
name: 'New CE',
participants: [
{
canCollaborate: true,
canReleaseMessages: false,
force: 'White',
forceUniqid: 'umpire',
roles: [],
subscriptionId: 'oqoj',
templates: [
{ title: 'RFI', _id: 'k16eedkj' }
]
}
],
uniqid: 'ks8soryj'
}

const testChannelColb: ChannelCollab = {
channelType: CHANNEL_COLLAB,
requestChangesVerbs: [],
Expand Down Expand Up @@ -242,7 +216,6 @@ it('CoaStatusBoard renders correctly', () => {
forces={forces}
role={role}
isUmpire={true}
channel={testChannel}
channelColb={testChannelColb}
messages={testMock}
onChange={onChange}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { MessageCustom } from '@serge/custom-types'
import Props from './types/props'
import { mostRecentOnly } from '@serge/helpers'
import {
channelCollaborativeEditing,
channelCollaborativeResponding,
channelCollaborativeEditing2,
channelCollaborativeResponding2,
MessageTemplatesMockByKey,
Expand Down Expand Up @@ -109,7 +107,6 @@ const mostColabResponseMock = mostColabResponseMockRaw.map((message: MessageCust

export const CollaborativeEditEditor = Template.bind({})
CollaborativeEditEditor.args = {
channel: channelCollaborativeEditing,
channelColb: channelCollaborativeEditing2,
messages: mostColabEditMock,
isUmpire: false,
Expand All @@ -119,7 +116,6 @@ CollaborativeEditEditor.args = {

export const CollaborativeEditReleaseManager = Template.bind({})
CollaborativeEditReleaseManager.args = {
channel: channelCollaborativeEditing,
channelColb: channelCollaborativeEditing2,
messages: mostColabEditMock,
isUmpire: false,
Expand All @@ -129,7 +125,6 @@ CollaborativeEditReleaseManager.args = {

export const CollaborativeResponseSubmit = Template.bind({})
CollaborativeResponseSubmit.args = {
channel: channelCollaborativeResponding,
channelColb: channelCollaborativeResponding2,
messages: mostColabResponseMock,
isUmpire: true,
Expand All @@ -139,7 +134,6 @@ CollaborativeResponseSubmit.args = {

export const CollaborativeResponseParticipateWhite = Template.bind({})
CollaborativeResponseParticipateWhite.args = {
channel: channelCollaborativeResponding,
channelColb: channelCollaborativeResponding2,
messages: mostColabResponseMock,
isUmpire: true,
Expand All @@ -149,7 +143,6 @@ CollaborativeResponseParticipateWhite.args = {

export const CollaborativeResponseParticipateExcon = Template.bind({})
CollaborativeResponseParticipateExcon.args = {
channel: channelCollaborativeResponding,
channelColb: channelCollaborativeResponding2,
messages: mostColabResponseMock,
isUmpire: true,
Expand All @@ -159,7 +152,6 @@ CollaborativeResponseParticipateExcon.args = {

export const CollaborativeResponseRelease = Template.bind({})
CollaborativeResponseRelease.args = {
channel: channelCollaborativeResponding,
channelColb: channelCollaborativeResponding2,
messages: mostColabResponseMock,
isUmpire: true,
Expand Down
25 changes: 3 additions & 22 deletions packages/components/src/local/coa-status-board-2/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { useState } from 'react'
import { CollaborativeMessageStates, CollaborativePermission } from '@serge/config'
import { CollaborativePermission } from '@serge/config'
import { Button, Checkbox, FormControl, FormControlLabel, Input } from '@material-ui/core'
import { genData2 } from './helpers/gen-data'
import getKey from './helpers/get-key'
import { setMessageState } from '@serge/helpers'
import DataTable from 'react-data-table-component'
import { faSearch } from '@fortawesome/free-solid-svg-icons'
Expand All @@ -24,21 +23,14 @@ export interface ForceColor {
}

/* Render component */
export const CoaStatusBoard2: React.FC<Props> = ({ templates, messages, channel, channelColb, isUmpire, onChange, role, forces, gameDate, onMessageRead, currentWargame }: Props) => {
export const CoaStatusBoard2: React.FC<Props> = ({ templates, messages, channelColb, isUmpire, onChange, role, forces, gameDate, onMessageRead, currentWargame }: Props) => {
const [showArchived, setShowArchived] = useState<boolean>(false)
const [filteredRows, setFilterdRows] = useState<Row[]>([])
const [inFilterMode, setFilterMode] = useState<boolean>(false)

const myParticipations: ParticipantCollab[] = channelColb.participants.filter((p: ParticipantCollab) => p.force === role.forceName && ((p.roles.includes(role.roleId)) || p.roles.length === 0))
// find my highest permission
const permission: CollaborativePermission = myParticipations.reduce((a, b) => a.permission > b.permission ? a : b).permission
console.log('max permission:', permission)
const canCollaborate = !!myParticipations.find(p => p.permission >= CollaborativePermission.CanEdit)
const canReleaseMessages = !!myParticipations.find(p => p.permission >= CollaborativePermission.CanRelease)
const canUnClaimMessages = !!myParticipations.find(p => p.permission >= CollaborativePermission.CanUnClaim)

// whether this user should see metadata about the message being edited
const isCollaborating = canCollaborate || canReleaseMessages || isUmpire

// (optionally) include archived messages
const filteredDoc = filteredMessages(messages, showArchived)
Expand All @@ -50,15 +42,9 @@ export const CoaStatusBoard2: React.FC<Props> = ({ templates, messages, channel,
currentWargame,
templates,
isUmpire,
channel,
channelColb,
permission,
canCollaborate,
canReleaseMessages,
canUnClaimMessages,
gameDate,
isCollaborating,
isUmpire,
onChange
)

Expand All @@ -69,12 +55,7 @@ export const CoaStatusBoard2: React.FC<Props> = ({ templates, messages, channel,
const handleMarkAllAsRead = (): void => {
for (const message of filteredDoc) {
// flag for if we tell original sender of RFI that it has been responded to
const collab = message.details.collaboration
const status = collab && collab.status
const isFinalised = status === CollaborativeMessageStates.Closed ||
status === CollaborativeMessageStates.Finalized ||
status === CollaborativeMessageStates.Released
const key = getKey(message, canCollaborate, canReleaseMessages, canUnClaimMessages, isFinalised, isUmpire)
const key = message._id
setMessageState(currentWargame, role.forceName, role.roleName, key)
}
onMessageRead && onMessageRead(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,12 @@ export type Column = TableColumnBase & {
export default interface Props {
currentWargame: string
messages: MessageCustom[]
channel: ChannelData
channelColb: ChannelCollab
onChange: (nextMessage: MessageCustom) => void
/** if this player is from the UMPIRE force */
isUmpire: boolean
/** if this player has "RFI Manager" attribute in their role */
// isRFIManager: boolean
/** role of logged in player */
role: ForceRole
/** if this set of participants can take part in collaborative working */
canCollaborate?: boolean
/** if this set of participants can release collaborative messages */
canReleaseMessages?: boolean
templates: TemplateBodysByKey
/** list of forces */
forces: ForceData[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import React from 'react'
import renderer from 'react-test-renderer'
import ChannelCoaMessageDetail2 from './index'

import { ChannelCollab, ChannelData } from '@serge/custom-types'
import { InitialStates, CHANNEL_COLLAB, CollaborativePermission, SpecialChannelTypes } from '@serge/config'
import { ChannelCollab } from '@serge/custom-types'
import { InitialStates, CHANNEL_COLLAB, CollaborativePermission } from '@serge/config'

import { GameMessagesMockRFI, MessageTemplatesMockByKey, WargameMock } from '@serge/mocks'

Expand Down Expand Up @@ -35,40 +35,13 @@ const testChannel2: ChannelCollab = {
uniqid: 'ks8soryj'
}

const testChannel: ChannelData = {
collabOptions: {
extraColumns: [],
mode: 'edit',
returnVerbs: ['Endorse', 'Request Changes'],
startWithReview: true
},
format: SpecialChannelTypes.CHANNEL_COLLAB_EDIT,
name: 'New CE',
participants: [
{
canCollaborate: true,
canReleaseMessages: false,
force: 'White',
forceUniqid: 'umpire',
roles: [],
subscriptionId: 'oqoj',
templates: [
{ title: 'RFI', _id: 'k16eedkj' }
]
}
],
uniqid: 'ks8soryj'
}

describe('ChannelMessageDetail:', () => {
it('renders correctly', () => {
const tree = renderer
.create(<ChannelCoaMessageDetail2
templates={MessageTemplatesMockByKey}
role={ { forceId: 'umpire', forceName: 'Umpire', roleId: 'co', roleName: 'CO' } }
canUnClaimMessages={true}
permission={CollaborativePermission.CanEdit}
channel={testChannel}
channelColb={testChannel2}
isUmpire={true}
message={defMessage}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import RFIPropTypes from './types/props'

import {
MessageTemplatesMockByKey,
channelCollaborativeEditing,
messageDataCollaborativeEditing,
GameChannels,
GameChannels2,
GameMessagesMock,
WargameMock
Expand Down Expand Up @@ -77,9 +75,7 @@ const Template: Story<RFIPropTypes> = (args) => {
onChange={(nextMessage): void => setMessageState(nextMessage)}
role={role}
permission={CollaborativePermission.CanEdit}
canUnClaimMessages={true}
isUmpire={isUmpire}
channel={GameChannels[0]}
channelColb={collabChannel}
gameDate={WargameMock.data.overview.gameDate}
/>
Expand All @@ -91,18 +87,12 @@ export const Unallocated = Template.bind({})
Unallocated.args = {
message: messageDataCollaborativeEditing[0],
isUmpire: true,
canCollaborate: true,
canReleaseMessages: false,
channel: channelCollaborativeEditing,
role: role
}

export const CustomMessage = Template.bind({})
CustomMessage.args = {
message: GameMessagesMock[0] as MessageCustom,
isUmpire: true,
canCollaborate: true,
canReleaseMessages: false,
channel: channelCollaborativeEditing,
role: role
}
Loading

0 comments on commit 20df71b

Please sign in to comment.