Skip to content

Commit

Permalink
fix: sonar issues (#1346)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-Orlov authored Oct 11, 2024
1 parent f38316a commit 88cf26a
Show file tree
Hide file tree
Showing 29 changed files with 98 additions and 70 deletions.
2 changes: 1 addition & 1 deletion client-app/core/composables/useThemeContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function _useThemeContext() {
const { data } = await useFetch("/config/settings_data.json").get().json<IThemeConfig>();

if (IS_DEVELOPMENT && data.value) {
data.value.settings.show_details_in_separate_tab = false;
data.value.settings.details_browser_target = "_self";
}

return data.value;
Expand Down
1 change: 1 addition & 0 deletions client-app/core/types/browser-window-target.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type BrowserTargetType = "_blank" | "_self";
1 change: 1 addition & 0 deletions client-app/core/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./addresses";
export * from "./browser-window-target";
export * from "./category-tree";
export * from "./change-wishlist-payload";
export * from "./connect-token-response";
Expand Down
3 changes: 2 additions & 1 deletion client-app/core/types/theme-config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { BrowserTargetType } from "./browser-window-target";
import type { ISocialSharingService } from "./social-sharing";
import type { SortDirection } from "@/core/enums";

Expand Down Expand Up @@ -153,7 +154,7 @@ export interface IThemeConfigPreset {
}

export interface IThemeConfigSettings {
show_details_in_separate_tab?: boolean;
details_browser_target?: BrowserTargetType;

search_by_static_content_enabled?: boolean;

Expand Down
13 changes: 0 additions & 13 deletions client-app/core/utilities/common/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
getReturnUrlValue,
extractHostname,
truncate,
getLinkTarget,
appendSuffixToFilename,
stringFormat,
asyncForEach,
Expand Down Expand Up @@ -165,18 +164,6 @@ describe("truncate", () => {
});
});

describe("getLinkTarget", () => {
it('should return "_blank" when openInNewTab is true', () => {
const result = getLinkTarget(true);
expect(result).toBe("_blank");
});

it('should return "_self" when openInNewTab is false', () => {
const result = getLinkTarget(false);
expect(result).toBe("_self");
});
});

describe("appendSuffixToFilename", () => {
it("should append suffix to filename before extension", () => {
const filename = "document.pdf";
Expand Down
4 changes: 0 additions & 4 deletions client-app/core/utilities/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ export function truncate(str: string, length: number): string {
return str.length > length ? `${str.slice(0, length)}...` : str;
}

export function getLinkTarget(openInNewTab: boolean): "_blank" | "_self" {
return openInNewTab ? "_blank" : "_self";
}

export function appendSuffixToFilename(filename: string, suffix: string, checkIfSuffixExists = false) {
if (!filename) {
return filename;
Expand Down
1 change: 1 addition & 0 deletions client-app/modules/quotes/components/quote-line-items.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:items="normalizedItems"
:removable="!readonly"
:readonly="readonly"
:browser-target="$cfg.details_browser_target"
with-image
with-properties
with-price
Expand Down
2 changes: 1 addition & 1 deletion client-app/modules/quotes/pages/quotes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ function goToQuoteDetails(payload: { id: string; status?: string }): void {
const pathName: string = payload.status === "Draft" ? "EditQuote" : "ViewQuote";
const quoteRoute = router.resolve({ name: pathName, params: { quoteId: payload.id } });

if (themeContext.value.settings?.show_details_in_separate_tab) {
if (themeContext.value.settings?.details_browser_target === "_blank") {
window.open(quoteRoute.fullPath, "_blank")!.focus();
} else {
window.location.href = quoteRoute.fullPath;
Expand Down
8 changes: 7 additions & 1 deletion client-app/pages/product.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
:hide-controls="false"
@hide-popup-sidebar="hideFiltersSidebar"
@reset-facet-filters="resetFacetFilters"
@open-branches-modal="openBranchesModal"
@open-branches-modal="showBranchesModal"
@update-popup-sidebar-filters="updateFiltersSidebar"
@apply-filters="applyFilters"
/>
Expand Down Expand Up @@ -170,6 +170,7 @@ const Error404 = defineAsyncComponent(() => import("@/pages/404.vue"));
const { t } = useI18n();
const { product, fetching: fetchingProduct, fetchProduct } = useProduct();
const {
branchesFromSidebarFilters,
fetchingProducts: fetchingVariations,
products: variations,
pagesCount: variationsPagesCount,
Expand Down Expand Up @@ -331,6 +332,11 @@ async function resetFacetFilters(): Promise<void> {
await fetchProducts(variationsSearchParams.value);
}
function showBranchesModal(fromFiltersSidebar: boolean): void {
branchesFromSidebarFilters.value = fromFiltersSidebar;
openBranchesModal();
}
async function changeSortProductReviews(sort: string): Promise<void> {
productReviewsPayload.value.page = 1;
productReviewsPayload.value.sort = sort;
Expand Down
2 changes: 1 addition & 1 deletion client-app/public/config/settings_data.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"current": "default",
"settings": {
"show_details_in_separate_tab": true,
"details_browser_target": "_blank",

"files_enabled": true,

Expand Down
10 changes: 9 additions & 1 deletion client-app/shared/account/components/order-line-items.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<template>
<VcLineItems :items="preparedLineItems" with-image with-properties with-price with-total with-subtotal>
<VcLineItems
:items="preparedLineItems"
:browser-target="$cfg.details_browser_target"
with-image
with-properties
with-price
with-total
with-subtotal
>
<template #titles>
<div class="text-center">
{{ $t("common.labels.quantity") }}
Expand Down
2 changes: 1 addition & 1 deletion client-app/shared/account/components/orders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ function handleOrdersFilterChange(dateFilterType: DateFilterType): void {
function goToOrderDetails(order: CustomerOrderType): void {
const orderRoute = router.resolve({ name: "OrderDetails", params: { orderId: order.id } });

if (themeContext.value.settings.show_details_in_separate_tab) {
if (themeContext.value.settings.details_browser_target === "_blank") {
window.open(orderRoute.fullPath, "_blank")!.focus();
} else {
window.location.href = orderRoute.fullPath;
Expand Down
1 change: 1 addition & 0 deletions client-app/shared/cart/components/cart-line-items.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
:shared-selected-item-ids="sharedSelectedItemIds"
:disabled="disabled"
:readonly="readonly"
:browser-target="$cfg.details_browser_target"
with-image
with-properties
with-price
Expand Down
5 changes: 3 additions & 2 deletions client-app/shared/cart/components/gifts-section.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
<VcLineItem
v-for="gift in gifts"
:key="gift.id"
with-image
selectable
:name="gift.name"
:image-url="gift.imageUrl"
:disabled="disabled"
:selected="gift.isAddedInCart"
:browser-target="$cfg.details_browser_target"
with-image
selectable
@select="$emit('toggle:gift', gift)"
>
<VcAddToCart v-model="gift.quantity" disabled hide-button />
Expand Down
8 changes: 7 additions & 1 deletion client-app/shared/catalog/components/category.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
:hide-controls="hideControls"
@hide-popup-sidebar="hideFiltersSidebar"
@reset-facet-filters="resetFacetFilters"
@open-branches-modal="openBranchesModal"
@open-branches-modal="showBranchesModal"
@update-popup-sidebar-filters="updateFiltersSidebar"
@apply-filters="applyFilters"
/>
Expand Down Expand Up @@ -295,6 +295,7 @@ const isMobile = breakpoints.smaller("lg");

const { themeContext } = useThemeContext();
const {
branchesFromSidebarFilters,
getFacets,
facetsQueryParam,
fetchingMoreProducts,
Expand Down Expand Up @@ -440,6 +441,11 @@ function selectProduct(product: Product): void {
ga.selectItem(product);
}
function showBranchesModal(fromFiltersSidebar: boolean): void {
branchesFromSidebarFilters.value = fromFiltersSidebar;
openBranchesModal();
}
whenever(() => !isMobile.value, hideFiltersSidebar);
watch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:view-mode="savedViewMode"
:items-per-page="itemsPerPage"
:products="products"
:open-product-in-new-tab="$cfg.show_details_in_separate_tab"
:browser-target="$cfg.details_browser_target"
:card-type="cardType"
:columns-amount-desktop="columnsAmountDesktop"
:columns-amount-tablet="columnsAmountTablet"
Expand Down
5 changes: 3 additions & 2 deletions client-app/shared/catalog/components/display-products.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
:key="item.id + index"
:product="item"
:lazy="index >= lazyCardsCount"
:open-in-new-tab="openProductInNewTab"
:browser-target="browserTarget"
:hide-properties="cardType === 'short'"
:product-reviews-enabled="productReviewsEnabled"
@link-click="$emit('itemLinkClick', item, $event)"
Expand All @@ -39,6 +39,7 @@ import ProductCardList from "./product-card-list.vue";
import ProductSkeletonGrid from "./product-skeleton-grid.vue";
import ProductSkeletonList from "./product-skeleton-list.vue";
import type { Product } from "@/core/api/graphql/types";
import type { BrowserTargetType } from "@/core/types";
interface IEmits {
(eventName: "itemLinkClick", product: Product, globalEvent: MouseEvent): void;
Expand All @@ -49,7 +50,7 @@ interface IProps {
products?: Product[];
itemsPerPage?: number;
viewMode?: string;
openProductInNewTab?: boolean;
browserTarget?: BrowserTargetType;
cardType?: "full" | "short";
columnsAmountTablet?: string;
columnsAmountDesktop?: string;
Expand Down
9 changes: 2 additions & 7 deletions client-app/shared/catalog/components/product-card-compare.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class="h-[3.125rem] text-sm"
:to="link"
:title="product.name"
:target="target"
:target="$cfg.details_browser_target"
@click="$emit('linkClick', $event)"
>
{{ product.name }}
Expand All @@ -32,7 +32,7 @@
v-if="product.hasVariations"
class="mb-4"
:to="link"
:target="target"
:target="$cfg.details_browser_target"
variant="outline"
size="sm"
full-width
Expand All @@ -59,7 +59,6 @@
<script setup lang="ts">
import { computed } from "vue";
import { useThemeContext } from "@/core/composables";
import { ProductType } from "@/core/enums";
import { getProductRoute } from "@/core/utilities";
import { AddToCart } from "@/shared/cart";
Expand All @@ -81,13 +80,9 @@ defineEmits<IEmits>();
const props = defineProps<IProps>();
const { themeContext } = useThemeContext();
const price = computed(() => (props.product.hasVariations ? props.product.minVariationPrice : props.product.price));
const link = computed<RouteLocationRaw>(() => getProductRoute(props.product.id, props.product.slug));
const isDigital = computed(() => props.product.productType === ProductType.Digital);
const target = computed(() => (themeContext.value?.settings?.show_details_in_separate_tab ? "_blank" : "_self"));
</script>
10 changes: 5 additions & 5 deletions client-app/shared/catalog/components/product-card-grid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<template #trigger>
<router-link
:to="link"
:target="target"
:target="browserTarget"
class="my-px line-clamp-2 h-11 cursor-pointer text-lg font-black text-[--link-color] hover:text-[--link-hover-color] lg:h-9 lg:text-sm"
@click="$emit('linkClick', $event)"
>
Expand Down Expand Up @@ -167,7 +167,7 @@
<VcVariationsButton
v-if="product.hasVariations"
:link="link"
:target="target"
:target="browserTarget"
:variations-count="(product.variations?.length || 0) + 1"
show-link
@link-click="$emit('linkClick', $event)"
Expand Down Expand Up @@ -196,14 +196,15 @@ import { Swiper, SwiperSlide } from "swiper/vue";
import { computed, ref } from "vue";
import { PropertyType } from "@/core/api/graphql/types";
import { ProductType } from "@/core/enums";
import { getLinkTarget, getProductRoute, getPropertiesGroupedByName } from "@/core/utilities";
import { getProductRoute, getPropertiesGroupedByName } from "@/core/utilities";
import { AddToCompareCatalog } from "@/shared/compare";
import { AddToList } from "@/shared/wishlists";
import CountInCart from "./count-in-cart.vue";
import DiscountBadge from "./discount-badge.vue";
import InStock from "./in-stock.vue";
import Vendor from "./vendor.vue";
import type { Product } from "@/core/api/graphql/types";
import type { BrowserTargetType } from "@/core/types";
import type { Swiper as SwiperInstance } from "swiper/types";
import ProductRating from "@/modules/customer-reviews/components/product-rating.vue";
Expand All @@ -216,7 +217,7 @@ const props = withDefaults(defineProps<IProps>(), {
interface IProps {
product: Product;
lazy?: boolean;
openInNewTab?: boolean;
browserTarget?: BrowserTargetType;
hideProperties?: boolean;
productReviewsEnabled?: boolean;
}
Expand All @@ -225,7 +226,6 @@ const swiperInstance = ref<SwiperInstance>();
const swiperBulletsState = ref<boolean[]>([true, false, false]);
const link = computed(() => getProductRoute(props.product.id, props.product.slug));
const target = computed(() => getLinkTarget(props.openInNewTab));
const isDigital = computed(() => props.product.productType === ProductType.Digital);
const properties = computed(() =>
Object.values(getPropertiesGroupedByName(props.product.properties ?? [], PropertyType.Product)).slice(0, 3),
Expand Down
12 changes: 6 additions & 6 deletions client-app/shared/catalog/components/product-card-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<template #trigger>
<router-link
:to="link"
:target="target"
:target="browserTarget"
class="vc-product-card-list__name w-full grow text-sm font-black text-[--link-color] hover:text-[--link-hover-color] sm:line-clamp-3 sm:overflow-hidden lg:mt-1 2xl:pr-2"
@click="$emit('linkClick', $event)"
>
Expand Down Expand Up @@ -96,7 +96,7 @@
<template v-if="product.hasVariations">
<VcButton
:to="link"
:target="target"
:target="browserTarget"
variant="outline"
size="sm"
full-width
Expand All @@ -107,7 +107,7 @@

<router-link
:to="link"
:target="target"
:target="browserTarget"
class="flex items-center gap-1 text-sm text-[--link-color] hover:text-[--link-hover-color] lg:mt-1 lg:text-xs"
>
<svg class="size-3 shrink-0 text-primary lg:size-2.5">
Expand Down Expand Up @@ -140,14 +140,15 @@
import { computed } from "vue";
import { PropertyType } from "@/core/api/graphql/types";
import { ProductType } from "@/core/enums";
import { getLinkTarget, getProductRoute, getPropertiesGroupedByName } from "@/core/utilities";
import { getProductRoute, getPropertiesGroupedByName } from "@/core/utilities";
import { AddToCompareCatalog } from "@/shared/compare";
import { AddToList } from "@/shared/wishlists";
import CountInCart from "./count-in-cart.vue";
import DiscountBadge from "./discount-badge.vue";
import InStock from "./in-stock.vue";
import Vendor from "./vendor.vue";
import type { Product } from "@/core/api/graphql/types";
import type { BrowserTargetType } from "@/core/types";
import ProductRating from "@/modules/customer-reviews/components/product-rating.vue";

defineEmits<{ (eventName: "linkClick", globalEvent: MouseEvent): void }>();
Expand All @@ -159,12 +160,11 @@ const props = withDefaults(defineProps<IProps>(), {
interface IProps {
product: Product;
lazy?: boolean;
openInNewTab?: boolean;
browserTarget?: BrowserTargetType;
productReviewsEnabled?: boolean;
}

const link = computed(() => getProductRoute(props.product.id, props.product.slug));
const target = computed(() => getLinkTarget(props.openInNewTab));
const isDigital = computed(() => props.product.productType === ProductType.Digital);
const properties = computed(() =>
Object.values(getPropertiesGroupedByName(props.product.properties ?? [], PropertyType.Product)).slice(0, 3),
Expand Down
Loading

0 comments on commit 88cf26a

Please sign in to comment.