-
Notifications
You must be signed in to change notification settings - Fork 78
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
LF-3761: Implement crop sales expandable content #2938
Merged
kathyavini
merged 15 commits into
integration
from
LF-3761/Implement_crop_sales_expandable_content
Nov 3, 2023
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bb89e38
LF-3761 remove unused properties in TableV2 stories
SayakaOno 8767b11
LF-3761 remove accessor prop that is incompatible with sorting from V…
SayakaOno cc861ff
LF-3761 fix expandable item hover style
SayakaOno 1a95734
LF-3761 add translations for transaction crop sale table
SayakaOno c04e6d3
LF-3761 create CropSaleTable component
SayakaOno 6ab7ca9
LF-3761 pass currencySymbol and mobileView to ExpandedContent
SayakaOno f0940fa
LF-3761 add CropSaleTable to ExpandedContent
SayakaOno 2379a18
LF-3761 fix Crop sale table footer padding
SayakaOno 49bbd1d
LF-3761 make Transaction row id unique
SayakaOno 70e73e6
LF-3761 update transactionDate tag to h4
SayakaOno 5e5c8f0
LF-3761 create quantityWithUnit variable in CropSaleTable
SayakaOno 27ce9b8
LF-3761 fix the way of getting componentKey for crop sale
SayakaOno 54c424e
LF-3761 adjust crop sale amount column width
SayakaOno 4e166e3
LF-3761 fix transaction amount format and width
SayakaOno b00bbb5
LF-3761 update buildTransactions test
SayakaOno 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
97 changes: 97 additions & 0 deletions
97
packages/webapp/src/components/Finances/Transaction/ExpandedContent/CropSaleTable.jsx
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright 2023 LiteFarm.org | ||
* This file is part of LiteFarm. | ||
* | ||
* LiteFarm is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* LiteFarm is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
import React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import Table from '../../../Table/v2'; | ||
import history from '../../../../history'; | ||
import styles from './styles.module.scss'; | ||
|
||
const getColumns = (t, mobileView, totalAmount, quantityTotal, currencySymbol) => [ | ||
{ | ||
id: 'title', | ||
label: t('FINANCES.TRANSACTION.CROPS'), | ||
format: (d) => | ||
mobileView ? ( | ||
<div className={styles.mobileCrops}> | ||
<div className={styles.mobileCropsTitle}>{d.title}</div> | ||
<div className={styles.mobileCropsQuantity}> | ||
{d.quantity} {d.quantityUnit} | ||
</div> | ||
</div> | ||
) : ( | ||
d.title | ||
), | ||
columnProps: { | ||
style: { padding: `0 ${mobileView ? 8 : 12}px` }, | ||
}, | ||
Footer: mobileView ? null : t('FINANCES.TRANSACTION.DAILY_TOTAL'), | ||
}, | ||
{ | ||
id: mobileView ? null : 'quantity', | ||
label: mobileView ? null : t('common:QUANTITY'), | ||
align: 'right', | ||
format: (d) => `${d.quantity} ${d.quantityUnit}`, | ||
columnProps: { | ||
style: { width: '100px' }, | ||
}, | ||
Footer: mobileView ? null : <div className={styles.bold}>{quantityTotal}</div>, | ||
}, | ||
{ | ||
id: 'amount', | ||
label: t('FINANCES.REVENUE'), | ||
align: 'right', | ||
format: (d) => `${currencySymbol}${Math.abs(d.amount).toFixed(2)}`, | ||
columnProps: { | ||
style: { width: '100px', paddingRight: `${mobileView ? 9 : 75}px` }, | ||
}, | ||
Footer: mobileView ? null : <div className={styles.bold}>{totalAmount}</div>, | ||
}, | ||
]; | ||
|
||
const FooterCell = ({ t, quantityTotal, totalAmount }) => ( | ||
<div className={styles.mobileCropSaleFooterCell}> | ||
<div>{t('FINANCES.TRANSACTION.DAILY_TOTAL')}</div> | ||
<div className={styles.bold}>{quantityTotal}</div> | ||
<div className={styles.bold}>{totalAmount}</div> | ||
</div> | ||
); | ||
|
||
export default function CropSaleTable({ data, currencySymbol, mobileView }) { | ||
const { t } = useTranslation(); | ||
const { items, amount, relatedId } = data; | ||
const quantityUnit = items?.[0]?.quantityUnit; | ||
const quantityTotal = items.reduce((total, { quantity }) => total + quantity, 0); | ||
const quantityWithUnit = `${quantityTotal} ${quantityUnit}`; | ||
const totalAmount = `${currencySymbol}${amount.toFixed(2)}`; | ||
|
||
if (!items?.length) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Table | ||
columns={getColumns(t, mobileView, totalAmount, quantityWithUnit, currencySymbol)} | ||
data={items} | ||
minRows={10} | ||
shouldFixTableLayout={true} | ||
FooterCell={ | ||
mobileView | ||
? () => <FooterCell t={t} totalAmount={totalAmount} quantityTotal={quantityWithUnit} /> | ||
: null | ||
} | ||
onClickMore={() => history.push(`/revenue/${relatedId}`)} | ||
/> | ||
); | ||
} |
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
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
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.
I kinda liked the hover effect on the expanded item because it showcases more clearly that the item can be clicked on to collapse, but not sure if Figma calls for anything specific in this situation
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.
I'll confirm with Loïc!
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.
Loïc's input:
It should not change colour on hover when the row is expanded, the reason is that it can be distracting when you process the info inside the expanded row.