Skip to content

Commit

Permalink
Merge branch 'master' into goal_speedup2
Browse files Browse the repository at this point in the history
  • Loading branch information
youngcw committed Sep 25, 2023
2 parents 37af707 + 89c5f15 commit 2866acb
Show file tree
Hide file tree
Showing 25 changed files with 457 additions and 231 deletions.
3 changes: 3 additions & 0 deletions packages/desktop-client/src/components/FinancesApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ function FinancesApp() {
</WideNotSupported>
}
/>

{/* redirect all other traffic to the budget page */}
<Route path="/*" element={<Navigate to="/budget" replace />} />
</Routes>

<Modals />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, {
createContext,
type Dispatch,
type ReactNode,
type SetStateAction,
useContext,
useState,
} from 'react';

type BudgetMonthCountContextValue = {
displayMax: number;
setDisplayMax: Dispatch<SetStateAction<number>>;
};

let BudgetMonthCountContext = createContext<BudgetMonthCountContextValue>(null);

type BudgetMonthCountProviderProps = {
children: ReactNode;
};

export function BudgetMonthCountProvider({
children,
}: BudgetMonthCountProviderProps) {
let [displayMax, setDisplayMax] = useState(1);

return (
<BudgetMonthCountContext.Provider value={{ displayMax, setDisplayMax }}>
{children}
</BudgetMonthCountContext.Provider>
);
}

export function useBudgetMonthCount() {
return useContext(BudgetMonthCountContext);
}
75 changes: 59 additions & 16 deletions packages/desktop-client/src/components/common/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ButtonProps = HTMLProps<HTMLButtonElement> & {
as?: ElementType;
};

type ButtonType = 'normal' | 'primary' | 'bare';
type ButtonType = 'normal' | 'primary' | 'bare' | 'link';

