|
@@ -76,34 +76,13 @@ class ScopeSearch extends ReactWidget {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const useOutsideClick = (
|
|
|
- ref: React.MutableRefObject<any>,
|
|
|
- callback: Function
|
|
|
-) => {
|
|
|
- const handleClickOutside = (e: Event) => {
|
|
|
- if (ref.current && !ref.current.contains(e.target)) {
|
|
|
- callback();
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- useEffect(() => {
|
|
|
- document.addEventListener('mousedown', handleClickOutside);
|
|
|
- return () => {
|
|
|
- document.removeEventListener('mousedown', handleClickOutside);
|
|
|
- };
|
|
|
- });
|
|
|
-};
|
|
|
-
|
|
|
const ScopeMenuComponent = ({ model }: { model: Variables.IModel }) => {
|
|
|
- // const [toggleState, setToggle] = useState(false);
|
|
|
- // const [scopes, setScopes] = useState(model.scopes);
|
|
|
const [scope, setScope] = useState(model.currentScope);
|
|
|
const wrapperRef = useRef(null);
|
|
|
|
|
|
useEffect(() => {
|
|
|
const updateScopes = (_: Variables.IModel, updates: Variables.IScope[]) => {
|
|
|
const scope = !!updates && updates.length > 0 ? updates[0] : null;
|
|
|
- // setScopes(updates);
|
|
|
setScope(scope);
|
|
|
};
|
|
|
model.scopesChanged.connect(updateScopes);
|
|
@@ -113,44 +92,10 @@ const ScopeMenuComponent = ({ model }: { model: Variables.IModel }) => {
|
|
|
};
|
|
|
});
|
|
|
|
|
|
- const onClickOutSide = () => {
|
|
|
- // setToggle(false);
|
|
|
- };
|
|
|
-
|
|
|
- const toggle = () => {
|
|
|
- // if (!!scopes) {
|
|
|
- // setToggle(!toggleState);
|
|
|
- // }
|
|
|
- };
|
|
|
-
|
|
|
- useOutsideClick(wrapperRef, onClickOutSide);
|
|
|
-
|
|
|
- // const changeScope = (newScope: Variables.IScope) => {
|
|
|
- // if (newScope === scope) {
|
|
|
- // return;
|
|
|
- // }
|
|
|
- // setScope(newScope);
|
|
|
- // model.currentScope = newScope;
|
|
|
- // setToggle(false);
|
|
|
- // };
|
|
|
-
|
|
|
- // const List = (
|
|
|
- // <ul>
|
|
|
- // {!!scopes
|
|
|
- // ? scopes.map(scope => (
|
|
|
- // <li key={scope.name} onClick={e => changeScope(scope)}>
|
|
|
- // {scope.name}
|
|
|
- // </li>
|
|
|
- // ))
|
|
|
- // : null}
|
|
|
- // </ul>
|
|
|
- // );
|
|
|
-
|
|
|
return (
|
|
|
- <div onClick={e => toggle()} ref={wrapperRef}>
|
|
|
+ <div ref={wrapperRef}>
|
|
|
<span className="label">{scope ? scope.name : '-'}</span>
|
|
|
<span className="fa fa-caret-down"></span>
|
|
|
- {/* {toggleState ? List : null} */}
|
|
|
</div>
|
|
|
);
|
|
|
};
|