Skip to content

Commit

Permalink
feat: enable selecting assignee in view (#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
hudy9x authored Jul 15, 2024
1 parent 90297e4 commit c52c1f3
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 28 deletions.
16 changes: 10 additions & 6 deletions packages/be-gateway/src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@ const router = Router()
const logger = createModuleLog('Request')

router.use((req, res, next) => {
logger.info(req.url, {
method: req.method,
url: req.url,
path: req.path
})
console.log('\x1b[0m', `🥝 ${req.method}: ${req.url}`, '\x1b[90m')
try {
logger.info(req.url, {
method: req.method,
url: req.url,
path: req.path
})
console.log('\x1b[0m', `🥝 ${req.method}: ${req.url}`, '\x1b[90m')
} catch (error) {
console.log()
}
next()
})

Expand Down
8 changes: 6 additions & 2 deletions packages/be-gateway/src/routes/project/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default class ProjectViewController extends BaseController {
point: string
groupBy: string
statusIds: string[]
assigneeIds: string[]
}
}

Expand All @@ -68,7 +69,8 @@ export default class ProjectViewController extends BaseController {
priority: data.priority,
point: data.point,
groupBy: data.groupBy,
statusIds: data.statusIds
statusIds: data.statusIds,
assigneeIds: data.assigneeIds
}
: {},

Expand Down Expand Up @@ -117,6 +119,7 @@ export default class ProjectViewController extends BaseController {
point: string
groupBy: string
statusIds: string[]
assigneeIds: string[]
}
}

Expand All @@ -130,7 +133,8 @@ export default class ProjectViewController extends BaseController {
priority: data.priority,
point: data.point,
groupBy: data.groupBy,
statusIds: data.statusIds
statusIds: data.statusIds,
assigneeIds: data.assigneeIds
}
: {},
type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ function TimelineTaskFilter() {
const { filter, setFilterValue } = useTaskFilter()
const { assigneeIds } = filter

const updatedAssigneeIds = assigneeIds.map(uid => {
const updatedAssigneeIds = assigneeIds ? assigneeIds.map(uid => {
if (uid === 'ME' && user?.id) {
return user.id
}

return uid
})

console.log('update assignee', updatedAssigneeIds)
}) : []

return <div>
<MultiMemberPicker value={updatedAssigneeIds}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function ProjectViewCreate() {
priority: 'ALL',
point: "-1",
statusIds: ['ALL'],
assigneeIds: ['ME'],
groupBy: ETaskFilterGroupByType.STATUS
})

Expand Down
43 changes: 34 additions & 9 deletions packages/ui-app/app/_features/ProjectView/ProjectViewModalForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ProjectView, ProjectViewType } from '@prisma/client'
import { useProjectViewContext } from './context'
import { IBoardFilter, useProjectViewContext } from './context'

import { useParams } from 'next/navigation'
import { useState } from 'react'
Expand All @@ -17,6 +17,7 @@ import { projectView } from '@/services/projectView'
import useTaskFilterContext from '../TaskFilter/useTaskFilterContext'
import { useReRenderView } from './useReRenderView'
import { projectViewMap } from './useProjectViewList'
import { useUser } from '@goalie/nextjs'

