Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-3959] implement Option to "Create New Category" under the "Move To..." option in the sidebar #4057

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions webapp/src/components/createCategory/createCategory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type Props = {
initialValue?: string
onClose: () => void
title: JSX.Element
onCreate?: () => Promise<void>
onCreate?: (id: Category) => Promise<void>
cannalee90 marked this conversation as resolved.
Show resolved Hide resolved
}

const CreateCategory = (props: Props): JSX.Element => {
Expand Down Expand Up @@ -71,8 +71,8 @@ const CreateCategory = (props: Props): JSX.Element => {
teamID,
} as Category

await mutator.createCategory(category)
await props.onCreate?.()
const createdCategory = await mutator.createCategory(category)
await props.onCreate?.(createdCategory)
}

props.onClose()
Expand Down
8 changes: 2 additions & 6 deletions webapp/src/components/sidebar/sidebarBoardItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import MenuWrapper from '../../widgets/menuWrapper'
import BoardPermissionGate from '../permissions/boardPermissionGate'

import './sidebarBoardItem.scss'
import {CategoryBoards, updateBoardCategories} from '../../store/sidebar'
import {Category, CategoryBoards, updateBoardCategories} from '../../store/sidebar'
import CreateNewFolder from '../../widgets/icons/newFolder'
import {useAppDispatch, useAppSelector} from '../../store/hooks'
import {getCurrentBoardViews, getCurrentViewId} from '../../store/views'
Expand Down Expand Up @@ -198,11 +198,7 @@ const SidebarBoardItem = (props: Props) => {
}
}

const handleOnCreate = async () => {
const nextCategoriesList = await octoClient.getSidebarCategories(teamID)
const toCategory = nextCategoriesList.
find((category) => props.allCategories.every((prevCategory) => prevCategory.id !== category.id))

const handleOnCreate = async (toCategory: Category) => {
if (!toCategory || !selectedBoardId) {
return
}
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/mutator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,8 +919,8 @@ class Mutator {
return this.unhideViewColumns(boardId, view, [columnOptionId])
}

async createCategory(category: Category): Promise<void> {
await octoClient.createSidebarCategory(category)
async createCategory(category: Category): Promise<Category> {
return octoClient.createSidebarCategory(category)
}

async deleteCategory(teamID: string, categoryID: string): Promise<void> {
Expand Down
6 changes: 4 additions & 2 deletions webapp/src/octoClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -767,14 +767,16 @@ class OctoClient {
return (await this.getJson(response, [])) as CategoryBoards[]
}

async createSidebarCategory(category: Category): Promise<Response> {
async createSidebarCategory(category: Category): Promise<Category> {
const path = `/api/v2/teams/${category.teamID}/categories`
const body = JSON.stringify(category)
return fetch(this.getBaseURL() + path, {
const response = await fetch(this.getBaseURL() + path, {
method: 'POST',
headers: this.headers(),
body,
})

return await response.json() as Category
}

async deleteSidebarCategory(teamID: string, categoryID: string): Promise<Response> {
Expand Down