PromucFlow_constructor/app/client/src/ce/entities/IDE/utils.ts
Ankita Kinger 9a315eabdc
chore: Updating plugin action name editor component to use ADS text component (#36960)
## Description

Updating plugin action name editor component to use ADS text component
instead of EditableText from blueprint. Also, adding permission checks
for editable tabs to not allow the name edits when the user doesn't have
the permission.

Fixes [#36793](https://github.com/appsmithorg/appsmith/issues/36793)

## Automation

/ok-to-test tags="@tag.All"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/11402567877>
> Commit: 0b695e8837a4c510df51ff3e7fcb799ed50a3666
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=11402567877&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Fri, 18 Oct 2024 12:36:26 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced conditional editing functionality in the FileTab component
based on user permissions.
- Enhanced the PluginActionNameEditor with real-time validation and
improved user interaction.
- Added user permissions information to entity items and selectors for
better access control.
- Integrated new functionality for saving entity names and managing
editable tab permissions.
- Expanded the EditorTabs component to include contextual entity
information for each tab.

- **Bug Fixes**
- Simplified the ActionNameEditor by removing unnecessary feature flag
checks.

- **Documentation**
- Updated interfaces and components to improve clarity and
functionality.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-10-18 19:07:50 +05:30

76 lines
1.9 KiB
TypeScript

import type { IDEType, EditorState } from "ee/entities/IDE/constants";
import { IDE_TYPE, IDEBasePaths } from "ee/entities/IDE/constants";
import { matchPath } from "react-router";
import { identifyEntityFromPath } from "navigation/FocusEntity";
import {
BUILDER_CUSTOM_PATH,
BUILDER_PATH,
BUILDER_PATH_DEPRECATED,
} from "ee/constants/routes/appRoutes";
import { saveActionName } from "actions/pluginActionActions";
import { saveJSObjectName } from "actions/jsActionActions";
import { EditorEntityTab, type EntityItem } from "ee/entities/IDE/constants";
import { getHasManageActionPermission } from "ee/utils/BusinessFeatures/permissionPageHelpers";
export interface SaveEntityName {
params: {
name: string;
id: string;
};
segment: EditorEntityTab;
entity?: EntityItem;
}
export const EDITOR_PATHS = [
BUILDER_CUSTOM_PATH,
BUILDER_PATH,
BUILDER_PATH_DEPRECATED,
];
export function getCurrentAppState(currentUrl: string): EditorState {
const entityInfo = identifyEntityFromPath(currentUrl);
return entityInfo.appState;
}
export function getIDETypeByUrl(path: string): IDEType {
for (const type in IDEBasePaths) {
const basePaths = IDEBasePaths[type as IDEType];
if (matchPath(path, { path: basePaths })) {
return type as IDEType;
}
}
return IDE_TYPE.None;
}
export function getBaseUrlsForIDEType(type: IDEType): string[] {
return IDEBasePaths[type];
}
export const saveEntityName = ({ params, segment }: SaveEntityName) => {
let saveNameAction = saveActionName(params);
if (EditorEntityTab.JS === segment) {
saveNameAction = saveJSObjectName(params);
}
return saveNameAction;
};
export interface EditableTabPermissions {
isFeatureEnabled: boolean;
entity?: EntityItem;
}
export const getEditableTabPermissions = ({
entity,
isFeatureEnabled,
}: EditableTabPermissions) => {
return getHasManageActionPermission(
isFeatureEnabled,
entity?.userPermissions || [],
);
};