Skip to content

Commit

Permalink
fix: in the manager view, filter projects by 'mine only' by default
Browse files Browse the repository at this point in the history
  • Loading branch information
beeman committed Aug 28, 2024
1 parent 2496514 commit 6148d8d
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions api-schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ input ManagerFindManyCommunityInput {
input ManagerFindManyProjectInput {
communityId: String
limit: Int = 10
mineOnly: Boolean
orderBy: ProjectOrderBy
orderDirection: OrderDirection
page: Int = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export class ManagerFindManyProjectInput extends PagingInput() {
@Field({ nullable: true })
communityId?: string
@Field({ nullable: true })
mineOnly?: boolean
@Field({ nullable: true })
search?: string
@Field(() => ProjectStatus, { nullable: true })
status?: ProjectStatus
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { User } from '@deanslist-platform/api-user-data-access'
import { Prisma } from '@prisma/client'
import { Prisma, ProjectRole } from '@prisma/client'
import { ManagerFindManyProjectInput } from '../dto/manager-find-many-project.input'
import { getProjectWhereManagerAccessInput } from './get-project-where-manager-access-input'

Expand All @@ -10,6 +10,15 @@ export function getProjectWhereManagerInput(user: User, input: ManagerFindManyPr
...getProjectWhereManagerAccessInput(user),
}

if (input.mineOnly) {
where.OR = [
...(where.OR ?? []),
{
members: { some: { userId: user.id, role: ProjectRole.Manager } },
},
]
}

if (input.search) {
where.OR = [
...(where.OR ?? []),
Expand Down
2 changes: 2 additions & 0 deletions libs/sdk/src/generated/graphql-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ export type ManagerFindManyCommunityInput = {
export type ManagerFindManyProjectInput = {
communityId?: InputMaybe<Scalars['String']['input']>
limit?: InputMaybe<Scalars['Int']['input']>
mineOnly?: InputMaybe<Scalars['Boolean']['input']>
orderBy?: InputMaybe<ProjectOrderBy>
orderDirection?: InputMaybe<OrderDirection>
page?: InputMaybe<Scalars['Int']['input']>
Expand Down Expand Up @@ -9557,6 +9558,7 @@ export function ManagerFindManyProjectInputSchema(): z.ZodObject<Properties<Mana
return z.object({
communityId: z.string().nullish(),
limit: z.number().nullish(),
mineOnly: z.boolean().nullish(),
orderBy: ProjectOrderBySchema.nullish(),
orderDirection: OrderDirectionSchema.nullish(),
page: z.number().nullish(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ import { useState } from 'react'
export function useManagerFindManyProject(props?: Partial<ManagerFindManyProjectInput>) {
const [limit, setLimit] = useState(props?.limit ?? 24)
const [page, setPage] = useState(props?.page ?? 1)
const [mineOnly, setMineOnly] = useState(props?.mineOnly ?? true)
const [search, setSearch] = useState<string>(props?.search ?? '')
const [orderBy, setOrderBy] = useState<ProjectOrderBy>(ProjectOrderBy.UpdatedAt)
const [orderDirection, setOrderDirection] = useState<OrderDirection>(OrderDirection.Desc)
const [status, setStatus] = useState<ProjectStatus | undefined>(props?.status ?? undefined)
const input: ManagerFindManyProjectInput = {
page,
limit,
mineOnly,
search,
status,
orderBy,
Expand All @@ -37,6 +39,8 @@ export function useManagerFindManyProject(props?: Partial<ManagerFindManyProject
return {
items,
query,
mineOnly,
setMineOnly,
pagination: {
page,
setPage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '@deanslist-platform/web-core-ui'
import { useManagerFindManyProject } from '@deanslist-platform/web-project-data-access'
import { ProjectUiEmptyState, ProjectUiGrid } from '@deanslist-platform/web-project-ui'
import { Button, Group } from '@mantine/core'
import { Button, Group, Switch } from '@mantine/core'
import { modals } from '@mantine/modals'
import { UiError, UiGroup, UiLoader, UiPage, UiStack } from '@pubkey-ui/core'
import { IconArrowsUpDown, IconChairDirector, IconFilter, IconPlus } from '@tabler/icons-react'
Expand All @@ -18,11 +18,10 @@ import { OrderOptionLabel } from './reviewer-project-list.feature'

export function ManagerProjectListFeature({ communityId }: { communityId?: string }) {
const { items: communities } = useManagerFindManyCommunity({ limit: 1000 })
const { items, pagination, query, search, setSearch, status, setStatus, order, setOrder } = useManagerFindManyProject(
{
const { items, pagination, query, mineOnly, setMineOnly, search, setSearch, status, setStatus, order, setOrder } =
useManagerFindManyProject({
communityId,
},
)
})
const searchField = (
<CoreUiSearchField
miw={300}
Expand Down Expand Up @@ -84,6 +83,11 @@ export function ManagerProjectListFeature({ communityId }: { communityId?: strin
>
Add Project
</Button>
<Switch
label="Show my projects only"
checked={mineOnly}
onChange={(e) => setMineOnly(e.currentTarget.checked)}
/>
</Group>
</UiGroup>

Expand Down

0 comments on commit 6148d8d

Please sign in to comment.