-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Custom Reports: add save reports menu #2257
Merged
Merged
Changes from 17 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
afa1c4b
Add schema work
carkom 27f9138
notes
carkom d362e92
Merge branch 'master' into createReportsSchema
carkom 41dcc69
merge fixes
carkom cf364e1
Add Reports Save Menu
carkom 71d3b05
Merge remote-tracking branch 'upstream/master' into addSaveReportsMenu
carkom 71b987d
merge fixes
carkom 4f60551
updates
carkom 89579f1
notes
carkom e961ef6
Merge branch 'master' into addSaveReportsMenu
carkom be8723b
updates
carkom 5fc710f
Merge branch 'master' into addSaveReportsMenu
carkom 1999b65
updates
carkom 6c395cb
save updates fix
carkom d49d3dd
typecheck fixes
carkom 2d5151b
Merge remote-tracking branch 'upstream/master' into addSaveReportsMenu
carkom da0f587
merge fixes
carkom c75d118
saveReport strict Typescript
carkom 217e5ba
fix sidebar
carkom aa9d11e
lint fix
carkom d469aa4
fixing functionality plus clean up
carkom ce4b670
clean up
carkom File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,134 @@ | ||
// @ts-strict-ignore | ||
import React, { useState } from 'react'; | ||
import React, { createRef, useState } from 'react'; | ||
|
||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
//import { send, sendCatch } from 'loot-core/src/platform/client/fetch'; | ||
import { type CustomReportEntity } from 'loot-core/src/types/models'; | ||
|
||
import { SvgExpandArrow } from '../../icons/v0'; | ||
import { Button } from '../common/Button'; | ||
import { Menu } from '../common/Menu'; | ||
import { MenuTooltip } from '../common/MenuTooltip'; | ||
import { Text } from '../common/Text'; | ||
import { View } from '../common/View'; | ||
|
||
function SaveReportMenu({ setMenuOpen }) { | ||
return ( | ||
<MenuTooltip width={150} onClose={() => setMenuOpen(false)}> | ||
<Menu | ||
onMenuSelect={item => { | ||
switch (item) { | ||
case 'save': | ||
case 'clear': | ||
setMenuOpen(false); | ||
break; | ||
default: | ||
} | ||
}} | ||
items={[ | ||
{ | ||
name: 'save', | ||
text: 'Save new report', | ||
disabled: true, | ||
}, | ||
{ | ||
name: 'clear', | ||
text: 'Clear all', | ||
disabled: true, | ||
}, | ||
]} | ||
/> | ||
</MenuTooltip> | ||
); | ||
} | ||
import { SaveReportMenu } from './SaveReportMenu'; | ||
import { SaveReportName } from './SaveReportName'; | ||
|
||
type SaveReportProps<T extends CustomReportEntity = CustomReportEntity> = { | ||
customReportItems: T; | ||
report: CustomReportEntity; | ||
savedStatus: string; | ||
onReportChange: (savedReport: T, type: string) => void; | ||
onResetReports: () => void; | ||
}; | ||
|
||
export function SaveReportMenuButton({ savedStatus }: { savedStatus: string }) { | ||
export function SaveReport({ | ||
customReportItems, | ||
report, | ||
savedStatus, | ||
onReportChange, | ||
onResetReports, | ||
}: SaveReportProps) { | ||
const [nameMenuOpen, setNameMenuOpen] = useState(false); | ||
const [menuOpen, setMenuOpen] = useState(false); | ||
const [menuItem, setMenuItem] = useState(null); | ||
const [err, setErr] = useState(null); | ||
const [name, setName] = useState(report.name); | ||
const inputRef = createRef<HTMLInputElement>(); | ||
|
||
const onAddUpdate = async () => { | ||
let savedReport: CustomReportEntity; | ||
let res; | ||
//save existing states | ||
savedReport = { | ||
...report, | ||
...customReportItems, | ||
}; | ||
|
||
if (menuItem === 'save-report') { | ||
//create new flow | ||
/* | ||
res = await sendCatch('report/create', { | ||
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. Next PR will use this to save the report props to the db table |
||
...savedReport, | ||
}); | ||
*/ | ||
savedReport = { | ||
...savedReport, | ||
id: uuidv4(), | ||
name, | ||
}; | ||
} | ||
|
||
if (menuItem === 'rename-report') { | ||
//rename | ||
savedReport = { | ||
...report, | ||
name, | ||
}; | ||
} | ||
|
||
if (menuItem === 'update-report') { | ||
savedReport = { | ||
...savedReport, | ||
name: report.name, | ||
}; | ||
//send update and rename to DB | ||
/* | ||
res = await sendCatch('report/update', { | ||
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. Next PR will use this to update the report props to the db table |
||
...savedReport, | ||
}); | ||
*/ | ||
} | ||
if (res) { | ||
setErr(res.error.message); | ||
setNameMenuOpen(true); | ||
} else { | ||
setNameMenuOpen(false); | ||
onReportChange( | ||
savedReport, | ||
menuItem === 'rename-report' ? 'rename' : 'add-update', | ||
); | ||
} | ||
}; | ||
|
||
const onNameChange = cond => { | ||
setName(cond); | ||
}; | ||
|
||
const onMenuSelect = async item => { | ||
setMenuItem(item); | ||
switch (item) { | ||
case 'rename-report': | ||
setErr(null); | ||
setMenuOpen(false); | ||
setNameMenuOpen(true); | ||
break; | ||
case 'delete-report': | ||
setMenuOpen(false); | ||
//await send('report/delete', id); | ||
onResetReports(); | ||
break; | ||
case 'update-report': | ||
setErr(null); | ||
setMenuOpen(false); | ||
onAddUpdate(); | ||
break; | ||
case 'save-report': | ||
setErr(null); | ||
setMenuOpen(false); | ||
setNameMenuOpen(true); | ||
break; | ||
case 'reload-report': | ||
setMenuOpen(false); | ||
onReportChange(null, 'reload'); | ||
break; | ||
case 'reset-report': | ||
setMenuOpen(false); | ||
onResetReports(); | ||
break; | ||
default: | ||
} | ||
}; | ||
|
||
return ( | ||
<View | ||
|
@@ -63,12 +152,29 @@ export function SaveReportMenuButton({ savedStatus }: { savedStatus: string }) { | |
flexShrink: 0, | ||
}} | ||
> | ||
Unsaved Report | ||
{!report.id ? 'Unsaved report' : report.name} | ||
</Text> | ||
{savedStatus === 'modified' && <Text>(modified) </Text>} | ||
<SvgExpandArrow width={8} height={8} style={{ marginRight: 5 }} /> | ||
</Button> | ||
{menuOpen && <SaveReportMenu setMenuOpen={setMenuOpen} />} | ||
{menuOpen && ( | ||
<SaveReportMenu | ||
onClose={() => setMenuOpen(false)} | ||
report={report} | ||
onMenuSelect={onMenuSelect} | ||
savedStatus={savedStatus} | ||
/> | ||
)} | ||
{nameMenuOpen && ( | ||
<SaveReportName | ||
onClose={() => setNameMenuOpen(false)} | ||
menuItem={menuItem} | ||
onNameChange={onNameChange} | ||
inputRef={inputRef} | ||
onAddUpdate={onAddUpdate} | ||
err={err} | ||
/> | ||
)} | ||
</View> | ||
); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Saved for next PR where db table is created and save menu is functional