-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Display columns on Record Board #3626
Changes from 3 commits
cd0c220
f7e58da
739c760
aedff24
5f3d97a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
import { createContext } from 'react'; | ||
|
||
import { BoardColumnDefinition } from '@/object-record/record-board-deprecated/types/BoardColumnDefinition'; | ||
import { RecordBoardColumnDefinition } from '@/object-record/record-board/types/RecordBoardColumnDefinition'; | ||
|
||
type RecordBoardColumnContextProps = { | ||
id: string; | ||
columnDefinition: BoardColumnDefinition; | ||
columnDefinition: RecordBoardColumnDefinition; | ||
isColumnFirst: boolean; | ||
isColumnLast: boolean; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would have name is isFirst/LastColumn |
||
}; | ||
|
||
export const RecordBoardColumnContext = | ||
createContext<RecordBoardColumnContextProps | null>(null); | ||
createContext<RecordBoardColumnContextProps>( | ||
{} as RecordBoardColumnContextProps, | ||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { RecordBoardScopeInternalContext } from '@/object-record/record-board/scopes/scope-internal-context/RecordBoardScopeInternalContext'; | ||
import { isRecordBoardColumnFirstFamilyStateScopeMap } from '@/object-record/record-board/states/isRecordBoardColumnFirstFamilyStateScopeMap'; | ||
import { recordBoardColumnIdsStateScopeMap } from '@/object-record/record-board/states/recordBoardColumnIdsStateScopeMap'; | ||
import { recordBoardColumnsFamilySelectorScopeMap } from '@/object-record/record-board/states/selectors/recordBoardColumnsFamilySelectorScopeMap'; | ||
import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId'; | ||
import { getFamilyState } from '@/ui/utilities/recoil-scope/utils/getFamilyState'; | ||
import { getScopeIdFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId'; | ||
import { getState } from '@/ui/utilities/recoil-scope/utils/getState'; | ||
|
||
export const useRecordBoardStates = (recordBoardId?: string) => { | ||
const scopeId = useAvailableScopeIdOrThrow( | ||
RecordBoardScopeInternalContext, | ||
getScopeIdFromComponentId(recordBoardId), | ||
); | ||
|
||
return { | ||
scopeId, | ||
getColumnIdsState: getState(recordBoardColumnIdsStateScopeMap, scopeId), | ||
isColumnLastFamilyState: getFamilyState( | ||
isRecordBoardColumnFirstFamilyStateScopeMap, | ||
scopeId, | ||
), | ||
isColumnFirstFamilyState: getFamilyState( | ||
isRecordBoardColumnFirstFamilyStateScopeMap, | ||
scopeId, | ||
), | ||
columnsFamilySelector: getFamilyState( | ||
recordBoardColumnsFamilySelectorScopeMap, | ||
scopeId, | ||
), | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,48 @@ | ||||||
import { useRecoilCallback } from 'recoil'; | ||||||
|
||||||
import { useRecordBoardStates } from '@/object-record/record-board/hooks/internal/useRecordBoardStates'; | ||||||
import { RecordBoardColumnDefinition } from '@/object-record/record-board/types/RecordBoardColumnDefinition'; | ||||||
import { isDeeplyEqual } from '~/utils/isDeeplyEqual'; | ||||||
|
||||||
export const useSetRecordBoardColumns = (recordBoardId?: string) => { | ||||||
const { scopeId, getColumnIdsState, columnsFamilySelector } = | ||||||
useRecordBoardStates(recordBoardId); | ||||||
|
||||||
const setRecordBoardColumns = useRecoilCallback( | ||||||
({ set, snapshot }) => | ||||||
(columns: RecordBoardColumnDefinition[]) => { | ||||||
const currentColumns = snapshot | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
.getLoadable(getColumnIdsState()) | ||||||
.getValue(); | ||||||
|
||||||
const columnIds = columns.map(({ id }) => id); | ||||||
Weiko marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
if (isDeeplyEqual(currentColumns, columnIds)) { | ||||||
return; | ||||||
} | ||||||
|
||||||
set( | ||||||
getColumnIdsState(), | ||||||
columns.map(({ id }) => id), | ||||||
); | ||||||
|
||||||
columns.forEach((column) => { | ||||||
const currentColumn = snapshot | ||||||
.getLoadable(columnsFamilySelector(column.id)) | ||||||
.getValue(); | ||||||
|
||||||
if (isDeeplyEqual(currentColumn, column)) { | ||||||
return; | ||||||
} | ||||||
|
||||||
set(columnsFamilySelector(column.id), column); | ||||||
}); | ||||||
}, | ||||||
[columnsFamilySelector, getColumnIdsState], | ||||||
); | ||||||
|
||||||
return { | ||||||
scopeId, | ||||||
setRecordBoardColumns, | ||||||
}; | ||||||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useRecordBoardStates } from '@/object-record/record-board/hooks/internal/useRecordBoardStates'; | ||
import { useSetRecordBoardColumns } from '@/object-record/record-board/hooks/internal/useSetRecordBoardColumns'; | ||
|
||
export const useRecordBoard = (recordBoardId?: string) => { | ||
const { scopeId, getColumnIdsState, columnsFamilySelector } = | ||
useRecordBoardStates(recordBoardId); | ||
|
||
const { setRecordBoardColumns } = useSetRecordBoardColumns(recordBoardId); | ||
|
||
return { | ||
scopeId, | ||
getColumnIdsState, | ||
columnsFamilySelector, | ||
setRecordBoardColumns, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useCallback, useContext, useRef } from 'react'; | ||
import styled from '@emotion/styled'; | ||
import { MenuItem } from 'tsup.ui.index'; | ||
|
||
import { RecordBoardColumnContext } from '@/object-record/record-board/contexts/RecordBoardColumnContext'; | ||
import { DropdownMenu } from '@/ui/layout/dropdown/components/DropdownMenu'; | ||
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer'; | ||
import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside'; | ||
|
||
const StyledMenuContainer = styled.div` | ||
position: absolute; | ||
top: ${({ theme }) => theme.spacing(10)}; | ||
width: 200px; | ||
z-index: 1; | ||
`; | ||
|
||
type RecordBoardColumnDropdownMenuProps = { | ||
onClose: () => void; | ||
onDelete?: (id: string) => void; | ||
stageId: string; | ||
}; | ||
|
||
export const RecordBoardColumnDropdownMenu = ({ | ||
onClose, | ||
}: RecordBoardColumnDropdownMenuProps) => { | ||
const boardColumnMenuRef = useRef<HTMLDivElement>(null); | ||
|
||
const closeMenu = useCallback(() => { | ||
onClose(); | ||
}, [onClose]); | ||
|
||
useListenClickOutside({ | ||
refs: [boardColumnMenuRef], | ||
callback: closeMenu, | ||
}); | ||
|
||
const { columnDefinition } = useContext(RecordBoardColumnContext); | ||
|
||
return ( | ||
<StyledMenuContainer ref={boardColumnMenuRef}> | ||
<DropdownMenu data-select-disable> | ||
<DropdownMenuItemsContainer> | ||
{columnDefinition.actions.map((action) => ( | ||
<MenuItem | ||
key={action.id} | ||
onClick={() => { | ||
action.callback(); | ||
closeMenu(); | ||
}} | ||
LeftIcon={action.icon} | ||
text={action.label} | ||
/> | ||
))} | ||
</DropdownMenuItemsContainer> | ||
</DropdownMenu> | ||
</StyledMenuContainer> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import React, { useContext, useState } from 'react'; | ||
import styled from '@emotion/styled'; | ||
|
||
import { RecordBoardColumnContext } from '@/object-record/record-board/contexts/RecordBoardColumnContext'; | ||
import { RecordBoardColumnDropdownMenu } from '@/object-record/record-board/record-board-column/components/RecordBoardColumnDropdownMenu'; | ||
import { BoardColumnHotkeyScope } from '@/object-record/record-board-deprecated/types/BoardColumnHotkeyScope'; | ||
import { IconDotsVertical } from '@/ui/display/icon'; | ||
import { Tag } from '@/ui/display/tag/components/Tag'; | ||
import { LightIconButton } from '@/ui/input/button/components/LightIconButton'; | ||
import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope'; | ||
|
||
const StyledHeader = styled.div` | ||
align-items: center; | ||
cursor: pointer; | ||
display: flex; | ||
flex-direction: row; | ||
height: 24px; | ||
justify-content: left; | ||
margin-bottom: ${({ theme }) => theme.spacing(2)}; | ||
width: 100%; | ||
`; | ||
|
||
const StyledAmount = styled.div` | ||
color: ${({ theme }) => theme.font.color.tertiary}; | ||
margin-left: ${({ theme }) => theme.spacing(2)}; | ||
`; | ||
|
||
const StyledNumChildren = styled.div` | ||
align-items: center; | ||
background-color: ${({ theme }) => theme.background.tertiary}; | ||
border-radius: ${({ theme }) => theme.border.radius.rounded}; | ||
color: ${({ theme }) => theme.font.color.tertiary}; | ||
display: flex; | ||
height: 20px; | ||
justify-content: center; | ||
line-height: ${({ theme }) => theme.text.lineHeight.lg}; | ||
margin-left: auto; | ||
width: 16px; | ||
`; | ||
|
||
const StyledHeaderActions = styled.div` | ||
display: flex; | ||
margin-left: auto; | ||
`; | ||
|
||
export const RecordBoardColumnHeader = () => { | ||
const [isBoardColumnMenuOpen, setIsBoardColumnMenuOpen] = useState(false); | ||
const [isHeaderHovered, setIsHeaderHovered] = useState(false); | ||
|
||
const { columnDefinition } = useContext(RecordBoardColumnContext); | ||
|
||
const { | ||
setHotkeyScopeAndMemorizePreviousScope, | ||
goBackToPreviousHotkeyScope, | ||
} = usePreviousHotkeyScope(); | ||
|
||
const handleBoardColumnMenuOpen = () => { | ||
setIsBoardColumnMenuOpen(true); | ||
setHotkeyScopeAndMemorizePreviousScope(BoardColumnHotkeyScope.BoardColumn, { | ||
goto: false, | ||
}); | ||
}; | ||
|
||
const handleBoardColumnMenuClose = () => { | ||
goBackToPreviousHotkeyScope(); | ||
setIsBoardColumnMenuOpen(false); | ||
}; | ||
|
||
const boardColumnTotal = 0; | ||
const cardIds = []; | ||
|
||
return ( | ||
<> | ||
<StyledHeader | ||
onMouseEnter={() => setIsHeaderHovered(true)} | ||
onMouseLeave={() => setIsHeaderHovered(false)} | ||
> | ||
<Tag | ||
onClick={handleBoardColumnMenuOpen} | ||
color={columnDefinition.color} | ||
text={columnDefinition.title} | ||
/> | ||
{!!boardColumnTotal && <StyledAmount>${boardColumnTotal}</StyledAmount>} | ||
{!isHeaderHovered && ( | ||
<StyledNumChildren>{cardIds.length}</StyledNumChildren> | ||
)} | ||
{isHeaderHovered && ( | ||
<StyledHeaderActions> | ||
<LightIconButton | ||
accent="tertiary" | ||
Icon={IconDotsVertical} | ||
onClick={handleBoardColumnMenuOpen} | ||
/> | ||
</StyledHeaderActions> | ||
)} | ||
</StyledHeader> | ||
{isBoardColumnMenuOpen && ( | ||
<RecordBoardColumnDropdownMenu | ||
onClose={handleBoardColumnMenuClose} | ||
stageId={columnDefinition.id} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { createFamilyStateScopeMap } from '@/ui/utilities/recoil-scope/utils/createFamilyStateScopeMap'; | ||
|
||
export const isRecordBoardColumnFirstFamilyStateScopeMap = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would also change this naming |
||
createFamilyStateScopeMap<boolean, string>({ | ||
key: 'isRecordBoardColumnFirstFamilyStateScopeMap', | ||
defaultValue: false, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why strict here? I feel like strict does not really tell what you want?