const backgroundColor = {
normal: theme.buttonNormalBackground,
Expand All @@ -33,6 +33,7 @@ const backgroundColor = {
bareDisabled: theme.buttonBareDisabledBackground,
menu: theme.buttonMenuBackground,
menuSelected: theme.buttonMenuSelectedBackground,
link: theme.buttonBareBackground,
};

const backgroundColorHover = {
Expand All @@ -41,6 +42,7 @@ const backgroundColorHover = {
bare: theme.buttonBareBackgroundHover,
menu: theme.buttonMenuBackgroundHover,
menuSelected: theme.buttonMenuSelectedBackgroundHover,
link: theme.buttonBareBackground,
};

const borderColor = {
Expand All @@ -50,6 +52,7 @@ const borderColor = {
primaryDisabled: theme.buttonPrimaryDisabledBorder,
menu: theme.buttonMenuBorder,
menuSelected: theme.buttonMenuSelectedBorder,
link: theme.buttonBareBackground,
};

const textColor = {
Expand All @@ -61,6 +64,7 @@ const textColor = {
bareDisabled: theme.buttonBareDisabledText,
menu: theme.buttonMenuText,
menuSelected: theme.buttonMenuSelectedText,
link: theme.pageTextLink,
};

const textColorHover = {
Expand All @@ -71,6 +75,55 @@ const textColorHover = {
menuSelected: theme.buttonMenuSelectedTextHover,
};

const linkButtonHoverStyles = {
textDecoration: 'underline',
boxShadow: 'none',
};

const _getBorder = (type, typeWithDisabled) => {
switch (type) {
case 'bare':
case 'link':
return 'none';

default:
return '1px solid ' + borderColor[typeWithDisabled];
}
};

const _getPadding = type => {
switch (type) {
case 'bare':
return '5px';
case 'link':
return '0';
default:
return '5px 10px';
}
};

const _getActiveStyles = (type, bounce) => {
switch (type) {
case 'bare':
return { backgroundColor: theme.buttonBareBackgroundActive };
case 'link':
return {
transform: 'none',
boxShadow: 'none',
};
default:
return {
transform: bounce && 'translateY(1px)',
boxShadow: `0 1px 4px 0 ${
type === 'primary'
? theme.buttonPrimaryShadow
: theme.buttonNormalShadow
}`,
transition: 'none',
};
}
};

const Button = forwardRef<HTMLButtonElement, ButtonProps>(
(
{
Expand All @@ -94,22 +147,13 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(

hoveredStyle = {
...(type !== 'bare' && styles.shadow),
...(type === 'link' && linkButtonHoverStyles),
backgroundColor: backgroundColorHover[type],
color: color || textColorHover[type],
...hoveredStyle,
};
activeStyle = {
...(type === 'bare'
? { backgroundColor: theme.buttonBareBackgroundActive }
: {
transform: bounce && 'translateY(1px)',
boxShadow:
'0 1px 4px 0 ' +
(type === 'primary'
? theme.buttonPrimaryShadow
: theme.buttonNormalShadow),
transition: 'none',
}),
..._getActiveStyles(type, bounce),
...activeStyle,
};

Expand All @@ -118,14 +162,13 @@ const Button = forwardRef<HTMLButtonElement, ButtonProps>(
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
padding: type === 'bare' ? '5px' : '5px 10px',
padding: _getPadding(type),
margin: 0,
overflow: 'hidden',
display: 'flex',
display: type === 'link' ? 'inline' : 'flex',
borderRadius: 4,
backgroundColor: backgroundColor[typeWithDisabled],
border:
type === 'bare' ? 'none' : '1px solid ' + borderColor[typeWithDisabled],
border: _getBorder(type, typeWithDisabled),
color: color || textColor[typeWithDisabled],
transition: 'box-shadow .25s',
WebkitAppRegion: 'no-drag',
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/reports/CashFlow.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function CashFlow() {

const [allMonths, setAllMonths] = useState(null);
const [start, setStart] = useState(
monthUtils.subMonths(monthUtils.currentMonth(), 30),
monthUtils.subMonths(monthUtils.currentMonth(), 5),
);
const [end, setEnd] = useState(monthUtils.currentDay());

Expand Down
60 changes: 38 additions & 22 deletions packages/desktop-client/src/components/rules/ActionExpression.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from 'react';

import { mapField, friendlyOp } from 'loot-core/src/shared/rules';
import { type ScheduleEntity } from 'loot-core/src/types/models';
import {
type LinkScheduleRuleActionEntity,
type RuleActionEntity,
type SetRuleActionEntity,
} from 'loot-core/src/types/models';

import { type CSSProperties, theme } from '../../style';
import Text from '../common/Text';
Expand All @@ -14,20 +18,13 @@ let valueStyle = {
color: theme.pageTextPositive,
};

type ActionExpressionProps = {
field: unknown;
op: unknown;
value: unknown;
options: unknown;
type ActionExpressionProps = RuleActionEntity & {
style?: CSSProperties;
};

export default function ActionExpression({
field,
op,
value,
options,
style,
...props
}: ActionExpressionProps) {
return (
<View
Expand All @@ -44,19 +41,38 @@ export default function ActionExpression({
...style,
}}
>
{op === 'set' ? (
<>
<Text>{friendlyOp(op)}</Text>{' '}
<Text style={valueStyle}>{mapField(field, options)}</Text>{' '}
<Text>to </Text>
<Value value={value} field={field} />
</>
) : op === 'link-schedule' ? (
<>
<Text>{friendlyOp(op)}</Text>{' '}
<ScheduleValue value={value as ScheduleEntity} />
</>
{props.op === 'set' ? (
<SetActionExpression {...props} />
) : props.op === 'link-schedule' ? (
<LinkScheduleActionExpression {...props} />
) : null}
</View>
);
}

function SetActionExpression({
op,
field,
value,
options,
}: SetRuleActionEntity) {
return (
<>
<Text>{friendlyOp(op)}</Text>{' '}
<Text style={valueStyle}>{mapField(field, options)}</Text>{' '}
<Text>to </Text>
<Value value={value} field={field} />
</>
);
}

function LinkScheduleActionExpression({
op,
value,
}: LinkScheduleRuleActionEntity) {
return (
<>
<Text>{friendlyOp(op)}</Text> <ScheduleValue value={value} />
</>
);
}
5 changes: 1 addition & 4 deletions packages/desktop-client/src/components/rules/RuleRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,7 @@ const RuleRow = memo(
{rule.actions.map((action, i) => (
<ActionExpression
key={i}
field={action.field}
op={action.op}
value={action.value}
options={action.options}
{...action}
style={i !== 0 && { marginTop: 3 }}
/>
))}
Expand Down
7 changes: 4 additions & 3 deletions packages/desktop-client/src/components/settings/UI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { css, media } from 'glamor';

import { type CSSProperties, theme } from '../../style';
import tokens from '../../tokens';
import LinkButton from '../common/LinkButton';
import Button from '../common/Button';
import View from '../common/View';

type SettingProps = {
Expand Down Expand Up @@ -77,8 +77,9 @@ export const AdvancedToggle = ({ children }: AdvancedToggleProps) => {
{children}
</View>
) : (
<LinkButton
<Button
id="advanced"
type="link"
onClick={() => setExpanded(true)}
style={{
flexShrink: 0,
Expand All @@ -88,6 +89,6 @@ export const AdvancedToggle = ({ children }: AdvancedToggleProps) => {
}}
>
Show advanced settings
</LinkButton>
</Button>
);
};
2 changes: 1 addition & 1 deletion packages/loot-core/src/server/accounts/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ let CONDITION_TYPES = {
},
string: {
ops: ['is', 'contains', 'oneOf', 'isNot', 'doesNotContain', 'notOneOf'],
nullable: false,
nullable: true,
parse(op, value, fieldName) {
if (op === 'oneOf' || op === 'notOneOf') {
assert(
Expand Down
Loading

0 comments on commit 2866acb

Please sign in to comment.