Skip to content

Commit

Permalink
AP-75 add initial asset tree
Browse files Browse the repository at this point in the history
  • Loading branch information
vin0401 committed Feb 15, 2024
1 parent a26c7f9 commit 8e0197f
Show file tree
Hide file tree
Showing 30 changed files with 315 additions and 212 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ module.exports = {
],
"rules": {
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/unbound-method": "off",
}
}
4 changes: 4 additions & 0 deletions assets/css/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
font-weight: 700;
}

* {
box-sizing: border-box;
}

body {
font-family: Lato, sans-serif;
}
2 changes: 1 addition & 1 deletion assets/js/build/openapi-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const config: ConfigFile = {
apiImport: 'api',
outputFiles: {
'../src/modules/asset/api/asset.gen.ts': {
filterEndpoints: [/apiAsset/i],
filterEndpoints: [/apiAsset/i]
}
},
exportName: 'api',
Expand Down
2 changes: 0 additions & 2 deletions assets/js/src/components/icon/icon.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ const config: Meta = {
tags: ['autodocs']
}

console.log(Icon)

export default config

export const _default = {
Expand Down
14 changes: 0 additions & 14 deletions assets/js/src/components/tree/__stories__/advanced-tree.tsx

This file was deleted.

25 changes: 0 additions & 25 deletions assets/js/src/components/tree/__stories__/pager/tree-pager.tsx

This file was deleted.

26 changes: 0 additions & 26 deletions assets/js/src/components/tree/__stories__/search/tree-search.tsx

This file was deleted.

92 changes: 0 additions & 92 deletions assets/js/src/components/tree/__stories__/tree.stories.tsx

This file was deleted.

8 changes: 5 additions & 3 deletions assets/js/src/components/tree/expander/tree-expander.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useContext } from 'react'
import React, { type MouseEvent, useContext } from 'react'
import { type TreeNodeProps } from '../node/tree-node'
import { TreeContext } from '../tree'
import { Icon } from '@Pimcore/components/icon/icon'
Expand All @@ -13,7 +13,9 @@ export const TreeExpander = ({ node, state }: TreeExpanderProps): React.JSX.Elem
const { onLoad } = useContext(TreeContext)
const [isExapanded, setIsExpanded] = state

async function onClick (): Promise<void> {
async function onClick (event: MouseEvent): Promise<void> {
event.stopPropagation()

if (hasChildren === true) {
const newExpandedValue = !isExapanded

Expand All @@ -26,7 +28,7 @@ export const TreeExpander = ({ node, state }: TreeExpanderProps): React.JSX.Elem
}

return (
<div className='tree-expander' style={{ width: 16, height: 16 }}>
<div className='tree-expander' style={{ minWidth: 16, width: 16, height: 16 }}>
{node.hasChildren === true && (
<span onClick={onClick}>
{isExapanded ? <Icon name="chevron-up" /> : <Icon name="chevron-down" />}
Expand Down
13 changes: 13 additions & 0 deletions assets/js/src/components/tree/list/tree-list.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { createStyles } from 'antd-style'

export const useStyles = createStyles(({ token, css }) => {
return {
'tree-list__pager': css`
padding: ${token.paddingSM}px 0;
&:empty {
padding: 0;
}
`
}
})
14 changes: 12 additions & 2 deletions assets/js/src/components/tree/list/tree-list.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import React, { useContext } from 'react'
import { TreeNode, type TreeNodeProps } from '../node/tree-node'
import { TreeContext } from '../tree'
import { theme } from 'antd'
import { useStyles } from './tree-list.styles'

interface TreeListProps {
node: TreeNodeProps
}

const { useToken } = theme

export const TreeList = ({ node }: TreeListProps): React.JSX.Element => {
const { token } = useToken()
const { styles } = useStyles()
const { renderFilter: RenderFilter, renderPager: RenderPager, nodeApiHook } = useContext(TreeContext)
const { apiHookResult, dataTransformer, setAdditionalQueryParams } = nodeApiHook(node.id)
const { apiHookResult, dataTransformer, setAdditionalQueryParams } = nodeApiHook(node)
const { isLoading, isError, data } = apiHookResult

if (isLoading === true) {
Expand All @@ -31,7 +37,11 @@ export const TreeList = ({ node }: TreeListProps): React.JSX.Element => {
))}
</div>

{RenderPager !== undefined && (<RenderPager node={node} total={total} setAdditionalQueryParams={setAdditionalQueryParams} />)}
{RenderPager !== undefined && (
<div className={['tree-list__pager', styles['tree-list__pager']].join(' ')} style={{ paddingLeft: token.paddingSM + (node.level + 1) * 24 }}>
<RenderPager node={node} total={total} setAdditionalQueryParams={setAdditionalQueryParams} />
</div>
)}
</>
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { type TreeNodeProps } from '../tree-node'
import { Space } from 'antd'
import { Flex } from 'antd'
import { Icon } from '@Pimcore/components/icon/icon'

export interface TreeNodeContentProps {
Expand All @@ -11,10 +11,10 @@ const TreeNodeContent = (props: TreeNodeContentProps): React.JSX.Element => {
const { icon, label } = props.node

return (
<Space>
<Flex gap={'small'}>
<Icon name={icon} />
<span>{label}</span>
</Space>
<span className="tree-node-content__label">{label}</span>
</Flex>
)
}

Expand Down
28 changes: 27 additions & 1 deletion assets/js/src/components/tree/node/tree-node.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,33 @@ export const useStyles = createStyles(({ token, css }) => {
return {
treeNode: css`
user-select: none;
padding-inline: 20px;
.tree-node__content {
cursor: pointer;
width: 100%;
padding: 2px ${token.paddingSM}px 2px 0;
white-space: nowrap;
@media (hover: hover) {
&:hover {
background-color: ${token.controlItemBgActiveHover};
}
}
}
&.tree-node--selected > .tree-node__content {
background-color: ${token.controlItemBgActive};
}
.tree-node__content-wrapper {
max-width: max(100px, calc(100% - 16px));
}
.tree-node-content__label {
display: inline-block;
text-overflow: ellipsis;
overflow: hidden;
}
`
}
})
Loading

0 comments on commit 8e0197f

Please sign in to comment.