forked from opensearch-project/index-management
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support edit transformation name (opensearch-project#27)
Support edit transformation name
- Loading branch information
Showing
10 changed files
with
312 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...reateTransform/components/PreviewOptions/Panels/EditTransformPanel/EditTransformPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import React, { useState } from "react"; | ||
import { EuiButton, EuiFieldText, EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiPanel, EuiSpacer, EuiText } from "@elastic/eui"; | ||
import { TransformAggItem } from "../../../../../../../models/interfaces"; | ||
|
||
interface EditTransformPanelProps { | ||
name: string; | ||
aggList: TransformAggItem[]; | ||
onEditTransformation: (oldName: string, newName: string) => void; | ||
closePopover: () => void; | ||
} | ||
|
||
export default function EditTransformPanel({ name, aggList, onEditTransformation, closePopover }: EditTransformPanelProps) { | ||
const [transformName, setTransformName] = useState(name); | ||
const [transformNameError, setTransformNameError] = useState(""); | ||
|
||
// Function to check if newName is already used | ||
const validateName = (newName: string) => { | ||
const isDuplicate = aggList.some((item) => { | ||
return item.name === newName; | ||
}); | ||
|
||
if (name !== newName && isDuplicate) setTransformNameError(`Transformation with name "${newName}" already exists`); | ||
else setTransformNameError(""); | ||
}; | ||
|
||
return ( | ||
<EuiPanel> | ||
<EuiFormRow label="Transformation name" isInvalid={transformNameError !== ""} error={transformNameError}> | ||
<EuiFieldText | ||
value={transformName} | ||
isInvalid={transformNameError !== ""} | ||
onChange={(e) => { | ||
validateName(e.target.value); | ||
setTransformName(e.target.value); | ||
}} | ||
/> | ||
</EuiFormRow> | ||
<EuiSpacer size="s" /> | ||
<EuiFlexGroup justifyContent={"flexEnd"} gutterSize={"m"}> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton fullWidth={false} onClick={() => closePopover()} style={{ minWidth: 84 }}> | ||
Cancel | ||
</EuiButton> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={false}> | ||
<EuiButton | ||
fill | ||
fullWidth={false} | ||
disabled={transformNameError !== ""} | ||
onClick={() => { | ||
// Update transform name if new value specified | ||
if (name !== transformName) onEditTransformation(name, transformName); | ||
closePopover(); | ||
}} | ||
style={{ minWidth: 55 }} | ||
> | ||
OK | ||
</EuiButton> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiPanel> | ||
); | ||
} |
14 changes: 14 additions & 0 deletions
14
public/pages/CreateTransform/components/PreviewOptions/Panels/EditTransformPanel/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
import EditTransformPanel from "./EditTransformPanel"; | ||
|
||
export default EditTransformPanel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.