Skip to content

Commit

Permalink
added the trackError method instead of throwing error
Browse files Browse the repository at this point in the history
  • Loading branch information
ValeriaMaltseva committed Dec 2, 2024
1 parent 876ca99 commit 8fa7d5e
Show file tree
Hide file tree
Showing 12 changed files with 1,901 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

import React, { useContext, useEffect, useState } from 'react'
import { isUndefined } from 'lodash'
import { ModalFooter } from '@Pimcore/components/modal/footer/modal-footer'
import { Dropdown } from '@Pimcore/components/dropdown/dropdown'
import {
Expand Down Expand Up @@ -40,6 +41,7 @@ import { Flex } from '@Pimcore/components/flex/flex'
import { ModalTitle } from '@Pimcore/components/modal/modal-title/modal-title'
import { eventBus } from '@Pimcore/lib/event-bus'
import { AssetContext } from '@Pimcore/modules/asset/asset-provider'
import trackError, { GeneralError } from '@Pimcore/modules/app/error-handler'

export interface BatchEditModalProps {
batchEditModalOpen: boolean
Expand Down Expand Up @@ -84,9 +86,10 @@ export const BatchEditModal = ({ batchEditModalOpen, setBatchEditModalOpen }: Ba
try {
const response = await patchAsset(assetPatchForUpdate())
const data = response.data
if (data?.jobRunId !== undefined) {
if (!isUndefined(data?.jobRunId)) {
return data.jobRunId
} else {
trackError(new GeneralError('JobRunId is undefined'))
throw new Error('JobRunId is undefined')
}
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ import { onKeyEnterExecuteClick } from '@Pimcore/utils/helpers'
import { Button } from '@Pimcore/components/button/button'
import { useElementHelper } from '@Pimcore/modules/element/hooks/use-element-helper'
import { type AbstractGridCellDefinition } from '../../dynamic-type-grid-cell-abstract'
import { isUndefined } from 'lodash'

export const OpenElementCell = (props: AbstractGridCellDefinition): React.JSX.Element => {
const { styles } = useStyle()
const { openElement, mapToElementType } = useElementHelper()
const elementType = mapToElementType(props.row.original.type as string)
const elementId = props.row.original.id

function renderCell (): React.JSX.Element {
function renderCell (): React.JSX.Element | null {
if (isUndefined(elementType)) return null

const onClick = async (): Promise<void> => {
await openElement({
id: elementId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

import React, { forwardRef, type MutableRefObject, type ReactElement } from 'react'
import { isUndefined } from 'lodash'
import { useDroppable } from '@Pimcore/components/drag-and-drop/hooks/use-droppable'
import { Grid } from '@Pimcore/components/grid/grid'
import { createColumnHelper } from '@tanstack/react-table'
Expand Down Expand Up @@ -83,8 +84,10 @@ export const ManyToManyRelationGrid = forwardRef(function ManyToManyRelationGrid
<IconButton
icon={ { value: 'group' } }
onClick={ async () => {
await openElement({
type: mapToElementType(rowValue.type),
const typeValue = mapToElementType(rowValue.type)

!isUndefined(typeValue) && await openElement({
type: typeValue,
id: rowValue.id
})
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { type DynamicTypeAbstract, type DynamicTypeRegistryAbstract } from '../.
import { DynamicTypeResolver, type DynamicTypesResolverTargets } from '../dynamic-type-resolver'
import { DynamicTypeRegistryContext } from '../../registry/provider/dynamic-type-registry-provider'
import { container } from '@Pimcore/app/depency-injection'
import trackError, { GeneralError } from '@Pimcore/modules/app/error-handler'

export interface IComponentRenderer {
ComponentRenderer: ((props: unknown) => ReactElement<unknown>) | null
Expand All @@ -35,10 +36,10 @@ export const useDynamicTypeResolver = (): UseDynamicTypeResolverReturnType => {
const context = useContext(DynamicTypeRegistryContext)

if (context === undefined || context === null) {
throw new Error('useDynamicTypeResolver must be used within a DynamicTypeRegistryProvider')
trackError(new GeneralError('useDynamicTypeResolver must be used within a DynamicTypeRegistryProvider'))
}

const { serviceIds } = context
const { serviceIds } = context!
const registries = serviceIds.map(serviceId => container.get<InstanceType<typeof DynamicTypeRegistryAbstract>>(serviceId))

function getComponentRenderer <T> (props: typeProps): IComponentRenderer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
type DataProperty as DataPropertyApi
} from '@Pimcore/modules/element/editor/shared-tab-manager/tabs/properties/properties-api-slice.gen'
import React, { useEffect, useState } from 'react'
import { isUndefined } from 'lodash'
import { Grid } from '@Pimcore/components/grid/grid'
import { createColumnHelper } from '@tanstack/react-table'
import { useTranslation } from 'react-i18next'
Expand Down Expand Up @@ -151,8 +152,10 @@ export const Table = ({
<IconButton
icon={ { value: 'group' } }
onClick={ async () => {
await openElement({
type: mapToElementType(info.row.original.type),
const typeValue = mapToElementType(info.row.original.type)

!isUndefined(typeValue) && await openElement({
type: typeValue,
id: info.row.original.data.id
})
} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { Flex } from '@Pimcore/components/flex/flex'
import { TreeElement } from '@Pimcore/components/tree-element/tree-element'
import { SearchInput } from '@Pimcore/components/search-input/search-input'
import { type TreeProps } from 'antd'
import trackError, { ApiError } from '@Pimcore/modules/app/error-handler'

export interface TagsTreeProps {
elementId: number
Expand Down Expand Up @@ -70,10 +71,10 @@ export const TagsTree = ({ elementId, elementType, tags, setFilter, isLoading, d
console.log('Failed to assign tag to element')
})

const response = (await assignTask) as any
const response = await assignTask

if (response.error !== undefined) {
throw new Error(response.error.data.error as string)
trackError(new ApiError(response.error))
}
}

Expand All @@ -88,10 +89,10 @@ export const TagsTree = ({ elementId, elementType, tags, setFilter, isLoading, d
console.log('Failed to remove tag from element')
})

const response = (await unassignTask) as any
const response = await unassignTask

if (response.error !== undefined) {
throw new Error(response.error.data.error as string)
trackError(new ApiError(response.error))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { useElementContext } from '@Pimcore/modules/element/hooks/use-element-co
import { useJobs } from '@Pimcore/modules/execution-engine/hooks/useJobs'
import { createJob } from '@Pimcore/modules/execution-engine/jobs/tag-assign/factory'
import { defaultTopics, topics } from '@Pimcore/modules/execution-engine/topics'
import trackError, { ApiError } from '@Pimcore/modules/app/error-handler'

interface UseShortcutActionsReturn {
removeAndApplyTagsToChildren: () => Promise<void>
Expand All @@ -41,13 +42,13 @@ export const useShortcutActions = (): UseShortcutActionsReturn => {
console.log('Failed to apply tags to children')
})

const response = (await assignTask) as any
const response = await assignTask

if (response.error !== undefined) {
throw new Error(response.error.data.error as string)
trackError(new ApiError(response.error))
}

const data = response.data
const data = response.data!
return data.jobRunId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { type ElementType } from 'types/element-type.d'
import { useContext } from 'react'
import { AssetContext } from '@Pimcore/modules/asset/asset-provider'
import { DataObjectContext } from '@Pimcore/modules/data-object/data-object-provider'
import trackError, { GeneralError } from '@Pimcore/modules/app/error-handler'

interface UseElementContextReturn {
id: number
Expand All @@ -31,5 +32,8 @@ export const useElementContext = (): UseElementContextReturn => {
return { id: dataObjectId, elementType: 'data-object' }
}

throw new Error('No element context found')
const errorMessage = 'No element context found'

trackError(new GeneralError(errorMessage))
throw new Error(errorMessage)
}
4 changes: 4 additions & 0 deletions assets/js/src/core/modules/element/hooks/use-element-draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { useDataObjectDraft } from '@Pimcore/modules/data-object/hooks/use-data-
import { type UseTabsDraftReturn } from '../draft/hooks/use-tabs'
import { type ElementEditorType } from '@Pimcore/modules/element/editor/services/type-registry'
import { type ElementPermissions } from '@Pimcore/modules/element/element-api-slice-enhanced'
import trackError, { GeneralError } from '@Pimcore/modules/app/error-handler'

interface IElementDraft extends PropertiesDraft, SchedulesDraft, TrackableChangesDraft {
id: number
Expand All @@ -48,13 +49,16 @@ interface UseElementDraftReturn extends
export const useElementDraft = (id: number, elementType: ElementType): UseElementDraftReturn => {
if (elementType === 'asset') {
const draft = useAssetDraft(id)

return { ...draft, element: draft.asset }
}

if (elementType === 'data-object') {
const draft = useDataObjectDraft(id)

return { ...draft, element: draft.dataObject }
}

trackError(new GeneralError('Element type not supported: ' + elementType))
throw new Error('Element type not supported: ' + elementType)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import { type ElementType } from 'types/element-type.d'
import { useAssetHelper } from '@Pimcore/modules/asset/hooks/use-asset-helper'
import { useDataObjectHelper } from '@Pimcore/modules/data-object/hooks/use-data-object-helper'
import trackError, { GeneralError } from '@Pimcore/modules/app/error-handler'

interface OpenElementWidgetProps {
id: number
Expand All @@ -22,7 +23,7 @@ interface OpenElementWidgetProps {

interface UseElementReturn {
openElement: (props: OpenElementWidgetProps) => Promise<void>
mapToElementType: (elementType: string) => ElementType
mapToElementType: (elementType: string) => ElementType | undefined
}

export const useElementHelper = (): UseElementReturn => {
Expand All @@ -46,7 +47,7 @@ export const useElementHelper = (): UseElementReturn => {
}
}

function mapToElementType (elementType: string): ElementType {
function mapToElementType (elementType: string): ElementType | undefined {
switch (elementType) {
case 'asset':
return 'asset'
Expand All @@ -60,7 +61,9 @@ export const useElementHelper = (): UseElementReturn => {
return 'data-object'

default:
throw new Error('Unknown element type: ' + elementType)
trackError(new GeneralError('Unknown element type: ' + elementType))

return undefined
}
}

Expand Down
14 changes: 14 additions & 0 deletions public/build/0fd04c0e-90f5-49e3-b2a4-f16b1b82d79e/entrypoints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"entrypoints": {
"main": {
"css": [
"http://localhost:3030/build/0fd04c0e-90f5-49e3-b2a4-f16b1b82d79e/vendors-node_modules_dnd-kit_modifiers_dist_modifiers_esm_js-node_modules_dnd-kit_sortable_di-41eabe.css",
"http://localhost:3030/build/0fd04c0e-90f5-49e3-b2a4-f16b1b82d79e/main.css"
],
"js": [
"http://localhost:3030/build/0fd04c0e-90f5-49e3-b2a4-f16b1b82d79e/vendors-node_modules_dnd-kit_modifiers_dist_modifiers_esm_js-node_modules_dnd-kit_sortable_di-41eabe.js",
"http://localhost:3030/build/0fd04c0e-90f5-49e3-b2a4-f16b1b82d79e/main.js"
]
}
}
}
Loading

0 comments on commit 8fa7d5e

Please sign in to comment.