Skip to content

Commit

Permalink
Merge pull request #1304 from qdraw/feature/202312_code_smellse_9
Browse files Browse the repository at this point in the history
  • Loading branch information
qdraw authored Dec 10, 2023
2 parents 87f7bb0 + 20fb12f commit 0652813
Show file tree
Hide file tree
Showing 38 changed files with 203 additions and 81 deletions.
3 changes: 3 additions & 0 deletions starsky/build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
using Nuke.Common.CI;
using Nuke.Common.ProjectModel;

// ReSharper disable once CheckNamespace
namespace build;

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage",
"S3887:Use an immutable collection or reduce the " +
"accessibility of the non-private readonly field",
Expand Down
3 changes: 3 additions & 0 deletions starsky/build/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Diagnostics.CodeAnalysis;
using Nuke.Common.Tooling;

// ReSharper disable once CheckNamespace
namespace build;

[TypeConverter(typeof(TypeConverter<Configuration>))]
[SuppressMessage("Usage", "CA2211:Non-constant fields should not be visible")]
[SuppressMessage("Usage", "S1104:Make this field 'private' and encapsulate it in a 'public' property")]
Expand Down
2 changes: 1 addition & 1 deletion starsky/build/helpers/ClientHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.IO;
using static SimpleExec.Command;
using static Build;
using static build.Build;

