|
@@ -2,23 +2,16 @@ import React, {
|
|
|
FC, useState, useCallback,
|
|
FC, useState, useCallback,
|
|
|
} from 'react';
|
|
} from 'react';
|
|
|
|
|
|
|
|
-import { useTranslation } from 'react-i18next';
|
|
|
|
|
|
|
+import { SupportedActionType } from '~/interfaces/activity';
|
|
|
|
|
|
|
|
-import { SupportedTargetModelType, SupportedActionType } from '~/interfaces/activity';
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-type DropdownProps = {
|
|
|
|
|
- targetModelName: SupportedTargetModelType
|
|
|
|
|
- actionNames: SupportedActionType[]
|
|
|
|
|
|
|
+type Props = {
|
|
|
|
|
+ dropdownItems: Array<{actionType: string, actionNames: SupportedActionType[]}>
|
|
|
checkedItems: Map<SupportedActionType, boolean>
|
|
checkedItems: Map<SupportedActionType, boolean>
|
|
|
onCheckItem: (action: SupportedActionType) => void
|
|
onCheckItem: (action: SupportedActionType) => void
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const Dropdown: FC<DropdownProps> = (props: DropdownProps) => {
|
|
|
|
|
-
|
|
|
|
|
- const {
|
|
|
|
|
- targetModelName, actionNames, checkedItems, onCheckItem,
|
|
|
|
|
- } = props;
|
|
|
|
|
|
|
+export const SelectActionDropdown: FC<Props> = (props: Props) => {
|
|
|
|
|
+ const { dropdownItems, checkedItems, onCheckItem } = props;
|
|
|
|
|
|
|
|
const [checkedAllItems, setCheckedAllItems] = useState(true);
|
|
const [checkedAllItems, setCheckedAllItems] = useState(true);
|
|
|
|
|
|
|
@@ -26,59 +19,6 @@ const Dropdown: FC<DropdownProps> = (props: DropdownProps) => {
|
|
|
onCheckItem(action);
|
|
onCheckItem(action);
|
|
|
}, [onCheckItem]);
|
|
}, [onCheckItem]);
|
|
|
|
|
|
|
|
- return (
|
|
|
|
|
- <>
|
|
|
|
|
- <div className="dropdown-item">
|
|
|
|
|
- <div className="form-group px-2 m-0">
|
|
|
|
|
- <input
|
|
|
|
|
- type="checkbox"
|
|
|
|
|
- className="form-check-input"
|
|
|
|
|
- checked={checkedAllItems}
|
|
|
|
|
- onChange={() => setCheckedAllItems(!checkedAllItems)}
|
|
|
|
|
- />
|
|
|
|
|
- <label className="form-check-label">{targetModelName}</label>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
- {
|
|
|
|
|
- actionNames.map(action => (
|
|
|
|
|
- <div className="dropdown-item" key={action}>
|
|
|
|
|
- <div className="form-group px-4 m-0">
|
|
|
|
|
- <input
|
|
|
|
|
- type="checkbox"
|
|
|
|
|
- className="form-check-input"
|
|
|
|
|
- id={`checkbox${action}`}
|
|
|
|
|
- onChange={() => { handleChange(action) }}
|
|
|
|
|
- checked={checkedItems.get(action)}
|
|
|
|
|
- />
|
|
|
|
|
- <label
|
|
|
|
|
- className="form-check-label"
|
|
|
|
|
- htmlFor={`checkbox${action}`}
|
|
|
|
|
- >
|
|
|
|
|
- {action}
|
|
|
|
|
- </label>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
- ))
|
|
|
|
|
- }
|
|
|
|
|
- </>
|
|
|
|
|
- );
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-type Props = {
|
|
|
|
|
- dropdownItems: Array<{
|
|
|
|
|
- targetModelName: SupportedTargetModelType
|
|
|
|
|
- actionNames: SupportedActionType[]
|
|
|
|
|
- checkedItems: Map<SupportedActionType, boolean>
|
|
|
|
|
- onCheckItem: (action: SupportedActionType) => void
|
|
|
|
|
- }>
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-export const SelectActionDropdown: FC<Props> = (props: Props) => {
|
|
|
|
|
- const { t } = useTranslation();
|
|
|
|
|
-
|
|
|
|
|
- const { dropdownItems } = props;
|
|
|
|
|
-
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className="btn-group mr-2 mb-3">
|
|
<div className="btn-group mr-2 mb-3">
|
|
|
<div className="dropdown">
|
|
<div className="dropdown">
|
|
@@ -87,13 +27,39 @@ export const SelectActionDropdown: FC<Props> = (props: Props) => {
|
|
|
</button>
|
|
</button>
|
|
|
<ul className="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
|
<ul className="dropdown-menu" aria-labelledby="dropdownMenuButton">
|
|
|
{dropdownItems.map(item => (
|
|
{dropdownItems.map(item => (
|
|
|
- <div key={item.targetModelName}>
|
|
|
|
|
- <Dropdown
|
|
|
|
|
- targetModelName={item.targetModelName}
|
|
|
|
|
- actionNames={item.actionNames}
|
|
|
|
|
- checkedItems={item.checkedItems}
|
|
|
|
|
- onCheckItem={item.onCheckItem}
|
|
|
|
|
- />
|
|
|
|
|
|
|
+ <div key={item.actionType}>
|
|
|
|
|
+ <div className="dropdown-item">
|
|
|
|
|
+ <div className="form-group px-2 m-0">
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="checkbox"
|
|
|
|
|
+ className="form-check-input"
|
|
|
|
|
+ checked={checkedAllItems}
|
|
|
|
|
+ onChange={() => setCheckedAllItems(!checkedAllItems)}
|
|
|
|
|
+ />
|
|
|
|
|
+ <label className="form-check-label">{item.actionType}</label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ {
|
|
|
|
|
+ item.actionNames.map(action => (
|
|
|
|
|
+ <div className="dropdown-item" key={action}>
|
|
|
|
|
+ <div className="form-group px-4 m-0">
|
|
|
|
|
+ <input
|
|
|
|
|
+ type="checkbox"
|
|
|
|
|
+ className="form-check-input"
|
|
|
|
|
+ id={`checkbox${action}`}
|
|
|
|
|
+ onChange={() => { handleChange(action) }}
|
|
|
|
|
+ checked={checkedItems.get(action)}
|
|
|
|
|
+ />
|
|
|
|
|
+ <label
|
|
|
|
|
+ className="form-check-label"
|
|
|
|
|
+ htmlFor={`checkbox${action}`}
|
|
|
|
|
+ >
|
|
|
|
|
+ {action}
|
|
|
|
|
+ </label>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ))
|
|
|
|
|
+ }
|
|
|
</div>
|
|
</div>
|
|
|
))}
|
|
))}
|
|
|
</ul>
|
|
</ul>
|