-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[Maintenance] Convert ExpenseGroup, ExpenseCategory, IncomeCategory components to Typescript. #1897
Changes from all commits
6628f66
d812f01
970e191
e50e3b8
3217e07
9c41c5e
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,16 +1,39 @@ | ||
import React from 'react'; | ||
import React, { type ComponentProps } from 'react'; | ||
|
||
import { type CategoryEntity } from 'loot-core/src/types/models'; | ||
|
||
import { theme } from '../../style'; | ||
import View from '../common/View'; | ||
import { useDraggable, useDroppable, DropHighlight } from '../sort'; | ||
import { | ||
useDraggable, | ||
useDroppable, | ||
DropHighlight, | ||
type DragState, | ||
type OnDragChangeCallback, | ||
type OnDropCallback, | ||
} from '../sort'; | ||
import { Row } from '../table'; | ||
|
||
import RenderMonths from './RenderMonths'; | ||
import SidebarCategory from './SidebarCategory'; | ||
|
||
type ExpenseCategoryProps = { | ||
cat: CategoryEntity; | ||
editingCell: { id: string; cell: string } | null; | ||
dragState: DragState<CategoryEntity>; | ||
MonthComponent: ComponentProps<typeof RenderMonths>['component']; | ||
onEditName?: ComponentProps<typeof SidebarCategory>['onEditName']; | ||
onEditMonth?: (id: string, monthIndex: number) => void; | ||
onSave?: ComponentProps<typeof SidebarCategory>['onSave']; | ||
onDelete?: ComponentProps<typeof SidebarCategory>['onDelete']; | ||
onDragChange: OnDragChangeCallback<CategoryEntity>; | ||
onBudgetAction: (idx: number, action: string, arg: unknown) => void; | ||
onShowActivity: (name: string, id: string, idx: number) => void; | ||
onReorder: OnDropCallback; | ||
}; | ||
|
||
function ExpenseCategory({ | ||
cat, | ||
budgetArray, | ||
editingCell, | ||
dragState, | ||
MonthComponent, | ||
|
@@ -22,7 +45,7 @@ function ExpenseCategory({ | |
onShowActivity, | ||
onDragChange, | ||
onReorder, | ||
}) { | ||
}: ExpenseCategoryProps) { | ||
let dragging = dragState && dragState.item === cat; | ||
|
||
if (dragState && dragState.item.id === cat.cat_group) { | ||
|
@@ -67,7 +90,6 @@ function ExpenseCategory({ | |
onEditName={onEditName} | ||
onSave={onSave} | ||
onDelete={onDelete} | ||
onDragChange={onDragChange} | ||
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. unused |
||
/> | ||
|
||
<RenderMonths | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ import Button from '../common/Button'; | |
import Menu from '../common/Menu'; | ||
import View from '../common/View'; | ||
import NotesButton from '../NotesButton'; | ||
import { type OnDragChangeCallback } from '../sort'; | ||
import { InputCell } from '../table'; | ||
import { Tooltip } from '../tooltips'; | ||
|
||
|
@@ -18,14 +17,13 @@ type SidebarCategoryProps = { | |
dragPreview?: boolean; | ||
dragging?: boolean; | ||
editing: boolean; | ||
style: CSSProperties; | ||
borderColor: string; | ||
style?: CSSProperties; | ||
borderColor?: string; | ||
isLast?: boolean; | ||
onDragChange?: OnDragChangeCallback; | ||
onEditName: (id: string) => void; | ||
onSave: (group) => void; | ||
onDelete: (id: string) => Promise<void>; | ||
onHideNewCategory: () => void; | ||
onHideNewCategory?: () => void; | ||
}; | ||
|
||
function SidebarCategory({ | ||
|
@@ -36,7 +34,6 @@ function SidebarCategory({ | |
editing, | ||
style, | ||
isLast, | ||
onDragChange, | ||
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. Unused |
||
onEditName, | ||
onSave, | ||
onDelete, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,28 +14,32 @@ import { theme } from '../style'; | |
|
||
import View from './common/View'; | ||
|
||
type DragState = { | ||
export type DragState<T> = { | ||
state: 'start-preview' | 'start' | 'end'; | ||
type?: string; | ||
item?: unknown; | ||
item?: T; | ||
preview?: boolean; | ||
}; | ||
|
||
export type DropPosition = 'top' | 'bottom'; | ||
|
||
export type OnDragChangeCallback = (drag: DragState) => Promise<void> | void; | ||
type UseDraggableArgs = { | ||
item: unknown; | ||
export type OnDragChangeCallback<T> = ( | ||
drag: DragState<T>, | ||
) => Promise<void> | void; | ||
|
||
type UseDraggableArgs<T> = { | ||
item?: T; | ||
type: string; | ||
canDrag: boolean; | ||
onDragChange: OnDragChangeCallback; | ||
onDragChange: OnDragChangeCallback<T>; | ||
}; | ||
|
||
export function useDraggable({ | ||
export function useDraggable<T>({ | ||
item, | ||
type, | ||
canDrag, | ||
onDragChange, | ||
}: UseDraggableArgs) { | ||
}: UseDraggableArgs<T>) { | ||
let _onDragChange = useRef(onDragChange); | ||
|
||
const [, dragRef] = useDrag({ | ||
|
@@ -51,8 +55,8 @@ export function useDraggable({ | |
}, | ||
collect: monitor => ({ isDragging: monitor.isDragging() }), | ||
|
||
end(item) { | ||
_onDragChange.current({ state: 'end', type, item }); | ||
end(dragState) { | ||
_onDragChange.current({ state: 'end', type, item: dragState.item }); | ||
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've changed this - it was a bug - the type checking picked it up. The end function passes in the DragState as its prop. We were passing the full DragState through as the "item" when we should pass the item that is being dragged(T). I have checked and this isn't getting used anywhere - so the bug wasn't visible/depended on - safe to change. |
||
}, | ||
|
||
canDrag() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
category: Maintenance | ||
authors: [MikesGlitch] | ||
--- | ||
|
||
Convert ExpenseGroup, ExpenseCategory, IncomeCategory components to Typescript. |
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.
unused