-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eef92db
commit 3debcd7
Showing
22 changed files
with
974 additions
and
100 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"/js/app.js": "/js/app.js?id=421f94c4e76ff90ad8b56d037c27e657", | ||
"/js/manifest.js": "/js/manifest.js?id=22bb55ce20c9c883a45b5c11d8eca703", | ||
"/js/vendor.js": "/js/vendor.js?id=a21c2dcb4fdd557ce1ec6c040ad40be4", | ||
"/js/app.js": "/js/app.js?id=82c6422f61e56e2fcf4f223d37ae20ba", | ||
"/js/manifest.js": "/js/manifest.js?id=35aa9d461e033ff05abe890341153838", | ||
"/js/vendor.js": "/js/vendor.js?id=b53083a0bb34e922d0d09ba0e52241c6", | ||
"/css/app.css": "/css/app.css?id=d75c395a1c5c29d8b4c39d09727b550c" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useSelector } from "react-redux"; | ||
import api from "../api/api"; | ||
import str from "../util/str"; | ||
import i18n from "../util/i18n"; | ||
import Tree from "../core/ui/tree"; | ||
import path from "../state/path"; | ||
|
||
function TreeIndex(props) { | ||
|
||
const [state, setState] = useState({ | ||
isLoading: true, | ||
rows: [] | ||
}); | ||
|
||
const location = useSelector(state => state.location); | ||
|
||
useEffect(() => { | ||
load(location.current.params); | ||
}, [location.current.params]); | ||
|
||
useEffect(() => { | ||
if (location.refresh) { | ||
load(location.current.params); | ||
} | ||
}, [location.refresh]); | ||
|
||
const load = async (params = {}) => { | ||
|
||
// Execute the get request | ||
const response = await api.execute.get(props.path, props.id,'load', params); | ||
|
||
setState({ | ||
...state, | ||
isLoading: false, | ||
rows: response.data.data | ||
}); | ||
} | ||
|
||
const handleParentChange = async (id, parentId, children = []) => { | ||
await api.execute.get(props.path, props.id,'updateParent', {id, parentId, children}); | ||
}; | ||
|
||
const handleOrderChange = async (children = []) => { | ||
await api.execute.get(props.path, props.id,'updateOrder', {children}); | ||
}; | ||
|
||
const handleRowClick = (row) => { | ||
path.goTo(props.path.module, props.action, { | ||
id: row.id | ||
}); | ||
} | ||
|
||
const renderHeader = () => { | ||
return ( | ||
<div className="index__header"> | ||
<div className="index__header-title"> | ||
{str.toUpperCaseFirst(props.plural)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
const renderPlaceholder = () => { | ||
return ( | ||
<div className="index__placeholder"> | ||
{i18n.get('snippets.no_plural_found', {plural: props.plural})} | ||
</div> | ||
); | ||
} | ||
|
||
const renderRows = () => { | ||
|
||
if (state.rows.length) { | ||
return <Tree | ||
data={state.rows} | ||
onParentChange={handleParentChange} | ||
onOrderChange={handleOrderChange} | ||
onClick={handleRowClick} | ||
/>; | ||
} | ||
|
||
return renderPlaceholder(); | ||
} | ||
|
||
const render = () => { | ||
return ( | ||
<div className={'index index--'+props.style+(state.isLoading ? ' index--loading' : '')}> | ||
{renderHeader()} | ||
{renderRows()} | ||
</div> | ||
); | ||
} | ||
|
||
return render(); | ||
} | ||
|
||
TreeIndex.defaultProps = { | ||
type: '', | ||
components: [], | ||
path: {}, | ||
id: 0, | ||
data: {}, | ||
params: {}, | ||
action: '', | ||
plural: '', | ||
singular: '' | ||
}; | ||
|
||
export default TreeIndex; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import './index.scss'; | ||
import React from "react"; | ||
|
||
function DragInsertPlaceholder() { | ||
return ( | ||
<div className="drag-insert-placeholder"></div> | ||
); | ||
} | ||
|
||
export default DragInsertPlaceholder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@import 'resources/sass/settings'; | ||
@import 'resources/sass/tools'; | ||
|
||
@include block(drag-insert-placeholder) | ||
{ | ||
height: 2px; | ||
width: 100%; | ||
background-color: $primary-color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import './index.scss'; | ||
import React from "react"; | ||
|
||
function DragPlaceholder({text}) { | ||
return ( | ||
<span className="drag-placeholder">{text}</span> | ||
); | ||
} | ||
|
||
export default DragPlaceholder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@import 'resources/sass/settings'; | ||
@import 'resources/sass/tools'; | ||
|
||
@include block(drag-placeholder) | ||
{ | ||
background-color: $primary-color; | ||
border-radius: $border-radius-1; | ||
color: $color01; | ||
padding: calc($rule / 6) calc($rule / 3); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import './index.scss'; | ||
|
||
import React, { useState } from "react"; | ||
import { DndProvider } from "react-dnd"; | ||
import {Tree as TreeView, MultiBackend, getBackendOptions} from "@minoru/react-dnd-treeview"; | ||
import Icon from "../icon"; | ||
import DragInsertPlaceholder from "../drag-insert-placeholder"; | ||
import clsx from "clsx"; | ||
import DragPlaceholder from "../drag-placeholder"; | ||
|
||
function TreeRow({onClick, isDroppable, isDropTarget, isOpen, onToggle, text, depth}) { | ||
return ( | ||
<div onClick={onClick} className={clsx('tree__item tree-row', { | ||
'tree-row--drop-target': isDropTarget | ||
})}> | ||
<div className="tree-row__content" style={{ paddingInlineStart: depth * 25 }}> | ||
{isDroppable && ( | ||
<div className="tree-row__toggle"> | ||
<Icon name={(isOpen ? 'expand_more' : 'chevron_right')} onClick={onToggle} /> | ||
</div> | ||
)} | ||
{text} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
function Tree({data, onParentChange = null, onOrderChange = null, onClick = null}) { | ||
|
||
const [treeData, setTreeData] = useState(data); | ||
|
||
const handleDrop = (newTree, { dragSourceId, dropTargetId, dragSource, dropTarget }) => { | ||
const children = newTree.filter((item) => item.parent === dropTargetId).map(child => child.id); | ||
|
||
if (dragSource.parent !== dropTargetId) { | ||
if (onParentChange) { | ||
onParentChange(dragSourceId, dropTargetId, children); | ||
} | ||
} else { | ||
if (onOrderChange) { | ||
onOrderChange(children); | ||
} | ||
} | ||
setTreeData(newTree); | ||
}; | ||
|
||
const handleClick = (item) => { | ||
if (onClick) { | ||
onClick(item); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="tree"> | ||
<DndProvider backend={MultiBackend} options={getBackendOptions()}> | ||
<TreeView | ||
tree={treeData} | ||
rootId={null} | ||
sort={false} | ||
listComponent={'div'} | ||
listItemComponent={'div'} | ||
dropTargetOffset={5} | ||
insertDroppableFirst={false} | ||
render={(node, { isDropTarget, depth, isOpen, onToggle }) => ( | ||
<TreeRow | ||
onClick={() => handleClick(node)} | ||
isDropTarget={isDropTarget} | ||
isDroppable={node.droppable} | ||
onToggle={onToggle} | ||
depth={depth} | ||
isOpen={isOpen} | ||
text={node.text} | ||
/> | ||
)} | ||
dragPreviewRender={(monitorProps) => ( | ||
<DragPlaceholder text={monitorProps.item.text} /> | ||
)} | ||
canDrop={(tree, { dragSource, dropTargetId, dropTarget }) => { | ||
if (dragSource?.parent === dropTargetId) { | ||
return true; | ||
} | ||
}} | ||
placeholderRender={() => ( | ||
<DragInsertPlaceholder /> | ||
)} | ||
onDrop={handleDrop} | ||
/> | ||
</DndProvider> | ||
</div> | ||
); | ||
} | ||
|
||
export default Tree; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
@import 'resources/sass/settings'; | ||
@import 'resources/sass/tools'; | ||
|
||
@include block(tree) | ||
{ | ||
@include element(item) | ||
{ | ||
// for ref | ||
} | ||
} | ||
|
||
@include block(tree-row) | ||
{ | ||
cursor: pointer; | ||
padding: calc($rule / 3) $rule; | ||
transition: background-color .25s; | ||
|
||
@include modifier(drop-target) | ||
{ | ||
background-color: $fill-color-alt-1; | ||
} | ||
|
||
&:hover | ||
{ | ||
background-color: $fill-color; | ||
} | ||
|
||
@include element(content) | ||
{ | ||
display: flex; | ||
} | ||
|
||
@include element(toggle) | ||
{ | ||
margin-right: calc($rule / 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.