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

Transaction Table Resize #3309

Closed
wants to merge 55 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
a024264
test
lelemm Aug 23, 2024
a9057e1
fixes
lelemm Aug 26, 2024
67ec8d6
maxsize fix
lelemm Aug 26, 2024
d489f62
maxsize fix #2
lelemm Aug 26, 2024
6df0e6a
fixes
lelemm Aug 26, 2024
fb323f9
calc fix
lelemm Aug 26, 2024
d36a9eb
clean up
lelemm Aug 26, 2024
25acb93
testing for manual resize
lelemm Aug 27, 2024
4b0dd0f
big mess
lelemm Aug 30, 2024
10d3840
Merge branch 'master' into table_resize_test
lelemm Sep 2, 2024
6c2ec5d
fixes and cleanup
lelemm Sep 2, 2024
ed5ace2
fixes and visual regression
lelemm Sep 2, 2024
848727f
missing scroll provider and typechecks
lelemm Sep 2, 2024
3ba0899
changed debounce import
lelemm Sep 2, 2024
d4b6d67
small test fix
lelemm Sep 2, 2024
059ad96
linter
lelemm Sep 2, 2024
1f4a72d
Fixes
lelemm Sep 2, 2024
cac2ffb
Fixes
lelemm Sep 2, 2024
a8c8d85
add reset menu to resizer
lelemm Sep 2, 2024
d729e37
multiple fixes and refactories
lelemm Sep 3, 2024
0c5f98d
Merge branch 'master' into table_resize_test
lelemm Sep 3, 2024
263b091
adjust field selection query
lelemm Sep 4, 2024
6169f69
new vrt snaps
lelemm Sep 4, 2024
613d548
3309.md
lelemm Sep 4, 2024
2f2bd59
linter
lelemm Sep 4, 2024
622c470
testing e2e fixes
lelemm Sep 4, 2024
e315330
revert changes
lelemm Sep 4, 2024
edca1fa
vrt
lelemm Sep 4, 2024
532c400
fixes
lelemm Oct 23, 2024
3b4e6be
Merge remote-tracking branch 'org/master' into table_resize_test
lelemm Oct 23, 2024
a62b1a7
merge fix
lelemm Oct 23, 2024
9691e4b
yarnlock?
lelemm Oct 23, 2024
82a1178
fix test
lelemm Oct 23, 2024
a2d6953
e2e
lelemm Oct 23, 2024
021db10
fix tests
lelemm Oct 23, 2024
9092e50
merge fix
lelemm Oct 23, 2024
25c7c13
linter
lelemm Oct 23, 2024
50c4b65
Merge branch 'master' into table_resize_test
lelemm Oct 24, 2024
38f752d
changes on newTransaction to fit on a new section of the table named …
lelemm Oct 24, 2024
b9f4d19
Merge branch 'table_resize_test' of https://github.com/lelemm/actual …
lelemm Oct 24, 2024
a479c95
fixes and e2e
lelemm Oct 25, 2024
e1f65ad
linter
lelemm Oct 25, 2024
e33dad3
Merge branch 'master' into table_resize_test
lelemm Oct 25, 2024
cc1e804
Update packages/desktop-client/src/components/HorizontalFakeScrollbar…
lelemm Oct 25, 2024
fff2153
Update packages/desktop-client/src/components/HorizontalFakeScrollbar…
lelemm Oct 25, 2024
c8d49e0
changes proposed by coderabbit and fixes
lelemm Oct 25, 2024
eaed656
Update packages/desktop-client/src/components/Resizer.tsx
lelemm Oct 25, 2024
6e3fb4e
coderabbit review suggestion
lelemm Oct 25, 2024
3da670b
removed fake scrollbar
lelemm Nov 14, 2024
0fc422c
Update packages/desktop-client/src/components/table.tsx
lelemm Nov 14, 2024
6e2b747
Merge remote-tracking branch 'org/master' into table_resize_test
lelemm Nov 14, 2024
79e51a3
some minor fixes
lelemm Nov 14, 2024
6aac0b0
test fix
lelemm Nov 14, 2024
76838be
e2e update
lelemm Nov 14, 2024
6ac5a5c
Update VRT
github-actions[bot] Nov 21, 2024
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
Prev Previous commit
Next Next commit
fixes
  • Loading branch information
