Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,59 @@
* @license Pimcore Open Core License (POCL)
*/

import React, { type Key } from 'react'
import React, { type Key, useState } from 'react'
import { Content } from '@Pimcore/components/content/content'
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 {
createTreeStructure
} from '@Pimcore/modules/element/editor/shared-tab-manager/tabs/tags/components/tags-tree/create-tree-structure'
import {
useTagGetCollectionQuery
} from '@Pimcore/modules/element/editor/shared-tab-manager/tabs/tags/tags-api-slice-enhanced'
export const TagsTreeFiltersContainer = ({ checkedKeys, setCheckedKeys }: { checkedKeys: any, setCheckedKeys: any }): React.JSX.Element => {
import { isEmpty, isUndefined } from 'lodash'
import { useTranslation } from 'react-i18next'

interface TagsTreeFiltersContainerProps {
checkedKeys: Key[]
setCheckedKeys: (keys: Key[]) => void
}

export const TagsTreeFiltersContainer = ({ checkedKeys, setCheckedKeys }: TagsTreeFiltersContainerProps): React.JSX.Element => {
const { t } = useTranslation()
const [filter, setFilter] = useState<string>('')
const [expandedKeys, setExpandedKeys] = useState<Key[]>([0])
const { data: tags, isLoading: tagsLoading } = useTagGetCollectionQuery({
page: 1,
pageSize: 9999
pageSize: 9999,
filter
})

const treeData = !isUndefined(tags?.items)
? createTreeStructure({ tags: tags.items, loadingNodes: new Set<string>() })
: []

const handleSearch = (value: string): void => {
setFilter(value)

if (!isEmpty(value)) {
setExpandedKeys((prevKeys) => {
const hasRoot = prevKeys.some((key) => String(key) === '0')

return hasRoot ? prevKeys : [0, ...prevKeys]
})
}
}

if (tagsLoading) {
return <Content loading />
}

if (tags?.items === undefined) {
if (isUndefined(tags?.items)) {
return <div>Failed to load tags</div>
}

const treeData = createTreeStructure({ tags: tags.items, loadingNodes: new Set<string>() })

const handleCheck = (currentCheckedKeys: { checked: Key[], halfChecked: Key[] }): void => {
const checkedKeysList = currentCheckedKeys.checked

Expand All @@ -47,10 +74,18 @@ export const TagsTreeFiltersContainer = ({ checkedKeys, setCheckedKeys }: { chec
gap={ 'small' }
vertical
>
<SearchInput
loading={ tagsLoading }
onSearch={ handleSearch }
placeholder={ t('search') }
/>

<TreeElement
checkStrictly
checkedKeys={ { checked: checkedKeys, halfChecked: [] } }
defaultExpandedKeys={ expandedKeys }
onCheck={ handleCheck }
onExpand={ (keys) => { setExpandedKeys(keys) } }
treeData={ treeData }
withCustomSwitcherIcon
/>
Expand Down

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

22 changes: 22 additions & 0 deletions public/build/0443ea0a-04ef-4091-826c-09c00ee310f0/entrypoints.json

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

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

33 changes: 33 additions & 0 deletions public/build/0443ea0a-04ef-4091-826c-09c00ee310f0/manifest.json

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

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

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

Large diffs are not rendered by default.

Large diffs are not rendered by default.

23 changes: 0 additions & 23 deletions public/build/22b98483-c82e-4ca2-a8ec-112f00562251/entrypoints.json

This file was deleted.

Loading
Loading