Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions workspace/src/app/store/ducks/common/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ export interface IPluginDetails {
pluginType?: PluginType;
markdownDocumentation?: string;
autoConfigurable?: boolean;
relatedPlugins?: RelatedPlugin[];
}

export interface RelatedPlugin {
id: string;
description: string;
}

/** Overview version of an item description. */
Expand Down
11 changes: 8 additions & 3 deletions workspace/src/app/views/shared/MultiTagSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ interface IProps {
projectId?: string;
handleTagSelectionChange: (params: MultiSuggestFieldSelectionProps<Keyword>) => any;
initialTags?: Keyword[];
selectedTags?: Keyword[];
dataTestId?: string;
}

/** Multi selection component for project and task tags. */
export const MultiTagSelect = ({ projectId, handleTagSelectionChange, initialTags }: IProps) => {
export const MultiTagSelect = ({ projectId, handleTagSelectionChange, initialTags, selectedTags, dataTestId }: IProps) => {
const modalContext = React.useContext(CreateArtefactModalContext);
const { registerError: globalErrorHandler } = useErrorHandler();
const registerError = modalContext.registerModalError ? modalContext.registerModalError : globalErrorHandler;
Expand All @@ -41,11 +43,14 @@ export const MultiTagSelect = ({ projectId, handleTagSelectionChange, initialTag

return (
<MultiSuggestField<Keyword>
prePopulateWithItems={!!initialTags}
{...(selectedTags !== undefined
? { selectedItems: selectedTags }
: { prePopulateWithItems: !!initialTags })}
data-test-id={dataTestId}
openOnKeyDown
itemId={(keyword) => keyword.uri}
itemLabel={(keyword) => keyword.label}
items={initialTags ?? []}
items={selectedTags ?? initialTags ?? []}
onSelection={handleTagSelectionChange}
runOnQueryChange={handleTagQueryChange}
newItemCreationText={t("Metadata.addNewTag")}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ export function ProjectForm({ form, goBackOnEscape = () => {}, updateProjectAcl
};

const handleTagSelectionChange = React.useCallback(
(params: MultiSuggestFieldSelectionProps<Keyword>) => setValue("tags", params),
[],
(params: MultiSuggestFieldSelectionProps<Keyword>) => {
setValue(TAGS, params);
if ((params.newlySelected || params.newlyRemoved) && !escapeKeyDisabled.current) {
escapeKeyDisabled.current = true;
}
},
[setValue],
);

const CodeEditorMemoed = React.useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,14 @@ const ProjectSelection: React.FC<ProjectSelectionProps> = ({
isOpen={true}
canEscapeKeyClose={true}
onClose={onClose}
title={t("CreateModal.projectContext.resetModalTitle", "Project change warning")}
title={t("CreateModal.projectContext.resetModalTitle")}
actions={[
<Button text={t("CreateModal.projectContext.changeProjectButton", "Ok")} onClick={onSubmit} />,
<Button text={t("common.action.cancel", "Cancel")} onClick={onClose} />,
<Button text={t("CreateModal.projectContext.changeProjectButton")} onClick={onSubmit} />,
<Button text={t("common.action.cancel")} onClick={onClose} />,
]}
>
<p>
{t(
"CreateModal.projectContext.configResetInfo",
"All settings except title/description are going to be reset."
)}
{t("CreateModal.projectContext.configResetInfo")}
</p>
</AlertDialog>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ const extractDefaultValues = (pluginDetails: IPluginDetails): Map<string, string
return m;
};

const serializeTagSelection = (selection?: MultiSuggestFieldSelectionProps<Keyword>): string =>
JSON.stringify({
createdItems: (selection?.createdItems ?? []).map((tag) => tag.uri).sort(),
selectedItems: (selection?.selectedItems ?? []).map((tag) => tag.uri).sort(),
});

/** The task creation/update form. */
export function TaskForm({
form,
Expand Down Expand Up @@ -172,6 +178,7 @@ export function TaskForm({
const [t] = useTranslation();
const parameterLabels = React.useRef(new Map<string, string>());
const { label, description } = form.watch([LABEL, DESCRIPTION]);
const tagSelection = form.watch(TAGS) as MultiSuggestFieldSelectionProps<Keyword> | undefined;
const dataPreviewPlugin = pluginRegistry.pluginReactComponent<DataPreviewProps>(SUPPORTED_PLUGINS.DATA_PREVIEW);
const escapeKeyDisabled = React.useRef(false);

Expand Down Expand Up @@ -440,8 +447,19 @@ export function TaskForm({
);

const handleTagSelectionChange = React.useCallback(
(params: MultiSuggestFieldSelectionProps<Keyword>) => setValue(TAGS, params),
[],
(params: MultiSuggestFieldSelectionProps<Keyword>) => {
const oldValue = getValues()[TAGS] as MultiSuggestFieldSelectionProps<Keyword> | undefined;
if (params.newlySelected || params.newlyRemoved) {
setValue(TAGS, params);
detectChange(TAGS, serializeTagSelection(params), serializeTagSelection(oldValue));
if (!escapeKeyDisabled.current) {
escapeKeyDisabled.current = true;
}
} else if (!oldValue) {
setValue(TAGS, params);
}
},
[detectChange, getValues, setValue],
);
const preConfiguredFileAndLabel =
newTaskPreConfiguration?.preConfiguredParameterValues?.file && newTaskPreConfiguration?.metaData?.label;
Expand Down Expand Up @@ -538,8 +556,10 @@ export function TaskForm({
label={t("form.field.tags")}
inputElementFactory={() => (
<MultiTagSelect
dataTestId="task-tags-select"
projectId={projectId}
handleTagSelectionChange={handleTagSelectionChange}
selectedTags={tagSelection?.selectedItems}
/>
)}
/>
Expand Down
Loading
Loading