-
Notifications
You must be signed in to change notification settings - Fork 4
Feature/add table extra rows #235
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /** | ||
| * Copyright 2026 OpenStack Foundation | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * */ | ||
|
|
||
| import React from "react"; | ||
| import T from "i18n-react/dist/i18n-react"; | ||
| import TableRow from "@mui/material/TableRow"; | ||
| import TableCell from "@mui/material/TableCell"; | ||
| import Typography from "@mui/material/Typography"; | ||
| import { currencyAmountFromCents } from "../../../../utils/money"; | ||
|
|
||
|
|
||
| const DiscountRow = ({ discount, discountTotal, colGap = 2, trailing = 0 }) => { | ||
|
|
||
| if (discountTotal === 0) return null; | ||
|
|
||
| return ( | ||
| <TableRow sx={{backgroundColor: "#2E7D3214"}}> | ||
| <TableCell>{T.translate("mui_table.dis")}</TableCell> | ||
| <TableCell> | ||
| <Typography | ||
| variant="body2" | ||
| sx={{ color: "success.main", fontWeight: 500 }} | ||
| > | ||
| {T.translate("mui_table.discount")} | ||
| </Typography> | ||
| </TableCell> | ||
| {[...Array(colGap)].map((_, i) => ( | ||
| // eslint-disable-next-line react/no-array-index-key | ||
| <TableCell key={`pay-col-gap-${i}`} /> | ||
| ))} | ||
| <TableCell> | ||
| <Typography variant="body2" sx={{ color: "text.secondary" }}> | ||
| {discount} | ||
| </Typography> | ||
| </TableCell> | ||
| <TableCell> | ||
| <Typography | ||
| variant="body2" | ||
| sx={{ color: "success.main", fontWeight: 500 }} | ||
| > | ||
| -{currencyAmountFromCents(discountTotal)} | ||
| </Typography> | ||
| </TableCell> | ||
| {[...Array(trailing)].map((_, i) => ( | ||
| // eslint-disable-next-line react/no-array-index-key | ||
| <TableCell key={`pay-trailing-col-${i}`} sx={{ width: 40 }} /> | ||
| ))} | ||
| </TableRow> | ||
| ); | ||
| }; | ||
|
|
||
| export default DiscountRow; | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,15 +15,22 @@ import TableCell from "@mui/material/TableCell"; | |||||||
| import TableRow from "@mui/material/TableRow"; | ||||||||
| import * as React from "react"; | ||||||||
| import { Typography } from "@mui/material"; | ||||||||
| import T from "i18n-react"; | ||||||||
|
|
||||||||
| const NotesRow = ({ colCount, note }) => ( | ||||||||
| const NotesRow = ({ colCount, note, showCode = false }) => { | ||||||||
| const colSpan = showCode ? colCount - 1 : colCount; | ||||||||
|
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. Clamp At Line 21, Proposed fix- const colSpan = showCode ? colCount - 1 : colCount;
+ const computedColSpan = showCode ? colCount - 1 : colCount;
+ const colSpan = Math.max(1, Number(computedColSpan) || 1);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| return ( | ||||||||
| <TableRow> | ||||||||
| <TableCell sx={{ fontWeight: 800 }} colSpan={colCount}> | ||||||||
| <Typography variant="body2" sx={{ color: "text.secondary" }}> | ||||||||
| {showCode && ( | ||||||||
| <TableCell>{T.translate("mui_table.note")}</TableCell> | ||||||||
| )} | ||||||||
| <TableCell sx={{fontWeight: 800}} colSpan={colSpan}> | ||||||||
| <Typography variant="body2" sx={{color: "text.secondary"}}> | ||||||||
| {note} | ||||||||
| </Typography> | ||||||||
| </TableCell> | ||||||||
| </TableRow> | ||||||||
| ); | ||||||||
| } | ||||||||
|
|
||||||||
| export default NotesRow; | ||||||||
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.
Guard
discountTotalbefore formatting to prevent invalid output.At Line 24, only
=== 0is checked. IfdiscountTotalisundefined/null/non-numeric, Line 51 can render an invalid amount. Normalize and validate first.Proposed fix
Also applies to: 51-51
🤖 Prompt for AI Agents