|
|
@@ -5,9 +5,11 @@ import nodePath from 'path';
|
|
|
import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
import { ItemNode } from './ItemNode';
|
|
|
+import { IPageHasId } from '~/interfaces/page';
|
|
|
import { useSWRxPageChildren } from '../../../stores/page-listing';
|
|
|
import { usePageId } from '../../../stores/context';
|
|
|
import ClosableTextInput, { AlertInfo, AlertType } from '../../Common/ClosableTextInput';
|
|
|
+import PageItemControl from '../../Common/Dropdown/PageItemControl';
|
|
|
|
|
|
|
|
|
interface ItemProps {
|
|
|
@@ -28,32 +30,39 @@ const markTarget = (children: ItemNode[], targetId: string): void => {
|
|
|
};
|
|
|
|
|
|
type ItemControlProps = {
|
|
|
+ page: Partial<IPageHasId>
|
|
|
+ onClickDeleteButtonHandler?(): void
|
|
|
onClickPlusButtonHandler?(): void
|
|
|
}
|
|
|
|
|
|
const ItemControl: FC<ItemControlProps> = memo((props: ItemControlProps) => {
|
|
|
- const onClickHandler = () => {
|
|
|
- const { onClickPlusButtonHandler: handler } = props;
|
|
|
- if (handler == null) {
|
|
|
+ const onClickPlusButton = () => {
|
|
|
+ if (props.onClickPlusButtonHandler == null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- handler();
|
|
|
+ props.onClickPlusButtonHandler();
|
|
|
};
|
|
|
|
|
|
+ const onClickDeleteButton = () => {
|
|
|
+ if (props.onClickDeleteButtonHandler == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ props.onClickDeleteButtonHandler();
|
|
|
+ };
|
|
|
+
|
|
|
+ if (props.page == null) {
|
|
|
+ return <></>;
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
- <button
|
|
|
- type="button"
|
|
|
- className="btn-link nav-link dropdown-toggle dropdown-toggle-no-caret border-0 rounded grw-btn-page-management py-0"
|
|
|
- data-toggle="dropdown"
|
|
|
- >
|
|
|
- <i className="icon-options-vertical text-muted"></i>
|
|
|
- </button>
|
|
|
+ <PageItemControl page={props.page} onClickDeleteButton={onClickDeleteButton} />
|
|
|
<button
|
|
|
type="button"
|
|
|
className="btn-link nav-link border-0 rounded grw-btn-page-management py-0"
|
|
|
- onClick={onClickHandler}
|
|
|
+ onClick={onClickPlusButton}
|
|
|
>
|
|
|
<i className="icon-plus text-muted"></i>
|
|
|
</button>
|
|
|
@@ -65,7 +74,7 @@ const ItemCount: FC = () => {
|
|
|
return (
|
|
|
<>
|
|
|
<span className="grw-pagetree-count badge badge-pill badge-light">
|
|
|
- 10
|
|
|
+ {/* TODO: consider to show the number of children pages */}
|
|
|
</span>
|
|
|
</>
|
|
|
);
|
|
|
@@ -93,6 +102,10 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
|
|
|
setIsOpen(!isOpen);
|
|
|
}, [isOpen]);
|
|
|
|
|
|
+ const onClickDeleteButtonHandler = useCallback(() => {
|
|
|
+ console.log('Show delete modal');
|
|
|
+ }, []);
|
|
|
+
|
|
|
const inputValidator = (title: string | null): AlertInfo | null => {
|
|
|
if (title == null || title === '') {
|
|
|
return {
|
|
|
@@ -158,7 +171,11 @@ const Item: FC<ItemProps> = (props: ItemProps) => {
|
|
|
<ItemCount />
|
|
|
</div>
|
|
|
<div className="grw-pagetree-control d-none">
|
|
|
- <ItemControl onClickPlusButtonHandler={() => { setNewPageInputShown(true) }} />
|
|
|
+ <ItemControl
|
|
|
+ page={page}
|
|
|
+ onClickDeleteButtonHandler={onClickDeleteButtonHandler}
|
|
|
+ onClickPlusButtonHandler={() => { setNewPageInputShown(true) }}
|
|
|
+ />
|
|
|
</div>
|
|
|
</div>
|
|
|
|