-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[WIP] Make the width of categories column in the budget view customizable #3445
Changes from all commits
25d5fe0
98dc88b
14fc8d7
2947f2d
a7c6483
7a5e6f6
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { useState, type HTMLProps } from 'react'; | ||
import { Trans } from 'react-i18next'; | ||
|
||
import { useLocalPref } from '../../hooks/useLocalPref'; | ||
import { theme as themeStyle } from '../../style'; | ||
import { Input } from '../common/Input'; | ||
import { Text } from '../common/Text'; | ||
import { View } from '../common/View'; | ||
|
||
import { Column, Setting } from './UI'; | ||
|
||
export function DisplaySettings() { | ||
const [prefWidth = 200, setPrefWidth] = useLocalPref('category.width'); | ||
const [tempWidth, setTempWidth] = useState(prefWidth.toString()); | ||
|
||
const onBlur: HTMLProps<HTMLInputElement>['onBlur'] = event => { | ||
if (document.hasFocus()) { | ||
const value = parseInt(event.target.value); | ||
|
||
if (Number.isInteger(value)) { | ||
const clampedValue = Math.max(100, Math.min(1024, value)); | ||
setPrefWidth(clampedValue); | ||
setTempWidth(clampedValue.toString()); | ||
} else { | ||
setTempWidth(prefWidth.toString()); | ||
} | ||
} | ||
}; | ||
Comment on lines
+16
to
+28
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. 🛠️ Refactor suggestion Consider refactoring the While the logic is correct, consider the following improvements:
Here's a suggested refactoring: const clampWidth = (value: number) => Math.max(100, Math.min(1024, value));
const useWidthInput = (initialWidth: number) => {
const [width, setWidth] = useState(initialWidth);
const [tempWidth, setTempWidth] = useState(initialWidth.toString());
const handleBlur = (event: React.FocusEvent<HTMLInputElement>) => {
if (document.hasFocus()) {
const value = parseInt(event.target.value, 10);
if (Number.isInteger(value)) {
const clampedValue = clampWidth(value);
setWidth(clampedValue);
setTempWidth(clampedValue.toString());
} else {
setTempWidth(width.toString());
}
}
};
return { width, tempWidth, setTempWidth, handleBlur };
};
// In your component:
const { width, tempWidth, setTempWidth, handleBlur } = useWidthInput(prefWidth); This refactoring improves readability, reusability, and separation of concerns. |
||
|
||
return ( | ||
<Setting | ||
primaryAction={ | ||
<View | ||
style={{ | ||
flexDirection: 'column', | ||
gap: '1em', | ||
width: '100%', | ||
}} | ||
> | ||
<Column title="Categories Width"> | ||
<Text> | ||
<Trans> | ||
Width of the categories column in pixels. Must be between | ||
</Trans> | ||
</Text> | ||
<Input | ||
value={tempWidth} | ||
onChange={event => setTempWidth(event.target.value)} | ||
onBlur={onBlur} | ||
style={{ | ||
':hover': { | ||
backgroundColor: themeStyle.buttonNormalBackgroundHover, | ||
}, | ||
}} | ||
/> | ||
</Column> | ||
</View> | ||
} | ||
> | ||
<Text> | ||
<Trans> | ||
<strong>Display settings</strong> change how certain elements of the | ||
interface are displayed. | ||
</Trans> | ||
</Text> | ||
</Setting> | ||
); | ||
} | ||
Comment on lines
+30
to
+68
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. 🛠️ Refactor suggestion Consider extracting styles and improving component structure. The component structure is well-organized, but there are a few areas for improvement:
Here's a suggestion for extracting styles: import styled from 'styled-components';
const StyledInput = styled(Input)`
&:hover {
background-color: ${props => props.theme.buttonNormalBackgroundHover};
}
`;
const SettingContainer = styled(View)`
flex-direction: column;
gap: 1em;
width: 100%;
`;
// Then in your JSX:
<SettingContainer>
<Column title={<Trans>Categories Width</Trans>}>
{/* ... */}
<StyledInput
value={tempWidth}
onChange={event => setTempWidth(event.target.value)}
onBlur={handleBlur}
/>
</Column>
</SettingContainer> This approach improves code readability and maintainability by separating concerns. |
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.
💡 Codebase verification
Action Required: Hardcoded width detected in IncomeHeader.tsx
The search revealed that
width: 200
is still hardcoded in the following file:packages/desktop-client/src/components/budget/IncomeHeader.tsx
Please replace the hardcoded value with the
categoryWidth
variable to maintain consistency and support dynamic width adjustment.🔗 Analysis chain
LGTM: Consistent usage of
categoryWidth
in Popover components.The
categoryWidth
variable is correctly used to set the width of the Popover components, replacing the hardcoded value of 200. This change successfully implements the customizable width feature as per the PR objectives.To ensure consistency across the codebase:
If the script returns any results, please review those occurrences to determine if they should also use the
categoryWidth
variable.Also applies to: 392-392
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 116
Script:
Length of output: 102
Script:
Length of output: 163