Skip to content

A local-first personal finance app

Move rules action buttons to the top

Jed Fox8893270fccf8
diff --git a/packages/desktop-client/src/components/ManageRules.js b/packages/desktop-client/src/components/ManageRules.js
index 00a6f18088..29d88b17a9 100644
--- a/packages/desktop-client/src/components/ManageRules.js
+++ b/packages/desktop-client/src/components/ManageRules.js
@@ -499,7 +499,11 @@ function RulesList({
);
}
-export default function ManageRules({ payeeId, setLoading = () => {} }) {
+export default function ManageRules({
+ isModal,
+ payeeId,
+ setLoading = () => {}
+}) {
let [allRules, setAllRules] = useState(null);
let [rules, setRules] = useState(null);
let dispatch = useDispatch();
@@ -513,7 +517,9 @@ export default function ManageRules({ payeeId, setLoading = () => {} }) {
let loadedRules = null;
if (payeeId) {
- loadedRules = await send('payees-get-rules', { id: payeeId });
+ loadedRules = await send('payees-get-rules', {
+ id: payeeId
+ });
} else {
loadedRules = await send('rules-get');
}
@@ -592,7 +598,14 @@ export default function ManageRules({ payeeId, setLoading = () => {} }) {
rule: {
stage: null,
conditions: [{ op: 'is', field: 'payee', value: null, type: 'id' }],
- actions: [{ op: 'set', field: 'category', value: null, type: 'id' }]
+ actions: [
+ {
+ op: 'set',
+ field: 'category',
+ value: null,
+ type: 'id'
+ }
+ ]
},
onSave: async newRule => {
let newRules = await loadRules();
@@ -618,10 +631,55 @@ export default function ManageRules({ payeeId, setLoading = () => {} }) {
return null;
}
+ let actions = (
+ <View
+ style={{
+ flexDirection: 'row',
+ alignItems: 'center',
+ padding: isModal ? '13px 15px' : '0 0 15px',
+ borderTop: '1px solid ' + colors.border
+ }}
+ >
+ <View
+ style={{
+ color: colors.n4,
+ flexDirection: 'row',
+ alignItems: 'center',
+ width: '50%'
+ }}
+ >
+ <Text>
+ Rules are always run in the order that you see them.{' '}
+ <ExternalLink
+ asAnchor={true}
+ href="https://actualbudget.com/docs/other/rules/"
+ style={{ color: colors.n4 }}
+ >
+ Learn more
+ </ExternalLink>
+ </Text>
+ </View>
+
+ <View style={{ flex: 1 }} />
+
+ <Stack direction="row" align="center" justify="flex-end" spacing={2}>
+ {selectedInst.items.size > 0 && (
+ <Button onClick={onDeleteSelected}>
+ Delete {selectedInst.items.size} rules
+ </Button>
+ )}
+ <Button primary onClick={onCreateRule}>
+ Create new rule
+ </Button>
+ </Stack>
+ </View>
+ );
+
return (
<SchedulesQuery.Provider>
<SelectedProvider instance={selectedInst}>
- <View style={{ marginTop: 20, overflow: 'hidden' }}>
+ <View style={{ overflow: 'hidden' }}>
+ {!isModal && actions}
<View style={{ flex: 1 }}>
<RulesHeader />
<SimpleTable
@@ -642,53 +700,7 @@ export default function ManageRules({ payeeId, setLoading = () => {} }) {
/>
</SimpleTable>
</View>
-
- <View
- style={{
- flexDirection: 'row',
- alignItems: 'center',
- padding: '13px 15px',
- borderTop: '1px solid ' + colors.border
- }}
- >
- <View
- style={{
- color: colors.n4,
- flexDirection: 'row',
- alignItems: 'center',
- width: '50%'
- }}
- >
- <Text>
- Rules are always run in the order that you see them.{' '}
- <ExternalLink
- asAnchor={true}
- href="https://actualbudget.com/docs/other/rules/"
- style={{ color: colors.n4 }}
- >
- Learn more
- </ExternalLink>
- </Text>
- </View>
-
- <View style={{ flex: 1 }} />
-
- <Stack
- direction="row"
- align="center"
- justify="flex-end"
- spacing={2}
- >
- {selectedInst.items.size > 0 && (
- <Button onClick={onDeleteSelected}>
- Delete {selectedInst.items.size} rules
- </Button>
- )}
- <Button primary onClick={onCreateRule}>
- Create new rule
- </Button>
- </Stack>
- </View>
+ {isModal && actions}
</View>
</SelectedProvider>
</SchedulesQuery.Provider>
diff --git a/packages/desktop-client/src/components/modals/ManageRulesModal.js b/packages/desktop-client/src/components/modals/ManageRulesModal.js
index 4b39870a2a..2b915f71b5 100644
--- a/packages/desktop-client/src/components/modals/ManageRulesModal.js
+++ b/packages/desktop-client/src/components/modals/ManageRulesModal.js
@@ -17,9 +17,9 @@ export default function ManageRulesModal({ modalProps, payeeId }) {
padding={0}
loading={loading}
{...modalProps}
- style={[modalProps.style, { flex: 1, maxWidth: '90%' }]}
+ style={[modalProps.style, { flex: 1, maxWidth: '90%', maxHeight: '90%' }]}
>
- {() => <ManageRules payeeId={payeeId} setLoading={setLoading} />}
+ {() => <ManageRules isModal payeeId={payeeId} setLoading={setLoading} />}
</Modal>
);
}
diff --git a/packages/loot-design/src/components/common.js b/packages/loot-design/src/components/common.js
index b54c259f90..415d8dd910 100644
--- a/packages/loot-design/src/components/common.js
+++ b/packages/loot-design/src/components/common.js
@@ -3,7 +3,7 @@ import React, {
useEffect,
useLayoutEffect,
useState,
- useCallback,
+ useCallback
} from 'react';
import { css } from 'glamor';
import mergeRefs from 'react-merge-refs';
@@ -820,7 +820,8 @@ export function Modal({
<View
style={{
padding: 20,
- position: 'relative'
+ position: 'relative',
+ flexShrink: 0
}}
>
{showTitle && (
diff --git a/packages/loot-design/src/components/table.js b/packages/loot-design/src/components/table.js
index efe1ee15c3..a282e136cc 100644
--- a/packages/loot-design/src/components/table.js
+++ b/packages/loot-design/src/components/table.js
@@ -31,10 +31,7 @@ import SheetValue from './spreadsheet/SheetValue';
import DateSelect from './DateSelect';
import format from './spreadsheet/format';
import { keys } from '../util/keys';
-import {
- AvoidRefocusScrollProvider,
- useProperFocus,
-} from './useProperFocus';
+import { AvoidRefocusScrollProvider, useProperFocus } from './useProperFocus';
import { useSelectedItems } from './useSelected';
export const ROW_HEIGHT = 32;
@@ -250,26 +247,23 @@ export function Row({
let rowRef = useRef(null);
let timer = useRef(null);
- useEffect(
- () => {
- if (highlighted && !prevHighlighted.current && rowRef.current) {
- rowRef.current.classList.add('animated');
- setShouldHighlight(true);
+ useEffect(() => {
+ if (highlighted && !prevHighlighted.current && rowRef.current) {
+ rowRef.current.classList.add('animated');
+ setShouldHighlight(true);
- clearTimeout(timer.current);
- timer.current = setTimeout(() => {
- setShouldHighlight(false);
+ clearTimeout(timer.current);
+ timer.current = setTimeout(() => {
+ setShouldHighlight(false);
- timer.current = setTimeout(() => {
- if (rowRef.current) {
- rowRef.current.classList.remove('animated');
- }
- }, 500);
+ timer.current = setTimeout(() => {
+ if (rowRef.current) {
+ rowRef.current.classList.remove('animated');
+ }
}, 500);
- }
- },
- [highlighted]
- );
+ }, 500);
+ }
+ }, [highlighted]);
useEffect(() => {
prevHighlighted.current = highlighted;
@@ -724,7 +718,11 @@ export function TableHeader({ headers, children, version, ...rowProps }) {
return (
<View
style={
- version === 'v2' && { borderRadius: '6px 6px 0 0', overflow: 'hidden' }
+ version === 'v2' && {
+ borderRadius: '6px 6px 0 0',
+ overflow: 'hidden',
+ flexShrink: 0
+ }
}
>
<Row
@@ -1233,8 +1231,8 @@ export function useTableNavigator(data, fields, opts = {}) {
? 'up'
: 'down'
: e.shiftKey
- ? 'left'
- : 'right'
+ ? 'left'
+ : 'right'
);
break;
default: