mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
added button on hover for exposing fields to linear workflow ui
This commit is contained in:
parent
6c5f743e2b
commit
2ce70b4457
@ -0,0 +1,74 @@
|
|||||||
|
import { IconButton } from '@invoke-ai/ui-library';
|
||||||
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
|
import { useAppDispatch, useAppSelector } from 'app/store/storeHooks';
|
||||||
|
import {
|
||||||
|
selectWorkflowSlice,
|
||||||
|
workflowExposedFieldAdded,
|
||||||
|
workflowExposedFieldRemoved,
|
||||||
|
} from 'features/nodes/store/workflowSlice';
|
||||||
|
import { memo, useCallback, useMemo } from 'react';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { PiMinusBold, PiPlusBold } from 'react-icons/pi';
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
nodeId: string;
|
||||||
|
fieldName: string;
|
||||||
|
isHovered: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
const FieldLinearViewToggle = ({ nodeId, fieldName, isHovered }: Props) => {
|
||||||
|
const dispatch = useAppDispatch();
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const selectIsExposed = useMemo(
|
||||||
|
() =>
|
||||||
|
createSelector(selectWorkflowSlice, (workflow) => {
|
||||||
|
return Boolean(workflow.exposedFields.find((f) => f.nodeId === nodeId && f.fieldName === fieldName));
|
||||||
|
}),
|
||||||
|
[fieldName, nodeId]
|
||||||
|
);
|
||||||
|
|
||||||
|
const isExposed = useAppSelector(selectIsExposed);
|
||||||
|
|
||||||
|
const handleExposeField = useCallback(() => {
|
||||||
|
dispatch(workflowExposedFieldAdded({ nodeId, fieldName }));
|
||||||
|
}, [dispatch, fieldName, nodeId]);
|
||||||
|
|
||||||
|
const handleUnexposeField = useCallback(() => {
|
||||||
|
dispatch(workflowExposedFieldRemoved({ nodeId, fieldName }));
|
||||||
|
}, [dispatch, fieldName, nodeId]);
|
||||||
|
|
||||||
|
const ToggleButton = useMemo(() => {
|
||||||
|
if (!isHovered) {
|
||||||
|
return null;
|
||||||
|
} else if (!isExposed) {
|
||||||
|
return (
|
||||||
|
<IconButton
|
||||||
|
mx="2"
|
||||||
|
tooltip={t('nodes.addLinearView')}
|
||||||
|
aria-label={t('nodes.addLinearView')}
|
||||||
|
icon={<PiPlusBold />}
|
||||||
|
onClick={handleExposeField}
|
||||||
|
pointerEvents="auto"
|
||||||
|
size="xs"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
} else if (isExposed) {
|
||||||
|
return (
|
||||||
|
<IconButton
|
||||||
|
mx="2"
|
||||||
|
tooltip={t('nodes.removeLinearView')}
|
||||||
|
aria-label={t('nodes.removeLinearView')}
|
||||||
|
icon={<PiMinusBold />}
|
||||||
|
onClick={handleUnexposeField}
|
||||||
|
pointerEvents="auto"
|
||||||
|
size="xs"
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}, [isHovered, handleExposeField, handleUnexposeField, isExposed, t]);
|
||||||
|
|
||||||
|
return ToggleButton;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default memo(FieldLinearViewToggle);
|
@ -4,12 +4,13 @@ import { useDoesInputHaveValue } from 'features/nodes/hooks/useDoesInputHaveValu
|
|||||||
import { useFieldInputInstance } from 'features/nodes/hooks/useFieldInputInstance';
|
import { useFieldInputInstance } from 'features/nodes/hooks/useFieldInputInstance';
|
||||||
import { useFieldInputTemplate } from 'features/nodes/hooks/useFieldInputTemplate';
|
import { useFieldInputTemplate } from 'features/nodes/hooks/useFieldInputTemplate';
|
||||||
import type { PropsWithChildren } from 'react';
|
import type { PropsWithChildren } from 'react';
|
||||||
import { memo, useMemo } from 'react';
|
import { memo, useCallback, useMemo, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
import EditableFieldTitle from './EditableFieldTitle';
|
import EditableFieldTitle from './EditableFieldTitle';
|
||||||
import FieldContextMenu from './FieldContextMenu';
|
import FieldContextMenu from './FieldContextMenu';
|
||||||
import FieldHandle from './FieldHandle';
|
import FieldHandle from './FieldHandle';
|
||||||
|
import FieldLinearViewToggle from './FieldLinearViewToggle';
|
||||||
import InputFieldRenderer from './InputFieldRenderer';
|
import InputFieldRenderer from './InputFieldRenderer';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@ -22,6 +23,7 @@ const InputField = ({ nodeId, fieldName }: Props) => {
|
|||||||
const fieldTemplate = useFieldInputTemplate(nodeId, fieldName);
|
const fieldTemplate = useFieldInputTemplate(nodeId, fieldName);
|
||||||
const fieldInstance = useFieldInputInstance(nodeId, fieldName);
|
const fieldInstance = useFieldInputInstance(nodeId, fieldName);
|
||||||
const doesFieldHaveValue = useDoesInputHaveValue(nodeId, fieldName);
|
const doesFieldHaveValue = useDoesInputHaveValue(nodeId, fieldName);
|
||||||
|
const [isHovered, setIsHovered] = useState(false);
|
||||||
|
|
||||||
const { isConnected, isConnectionInProgress, isConnectionStartField, connectionError, shouldDim } =
|
const { isConnected, isConnectionInProgress, isConnectionStartField, connectionError, shouldDim } =
|
||||||
useConnectionState({ nodeId, fieldName, kind: 'input' });
|
useConnectionState({ nodeId, fieldName, kind: 'input' });
|
||||||
@ -46,6 +48,14 @@ const InputField = ({ nodeId, fieldName }: Props) => {
|
|||||||
return false;
|
return false;
|
||||||
}, [fieldTemplate, isConnected, doesFieldHaveValue]);
|
}, [fieldTemplate, isConnected, doesFieldHaveValue]);
|
||||||
|
|
||||||
|
const handleMouseOver = useCallback(() => {
|
||||||
|
setIsHovered(true);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleMouseOut = useCallback(() => {
|
||||||
|
setIsHovered(false);
|
||||||
|
}, []);
|
||||||
|
|
||||||
if (!fieldTemplate || !fieldInstance) {
|
if (!fieldTemplate || !fieldInstance) {
|
||||||
return (
|
return (
|
||||||
<InputFieldWrapper shouldDim={shouldDim}>
|
<InputFieldWrapper shouldDim={shouldDim}>
|
||||||
@ -87,17 +97,20 @@ const InputField = ({ nodeId, fieldName }: Props) => {
|
|||||||
return (
|
return (
|
||||||
<InputFieldWrapper shouldDim={shouldDim}>
|
<InputFieldWrapper shouldDim={shouldDim}>
|
||||||
<FormControl isInvalid={isMissingInput} isDisabled={isConnected} orientation="vertical" px={2}>
|
<FormControl isInvalid={isMissingInput} isDisabled={isConnected} orientation="vertical" px={2}>
|
||||||
<Flex flexDir="column" w="full" gap={1}>
|
<Flex flexDir="column" w="full" gap={1} onMouseEnter={handleMouseOver} onMouseLeave={handleMouseOut}>
|
||||||
<FieldContextMenu nodeId={nodeId} fieldName={fieldName} kind="input">
|
<FieldContextMenu nodeId={nodeId} fieldName={fieldName} kind="input">
|
||||||
{(ref) => (
|
{(ref) => (
|
||||||
<EditableFieldTitle
|
<Flex>
|
||||||
ref={ref}
|
<EditableFieldTitle
|
||||||
nodeId={nodeId}
|
ref={ref}
|
||||||
fieldName={fieldName}
|
nodeId={nodeId}
|
||||||
kind="input"
|
fieldName={fieldName}
|
||||||
isMissingInput={isMissingInput}
|
kind="input"
|
||||||
withTooltip
|
isMissingInput={isMissingInput}
|
||||||
/>
|
withTooltip
|
||||||
|
/>
|
||||||
|
<FieldLinearViewToggle nodeId={nodeId} fieldName={fieldName} isHovered={isHovered} />
|
||||||
|
</Flex>
|
||||||
)}
|
)}
|
||||||
</FieldContextMenu>
|
</FieldContextMenu>
|
||||||
<InputFieldRenderer nodeId={nodeId} fieldName={fieldName} />
|
<InputFieldRenderer nodeId={nodeId} fieldName={fieldName} />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user