Skip to content

Commit

Permalink
Update folder structure (#55)
Browse files Browse the repository at this point in the history
* Update folder structure

* Remove unused preview component
  • Loading branch information
vin0401 authored Feb 26, 2024
1 parent 1be49f0 commit bfb6be8
Show file tree
Hide file tree
Showing 82 changed files with 639 additions and 645 deletions.
2 changes: 1 addition & 1 deletion assets/js/build/openapi-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const config: ConfigFile = {
apiFile: '../src/app/api/pimcore/index.ts',
apiImport: 'api',
outputFiles: {
'../src/modules/asset/api/asset.gen.ts': {
'../src/modules/asset/asset-api-slice.gen.ts': {
filterEndpoints: [/apiAsset/i]
}
},
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions assets/js/src/components/formatted-date/formatted-date.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react'
import { useTranslation } from 'react-i18next'

interface FormattedDateProps {
timestamp: number
}

const FormattedDate = (props: FormattedDateProps): React.JSX.Element => {
const { i18n } = useTranslation()
const formattedDate = i18n.format(new Date(props.timestamp), 'datetime', i18n.language)

return (
<>
{formattedDate}
</>
)
}

export { FormattedDate }
46 changes: 46 additions & 0 deletions assets/js/src/components/grid/grid.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react'
import { type Meta } from '@storybook/react'
import { Grid } from './grid'
import { createColumnHelper } from '@tanstack/react-table'

const config: Meta = {
title: 'Pimcore studio/UI/Grid',
component: Grid,
parameters: {
layout: 'centered'
},

tags: ['autodocs']
}

export default config

interface User {
firstname: string
lastname: string
age: number
}

const data: User[] = [
{ firstname: 'John', lastname: 'Doe', age: 25 },
{ firstname: 'Jane', lastname: 'Doe', age: 22 }
]

const columnHelper = createColumnHelper<User>()

const columns = [
columnHelper.accessor('firstname', {}),
columnHelper.accessor('lastname', {
cell: info => <b>{info.getValue()}</b>
}),
columnHelper.accessor('age', {
cell: info => <b>{info.getValue()}</b>
})
]

export const _default = {
args: {
data,
columns
}
}
19 changes: 19 additions & 0 deletions assets/js/src/components/grid/grid.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { createStyles } from 'antd-style'

export const useStyles = createStyles(({ token, css }) => {
return {
grid: css`
table {
table-layout: auto;
}
.ant-table-cell {
border-left: 1px solid #F0F0F0;
&:first-of-type {
border-left: 0;
}
}
`
}
})
62 changes: 62 additions & 0 deletions assets/js/src/components/grid/grid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { useCssComponentHash } from '@Pimcore/modules/ant-design/hooks/use-css-component-hash'
import { type ColumnDef, flexRender, getCoreRowModel, useReactTable } from '@tanstack/react-table'
import React, { useState } from 'react'
import { useStyles } from './grid.styles'

export interface GridProps {
data: any[]
columns: Array<ColumnDef<any>>
}

export const Grid = (props: GridProps): React.JSX.Element => {
const { columns } = props
const [data] = useState(props.data)
const hashId = useCssComponentHash('table')
const { styles } = useStyles()

const table = useReactTable({
data,
columns,
getCoreRowModel: getCoreRowModel()
})

return (
<div className={['ant-table-wrapper', hashId, styles.grid].join(' ')}>
<div className="ant-table ant-table-small">
<div className='ant-table-container'>
<div className='ant-table-content'>
<table>
<thead className='ant-table-thead'>
{table.getHeaderGroups().map(headerGroup => (
<tr key={headerGroup.id}>
{headerGroup.headers.map(header => (
<th className='ant-table-cell' key={header.id} style={{ width: header.column.getSize() }}>
{header.isPlaceholder
? null
: flexRender(
header.column.columnDef.header,
header.getContext()
)}
</th>
))}
</tr>
))}
</thead>
<tbody className="ant-table-tbody">
{table.getRowModel().rows.map(row => (
<tr className='ant-table-row' key={row.id}>
{row.getVisibleCells().map(cell => (
<td className='ant-table-cell' key={cell.id} style={{ width: cell.column.getSize() }} >
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</td>
))}
</tr>
))}
</tbody>
</table>
</div>
</div>
</div>
</div>
)
}
9 changes: 6 additions & 3 deletions assets/js/src/components/icon/icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const icons = {
hierarchy: React.lazy(async () => await import('@Pimcore/assets/icons/core/hierarchy.inline.svg')),
'view-details': React.lazy(async () => await import('@Pimcore/assets/icons/core/view-details.inline.svg')),
'tag-two-tone': React.lazy(async () => await import('@Pimcore/assets/icons/core/tag-two-tone.inline.svg')),
workflow: React.lazy(async () => await import('@Pimcore/assets/icons/core/workflow.inline.svg'))
workflow: React.lazy(async () => await import('@Pimcore/assets/icons/core/workflow.inline.svg')),
'unordered-list-outlined': React.lazy(async () => await import('@Pimcore/assets/icons/core/unordered-list-outlined.inline.svg'))
}

export interface IconProps {
Expand All @@ -26,11 +27,13 @@ export interface IconProps {

export const Icon = ({ name, options }: IconProps): React.JSX.Element => {
const SvgIcon = icons[name]
const width = options?.width ?? 16
const height = options?.height ?? 16

return (
<div style={{ width: options?.width, height: options?.height }} className={`pimcore-icon pimcore-icon-${name} anticon`}>
<div style={{ width, height }} className={`pimcore-icon pimcore-icon-${name} anticon`}>
<Suspense fallback={<div />}>
<SvgIcon {...options} />
<SvgIcon width={width} height={height} {...options} />
</Suspense>
</div>
)
Expand Down
30 changes: 18 additions & 12 deletions assets/js/src/components/tree/tree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,30 @@ const Tree = (props: TreeProps): React.JSX.Element => {
})
const { isLoading, isError, data } = apiHookResult

if (isLoading !== false) {
return <></>
}

if (isError !== false) {
return (<div>{'Error'}</div>)
}

const { nodes: items } = dataTransformer(data)
let items: any[] = []

if (isLoading === false && data !== undefined) {
const { nodes } = dataTransformer(data)
items = nodes
}

return (
<div className={['tree', styles.tree].join(' ')}>
<TreeContext.Provider value={{ ...props, selectedIdsState }}>
{items.map((item) => (
<TreeNode key={item.id} {...item} />
))}
</TreeContext.Provider>
</div>
<>
{isLoading === false && items.length !== 0 && (
<div className={['tree', styles.tree].join(' ')}>
<TreeContext.Provider value={{ ...props, selectedIdsState }}>
{items.map((item) => (
<TreeNode key={item.id} {...item} />
))}
</TreeContext.Provider>
</div>
)}
</>

)
}

Expand Down
12 changes: 12 additions & 0 deletions assets/js/src/modules/ant-design/hooks/use-css-component-hash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import useStyle from 'antd/es/table/style'
import { ConfigContext } from 'antd/es/config-provider/context'
import { useContext } from 'react'

export const useCssComponentHash = (componentName: string): string => {
const context = useContext(ConfigContext)
const prefix = context.getPrefixCls(componentName, '')

const hashId = useStyle(prefix)[1]

return hashId
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React, { StrictMode } from 'react'
import { GlobalProvider } from './global-provider'
import { BaseLayout } from '@Pimcore/modules/base-layout/components/base-layout'
import { BaseLayoutView } from '@Pimcore/modules/base-layout/base-layout-view'
import { App as AntApp } from 'antd'

export const App = (): React.JSX.Element => {
export const AppView = (): React.JSX.Element => {
return (
<>
<StrictMode>
<GlobalProvider>
<AntApp>
<BaseLayout />
<BaseLayoutView />
</AntApp>
</GlobalProvider>
</StrictMode>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { store } from '@Pimcore/app/store'
import { ThemeProvider } from '@Pimcore/modules/theme/components/ThemeProvider'
import { ThemeProvider } from '@Pimcore/modules/theme/theme-provider'
import React from 'react'
import { Provider } from 'react-redux'

Expand Down
4 changes: 2 additions & 2 deletions assets/js/src/modules/app/utils/app-runner.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { createRoot } from 'react-dom/client'
import { App } from '../components/app'
import { AppView } from '../app-view'

export function runApp (): void {
const domElement = document.getElementById('app')
Expand All @@ -10,5 +10,5 @@ export function runApp (): void {
}

const root = createRoot(domElement)
root.render(<App />)
root.render(<AppView />)
}
47 changes: 47 additions & 0 deletions assets/js/src/modules/asset-tree/asset-tree-container.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Tree } from '@Pimcore/components/tree/tree'
import React from 'react'
import { useNodeApiHook } from './hooks/use-node-api-hook'
import { type TreeNodeProps } from '@Pimcore/components/tree/node/tree-node'
import { PagerContainer } from './pager/pager-container'
import { useAsset } from '@Pimcore/modules/asset/hooks/use-asset'
import { api } from '@Pimcore/modules/asset/asset-api-slice.gen'
import { store } from '@Pimcore/app/store'

export interface AssetTreeContainerProps {
id: number
}

const defaultProps: AssetTreeContainerProps = {
id: 1
}

const AssetTreeContainer = (props: AssetTreeContainerProps): React.JSX.Element => {
const { id } = props
const { openAsset } = useAsset()

async function onSelect (node: TreeNodeProps): Promise<void> {
await store.dispatch(api.endpoints.apiAssetsIdGet.initiate({ id: node.id }))

openAsset({
name: node.label,
icon: node.icon,
config: {
id: node.id
}
})
}

return (
<Tree
nodeId={id}
nodeApiHook={useNodeApiHook}
maxItemsPerNode={20}
renderPager={PagerContainer}
onSelect={onSelect}
/>
)
}

AssetTreeContainer.defaultProps = defaultProps

export { AssetTreeContainer }
43 changes: 0 additions & 43 deletions assets/js/src/modules/asset-tree/containers/asset-tree.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type TreeNodeProps } from '@Pimcore/components/tree/node/tree-node'
import { TreeContext } from '@Pimcore/components/tree/tree'
import { type ApiAssetsGetCollectionApiResponse, useApiAssetsGetCollectionQuery } from '@Pimcore/modules/asset/api/asset.gen'
import { type ApiAssetsGetCollectionApiResponse, useApiAssetsGetCollectionQuery } from '@Pimcore/modules/asset/asset-api-slice.gen'
import { type UseQueryHookResult } from '@reduxjs/toolkit/dist/query/react/buildHooks'
import { type Dispatch, type SetStateAction, useContext, useState } from 'react'

Expand Down
4 changes: 2 additions & 2 deletions assets/js/src/modules/asset-tree/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { registerWidget } from '../widget-manager/utils/widget-registry'
import { AssetTree } from './containers/asset-tree'
import { AssetTreeContainer } from './asset-tree-container'

registerWidget({
name: 'asset-tree',
component: AssetTree
component: AssetTreeContainer
})
Loading

0 comments on commit bfb6be8

Please sign in to comment.