-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add Rename context menu (#37116)
- Loading branch information
Showing
19 changed files
with
234 additions
and
83 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
7 changes: 7 additions & 0 deletions
7
...lient/packages/design-system/ads/src/__assets__/icons/ads/input-cursor-move.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
30 changes: 30 additions & 0 deletions
30
app/client/src/IDE/Components/EditableName/RenameMenuItem.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,30 @@ | ||
import React, { useCallback } from "react"; | ||
import { MenuItem } from "@appsmith/ads"; | ||
import { useDispatch } from "react-redux"; | ||
import { setRenameEntity } from "actions/ideActions"; | ||
|
||
interface Props { | ||
disabled?: boolean; | ||
entityId: string; | ||
} | ||
|
||
export const RenameMenuItem = ({ disabled, entityId }: Props) => { | ||
const dispatch = useDispatch(); | ||
|
||
const setRename = useCallback(() => { | ||
// We add a delay to avoid having the focus stuck in the menu trigger | ||
setTimeout(() => { | ||
dispatch(setRenameEntity(entityId)); | ||
}, 100); | ||
}, [dispatch, entityId]); | ||
|
||
return ( | ||
<MenuItem | ||
disabled={disabled} | ||
onSelect={setRename} | ||
startIcon="input-cursor-move" | ||
> | ||
Rename | ||
</MenuItem> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export { EditableName } from "./EditableName"; | ||
export { RenameMenuItem } from "./RenameMenuItem"; | ||
export { useIsRenaming } from "./useIsRenaming"; |
35 changes: 35 additions & 0 deletions
35
app/client/src/IDE/Components/EditableName/useIsRenaming.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,35 @@ | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { getIsRenaming } from "selectors/ideSelectors"; | ||
import { useCallback, useEffect, useState } from "react"; | ||
import { setRenameEntity } from "actions/ideActions"; | ||
|
||
export const useIsRenaming = (id: string) => { | ||
const dispatch = useDispatch(); | ||
const [isEditing, setIsEditing] = useState(false); | ||
|
||
const isEditingViaExternal = useSelector(getIsRenaming(id)); | ||
|
||
useEffect( | ||
function onExternalEditEvent() { | ||
if (isEditingViaExternal) { | ||
setIsEditing(true); | ||
} | ||
|
||
return () => { | ||
setIsEditing(false); | ||
}; | ||
}, | ||
[isEditingViaExternal], | ||
); | ||
|
||
const enterEditMode = useCallback(() => { | ||
setIsEditing(true); | ||
}, []); | ||
|
||
const exitEditMode = useCallback(() => { | ||
dispatch(setRenameEntity("")); | ||
setIsEditing(false); | ||
}, [dispatch]); | ||
|
||
return { isEditing, enterEditMode, exitEditMode }; | ||
}; |
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.