Skip to content

Commit

Permalink
fix: Add Loading when JS is getting created
Browse files Browse the repository at this point in the history
  • Loading branch information
hetunandu committed Apr 11, 2024
1 parent b220151 commit fedc33d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
12 changes: 12 additions & 0 deletions app/client/src/ce/pages/Editor/IDE/EditorPane/JS/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ export const useJSAdd = () => {
]);
};

export const useIsJSAddLoading = () => {
const moduleCreationOptions = useModuleOptions();
const jsModuleCreationOptions = moduleCreationOptions.filter(
(opt) => opt.focusEntityType === FocusEntity.JS_MODULE_INSTANCE,
);
const { isCreating } = useSelector((state) => state.ui.jsPane);
if (jsModuleCreationOptions.length === 0) {
return isCreating;
}
return false;
};

export const useGroupedAddJsOperations = (): GroupedAddOperations => {
return [
{
Expand Down
30 changes: 20 additions & 10 deletions app/client/src/pages/Editor/IDE/EditorTabs/SplitScreenTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useCallback } from "react";
import { ToggleButton } from "design-system";
import { Flex, Spinner, ToggleButton } from "design-system";

import FileTabs from "./FileTabs";
import { useSelector } from "react-redux";
Expand All @@ -12,7 +12,10 @@ import {
EditorEntityTabState,
EditorViewMode,
} from "@appsmith/entities/IDE/constants";
import { useJSAdd } from "@appsmith/pages/Editor/IDE/EditorPane/JS/hooks";
import {
useIsJSAddLoading,
useJSAdd,
} from "@appsmith/pages/Editor/IDE/EditorPane/JS/hooks";
import { useQueryAdd } from "@appsmith/pages/Editor/IDE/EditorPane/Query/hooks";
import { TabSelectors } from "./constants";
import { getCurrentPageId } from "@appsmith/selectors/entitiesSelector";
Expand All @@ -27,6 +30,7 @@ const SplitScreenTabs = () => {
const { segment, segmentMode } = useCurrentEditorState();

const onJSAddClick = useJSAdd();
const isJSLoading = useIsJSAddLoading();
const onQueryAddClick = useQueryAdd();
const onAddClick = useCallback(() => {
if (segment === EditorEntityTab.JS) onJSAddClick();
Expand Down Expand Up @@ -58,14 +62,20 @@ const SplitScreenTabs = () => {
<>
{files.length > 0 ? (
<Container>
<ToggleButton
data-testid="t--ide-split-screen-add-button"
icon="add-line"
id="tabs-add-toggle"
isSelected={segmentMode === EditorEntityTabState.Add}
onClick={onAddClick}
size="md"
/>
{isJSLoading ? (
<Flex px="spaces-2">
<Spinner size="md" />
</Flex>
) : (
<ToggleButton
data-testid="t--ide-split-screen-add-button"
icon="add-line"
id="tabs-add-toggle"
isSelected={segmentMode === EditorEntityTabState.Add}
onClick={onAddClick}
size="md"
/>
)}
<FileTabs navigateToTab={onClick} tabs={files} />
<ListButton items={overflowList} navigateToTab={onClick} />
</Container>
Expand Down

0 comments on commit fedc33d

Please sign in to comment.