feat(actions): simplify action corner api through the toolbarService (#5033)
This commit is contained in:
1 parent
f71b88e639
commit
7c15bb8901
246 files changed
+7930
-4270
No files matched your search
@@ -8,12 +8,12 @@ import { useToolbar } from '@ohif/core/src/hooks/useToolbar';
|
||||
* @param props - Component props
|
||||
* @returns Component
|
||||
*/
|
||||
export function ToolBoxButtonGroupWrapper({ groupId, buttonSection, ...props }) {
|
||||
export function ToolBoxButtonGroupWrapper({ buttonSection, id }) {
|
||||
const { onInteraction, toolbarButtons } = useToolbar({
|
||||
buttonSection,
|
||||
});
|
||||
|
||||
if (!groupId) {
|
||||
if (!buttonSection) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ export function ToolBoxButtonGroupWrapper({ groupId, buttonSection, ...props })
|
||||
onInteraction={event => {
|
||||
onInteraction?.({
|
||||
event,
|
||||
groupId,
|
||||
id,
|
||||
commands: item.commands,
|
||||
itemId: item.id,
|
||||
item,
|
||||
|
||||
@@ -10,13 +10,9 @@ import {
|
||||
import { useToolbar } from '@ohif/core/src';
|
||||
|
||||
interface ToolButtonListWrapperProps {
|
||||
groupId: string;
|
||||
buttonSection: string;
|
||||
onInteraction?: (details: {
|
||||
groupId: string;
|
||||
itemId: string;
|
||||
commands?: Record<string, unknown>;
|
||||
}) => void;
|
||||
onInteraction?: (details: { itemId: string; commands?: Record<string, unknown> }) => void;
|
||||
id: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -25,10 +21,7 @@ interface ToolButtonListWrapperProps {
|
||||
* @returns Component
|
||||
* // test
|
||||
*/
|
||||
export default function ToolButtonListWrapper({
|
||||
groupId,
|
||||
buttonSection,
|
||||
}: ToolButtonListWrapperProps) {
|
||||
export default function ToolButtonListWrapper({ buttonSection, id }: ToolButtonListWrapperProps) {
|
||||
const { onInteraction, toolbarButtons } = useToolbar({
|
||||
buttonSection,
|
||||
});
|
||||
@@ -47,21 +40,21 @@ export default function ToolButtonListWrapper({
|
||||
<ToolButtonList>
|
||||
<ToolButtonListDefault>
|
||||
<div
|
||||
data-cy={`${groupId}-split-button-primary`}
|
||||
data-cy={`${id}-split-button-primary`}
|
||||
data-tool={primary.id}
|
||||
data-active={primary.isActive}
|
||||
>
|
||||
<ToolButton
|
||||
{...primary}
|
||||
onInteraction={({ itemId }) =>
|
||||
onInteraction?.({ groupId, itemId, commands: primary.commands })
|
||||
onInteraction?.({ id, itemId, commands: primary.commands })
|
||||
}
|
||||
className={primary.className}
|
||||
/>
|
||||
</div>
|
||||
</ToolButtonListDefault>
|
||||
<ToolButtonListDivider className={primary.isActive ? 'opacity-0' : 'opacity-100'} />
|
||||
<div data-cy={`${groupId}-split-button-secondary`}>
|
||||
<div data-cy={`${id}-split-button-secondary`}>
|
||||
<ToolButtonListDropDown>
|
||||
{items.map(item => {
|
||||
return (
|
||||
@@ -71,9 +64,7 @@ export default function ToolButtonListWrapper({
|
||||
data-cy={item.id}
|
||||
data-tool={item.id}
|
||||
data-active={item.isActive}
|
||||
onSelect={() =>
|
||||
onInteraction?.({ groupId, itemId: item.id, commands: item.commands })
|
||||
}
|
||||
onSelect={() => onInteraction?.({ id, itemId: item.id, commands: item.commands })}
|
||||
>
|
||||
<span className="pl-1">{item.label || item.tooltip || item.id}</span>
|
||||
</ToolButtonListItem>
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import React from 'react';
|
||||
import { useIconPresentation, Icons, Button } from '@ohif/ui-next';
|
||||
|
||||
export default function ToolButtonWrapper(props) {
|
||||
const { IconContainer, containerProps } = useIconPresentation();
|
||||
|
||||
const Icon = <Icons.ByName name={props.icon} />;
|
||||
|
||||
return (
|
||||
<div>
|
||||
{IconContainer ? (
|
||||
<IconContainer
|
||||
disabled={props.disabled}
|
||||
{...props}
|
||||
{...containerProps}
|
||||
>
|
||||
{Icon}
|
||||
</IconContainer>
|
||||
) : (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
disabled={props.disabled}
|
||||
>
|
||||
{Icon}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export { ToolButtonWrapper };
|
||||
@@ -0,0 +1,41 @@
|
||||
import React from 'react';
|
||||
import { useToolbar, ButtonLocation } from '@ohif/core';
|
||||
|
||||
interface ToolRowWrapperProps {
|
||||
buttonSection: string;
|
||||
className?: string;
|
||||
show?: boolean;
|
||||
}
|
||||
|
||||
function ToolRowWrapper({ buttonSection, className = '', show = true }: ToolRowWrapperProps) {
|
||||
const { onInteraction, toolbarButtons } = useToolbar({
|
||||
buttonSection,
|
||||
});
|
||||
|
||||
// No need for debugger statement
|
||||
if (!toolbarButtons?.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`space-x-1} flex flex-row items-center ${className}`}>
|
||||
{toolbarButtons.map((button, index) => {
|
||||
const { id, Component, componentProps } = button;
|
||||
return (
|
||||
<div
|
||||
key={id || index}
|
||||
className="flex-shrink-0"
|
||||
>
|
||||
<Component
|
||||
{...componentProps}
|
||||
onInteraction={onInteraction}
|
||||
location={componentProps.location || buttonSection}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default ToolRowWrapper;
|
||||
@@ -1,9 +1,22 @@
|
||||
import React from 'react';
|
||||
import { useToolbar } from '@ohif/core';
|
||||
|
||||
export function Toolbar({ servicesManager, buttonSection = 'primary' }) {
|
||||
const { toolbarButtons, onInteraction } = useToolbar({
|
||||
servicesManager,
|
||||
interface ToolbarProps {
|
||||
buttonSection?: string;
|
||||
viewportId?: string;
|
||||
location?: number;
|
||||
}
|
||||
|
||||
export function Toolbar({ buttonSection = 'primary', viewportId, location }: ToolbarProps) {
|
||||
const {
|
||||
toolbarButtons,
|
||||
onInteraction,
|
||||
isItemOpen,
|
||||
isItemLocked,
|
||||
openItem,
|
||||
closeItem,
|
||||
toggleLock,
|
||||
} = useToolbar({
|
||||
buttonSection,
|
||||
});
|
||||
|
||||
@@ -19,13 +32,31 @@ export function Toolbar({ servicesManager, buttonSection = 'primary' }) {
|
||||
}
|
||||
|
||||
const { id, Component, componentProps } = toolDef;
|
||||
|
||||
// Enhanced props with state and actions - respecting viewport specificity
|
||||
const enhancedProps = {
|
||||
...componentProps,
|
||||
isOpen: isItemOpen(id, viewportId),
|
||||
isLocked: isItemLocked(id, viewportId),
|
||||
onOpen: () => openItem(id, viewportId),
|
||||
onClose: () => closeItem(id, viewportId),
|
||||
onToggleLock: () => toggleLock(id, viewportId),
|
||||
viewportId,
|
||||
};
|
||||
|
||||
const tool = (
|
||||
<Component
|
||||
key={id}
|
||||
id={id}
|
||||
onInteraction={onInteraction}
|
||||
servicesManager={servicesManager}
|
||||
{...componentProps}
|
||||
location={location}
|
||||
onInteraction={args => {
|
||||
onInteraction({
|
||||
...args,
|
||||
itemId: id,
|
||||
viewportId,
|
||||
});
|
||||
}}
|
||||
{...enhancedProps}
|
||||
/>
|
||||
);
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import { ToolbarButton, ButtonGroup } from '@ohif/ui';
|
||||
|
||||
function ToolbarButtonGroupWithServices({ groupId, items, onInteraction, size }) {
|
||||
const getSplitButtonItems = useCallback(
|
||||
items =>
|
||||
items.map((item, index) => (
|
||||
<ToolbarButton
|
||||
key={item.id}
|
||||
icon={item.icon}
|
||||
label={item.label}
|
||||
disabled={item.disabled}
|
||||
className={item.className}
|
||||
disabledText={item.disabledText}
|
||||
id={item.id}
|
||||
size={size}
|
||||
onClick={() => {
|
||||
onInteraction({
|
||||
groupId,
|
||||
itemId: item.id,
|
||||
commands: item.commands,
|
||||
item,
|
||||
});
|
||||
}}
|
||||
// Note: this is necessary since tooltip will add
|
||||
// default styles to the tooltip container which
|
||||
// we don't want for groups
|
||||
toolTipClassName=""
|
||||
/>
|
||||
)),
|
||||
[onInteraction, groupId]
|
||||
);
|
||||
|
||||
return <ButtonGroup>{getSplitButtonItems(items)}</ButtonGroup>;
|
||||
}
|
||||
|
||||
export default ToolbarButtonGroupWithServices;
|
||||
@@ -1,89 +0,0 @@
|
||||
import { SplitButton, ToolbarButton } from '@ohif/ui';
|
||||
import React, { useCallback } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
function ToolbarSplitButtonWithServices({
|
||||
groupId,
|
||||
primary,
|
||||
secondary,
|
||||
items,
|
||||
renderer,
|
||||
onInteraction,
|
||||
servicesManager,
|
||||
}: withAppTypes) {
|
||||
const { toolbarService } = servicesManager?.services;
|
||||
|
||||
/* Bubbles up individual item clicks */
|
||||
const getSplitButtonItems = useCallback(
|
||||
items =>
|
||||
items.map((item, index) => ({
|
||||
...item,
|
||||
index,
|
||||
onClick: () => {
|
||||
onInteraction({
|
||||
groupId,
|
||||
itemId: item.id,
|
||||
item,
|
||||
});
|
||||
},
|
||||
})),
|
||||
[groupId, onInteraction]
|
||||
);
|
||||
|
||||
const PrimaryButtonComponent =
|
||||
toolbarService?.getButtonComponentForUIType(primary.uiType) ?? ToolbarButton;
|
||||
|
||||
const listItemRenderer = renderer;
|
||||
|
||||
return (
|
||||
<SplitButton
|
||||
primary={primary}
|
||||
secondary={secondary}
|
||||
items={getSplitButtonItems(items)}
|
||||
groupId={groupId}
|
||||
renderer={listItemRenderer}
|
||||
onInteraction={onInteraction}
|
||||
Component={props => (
|
||||
<PrimaryButtonComponent
|
||||
{...props}
|
||||
servicesManager={servicesManager}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
ToolbarSplitButtonWithServices.propTypes = {
|
||||
groupId: PropTypes.string,
|
||||
primary: PropTypes.shape({
|
||||
id: PropTypes.string.isRequired,
|
||||
uiType: PropTypes.string,
|
||||
}),
|
||||
secondary: PropTypes.shape({
|
||||
id: PropTypes.string,
|
||||
icon: PropTypes.string.isRequired,
|
||||
label: PropTypes.string,
|
||||
tooltip: PropTypes.string.isRequired,
|
||||
disabled: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
}),
|
||||
items: PropTypes.arrayOf(
|
||||
PropTypes.shape({
|
||||
id: PropTypes.string.isRequired,
|
||||
icon: PropTypes.string,
|
||||
label: PropTypes.string,
|
||||
tooltip: PropTypes.string,
|
||||
disabled: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
})
|
||||
),
|
||||
renderer: PropTypes.func,
|
||||
onInteraction: PropTypes.func.isRequired,
|
||||
servicesManager: PropTypes.shape({
|
||||
services: PropTypes.shape({
|
||||
toolbarService: PropTypes.object,
|
||||
}),
|
||||
}),
|
||||
};
|
||||
|
||||
export default ToolbarSplitButtonWithServices;
|
||||
@@ -0,0 +1,7 @@
|
||||
export * from './Toolbar';
|
||||
export * from './ToolButtonWrapper';
|
||||
export * from './ToolButtonListWrapper';
|
||||
export * from './ToolRowWrapper';
|
||||
export * from './ToolBoxWrapper';
|
||||
export * from './ToolbarDivider';
|
||||
export * from './ToolbarLayoutSelector';
|
||||
Reference in new issue
Block a user