Skip to content
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

Small SAST fixes #8534

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/frontend/src/components/forms/ApiForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export function ApiForm({
// If the user has specified initial data, that overrides default values
// But, *only* for the fields we have specified
if (props.initialData) {
Object.keys(props.initialData).map((key) => {
Object.keys(props.initialData).forEach((key) => {
if (key in defaultValuesMap) {
defaultValuesMap[key] =
props?.initialData?.[key] ?? defaultValuesMap[key];
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/components/forms/fields/DateField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function DateField({
let dv: Date | null = null;

if (field.value) {
dv = new Date(field.value) ?? null;
dv = new Date(field.value);
}

// Ensure that the date is valid
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/components/importer/ImporterDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export default function ImporterDrawer({
// Map from import steps to stepper steps
const currentStep = useMemo(() => {
switch (session.status) {
default:
case importSessionStatus.INITIAL:
return 0;
case importSessionStatus.MAPPING:
Expand All @@ -81,6 +80,8 @@ export default function ImporterDrawer({
return 3;
case importSessionStatus.COMPLETE:
return 4;
default:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 'default' case should return a value here still, otherwise you are changing functionality.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure? default is empty in the current code base

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scratch that

return 0;
}
}, [session.status]);

Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/components/plugins/PluginUIFeature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const getPluginTemplateEditor = (
useEffect(() => {
(async () => {
try {
await func({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the await needed here so that asynchronous errors are catched too? But not sure about it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't func be marked async for that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be asynchronous if

https://github.com/inventree/InvenTree/blob/master/src/frontend/src/components/plugins/PluginUIFeatureTypes.ts#L1is defined as a promise by the individual feature.

Copy link
Contributor

@wolflu05 wolflu05 Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you’re right, in this case it can’t be async, so its fine removing it. Good catch.

Or we could define it as void | Promise<void> instead of undefined in the Template editor feature, and use await Promise.resolve(func)… then.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH all of those were caught by SonarCloud and were marked as middle to high importance so I mainly fixed them to get the quality gate back to good-ish before the release

func({
ref: elRef.current!,
registerHandlers: ({ getCode, setCode }) => {
setCodeRef.current = setCode;
Expand Down Expand Up @@ -136,7 +136,7 @@ export const getPluginTemplatePreview = (
useEffect(() => {
(async () => {
try {
await func({
func({
ref: elRef.current!,
registerHandlers: ({ updatePreview }) => {
updatePreviewRef.current = updatePreview;
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/forms/StockForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export function useStockFields({
hidden:
create ||
partInstance.trackable == false ||
(!stockItem?.quantity != undefined && stockItem?.quantity != 1)
(stockItem?.quantity != undefined && stockItem?.quantity != 1)
},
batch: {
placeholder: nextBatchCode
Expand Down
8 changes: 3 additions & 5 deletions src/frontend/src/tables/part/ParametricPartTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,10 @@ export default function ParametricPartTable({
if (column?.accessor?.toString()?.startsWith('parameter_')) {
const col = column as any;
onParameterClick(col.extra.template, record);
} else {
} else if (record?.pk) {
// Navigate through to the part detail page
if (record?.pk) {
const url = getDetailUrl(ModelType.part, record.pk);
navigateToLink(url, navigate, event);
}
const url = getDetailUrl(ModelType.part, record.pk);
navigateToLink(url, navigate, event);
}
}
}}
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/tables/settings/TemplateTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ export function TemplateTable({
sortable: false,
switchable: true
},
...Object.entries(additionalFormFields || {})?.map(([key, field]) => ({
...Object.entries(additionalFormFields || {}).map(([key, field]) => ({
accessor: key,
...field,
title: field.label,
Expand Down
Loading