export default function ProjectViewModalForm({
type,
Expand All @@ -27,6 +28,7 @@ export default function ProjectViewModalForm({
name: string
desc: string
}) {
const { user } = useUser()
const { projectId } = useParams()
const { setVisible, name: viewName, icon, onlyMe, setOnlyMe, setName, filter, customView, setCustomView } = useProjectViewContext()
const [loading, setLoading] = useState(false)
Expand All @@ -38,7 +40,6 @@ export default function ProjectViewModalForm({

const hideModal = () => {
setTimeout(() => {
console.log('hide')
setLoading(false)
setVisible(false)
setCustomView(false)
Expand All @@ -47,15 +48,38 @@ export default function ProjectViewModalForm({
}, 500)
}

const replaceUidToRelativeValue = (filter: IBoardFilter) => {
const cloneFilter = { ...filter }

if (type === ProjectViewType.GOAL) {
cloneFilter.assigneeIds = ['ALL']
} else {
cloneFilter.assigneeIds = cloneFilter.assigneeIds.map(uid => {
if (user?.id === uid) {
return "ME"
}

return uid
})
}


return cloneFilter
}

const addHandler = () => {

// setLoading(false)
const newFilter = replaceUidToRelativeValue(filter)
const isCustomView = customView || type === ProjectViewType.GOAL

addProjectView({
onlyMe: onlyMe || false,
icon,
name: viewName || name,
type,
projectId,
data: customView ? filter : undefined
data: isCustomView ? newFilter : undefined
})
.catch(err => {
hideModal()
Expand All @@ -71,7 +95,7 @@ export default function ProjectViewModalForm({

const updateHandler = () => {
const id = updateId
const dataFilter = filter
const newDataFilter = replaceUidToRelativeValue(filter)
const dataView = filter as unknown as Pick<ProjectView, 'data'>

updateView(id, {
Expand All @@ -92,11 +116,12 @@ export default function ProjectViewModalForm({
setFilter(filter => ({
...filter,
...{
date: dataFilter.date,
groupBy: dataFilter.groupBy,
priority: dataFilter.priority,
statusIds: dataFilter.statusIds,
point: dataFilter.point
date: newDataFilter.date,
groupBy: newDataFilter.groupBy,
priority: newDataFilter.priority,
statusIds: newDataFilter.statusIds,
point: newDataFilter.point,
assigneeIds: newDataFilter.assigneeIds
}
}))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import { Dialog, messageError, setFixLoading } from '@shared/ui'
import { Dialog, messageError } from '@shared/ui'
import { useEffect, useState } from 'react'
import ProjectViewModal from './ProjectViewModal'
import { IBoardFilter, ProjectViewModalProvider } from './context'
import { ETaskFilterGroupByType } from '../TaskFilter/context'
import { projectView } from '@/services/projectView'
import { ProjectView } from '@prisma/client'
import { useProjectViewUpdateContext } from './updateContext'
import { useProjectViewStore } from '@/store/projectView'

Expand All @@ -26,6 +24,7 @@ export default function ProjectViewUpdate({
priority: 'ALL',
point: "-1",
statusIds: ['ALL'],
assigneeIds: ['ME'],
groupBy: ETaskFilterGroupByType.STATUS
})

Expand Down Expand Up @@ -77,6 +76,7 @@ export default function ProjectViewUpdate({
priority: 'ALL',
point: "-1",
statusIds: ['ALL'],
assigneeIds: ['ME'],
groupBy: ETaskFilterGroupByType.STATUS
})
}
Expand Down
2 changes: 2 additions & 0 deletions packages/ui-app/app/_features/ProjectView/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface IBoardFilter {
point: string
groupBy: ETaskFilterGroupByType
statusIds: string[]
assigneeIds: string[]
}

interface IProjectViewContextProps {
Expand Down Expand Up @@ -48,6 +49,7 @@ const ProjectViewContext = createContext<IProjectViewContextProps>({
priority: 'ALL',
point: "-1",
statusIds: ['ALL'],
assigneeIds: ['ME'],
groupBy: ETaskFilterGroupByType.STATUS
},
setFilter: () => { console.log(1) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const useProjectViewAdd = () => {
priority: data.priority,
point: data.point,
statusIds: data.statusIds,
assigneeIds: data.assigneeIds,
groupBy: data.groupBy
} : null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default function useSetViewFilter() {
groupBy: data.groupBy,
priority: data.priority,
statusIds: data.statusIds,
assigneeIds: data.assigneeIds,
point: data.point
}
}))
Expand Down
21 changes: 20 additions & 1 deletion packages/ui-app/app/_features/ProjectViewFilter/FilterForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,22 @@ import { ETaskFilterGroupByType } from '../TaskFilter/context'
import { useProjectViewContext } from '../ProjectView/context'
import StatusSelectMultiple from '@/components/StatusSelectMultiple'
import { ProjectViewType } from '@prisma/client'
import MultiMemberPicker from '@/components/MultiMemberPicker'
import { useUser } from '@goalie/nextjs'

export default function FilterForm({ type }: { type?: ProjectViewType }) {
const { customView, setCustomView, filter, setFilterValue } =
useProjectViewContext()
const hidden = customView ? '' : 'hidden'
const { date, point, priority, groupBy, statusIds } = filter
const { user } = useUser()
const { date, point, priority, groupBy, statusIds, assigneeIds } = filter

const updatedAssigneeIds = assigneeIds.map(uid => {
if (uid === 'ME' && user?.id) {
return user.id
}
return uid
})

return (
<>
Expand Down Expand Up @@ -74,6 +84,15 @@ export default function FilterForm({ type }: { type?: ProjectViewType }) {
}}
/>
) : null}

{type === ProjectViewType.LIST ||
type === ProjectViewType.BOARD ||
type === ProjectViewType.CALENDAR ||
type === ProjectViewType.GOAL ?
<MultiMemberPicker compact={true} all={true} value={updatedAssigneeIds} onChange={val => {
setFilterValue('assigneeIds', val)
}} />
: null}
</div>

<div className={`mb-6 ${hidden}`}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function ProjectViewFilterByList({ type, desc, isUpdate, onAdd }:
<h2 className="text-xl mb-3">List</h2>
<p className="text-sm text-gray-500 mb-6">{desc}</p>

<FilterForm />
<FilterForm type="LIST" />
<ProjectViewForMe />
<div className="text-right">
<Button
Expand Down
8 changes: 6 additions & 2 deletions packages/ui-app/app/_features/TaskFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ export default function TaskFilter({
statusIds
} = filter

const updatedAssigneeIds = assigneeIds.map(uid => {
if (!assigneeIds) {
console.error(`${assigneeIds} is undefined, use ALL for default`)
}

const updatedAssigneeIds = assigneeIds ? assigneeIds.map(uid => {
if (uid === 'ME' && user?.id) {
return user.id
}

return uid
})
}) : ['ALL']

const isDateRange = date === 'date-range'
const isCalendarMode = currentViewType === ProjectViewType.CALENDAR
Expand Down

0 comments on commit c52c1f3

Please sign in to comment.