Skip to content

Commit

Permalink
Update the usage of the type utils (#735)
Browse files Browse the repository at this point in the history
* updated the using of the type utils

* reverted changes

* added the comment for isEmptyValue function

* reverted changes

* Automatic frontend build

---------

Co-authored-by: ValeriaMaltseva <[email protected]>
  • Loading branch information
ValeriaMaltseva and ValeriaMaltseva authored Nov 25, 2024
1 parent 1a6b2b9 commit b69ac1b
Show file tree
Hide file tree
Showing 33 changed files with 2,335 additions and 42 deletions.
12 changes: 6 additions & 6 deletions assets/js/src/core/components/flex/flex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import React from 'react'
import { Flex as AntFlex, type FlexProps as AntFlexProps, theme } from 'antd'
import cn from 'classnames'
import { isString, isNumber, isObject } from 'lodash'
import { mapGapToTokenValue } from '@Pimcore/components/flex/utils/mapGapToTokenValue'
import { isString, isNumber, isObject } from '@Pimcore/utils/type-utils'
import { useStyles } from '@Pimcore/components/flex/flex.styles'
import { type GapRowColGroupType, type GapType } from '@Pimcore/types/components/types'
import { type GapType } from '@Pimcore/types/components/types'

export interface FlexProps extends Omit<AntFlexProps, 'gap'> {
gap?: GapType
Expand All @@ -43,17 +43,17 @@ export const Flex = ({ gap = 0, className, rootClassName, children, ...props }:
*/
function calculateGap (gap: GapType): { x: number, y: number } {
const getGapValue = (gap: GapType): number => {
return isNumber(gap) ? gap as number : mapGapToTokenValue({ token, gap })
return isNumber(gap) ? gap : mapGapToTokenValue({ token, gap })
}

if (isString(gap)) return { x: getGapValue(gap), y: getGapValue(gap) }

if (isNumber(gap)) return { x: gap as number, y: gap as number }
if (isNumber(gap)) return { x: gap, y: gap }

if (isObject(gap)) {
return {
x: getGapValue((gap as GapRowColGroupType).x),
y: getGapValue((gap as GapRowColGroupType).y)
x: getGapValue((gap).x),
y: getGapValue((gap).y)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
import React, { useState } from 'react'
import type { FetchBaseQueryError } from '@reduxjs/toolkit/query'
import { Tooltip } from 'antd'
import { isObject } from 'lodash'
import TextArea from 'antd/es/input/TextArea'
import { Flex } from '@Pimcore/components/flex/flex'
import { Text } from '@Pimcore/components/text/text'
import { Alert } from '@Pimcore/components/alert/alert'
import { isObject } from '@Pimcore/utils/type-utils'
import { useStyles } from './pql-query-input.styles'
import { Icon } from '../icon/icon'

Expand All @@ -40,7 +40,7 @@ export const PQLQueryInput = ({ value, handleChange, handleBlur, errorData, isSh
const getDescription = (): string => {
const error = errorData?.data

if (error !== null && isObject(error) && 'message' in (error as object)) {
if (error !== null && isObject(error) && 'message' in error) {
return (error as { message: string }).message
}

Expand Down
8 changes: 4 additions & 4 deletions assets/js/src/core/components/select/select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import React, { forwardRef, useRef, useImperativeHandle, useState } from 'react'
import type { RefSelectProps } from 'antd/es/select'
import { Checkbox, Select as AntdSelect, type SelectProps as AntdSelectProps } from 'antd'
import cn from 'classnames'
import { isString, isEmpty } from 'lodash'
import { Icon } from '@Pimcore/components/icon/icon'
import { isEmptyValue, isString } from '@Pimcore/utils/type-utils'
import { useStyles } from './select.styles'

interface SelectProps extends AntdSelectProps {
Expand All @@ -35,7 +35,7 @@ export const Select = forwardRef<RefSelectProps, SelectProps>(({ customIcon, cus

const { styles } = useStyles({ width })

const withCustomIcon = !isEmptyValue(customIcon)
const withCustomIcon = !isEmpty(customIcon)
const isStatusWarning = status === 'warning'
const isStatusError = status === 'error'

Expand All @@ -55,8 +55,8 @@ export const Select = forwardRef<RefSelectProps, SelectProps>(({ customIcon, cus
const handleClick = (): void => { setIsActive(!isActive) }

const getSuffixIcon = (): React.JSX.Element => {
const isShowCustomIcon = !isEmptyValue(customArrowIcon) && isString(customArrowIcon)
const iconToShow = isShowCustomIcon ? customArrowIcon! : (isActive ? 'chevron-up' : 'chevron-down')
const isShowCustomIcon = !isEmpty(customArrowIcon) && isString(customArrowIcon)
const iconToShow = isShowCustomIcon ? customArrowIcon : (isActive ? 'chevron-up' : 'chevron-down')

return (
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

import React from 'react'
import { isEmpty } from 'lodash'
import { useListGridAvailableColumns, getFormattedDropDownMenu } from '../../../hooks/use-list'
import { useDynamicTypeResolver } from '@Pimcore/modules/element/dynamic-types/resolver/hooks/use-dynamic-type-resolver'
import { Space } from 'antd'
Expand All @@ -21,7 +22,6 @@ import { type GridColumnConfiguration } from 'src/sdk/main'
import { FieldFiltersListContainer } from './field-filters-list-container'
import { useFilters } from '../hooks/use-filters'
import { Dropdown } from '@Pimcore/components/dropdown/dropdown'
import { isEmptyValue } from '@Pimcore/utils/type-utils'

const FILTER_FIELD_KEY_IGNORE_LIST = ['size']

Expand Down Expand Up @@ -60,7 +60,7 @@ export const FieldFiltersContainer = (): React.JSX.Element => {
>
<FieldFiltersListContainer columns={ columns } />

{!isEmptyValue(filteredDropDownMenu) && (
{!isEmpty(filteredDropDownMenu) && (
<Dropdown menu={ { items: getFormattedDropDownMenu(filteredDropDownMenu, handleColumnClick) } }>
<IconTextButton
icon={ { value: 'PlusCircleOutlined' } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { Content } from '@Pimcore/components/content/content'
import {
DEFAULT_IS_INCLUDE_DESCENDANTS_VALUE
} from '@Pimcore/modules/asset/editor/types/folder/tab-manager/tabs/list/constants/filters'
import { isEmptyValue } from '@Pimcore/utils/type-utils'
import { isEmpty } from 'lodash'

export const FilterContainerInner = (): React.JSX.Element => {
const [isAdvancedMode, setIsAdvancedMode] = useState<boolean>(false)
Expand All @@ -54,7 +54,7 @@ export const FilterContainerInner = (): React.JSX.Element => {
const { searchValue, setSearchValue, handleChangeSearchValue, handleSaveSearchValue } = useSearchFilter()

useEffect(() => {
if (!isEmptyValue(filterError)) {
if (!isEmpty(filterError)) {
setIsShowPQLQueryError(true)
}
}, [filterError])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { Dropdown, type DropdownMenuProps } from '@Pimcore/components/dropdown/d
import React from 'react'
import { useTranslation } from 'react-i18next'
import { Tooltip } from 'antd'
import { isEmpty } from 'lodash'
import { IconTextButton } from '@Pimcore/components/icon-text-button/icon-text-button'
import { GridConfigList } from '../grid-config-list'
import { isEmptyValue } from '@Pimcore/utils/type-utils'

export interface EditViewProps {
onCancelClick: () => void
Expand Down Expand Up @@ -91,7 +91,7 @@ export const EditView = ({ onCancelClick, onApplyClick, onSaveConfigurationClick
>
<GridConfigList columns={ columns } />

{!isEmptyValue(addColumnMenu) && (
{!isEmpty(addColumnMenu) && (
<Dropdown menu={ { items: addColumnMenu } }>
<IconTextButton
icon={ { value: 'PlusCircleOutlined' } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
*/

import React from 'react'
import { isEmpty } from 'lodash'
import { AccordionView } from './accordion-view'
import { CardView } from './card-view'
import { isEmptyValue } from '@Pimcore/utils/type-utils'

export interface BaseViewProps {
title?: string
Expand All @@ -25,7 +25,7 @@ export interface BaseViewProps {
}

export const BaseView = (props: BaseViewProps): React.JSX.Element => {
const isPaddedLayout = props.border === true || props.collapsible === true || !isEmptyValue(props.title)
const isPaddedLayout = props.border === true || props.collapsible === true || !isEmpty(props.title)

if (!isPaddedLayout) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/

import { Card } from '@Pimcore/components/card/card'
import { isEmptyValue } from '@Pimcore/utils/type-utils'
import React from 'react'
import { isEmpty } from 'lodash'
import { Card } from '@Pimcore/components/card/card'

export interface CardViewProps {
title?: string
Expand All @@ -27,7 +27,7 @@ export const CardView = (props: CardViewProps): React.JSX.Element => {
return (
<Card
bordered={ props.bordered === true }
title={ isEmptyValue(props.title) ? undefined : props.title }
title={ isEmpty(props.title) ? undefined : props.title }
>
{props.children}
</Card>
Expand Down
20 changes: 1 addition & 19 deletions assets/js/src/core/utils/type-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,7 @@
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/

export const isObject = (value: any): boolean => {
const type = typeof value

return value != null && (type === 'object' || type === 'function')
}

export const isString = (value: any): boolean => {
if (value === undefined || value === null) return false

return typeof value.valueOf() === 'string'
}

export const isNumber = (value: unknown): boolean => {
return (
typeof value === 'number' ||
(typeof value === 'object' && value !== null && Object.prototype.toString.call(value) === '[object Number]')
)
}

// Difference from Lodash: primitive values like booleans and numbers are NOT considered empty
export const isEmptyValue = (value: unknown): boolean => {
if (value === null || value === undefined) {
return true
Expand Down
2 changes: 2 additions & 0 deletions public/build/90969d98-df30-4d29-8458-b8a91dacadbc/105.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*!
*
* /**
* * Pimcore
* *
* * This source file is available under two different licenses:
* * - Pimcore Open Core License (POCL)
* * - Pimcore Commercial License (PCL)
* * Full copyright and license information is available in
* * LICENSE.md which is distributed with this source code.
* *
* * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* * @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
* * /
*
*/
16 changes: 16 additions & 0 deletions public/build/90969d98-df30-4d29-8458-b8a91dacadbc/core-dll.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions public/build/90969d98-df30-4d29-8458-b8a91dacadbc/core-dll.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/* @preserve
* Leaflet 1.9.4, a JS library for interactive maps. https://leafletjs.com
* (c) 2010-2023 Vladimir Agafonkin, (c) 2010-2011 CloudMade
*/

/*!
Copyright (c) 2018 Jed Watson.
Licensed under the MIT License (MIT), see
http://jedwatson.github.io/classnames
*/

/*!
*
* /**
* * Pimcore
* *
* * This source file is available under two different licenses:
* * - Pimcore Open Core License (POCL)
* * - Pimcore Commercial License (PCL)
* * Full copyright and license information is available in
* * LICENSE.md which is distributed with this source code.
* *
* * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* * @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
* * /
*
*/

/*! @license DOMPurify 3.2.1 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.2.1/LICENSE */

/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

/**
* react-table
*
* Copyright (c) TanStack
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/

/**
* table-core
*
* Copyright (c) TanStack
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/

/**
* @license
* Lodash <https://lodash.com/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/

/**
* @license React
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* use-sync-external-store-with-selector.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @remix-run/router v1.21.0
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/

/**
* React Router DOM v6.28.0
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/

/**
* React Router v6.28.0
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/

/**
* Pimcore
*
* This source file is available under two different licenses:
* - Pimcore Open Core License (POCL)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license https://github.com/pimcore/studio-ui-bundle/blob/1.x/LICENSE.md POCL and PCL
*/
12 changes: 12 additions & 0 deletions public/build/90969d98-df30-4d29-8458-b8a91dacadbc/entrypoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"entrypoints": {
"core-dll": {
"css": [
"/bundles/pimcorestudioui/build/90969d98-df30-4d29-8458-b8a91dacadbc/core-dll.css"
],
"js": [
"/bundles/pimcorestudioui/build/90969d98-df30-4d29-8458-b8a91dacadbc/core-dll.js"
]
}
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b69ac1b

Please sign in to comment.