Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
carkom committed Jan 26, 2024
1 parent cb01d5d commit 12dea5f
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 54 deletions.
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/common/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function Keybinding({ keyName }: KeybindingProps) {
);
}

export type MenuItem = {
type MenuItem = {
type?: string | symbol;
name: string;
disabled?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function CondOpMenu({
['or', 'any'],
]}
value={conditionsOp}
onChange={value => onCondOpChange(value, filters)}
onChange={(value: string) => onCondOpChange(value, filters)}
/>
of:
</Text>
Expand Down
56 changes: 28 additions & 28 deletions packages/desktop-client/src/components/filters/FilterMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,51 @@ import React from 'react';
import { Menu } from '../common/Menu';
import { MenuTooltip } from '../common/MenuTooltip';

import { type SavedFilter } from './SavedFilterMenuButton';

export function FilterMenu({
onClose,
filterId,
onFilterMenuSelect,
}: {
onClose: () => void;
filterId: any;
onFilterMenuSelect: any;
filterId: SavedFilter;
onFilterMenuSelect: (item: string) => void;
}) {
return (
<MenuTooltip width={200} onClose={onClose}>
<Menu
onMenuSelect={item => {
onFilterMenuSelect(item);
}}
items={[
...(!filterId.id
items={
!filterId.id
? [
{ name: 'save-filter', text: 'Save new filter' },
{ name: 'clear-filter', text: 'Clear all conditions' },
]
: [
...(filterId.id !== null && filterId.status === 'saved'
? [
{ name: 'rename-filter', text: 'Rename' },
{ name: 'delete-filter', text: 'Delete' },
Menu.line,
{
name: 'save-filter',
text: 'Save new filter',
disabled: true,
},
{ name: 'clear-filter', text: 'Clear all conditions' },
]
: [
{ name: 'rename-filter', text: 'Rename' },
{ name: 'update-filter', text: 'Update condtions' },
{ name: 'reload-filter', text: 'Revert changes' },
{ name: 'delete-filter', text: 'Delete' },
Menu.line,
{ name: 'save-filter', text: 'Save new filter' },
{ name: 'clear-filter', text: 'Clear all conditions' },
]),
]),
]}
: filterId.id !== null && filterId.status === 'saved'
? [
{ name: 'rename-filter', text: 'Rename' },
{ name: 'delete-filter', text: 'Delete' },
Menu.line,
{
name: 'save-filter',
text: 'Save new filter',
disabled: true,
},
{ name: 'clear-filter', text: 'Clear all conditions' },
]
: [
{ name: 'rename-filter', text: 'Rename' },
{ name: 'update-filter', text: 'Update condtions' },
{ name: 'reload-filter', text: 'Revert changes' },
{ name: 'delete-filter', text: 'Delete' },
Menu.line,
{ name: 'save-filter', text: 'Save new filter' },
{ name: 'clear-filter', text: 'Clear all conditions' },
]
}
/>
</MenuTooltip>
);
Expand Down
15 changes: 11 additions & 4 deletions packages/desktop-client/src/components/filters/NameFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export function NameFilter({
adding,
onAddUpdate,
err,
}: {
onClose: () => void;
menuItem: string;
name: string;
setName: (item: string) => void;
adding: boolean;
onAddUpdate: () => void;
err: string | null;
}) {
const inputRef = useRef<HTMLInputElement>();

Expand All @@ -42,11 +50,10 @@ export function NameFilter({
style={{ userSelect: 'none' }}
/>
<Input
inputRef={inputRef}
id="name-field"
type="string"
value={name}
onChange={setName}
inputRef={inputRef}
defaultValue={name || ''}
onUpdate={(item: string) => setName(item)}
/>
</FormField>
<Button
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useState } from 'react';

import { send, sendCatch } from 'loot-core/src/platform/client/fetch';
import { type RuleConditionEntity } from 'loot-core/types/models/rule';

import { SvgExpandArrow } from '../../icons/v0';
import { Button } from '../common/Button';
Expand All @@ -10,25 +11,39 @@ import { View } from '../common/View';
import { FilterMenu } from './FilterMenu';
import { NameFilter } from './NameFilter';

export type SavedFilter = {
conditions?: RuleConditionEntity[];
conditionsOp?: string;
id?: string;
name: string;
status?: string;
};

export function SavedFilterMenuButton({
filters,
conditionsOp,
filterId,
onClearFilters,
onReloadSavedFilter,
filtersList,
}: {
filters: RuleConditionEntity[];
conditionsOp: string;
filterId: SavedFilter;
onClearFilters: () => void;
onReloadSavedFilter: (savedFilter: SavedFilter, value?: string) => void;
filtersList: RuleConditionEntity[];
}) {
const [nameOpen, setNameOpen] = useState(false);
const [adding, setAdding] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);
const [err, setErr] = useState(null);
const [menuItem, setMenuItem] = useState(null);
const [menuItem, setMenuItem] = useState('');
const [name, setName] = useState(filterId.name);
const id = filterId.id;
let res;
let savedFilter;
let savedFilter: SavedFilter;

const onFilterMenuSelect = async item => {
const onFilterMenuSelect = async (item: string) => {
setMenuItem(item);
switch (item) {
case 'rename-filter':
Expand All @@ -53,16 +68,11 @@ export function SavedFilterMenuButton({
name: filterId.name,
status: 'saved',
};
res = await sendCatch('filter-update', {
await sendCatch('filter-update', {
state: savedFilter,
filters: [...filtersList],
});
if (res.error) {
setErr(res.error.message);
setNameOpen(true);
} else {
onReloadSavedFilter(savedFilter, 'update');
}
onReloadSavedFilter(savedFilter, 'update');
break;
case 'save-filter':
setErr(null);
Expand All @@ -73,6 +83,7 @@ export function SavedFilterMenuButton({
case 'reload-filter':
setMenuOpen(false);
savedFilter = {
...savedFilter,
status: 'saved',
};
onReloadSavedFilter(savedFilter, 'reload');
Expand All @@ -94,13 +105,13 @@ export function SavedFilterMenuButton({
name,
status: 'saved',
};
res = await sendCatch('filter-create', {
const res: string = await sendCatch('filter-create', {
state: savedFilter,
filters: [...filtersList],
});
savedFilter = {
...savedFilter,
id: res.data,
id: res,
};
} else {
//rename flow
Expand All @@ -110,17 +121,13 @@ export function SavedFilterMenuButton({
id: filterId.id,
name,
};
res = await sendCatch('filter-update', {
await sendCatch('filter-update', {
state: savedFilter,
filters: [...filtersList],
});
}
if (res.error) {
setErr(res.error.message);
} else {
setNameOpen(false);
onReloadSavedFilter(savedFilter);
}
setNameOpen(false);
onReloadSavedFilter(savedFilter);
}

return (
Expand Down

0 comments on commit 12dea5f

Please sign in to comment.