Skip to content

Commit

Permalink
removing duplicate hook
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitakinger committed Jan 17, 2025
1 parent 580638b commit 40ba4f9
Show file tree
Hide file tree
Showing 19 changed files with 48 additions and 110 deletions.
6 changes: 3 additions & 3 deletions app/client/src/ce/hooks/datasourceEditorHooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { getPagePermissions } from "selectors/editorSelectors";
import { getIsAnvilEnabledInCurrentApplication } from "layoutSystems/anvil/integrations/selectors";
import { isEnabledForPreviewData } from "utils/editorContextUtils";
import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
import { EditorNames } from "./";
import { getCurrentApplication } from "ee/selectors/applicationSelectors";
import { openGeneratePageModal } from "pages/Editor/GeneratePage/store/generatePageActions";
import { IDE_TYPE, type IDEType } from "ee/entities/IDE/constants";

export interface HeaderActionProps {
datasource: Datasource | ApiDatasourceForm | undefined;
Expand All @@ -33,7 +33,7 @@ export interface HeaderActionProps {
}

export const useHeaderActions = (
editorType: string,
ideType: IDEType,
{
datasource,
isPluginAuthorized,
Expand Down Expand Up @@ -72,7 +72,7 @@ export const useHeaderActions = (
? false
: !!isPluginAllowedToPreviewData;

if (editorType === EditorNames.APPLICATION) {
if (ideType === IDE_TYPE.App) {
const canCreateDatasourceActions = hasCreateDSActionPermissionInApp({
isEnabled: isFeatureEnabled,
dsPermissions: datasource?.userPermissions ?? [],
Expand Down
25 changes: 0 additions & 25 deletions app/client/src/ce/hooks/hooks.test.ts

This file was deleted.

35 changes: 0 additions & 35 deletions app/client/src/ce/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,4 @@
import {
BUILDER_BASE_PATH_DEPRECATED,
BUILDER_VIEWER_PATH_PREFIX,
} from "constants/routes";
import { useEffect, type RefObject } from "react";
import { matchPath } from "react-router";

export const EditorNames = {
APPLICATION: "app",
};

export interface EditorType {
[key: string]: string;
}

export const editorType: EditorType = {
[BUILDER_VIEWER_PATH_PREFIX]: EditorNames.APPLICATION,
[BUILDER_BASE_PATH_DEPRECATED]: EditorNames.APPLICATION,
};

// Utility function to get editor type based on path
// to be used in non react functions
export const getEditorType = (path: string) => {
const basePath = matchPath(path, {
path: [BUILDER_VIEWER_PATH_PREFIX, BUILDER_BASE_PATH_DEPRECATED],
});

return basePath
? editorType[basePath.path]
: editorType[BUILDER_VIEWER_PATH_PREFIX];
};

// custom hook to get editor type based on path
export const useEditorType = (path: string) => {
return getEditorType(path);
};

export function useOutsideClick<T extends HTMLElement>(
ref: RefObject<T>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { IDE_TYPE } from "ee/entities/IDE/constants";
import { builderURL } from "ee/RouteBuilder";
import {
RECONNECT_MISSING_DATASOURCE_CREDENTIALS_DESCRIPTION,
SKIP_TO_APPLICATION,
createMessage,
} from "ee/constants/messages";
import { EditorNames } from "ee/hooks";
import { getApplicationByIdFromWorkspaces } from "ee/selectors/applicationSelectors";
import { useSelector } from "react-redux";

Expand Down Expand Up @@ -36,7 +36,7 @@ function useReconnectModalData({ appId, pageId }: UseReconnectModalDataProps) {
editorURL,
editorId: appId,
parentEntityId: pageId,
editorType: EditorNames.APPLICATION,
ideType: IDE_TYPE.App,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { hasExecuteActionPermission as hasExecuteActionPermission_EE } from "ee/

import { hasAuditLogsReadPermission as hasAuditLogsReadPermission_CE } from "ce/utils/permissionHelpers";
import { hasAuditLogsReadPermission as hasAuditLogsReadPermission_EE } from "ee/utils/permissionHelpers";
import { EditorNames } from "ee/hooks";
import { IDE_TYPE, type IDEType } from "ee/entities/IDE/constants";

export const getHasCreateWorkspacePermission = (
isEnabled: boolean,
Expand Down Expand Up @@ -167,16 +167,16 @@ export const getHasAuditLogsReadPermission = (

export const hasCreateDSActionPermissionInApp = ({
dsPermissions,
editorType,
ideType,
isEnabled,
pagePermissions,
}: {
dsPermissions?: string[];
editorType?: string;
ideType?: IDEType;
isEnabled: boolean;
pagePermissions?: string[];
}) => {
return !editorType || editorType === EditorNames.APPLICATION
return !ideType || ideType === IDE_TYPE.App
? getHasCreateDatasourceActionPermission(isEnabled, dsPermissions) &&
getHasCreateActionPermission(isEnabled, pagePermissions)
: getHasCreateDatasourceActionPermission(isEnabled, dsPermissions);
Expand Down
4 changes: 3 additions & 1 deletion app/client/src/ce/utils/lintRulesHelpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type { IDEType } from "ee/entities/IDE/constants";

interface ContextType {
editorType: string;
ideType: IDEType;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions app/client/src/pages/Editor/DataSourceEditor/DSFormHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import {
} from "ee/utils/Environments";
import { getCurrentEnvironmentId } from "ee/selectors/environmentSelectors";
import type { PluginType } from "entities/Plugin";
import { useEditorType } from "ee/hooks";
import { useHistory } from "react-router";
import { useHeaderActions } from "ee/hooks/datasourceEditorHooks";
import { getIDETypeByUrl } from "ee/entities/IDE/utils";

export const ActionWrapper = styled.div`
display: flex;
Expand Down Expand Up @@ -117,7 +117,7 @@ export const DSFormHeader = (props: DSFormHeaderProps) => {
const [confirmDelete, setConfirmDelete] = useState(false);
const dispatch = useDispatch();
const history = useHistory();
const editorType = useEditorType(history.location.pathname);
const ideType = getIDETypeByUrl(history.location.pathname);

const deleteAction = () => {
if (isDeleting) return;
Expand Down Expand Up @@ -165,7 +165,7 @@ export const DSFormHeader = (props: DSFormHeaderProps) => {
: true)
);

const headerActions = useHeaderActions(editorType, {
const headerActions = useHeaderActions(ideType, {
datasource,
isPluginAuthorized,
pluginType,
Expand Down
6 changes: 3 additions & 3 deletions app/client/src/pages/Editor/DataSourceEditor/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import { FEATURE_FLAG } from "ee/entities/FeatureFlag";
import type { AppState } from "ee/reducers";
import { getPagePermissions } from "selectors/editorSelectors";
import { get } from "lodash";
import { useEditorType } from "ee/hooks";
import history from "utils/history";
import { getCurrentApplication } from "ee/selectors/applicationSelectors";
import { getIDETypeByUrl } from "ee/entities/IDE/utils";

interface FetchPreviewData {
datasourceId: string;
Expand Down Expand Up @@ -141,7 +141,7 @@ export const useShowPageGenerationOnHeader = (
getGenerateCRUDEnabledPluginMap,
);

const editorType = useEditorType(history.location.pathname);
const ideType = getIDETypeByUrl(history.location.pathname);

const canCreatePages = getHasCreatePagePermission(
isGACEnabled,
Expand All @@ -151,7 +151,7 @@ export const useShowPageGenerationOnHeader = (
isEnabled: isGACEnabled,
dsPermissions: datasourcePermissions,
pagePermissions,
editorType,
ideType,
});

const canGeneratePage = canCreateDatasourceActions && canCreatePages;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import { Virtuoso } from "react-virtuoso";
import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
import { FEATURE_FLAG } from "ee/entities/FeatureFlag";
import { hasCreateDSActionPermissionInApp } from "ee/utils/BusinessFeatures/permissionPageHelpers";
import { useEditorType } from "ee/hooks";
import history from "utils/history";
import { getIDETypeByUrl } from "ee/entities/IDE/utils";

interface DatasourceStructureItemProps {
dbStructure: DatasourceTable;
Expand Down Expand Up @@ -66,13 +66,13 @@ const DatasourceStructureItem = memo((props: DatasourceStructureItemProps) => {
const datasourcePermissions = datasource?.userPermissions || [];
const pagePermissions = useSelector(getPagePermissions);
const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled);
const editorType = useEditorType(history.location.pathname);
const ideType = getIDETypeByUrl(history.location.pathname);

const canCreateDatasourceActions = hasCreateDSActionPermissionInApp({
isEnabled: isFeatureEnabled,
dsPermissions: datasourcePermissions,
pagePermissions,
editorType,
ideType,
});

const onSelect = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ import {
TableWrapper,
ViewModeSchemaContainer,
} from "./SchemaViewModeCSS";
import { useEditorType } from "ee/hooks";
import history from "utils/history";
import { getIsGeneratingTemplatePage } from "selectors/pageListSelectors";
import { setDatasourcePreviewSelectedTableName } from "actions/datasourceActions";
import { getIsAnvilEnabledInCurrentApplication } from "layoutSystems/anvil/integrations/selectors";
import { getIDETypeByUrl } from "ee/entities/IDE/utils";

interface Props {
datasource: Datasource;
Expand Down Expand Up @@ -82,7 +82,7 @@ const DatasourceViewModeSchema = (props: Props) => {
FEATURE_FLAG.release_drag_drop_building_blocks_enabled,
);

const editorType = useEditorType(history.location.pathname);
const ideType = getIDETypeByUrl(history.location.pathname);

const canCreatePages = getHasCreatePagePermission(
isFeatureEnabled,
Expand All @@ -93,7 +93,7 @@ const DatasourceViewModeSchema = (props: Props) => {
isEnabled: isFeatureEnabled,
dsPermissions: datasourcePermissions,
pagePermissions,
editorType,
ideType,
});

const applicationId: string = useSelector(getCurrentApplicationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ import Entity from "../Explorer/Entity";
import DatasourceField from "./DatasourceField";
import { setEntityCollapsibleState } from "actions/editorContextActions";
import ItemLoadingIndicator from "./ItemLoadingIndicator";
import { useEditorType } from "ee/hooks";
import history from "utils/history";
import { getIsGeneratingTemplatePage } from "selectors/pageListSelectors";
import { getIsAnvilEnabledInCurrentApplication } from "layoutSystems/anvil/integrations/selectors";
import { getIDETypeByUrl } from "ee/entities/IDE/utils";

interface Props {
datasourceId: string;
Expand Down Expand Up @@ -360,7 +360,7 @@ function GoogleSheetSchema(props: Props) {
FEATURE_FLAG.release_drag_drop_building_blocks_enabled,
);

const editorType = useEditorType(history.location.pathname);
const ideType = getIDETypeByUrl(history.location.pathname);

const canCreatePages = getHasCreatePagePermission(
isFeatureEnabled,
Expand All @@ -371,7 +371,7 @@ function GoogleSheetSchema(props: Props) {
isEnabled: isFeatureEnabled,
dsPermissions: datasourcePermissions,
pagePermissions,
editorType,
ideType,
});

const refreshSpreadSheetButton = (option: DropdownOption) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ import {
getDatasource,
getPlugins,
} from "ee/selectors/entitiesSelector";
import {
PluginType,
type Action,
type StoredDatasource,
} from "entities/Action";
import { type Action, type StoredDatasource } from "entities/Action";
import { useDispatch, useSelector } from "react-redux";
import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
import { FEATURE_FLAG } from "ee/entities/FeatureFlag";
Expand All @@ -31,6 +27,7 @@ import { getIDETypeByUrl } from "ee/entities/IDE/utils";
import { getActionConfig } from "pages/Editor/Explorer/Actions/helpers";
import { QueryEntityContextMenu } from "./QueryEntityContextMenu";
import { useActiveActionBaseId } from "ee/pages/Editor/Explorer/hooks";
import { PluginType } from "entities/Plugin";

export const QueryEntity = ({
item,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import ContextMenu from "pages/Editor/Explorer/ContextMenu";
import type { TreeDropdownOption } from "pages/Editor/Explorer/ContextMenu";
import { useConvertToModuleOptions } from "ee/pages/Editor/Explorer/hooks";
import { MODULE_TYPE } from "ee/constants/ModuleConstants";
import { PluginType } from "entities/Action";
import { PluginType } from "entities/Plugin";
import { EntityClassNames } from "pages/Editor/Explorer/Entity";
import { useLocation } from "react-router";
import {
Expand Down
6 changes: 3 additions & 3 deletions app/client/src/pages/Editor/IDE/LeftPane/DataSidePane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
DATASOURCE_LIST_BLANK_DESCRIPTION,
} from "ee/constants/messages";
import PaneHeader from "./PaneHeader";
import { useEditorType } from "ee/hooks";
import { INTEGRATION_TABS } from "constants/routes";
import type { AppState } from "ee/reducers";
import { getCurrentAppWorkspace } from "ee/selectors/selectedWorkspaceSelectors";
Expand All @@ -31,6 +30,7 @@ import { getHasCreateDatasourcePermission } from "ee/utils/BusinessFeatures/perm
import { EmptyState } from "@appsmith/ads";
import { getAssetUrl } from "ee/utils/airgapHelpers";
import { getCurrentBasePageId } from "selectors/editorSelectors";
import { getIDETypeByUrl } from "ee/entities/IDE/utils";

const PaneBody = styled.div`
padding: var(--ads-v2-spaces-3) 0;
Expand All @@ -51,7 +51,6 @@ interface DataSidePaneProps {

const DataSidePane = (props: DataSidePaneProps) => {
const { dsUsageSelector = getDatasourceUsageCountForApp } = props;
const editorType = useEditorType(history.location.pathname);
const basePageId = useSelector(getCurrentBasePageId) as string;
const [currentSelectedDatasource, setCurrentSelectedDatasource] = useState<
string | undefined
Expand All @@ -60,7 +59,8 @@ const DataSidePane = (props: DataSidePaneProps) => {
const groupedDatasources = useSelector(getDatasourcesGroupedByPluginCategory);
const plugins = useSelector(getPlugins);
const groupedPlugins = keyBy(plugins, "id");
const dsUsageMap = useSelector((state) => dsUsageSelector(state, editorType));
const ideType = getIDETypeByUrl(history.location.pathname);
const dsUsageMap = useSelector((state) => dsUsageSelector(state, ideType));
const goToDatasource = useCallback((id: string) => {
history.push(datasourcesEditorIdURL({ datasourceId: id }));
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ import {
getHasManageDatasourcePermission,
hasCreateDSActionPermissionInApp,
} from "ee/utils/BusinessFeatures/permissionPageHelpers";
import { useEditorType } from "ee/hooks";
import { getIsAnvilEnabledInCurrentApplication } from "layoutSystems/anvil/integrations/selectors";
import { openGeneratePageModal } from "../GeneratePage/store/generatePageActions";
import { getIDETypeByUrl } from "ee/entities/IDE/utils";

const Wrapper = styled.div`
padding: 15px;
Expand Down Expand Up @@ -179,7 +179,7 @@ function DatasourceCard(props: DatasourceCardProps) {
const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled);
const isAnvilEnabled = useSelector(getIsAnvilEnabledInCurrentApplication);

const editorType = useEditorType(history.location.pathname);
const ideType = getIDETypeByUrl(history.location.pathname);

const canCreatePages = getHasCreatePagePermission(
isFeatureEnabled,
Expand All @@ -190,7 +190,7 @@ function DatasourceCard(props: DatasourceCardProps) {
isEnabled: isFeatureEnabled,
dsPermissions: datasourcePermissions,
pagePermissions,
editorType,
ideType,
});

const canEditDatasource = getHasManageDatasourcePermission(
Expand Down
Loading

0 comments on commit 40ba4f9

Please sign in to comment.