lelemm committed Aug 26, 2024
commit a9057e1bc08863ccf1e80e524ef1768c5f38d343
17 changes: 13 additions & 4 deletions packages/desktop-client/src/components/ColumnWidthContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@ export const ColumnWidthProvider = ({ children }) => {
const [columnWidths, setColumnWidths] = useState({});

const updateColumnWidth = useCallback((columnName, width) => {
setColumnWidths((prevWidths) => ({
setColumnWidths(prevWidths => ({
...prevWidths,
[columnName]: Math.max(prevWidths[columnName] || 100, width),
}));
}, []);

const resetColumnWidths = useCallback(() => {
setColumnWidths({});
const resetColumnWidths = useCallback((columnName = '') => {
if (columnName) {
setColumnWidths(prevWidths => ({
...prevWidths,
[columnName]: 0,
}));
} else {
setColumnWidths({});
}
}, []);

return (
<ColumnWidthContext.Provider value={{ columnWidths, updateColumnWidth, resetColumnWidths }}>
<ColumnWidthContext.Provider
value={{ columnWidths, updateColumnWidth, resetColumnWidths }}
>
{children}
</ColumnWidthContext.Provider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ type PayeeAutocompleteProps = ComponentProps<
) => ReactElement<typeof PayeeItem>;
accounts?: AccountEntity[];
payees?: PayeeAutocompleteItem[];
onBlur?: (e: unknown) => void;
};

export function PayeeAutocomplete({
Expand Down Expand Up @@ -358,9 +359,10 @@ export function PayeeAutocomplete({
inputProps={{
...inputProps,
autoCapitalize: 'words',
onBlur: () => {
onBlur: e => {
setRawPayee('');
setPayeeFieldFocused(false);
inputProps?.onBlur?.(e);
},
onFocus: () => setPayeeFieldFocused(true),
onChange: setRawPayee,
Expand Down
182 changes: 96 additions & 86 deletions packages/desktop-client/src/components/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import React, {
import { useStore } from 'react-redux';
import AutoSizer from 'react-virtualized-auto-sizer';

import { useMergedRefs } from '../hooks/useMergedRefs';
import {
AvoidRefocusScrollProvider,
useProperFocus,
Expand Down Expand Up @@ -48,7 +49,6 @@ import {
} from './spreadsheet';
import { type FormatType, useFormat } from './spreadsheet/useFormat';
import { useSheetValue } from './spreadsheet/useSheetValue';
import { useMergedRefs } from '../hooks/useMergedRefs';

export const ROW_HEIGHT = 32;

Expand Down Expand Up @@ -157,32 +157,38 @@ type CellProps = Omit<ComponentProps<typeof View>, 'children' | 'value'> & {
typeof ConditionalPrivacyFilter
>['privacyFilter'];
};
export const Cell = forwardRef<HTMLDivElement, CellProps>(function Cell({
width,
name,
exposed,
focused,
value,
formatter,
textAlign,
alignItems,
onExpose,
children,
plain,
style,
valueStyle,
unexposedContent,
privacyFilter,
...viewProps
}: CellProps, ref) {
export const Cell = forwardRef<HTMLDivElement, CellProps>(function Cell(
{
width,
name,
exposed,
focused,
value,
formatter,
textAlign,
alignItems,
onExpose,
children,
plain,
style,
valueStyle,
unexposedContent,
privacyFilter,
...viewProps
}: CellProps,
ref,
) {
const mouseCoords = useRef(null);
const viewRef = useRef(null);
const mergeRef = useMergedRefs(ref, viewRef);

useProperFocus(viewRef, focused !== undefined ? focused : exposed);

const widthStyle: CSSProperties =
width ? (width === 'flex' ? { flex: 1, flexBasis: 0 } : { width }) : { width: 'auto'};
const widthStyle: CSSProperties = width
? width === 'flex'
? { flex: 1, flexBasis: 0 }
: { width }
: { width: 'auto' };
const cellStyle: CSSProperties = {
position: 'relative',
textAlign: textAlign || 'left',
Expand Down Expand Up @@ -269,7 +275,7 @@ export const Cell = forwardRef<HTMLDivElement, CellProps>(function Cell({

return (
<View
innerRef={ref}
innerRef={mergeRef}
style={{ ...widthStyle, ...cellStyle, ...style }}
{...viewProps}
data-testid={name}
Expand Down Expand Up @@ -395,27 +401,26 @@ type InputCellProps = ComponentProps<typeof Cell> & {
onBlur?: ComponentProps<typeof InputValue>['onBlur'];
textAlign?: CSSProperties['textAlign'];
};
export const InputCell = forwardRef<HTMLInputElement, InputCellProps>(function InputCell({
inputProps,
onUpdate,
onBlur,
textAlign,
...props
}: InputCellProps, ref) {
return (
<Cell textAlign={textAlign} {...props} ref={ref}>
{() => (
<InputValue
value={props.value}
onUpdate={onUpdate}
onBlur={onBlur}
style={{ textAlign, ...(inputProps && inputProps.style) }}
{...inputProps}
/>
)}
</Cell>
);
});
export const InputCell = forwardRef<HTMLInputElement, InputCellProps>(
function InputCell(
{ inputProps, onUpdate, onBlur, textAlign, ...props }: InputCellProps,
ref,
) {
return (
<Cell textAlign={textAlign} {...props} ref={ref}>
{() => (
<InputValue
value={props.value}
onUpdate={onUpdate}
onBlur={onBlur}
style={{ textAlign, ...(inputProps && inputProps.style) }}
{...inputProps}
/>
)}
</Cell>
);
},
);

function shouldSaveFromKey(e) {
switch (e.key) {
Expand All @@ -440,55 +445,60 @@ type CustomCellProps = Omit<ComponentProps<typeof Cell>, 'children'> & {
onUpdate: (value: string) => void;
onBlur: (ev: UIEvent<unknown>) => void;
};
export const CustomCell = forwardRef<HTMLDivElement, CustomCellProps>(function CustomCell({
value: defaultValue,
children,
onUpdate,
onBlur,
...props
}: CustomCellProps, ref) {
const [value, setValue] = useState(defaultValue);
const [prevDefaultValue, setPrevDefaultValue] = useState(defaultValue);

if (prevDefaultValue !== defaultValue) {
setValue(defaultValue);
setPrevDefaultValue(defaultValue);
}
export const CustomCell = forwardRef<HTMLDivElement, CustomCellProps>(
function CustomCell(
{
value: defaultValue,
children,
onUpdate,
onBlur,
...props
}: CustomCellProps,
ref,
) {
const [value, setValue] = useState(defaultValue);
const [prevDefaultValue, setPrevDefaultValue] = useState(defaultValue);

function onBlur_(e) {
// Only save on blur if the app is focused. Blur events fire when
// the app unfocuses, and it's unintuitive to save the value since
// the input will be focused again when the app regains focus
if (document.hasFocus()) {
onUpdate?.(value);
fireBlur(onBlur, e);
if (prevDefaultValue !== defaultValue) {
setValue(defaultValue);
setPrevDefaultValue(defaultValue);
}
}

function onKeyDown(e) {
if (shouldSaveFromKey(e)) {
onUpdate?.(value);
function onBlur_(e) {
// Only save on blur if the app is focused. Blur events fire when
// the app unfocuses, and it's unintuitive to save the value since
// the input will be focused again when the app regains focus
if (document.hasFocus()) {
onUpdate?.(value);
fireBlur(onBlur, e);
}
}
}

return (
<Cell {...props} value={defaultValue} ref={ref}>
{() =>
children({
onBlur: onBlur_,
onKeyDown,
onUpdate: val => setValue(val),
onSave: val => {
setValue(val);
onUpdate?.(val);
},
shouldSaveFromKey,
inputStyle: inputCellStyle,
})
function onKeyDown(e) {
if (shouldSaveFromKey(e)) {
onUpdate?.(value);
}
</Cell>
);
});
}

return (
<Cell {...props} value={defaultValue} ref={ref}>
{() =>
children({
onBlur: onBlur_,
onKeyDown,
onUpdate: val => setValue(val),
onSave: val => {
setValue(val);
onUpdate?.(val);
},
shouldSaveFromKey,
inputStyle: inputCellStyle,
})
}
</Cell>
);
},
);

type DeleteCellProps = Omit<ComponentProps<typeof Cell>, 'children'> & {
onDelete?: () => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { getChangedValues, applyChanges } from 'loot-core/src/shared/util';

import { useNavigate } from '../../hooks/useNavigate';
import { theme } from '../../style';
import { ColumnWidthProvider } from '../ColumnWidthContext';

import { TransactionTable } from './TransactionsTable';
import { ColumnWidthProvider } from '../ColumnWidthContext';

// When data changes, there are two ways to update the UI:
//
Expand Down
Loading
Loading