2020-09-15 03:18:46 +02:00
|
|
|
import React from 'react';
|
2025-02-28 21:17:55 +01:00
|
|
|
import { LabellingFlow } from '@ohif/ui';
|
|
|
|
|
import { InputDialog } from '@ohif/ui-next';
|
|
|
|
|
|
|
|
|
|
interface InputDialogDefaultProps {
|
|
|
|
|
hide: () => void;
|
|
|
|
|
onSave: (value: string) => void;
|
|
|
|
|
placeholder: string;
|
|
|
|
|
defaultValue: string;
|
|
|
|
|
submitOnEnter: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function InputDialogDefault({
|
|
|
|
|
hide,
|
|
|
|
|
onSave,
|
|
|
|
|
placeholder = 'Enter value',
|
|
|
|
|
defaultValue = '',
|
|
|
|
|
submitOnEnter,
|
|
|
|
|
}: InputDialogDefaultProps) {
|
|
|
|
|
return (
|
|
|
|
|
<InputDialog
|
|
|
|
|
submitOnEnter={submitOnEnter}
|
|
|
|
|
defaultValue={defaultValue}
|
|
|
|
|
>
|
|
|
|
|
<InputDialog.Field>
|
|
|
|
|
<InputDialog.Input placeholder={placeholder} />
|
|
|
|
|
</InputDialog.Field>
|
|
|
|
|
<InputDialog.Actions>
|
|
|
|
|
<InputDialog.ActionsSecondary onClick={hide}>Cancel</InputDialog.ActionsSecondary>
|
|
|
|
|
<InputDialog.ActionsPrimary
|
|
|
|
|
onClick={value => {
|
|
|
|
|
onSave(value);
|
|
|
|
|
hide();
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Save
|
|
|
|
|
</InputDialog.ActionsPrimary>
|
|
|
|
|
</InputDialog.Actions>
|
|
|
|
|
</InputDialog>
|
|
|
|
|
);
|
|
|
|
|
}
|
2020-09-15 03:18:46 +02:00
|
|
|
|
|
|
|
|
/**
|
2025-02-28 21:17:55 +01:00
|
|
|
* Shows an input dialog for entering text with customizable options
|
|
|
|
|
* @param uiDialogService - Service for showing UI dialogs
|
|
|
|
|
* @param onSave - Callback function called when save button is clicked with entered value
|
|
|
|
|
* @param defaultValue - Initial value to show in input field
|
|
|
|
|
* @param title - Title text to show in dialog header
|
|
|
|
|
* @param placeholder - Placeholder text for input field
|
|
|
|
|
* @param submitOnEnter - Whether to submit dialog when Enter key is pressed
|
2020-09-15 03:18:46 +02:00
|
|
|
*/
|
2025-02-28 21:17:55 +01:00
|
|
|
export async function callInputDialog({
|
2023-02-10 22:46:09 +01:00
|
|
|
uiDialogService,
|
2025-02-28 21:17:55 +01:00
|
|
|
defaultValue = '',
|
|
|
|
|
title = 'Annotation',
|
|
|
|
|
placeholder = '',
|
|
|
|
|
submitOnEnter = true,
|
|
|
|
|
}: {
|
|
|
|
|
uiDialogService: AppTypes.UIDialogService;
|
2025-03-07 04:19:47 +01:00
|
|
|
defaultValue?: string;
|
|
|
|
|
title?: string;
|
|
|
|
|
placeholder?: string;
|
|
|
|
|
submitOnEnter?: boolean;
|
2025-02-28 21:17:55 +01:00
|
|
|
}) {
|
2023-02-23 03:01:36 +01:00
|
|
|
const dialogId = 'dialog-enter-annotation';
|
|
|
|
|
|
2025-02-28 21:17:55 +01:00
|
|
|
const value = await new Promise<string>(resolve => {
|
|
|
|
|
uiDialogService.show({
|
2020-09-15 03:18:46 +02:00
|
|
|
id: dialogId,
|
2025-02-28 21:17:55 +01:00
|
|
|
content: InputDialogDefault,
|
|
|
|
|
title: title,
|
|
|
|
|
shouldCloseOnEsc: true,
|
2020-09-15 03:18:46 +02:00
|
|
|
contentProps: {
|
2025-02-28 21:17:55 +01:00
|
|
|
onSave: value => {
|
|
|
|
|
resolve(value);
|
2020-09-15 03:18:46 +02:00
|
|
|
},
|
2025-02-28 21:17:55 +01:00
|
|
|
placeholder,
|
|
|
|
|
defaultValue,
|
|
|
|
|
submitOnEnter,
|
2020-09-15 03:18:46 +02:00
|
|
|
},
|
|
|
|
|
});
|
2024-04-05 04:42:48 +02:00
|
|
|
});
|
2025-02-28 21:17:55 +01:00
|
|
|
|
|
|
|
|
return value;
|
2024-04-05 04:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
2025-02-28 21:17:55 +01:00
|
|
|
export async function callInputDialogAutoComplete({
|
2025-02-03 15:18:00 +01:00
|
|
|
measurement,
|
|
|
|
|
uiDialogService,
|
|
|
|
|
labelConfig,
|
2025-02-28 21:17:55 +01:00
|
|
|
renderContent = LabellingFlow,
|
|
|
|
|
}) {
|
2024-04-05 04:42:48 +02:00
|
|
|
const exclusive = labelConfig ? labelConfig.exclusive : false;
|
|
|
|
|
const dropDownItems = labelConfig ? labelConfig.items : [];
|
2025-02-28 21:17:55 +01:00
|
|
|
|
|
|
|
|
const value = await new Promise<Map<string, string>>((resolve, reject) => {
|
2025-03-20 14:22:45 +01:00
|
|
|
const labellingDoneCallback = newValue => {
|
2025-02-28 21:17:55 +01:00
|
|
|
uiDialogService.hide('select-annotation');
|
2025-03-20 14:22:45 +01:00
|
|
|
if (measurement && typeof newValue === 'string') {
|
|
|
|
|
measurement.label = newValue;
|
2024-04-05 04:42:48 +02:00
|
|
|
}
|
2025-03-20 14:22:45 +01:00
|
|
|
resolve(newValue);
|
2024-04-05 04:42:48 +02:00
|
|
|
};
|
|
|
|
|
|
2025-02-28 21:17:55 +01:00
|
|
|
uiDialogService.show({
|
2024-04-05 04:42:48 +02:00
|
|
|
id: 'select-annotation',
|
2025-02-28 21:17:55 +01:00
|
|
|
title: 'Annotation',
|
2025-02-03 15:18:00 +01:00
|
|
|
content: renderContent,
|
2024-04-05 04:42:48 +02:00
|
|
|
contentProps: {
|
|
|
|
|
labellingDoneCallback: labellingDoneCallback,
|
|
|
|
|
measurementData: measurement,
|
|
|
|
|
componentClassName: {},
|
|
|
|
|
labelData: dropDownItems,
|
|
|
|
|
exclusive: exclusive,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-02-28 21:17:55 +01:00
|
|
|
|
|
|
|
|
return value;
|
2024-04-05 04:42:48 +02:00
|
|
|
}
|
|
|
|
|
|
2020-09-15 03:18:46 +02:00
|
|
|
export default callInputDialog;
|