namespace helpers
{
Expand Down
3 changes: 2 additions & 1 deletion starsky/build/helpers/DotnetGenericHelper.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System;
using System.IO;
using build;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tools.DotNet;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
using static Build;
using static build.Build;

namespace helpers
{
Expand Down
1 change: 1 addition & 0 deletions starsky/build/helpers/DotnetRuntimeSpecificHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using build;
using Nuke.Common.IO;
using Nuke.Common.ProjectModel;
using Nuke.Common.Tooling;
Expand Down
1 change: 1 addition & 0 deletions starsky/build/helpers/DotnetTestHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using build;
using Nuke.Common.IO;
using Nuke.Common.Tools.DotNet;
using static Nuke.Common.IO.FileSystemTasks;
Expand Down
2 changes: 1 addition & 1 deletion starsky/build/helpers/ProjectCheckNetCoreCommandHelper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using System.IO;
using static SimpleExec.Command;
using static Build;
using static build.Build;

namespace helpers
{
Expand Down
1 change: 1 addition & 0 deletions starsky/build/helpers/SonarQube.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Linq;
using System.Text;
using build;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using static Nuke.Common.Tools.DotNet.DotNetTasks;
Expand Down
1 change: 1 addition & 0 deletions starsky/build/helpers/ZipperHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.IO.Compression;
using System.Linq;
using build;

namespace helpers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class OnMouseDownMouseAction {
this.down(clientX, clientY);
};

public onMouseDown = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
public onMouseDown = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
e.preventDefault();
this.down(e.clientX, e.clientY);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ export class OnWheelMouseAction {
private image: ImageObject;
private setPosition: React.Dispatch<React.SetStateAction<PositionObject>>;
public position: PositionObject;
private containerRef: React.RefObject<HTMLDivElement>;
private containerRef: React.RefObject<HTMLButtonElement>;
private onWheelCallback: (z: number) => void;

constructor(
image: ImageObject,
setPosition: React.Dispatch<React.SetStateAction<PositionObject>>,
position: PositionObject,
containerRef: React.RefObject<HTMLDivElement>,
containerRef: React.RefObject<HTMLButtonElement>,
onWheelCallback: (z: number) => void
) {
this.image = image;
Expand All @@ -24,7 +24,7 @@ export class OnWheelMouseAction {
this.onWheel = this.onWheel.bind(this);
}

public onWheel(e: React.WheelEvent<HTMLDivElement>) {
public onWheel(e: React.WheelEvent<HTMLButtonElement>) {
if (!e.deltaY) return;
this.zoom(e.deltaY, e.clientX);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const PanAndZoomImage = ({ src, id, ...props }: IPanAndZoomImage) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [id]);

const containerRef = useRef<HTMLDivElement>(null);
const containerRef = useRef<HTMLButtonElement>(null);

// only needed to re-render when the component is mounted

Expand Down Expand Up @@ -128,7 +128,7 @@ const PanAndZoomImage = ({ src, id, ...props }: IPanAndZoomImage) => {

return (
<>
<div
<button
className={className}
data-test="pan-zoom-image"
ref={containerRef}
Expand Down Expand Up @@ -158,6 +158,7 @@ const PanAndZoomImage = ({ src, id, ...props }: IPanAndZoomImage) => {
transform: `translate(${position.x}px, ${position.y}px) scale(${position.z})`
}}
>
{/* NOSONAR(S6847) */}
<img
className={`pan-zoom-image--image image--default ${props.translateRotation}`}
alt="image"
Expand All @@ -179,7 +180,7 @@ const PanAndZoomImage = ({ src, id, ...props }: IPanAndZoomImage) => {
}}
/>
</div>
</div>
</button>
<div className="gpx-controls">
<div className="gpx-controls--button">
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const FormControl: React.FunctionComponent<IFormControlProps> = ({
<div className="warning-box">{MessageFieldMaxLength}</div>
) : null}

{/* NOSONAR(S6847) */}
<div
data-test={props["data-test"] ? props["data-test"] : "form-control"}
onBlur={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const ListImage: React.FunctionComponent<IListImageProps> = memo((props) => {
data-test="list-image-img-parent-div"
>
{intersected ? (
<img
<img /* NOSONAR(S6847) */
src={src}
alt={alt}
data-test="list-image-img"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Router } from "../../../router-app/router-app";
import * as FlatListItem from "../../atoms/flat-list-item/flat-list-item";
import * as ListImageChildItem from "../../atoms/list-image-child-item/list-image-child-item";
import ItemListView from "./item-list-view";
import * as ShiftSelectionHelper from "./shift-selection-helper";
import * as ShiftSelectionHelper from "./shared/shift-selection-helper";

describe("ItemListView", () => {
it("renders (without state component)", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { UrlQuery } from "../../../shared/url-query";
import FlatListItem from "../../atoms/flat-list-item/flat-list-item";
import ListImageChildItem from "../../atoms/list-image-child-item/list-image-child-item";
import ListImageViewSelectContainer from "../list-image-view-select-container/list-image-view-select-container";
import { ShiftSelectionHelper } from "./shift-selection-helper";
import { ShiftSelectionHelper } from "./shared/shift-selection-helper";
import { WarningBoxNoPhotosFilter } from "./shared/warning-box-no-photos-filter";

interface ItemListProps {
fileIndexItems: Array<IFileIndexItem>;
Expand All @@ -37,9 +38,6 @@ const ItemListView: React.FunctionComponent<ItemListProps> = memo((props) => {
const MessageNewUserNoPhotosInFolder = language.key(
localization.MessageNewUserNoPhotosInFolder
);
const MessageItemsOutsideFilter = language.key(
localization.MessageItemsOutsideFilter
);

useEffect(() => {
const navigationState = history.location.state as INavigateState;
Expand Down Expand Up @@ -77,22 +75,12 @@ const ItemListView: React.FunctionComponent<ItemListProps> = memo((props) => {

return (
<div className={props.iconList ? "folder" : "folder-flat"} ref={folderRef}>
{props.pageType !== PageType.Loading &&
props.subPath !== "/" &&
items.length === 0 ? (
props.colorClassUsage.length >= 1 ? (
<div className="warning-box warning-box--left">
{MessageItemsOutsideFilter}
</div>
) : (
<div
className="warning-box"
data-test="list-view-no-photos-in-folder"
>
{MessageNoPhotosInFolder}
</div>
)
) : null}
<WarningBoxNoPhotosFilter
pageType={props.pageType}
subPath={props.subPath}
items={items}
colorClassUsage={props.colorClassUsage}
/>

{props.pageType !== PageType.Loading &&
items.length === 0 &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
newIFileIndexItem,
newIFileIndexItemArray
} from "../../../interfaces/IFileIndexItem";
} from "../../../../interfaces/IFileIndexItem";
import { ShiftSelectionHelper } from "./shift-selection-helper";
describe("ShiftSelectionHelper", () => {
it("items undefined", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { IUseLocation } from "../../../hooks/use-location/interfaces/IUseLocation";
import { IFileIndexItem } from "../../../interfaces/IFileIndexItem";
import { URLPath } from "../../../shared/url-path";
import { IUseLocation } from "../../../../hooks/use-location/interfaces/IUseLocation";
import { IFileIndexItem } from "../../../../interfaces/IFileIndexItem";
import { URLPath } from "../../../../shared/url-path";

/**
* Find the value that is the closest
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { render } from "@testing-library/react";
import * as useGlobalSettingsModule from "../../../../hooks/use-global-settings";
import { PageType } from "../../../../interfaces/IDetailView";
import { SupportedLanguages } from "../../../../shared/language";
import { WarningBoxNoPhotosFilter } from "./warning-box-no-photos-filter";

describe("WarningBoxNoPhotosFilter", () => {
beforeEach(() => {
// Mock the useGlobalSettings hook
jest.spyOn(useGlobalSettingsModule, "default").mockReturnValue({
language: SupportedLanguages.en
});
});

afterEach(() => {
// Clear the mock after each test
jest.restoreAllMocks();
});

test("renders no warning box when pageType is Loading", () => {
const { container } = render(
<WarningBoxNoPhotosFilter
pageType={PageType.Loading}
subPath="/some-path"
items={[]}
colorClassUsage={[]}
/>
);

// Assert that no warning box is rendered
expect(container.firstChild).toBeNull();
});

// ... (other test cases)

test("renders warning box when colorClassUsage is not empty", () => {
const component = render(
<WarningBoxNoPhotosFilter
pageType={PageType.Archive}
subPath="/some-path"
items={[]}
colorClassUsage={[1, 2, 3]}
/>
);

// Assert that the warning box is rendered with the correct message
expect(
component.getByTestId("list-view-message-items-outside-filter")
).toBeTruthy();

component.unmount();
});

test("renders warning box when items are empty", () => {
const component = render(
<WarningBoxNoPhotosFilter
pageType={PageType.Archive}
subPath="/some-path"
items={[]}
colorClassUsage={[]}
/>
);

// Assert that the warning box is rendered with the correct message
expect(component.getByTestId("list-view-no-photos-in-folder")).toBeTruthy();

component.unmount();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { memo } from "react";
import useGlobalSettings from "../../../../hooks/use-global-settings";
import { PageType } from "../../../../interfaces/IDetailView";
import { IFileIndexItem } from "../../../../interfaces/IFileIndexItem";
import localization from "../../../../localization/localization.json";
import { Language } from "../../../../shared/language";

interface IWarningBoxNoPhotosFilterProps {
pageType: PageType | undefined;
subPath: string | undefined;
items: IFileIndexItem[];
colorClassUsage: number[];
}

export const WarningBoxNoPhotosFilter: React.FunctionComponent<IWarningBoxNoPhotosFilterProps> =
memo(({ pageType, subPath, items, colorClassUsage }) => {
const settings = useGlobalSettings();
const language = new Language(settings.language);

const MessageNoPhotosInFolder = language.key(
localization.MessageNoPhotosInFolder
);
const MessageItemsOutsideFilter = language.key(
localization.MessageItemsOutsideFilter
);

let warningBox = null;

if (
pageType !== PageType.Loading &&
subPath !== "/" &&
items.length === 0
) {
if (colorClassUsage.length >= 1) {
warningBox = (
<div
className="warning-box warning-box--left"
data-test="list-view-message-items-outside-filter"
>
{MessageItemsOutsideFilter}
</div>
);
} else {
warningBox = (
<div
className="warning-box"
data-test="list-view-no-photos-in-folder"
>
{MessageNoPhotosInFolder}
</div>
);
}
}

return <>{warningBox}</>;
});
4 changes: 4 additions & 0 deletions starsky/starsky/clientapp/src/localization/localization.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@
"en": "Rotation to the right",
"nl": "Rotatie naar rechts"
},
"MessageItemsOutsideFilter111": {
"en": "",
"nl": ""
},
"temp1": {
"en": "",
"nl": ""
Expand Down
1 change: 1 addition & 0 deletions starsky/starsky/clientapp/src/style/css/24-detailview.css
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
overflow: hidden;
height: 100%;
width: 100%;
background-color: transparent;
}

.pan-zoom-image-container.grab {
Expand Down
Loading

1 comment on commit 0652813

@github-actions
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.