fix: Fixes inability to use duplicate names across multiple actions in different pages (#9360)

* Fixes inability to use duplicate names across multiple actions in different pages

* adds comments for better understanding and readability

Co-authored-by: Arpit Mohan <arpit@appsmith.com>
This commit is contained in:
Ayangade Adeoluwa 2021-12-16 13:40:53 +01:00 committed by GitHub
parent 7af727651d
commit e6bc975889
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 4 deletions

View File

@ -3,7 +3,7 @@ import EditableText, {
} from "components/editorComponents/EditableText";
import TooltipComponent from "components/ads/Tooltip";
import { Colors } from "constants/Colors";
import { get } from "lodash";
import _, { get } from "lodash";
import React, {
forwardRef,
@ -149,7 +149,9 @@ export const EntityName = forwardRef(
const dispatch = useDispatch();
const existingActionNames: string[] = useSelector(getExistingActionNames);
const existingActionNames: string[] | [] = _.compact(
useSelector(getExistingActionNames),
);
const existingJSCollectionNames: string[] = useSelector(
getExistingJSCollectionNames,

View File

@ -494,8 +494,40 @@ export const getExistingWidgetNames = createSelector(
export const getExistingActionNames = createSelector(
(state: AppState) => state.entities.actions,
(actions) =>
actions.map((action: { config: { name: string } }) => action.config.name),
getCurrentPageId,
// editingEntityName is actually an id and not a name per say and it points to the id of an action being edited through the explorer.
(state: AppState) => state.ui.explorer.entity.editingEntityName,
(actions, currentPageId, editingEntityId) => {
// get the current action being edited
const editingAction =
editingEntityId &&
actions.filter(
(action: { config: { id: string } }) =>
action.config.id === editingEntityId,
);
// if the current action being edited is on the same page, filter the actions on the page and return their names.
if (editingAction && editingAction[0].config.pageId === currentPageId) {
return actions.map(
(actionItem: { config: { name: string; pageId: string } }) => {
if (actionItem.config.pageId === currentPageId) {
return actionItem.config.name;
}
return undefined;
},
);
} else {
// if current action being edited is on another page, filter the actions not on the page and return their names.
return actions.map(
(actionItem: { config: { name: string; pageId: string } }) => {
if (actionItem.config.pageId !== currentPageId) {
return actionItem.config.name;
}
return undefined;
},
);
}
},
);
export const getExistingJSCollectionNames = createSelector(