Skip to content

Commit

Permalink
feat: Updated new tab ui with search and load more
Browse files Browse the repository at this point in the history
  • Loading branch information
albinAppsmith committed Jul 17, 2024
1 parent e58b10d commit 6ddf1c8
Show file tree
Hide file tree
Showing 16 changed files with 211 additions and 107 deletions.
6 changes: 4 additions & 2 deletions app/client/src/ce/constants/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2312,8 +2312,10 @@ export const EDITOR_PANE_TEXTS = {
query_create_tab_title: () => "Create new query from",
widgets_create_tab_title: () => "Drag & drop UI elements",
js_create_tab_title: () => "Create JS object from",
queries_create_from_existing: () => "From existing datasource",
queries_create_new: () => "New API",
js_create_modules: () => "JS modules (Beta)",
queries_create_from_existing: () => "Datasources",
queries_create_new: () => "Quick actions",
queries_create_modules: () => "Query modules (Beta)",
loading_building_blocks: () => "Loading building blocks",
empty_search_result: (type: string) => `No ${type} match your search`,
};
Expand Down
18 changes: 9 additions & 9 deletions app/client/src/ce/pages/Editor/IDE/EditorPane/Query/hooks.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo } from "react";
import { useCallback, useMemo } from "react";
import history from "utils/history";
import { useLocation } from "react-router";
import { FocusEntity, identifyEntityFromPath } from "navigation/FocusEntity";
Expand Down Expand Up @@ -33,7 +33,7 @@ import ListQuery from "pages/Editor/IDE/EditorPane/Query/List";
import type { AppState } from "@appsmith/reducers";
import keyBy from "lodash/keyBy";
import { getPluginEntityIcon } from "pages/Editor/Explorer/ExplorerIcons";
import { Tag, type ListItemProps } from "design-system";
import type { ListItemProps } from "design-system";
import { useCurrentEditorState } from "pages/Editor/IDE/hooks";
import { createAddClassName } from "pages/Editor/IDE/EditorPane/utils";
import { QueriesBlankState } from "pages/Editor/QueryEditor/QueriesBlankState";
Expand Down Expand Up @@ -182,12 +182,13 @@ export const useAddQueryListItems = () => {
[pageId, dispatch],
);

const getListItems = (data: any[]) => {
const getListItems = (data: ActionOperation[]) => {
return data.map((fileOperation) => {
const title =
fileOperation.entityExplorerTitle ||
fileOperation.title ||
fileOperation.dsName ||
fileOperation.title;
"";
const className = createAddClassName(title);
const icon =
fileOperation.icon ||
Expand All @@ -197,11 +198,10 @@ export const useAddQueryListItems = () => {
startIcon: icon,
wrapperClassName: className,
title,
description: !!fileOperation.isBeta ? (
<Tag isClosable={false}>Beta</Tag>
) : (
""
),
description:
fileOperation.focusEntityType === FocusEntity.QUERY_MODULE_INSTANCE
? fileOperation.dsName
: "",
descriptionType: "inline",
onClick: onCreateItemClick.bind(null, fileOperation),
} as ListItemProps;
Expand Down
43 changes: 27 additions & 16 deletions app/client/src/pages/Editor/IDE/EditorPane/JS/Add.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useCallback } from "react";
import React, { useCallback, useState } from "react";
import SegmentAddHeader from "../components/SegmentAddHeader";
import { EDITOR_PANE_TEXTS } from "@appsmith/constants/messages";
import type { ListItemProps } from "design-system";
import { Flex, Tag } from "design-system";
import { Flex, SearchInput } from "design-system";
import { useDispatch, useSelector } from "react-redux";
import { getCurrentPageId } from "selectors/editorSelectors";
import GroupedList from "../components/GroupedList";
Expand All @@ -12,11 +12,15 @@ import {
} from "@appsmith/pages/Editor/IDE/EditorPane/JS/hooks";
import type { ActionOperation } from "components/editorComponents/GlobalSearch/utils";
import type { AddProps } from "../types/AddProps";
import { createAddClassName } from "../utils";
import { createAddClassName, fuzzySearchInObjectItems } from "../utils";
import { FocusEntity } from "navigation/FocusEntity";
import type { GroupedListProps } from "../components/types";
import { EmptySearchResult } from "../components/EmptySearchResult";

const AddJS = ({ containerProps, innerContainerProps }: AddProps) => {
const dispatch = useDispatch();
const pageId = useSelector(getCurrentPageId);
const [searchTerm, setSearchTerm] = useState("");

const groupedJsOperations = useGroupedAddJsOperations();

Expand All @@ -35,13 +39,27 @@ const AddJS = ({ containerProps, innerContainerProps }: AddProps) => {
return {
startIcon: data.icon,
title,
description: !!data.isBeta ? <Tag isClosable={false}>Beta</Tag> : "",
description:
data.focusEntityType === FocusEntity.JS_MODULE_INSTANCE
? data.dsName
: "",
descriptionType: "inline",
onClick: onCreateItemClick.bind(null, data),
wrapperClassName: createAddClassName(title),
} as ListItemProps;
};

const groups = groupedJsOperations.map((op) => ({
groupTitle: op.title,
className: op.className,
items: op.operations.map(getListItems),
}));

const localGroups = fuzzySearchInObjectItems<GroupedListProps[]>(
searchTerm,
groups,
);

return (
<Flex
data-testid="t--ide-add-pane"
Expand All @@ -61,18 +79,11 @@ const AddJS = ({ containerProps, innerContainerProps }: AddProps) => {
onCloseClick={closeAddJS}
titleMessage={EDITOR_PANE_TEXTS.js_create_tab_title}
/>

<GroupedList
flexProps={{
pr: "spaces-2",
px: "spaces-3",
}}
groups={groupedJsOperations.map((op) => ({
groupTitle: op.title,
className: op.className,
items: op.operations.map(getListItems),
}))}
/>
<SearchInput onChange={setSearchTerm} value={searchTerm} />
{localGroups.length > 0 ? <GroupedList groups={localGroups} /> : null}
{localGroups.length === 0 && searchTerm !== "" ? (
<EmptySearchResult type="JS" />
) : null}
</Flex>
</Flex>
);
Expand Down
18 changes: 8 additions & 10 deletions app/client/src/pages/Editor/IDE/EditorPane/JS/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useSelector } from "react-redux";
import { Flex, Text } from "design-system";
import styled from "styled-components";

import type { EditorSegmentList } from "@appsmith/selectors/appIDESelectors";
import { selectJSSegmentEditorList } from "@appsmith/selectors/appIDESelectors";
import { useActiveAction } from "@appsmith/pages/Editor/Explorer/hooks";
import {
Expand All @@ -19,8 +20,8 @@ import { useJSAdd } from "@appsmith/pages/Editor/IDE/EditorPane/JS/hooks";
import { JSListItem } from "@appsmith/pages/Editor/IDE/EditorPane/JS/ListItem";
import { BlankState } from "./BlankState";
import { AddAndSearchbar } from "../components/AddAndSearchbar";
import { fuzzySearchInFiles } from "../utils";
import { EDITOR_PANE_TEXTS, createMessage } from "@appsmith/constants/messages";
import { fuzzySearchInObjectItems } from "../utils";
import { EmptySearchResult } from "../components/EmptySearchResult";

const JSContainer = styled(Flex)`
& .t--entity-item {
Expand All @@ -44,7 +45,10 @@ const ListJSObjects = () => {

const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled);

const localFiles = fuzzySearchInFiles(searchTerm, files);
const localFiles = fuzzySearchInObjectItems<EditorSegmentList>(
searchTerm,
files,
);

const canCreateActions = getHasCreateActionPermission(
isFeatureEnabled,
Expand Down Expand Up @@ -112,13 +116,7 @@ const ListJSObjects = () => {
);
})}
{localFiles.length === 0 && searchTerm !== "" ? (
<Text
className="font-normal text-center"
color="var(--ads-v2-color-fg-muted)"
kind="body-s"
>
{createMessage(EDITOR_PANE_TEXTS.empty_search_result, "JS")}
</Text>
<EmptySearchResult type="JS object" />
) : null}
</Flex>
</FilesContextProvider>
Expand Down
35 changes: 22 additions & 13 deletions app/client/src/pages/Editor/IDE/EditorPane/Query/Add.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Flex } from "design-system";
import React, { useState } from "react";
import { Flex, SearchInput } from "design-system";

import { EDITOR_PANE_TEXTS } from "@appsmith/constants/messages";
import SegmentAddHeader from "../components/SegmentAddHeader";
Expand All @@ -10,12 +10,27 @@ import {
useQueryAdd,
} from "@appsmith/pages/Editor/IDE/EditorPane/Query/hooks";
import type { AddProps } from "../types/AddProps";
import { fuzzySearchInObjectItems } from "../utils";
import type { GroupedListProps } from "../components/types";
import { EmptySearchResult } from "../components/EmptySearchResult";

const AddQuery = ({ containerProps, innerContainerProps }: AddProps) => {
const [searchTerm, setSearchTerm] = useState("");
const { getListItems } = useAddQueryListItems();
const groupedActionOperations = useGroupedAddQueryOperations();
const { closeAddQuery } = useQueryAdd();

const groups = groupedActionOperations.map((group) => ({
groupTitle: group.title,
className: group.className,
items: getListItems(group.operations),
}));

const localGroups = fuzzySearchInObjectItems<GroupedListProps[]>(
searchTerm,
groups,
);

return (
<Flex
data-testid="t--ide-add-pane"
Expand All @@ -35,17 +50,11 @@ const AddQuery = ({ containerProps, innerContainerProps }: AddProps) => {
onCloseClick={closeAddQuery}
titleMessage={EDITOR_PANE_TEXTS.query_create_tab_title}
/>
<GroupedList
flexProps={{
pr: "spaces-2",
px: "spaces-3",
}}
groups={groupedActionOperations.map((group) => ({
groupTitle: group.title,
className: group.className,
items: getListItems(group.operations),
}))}
/>
<SearchInput autofocus onChange={setSearchTerm} value={searchTerm} />
{localGroups.length > 0 ? <GroupedList groups={localGroups} /> : null}
{localGroups.length === 0 && searchTerm !== "" ? (
<EmptySearchResult type="datasources" />
) : null}
</Flex>
</Flex>
);
Expand Down
18 changes: 8 additions & 10 deletions app/client/src/pages/Editor/IDE/EditorPane/Query/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { useFeatureFlag } from "utils/hooks/useFeatureFlag";
import { FEATURE_FLAG } from "@appsmith/entities/FeatureFlag";
import { getCurrentPageId } from "@appsmith/selectors/entitiesSelector";
import type { EditorSegmentList } from "@appsmith/selectors/appIDESelectors";
import { selectQuerySegmentEditorList } from "@appsmith/selectors/appIDESelectors";
import { ActionParentEntityType } from "@appsmith/entities/Engine/actionHelpers";
import { FilesContextProvider } from "pages/Editor/Explorer/Files/FilesContextProvider";
Expand All @@ -19,8 +20,8 @@ import { QueryListItem } from "@appsmith/pages/Editor/IDE/EditorPane/Query/ListI
import { getShowWorkflowFeature } from "@appsmith/selectors/workflowSelectors";
import { BlankState } from "./BlankState";
import { AddAndSearchbar } from "../components/AddAndSearchbar";
import { fuzzySearchInFiles } from "../utils";
import { EDITOR_PANE_TEXTS, createMessage } from "@appsmith/constants/messages";
import { fuzzySearchInObjectItems } from "../utils";
import { EmptySearchResult } from "../components/EmptySearchResult";

const ListQuery = () => {
const [searchTerm, setSearchTerm] = useState("");
Expand All @@ -30,7 +31,10 @@ const ListQuery = () => {
const pagePermissions = useSelector(getPagePermissions);
const isFeatureEnabled = useFeatureFlag(FEATURE_FLAG.license_gac_enabled);

const localFiles = fuzzySearchInFiles(searchTerm, files);
const localFiles = fuzzySearchInObjectItems<EditorSegmentList>(
searchTerm,
files,
);

const canCreateActions = getHasCreateActionPermission(
isFeatureEnabled,
Expand Down Expand Up @@ -96,13 +100,7 @@ const ListQuery = () => {
);
})}
{localFiles.length === 0 && searchTerm !== "" ? (
<Text
className="font-normal text-center"
color="var(--ads-v2-color-fg-muted)"
kind="body-s"
>
{createMessage(EDITOR_PANE_TEXTS.empty_search_result, "queries")}
</Text>
<EmptySearchResult type="queries" />
) : null}
</Flex>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from "react";
import { Text } from "design-system";
import { EDITOR_PANE_TEXTS, createMessage } from "@appsmith/constants/messages";

const EmptySearchResult = ({ type }: { type: string }) => {
return (
<Text
className="font-normal text-center"
color="var(--ads-v2-color-fg-muted)"
kind="body-s"
>
{createMessage(EDITOR_PANE_TEXTS.empty_search_result, type)}
</Text>
);
};

export { EmptySearchResult };
76 changes: 76 additions & 0 deletions app/client/src/pages/Editor/IDE/EditorPane/components/Group.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import React, { useState } from "react";
import type { GroupedListProps } from "./types";
import { DEFAULT_GROUP_LIST_SIZE } from "./constants";
import { Flex, List, Text } from "design-system";
import styled from "styled-components";

interface GroupProps {
group: GroupedListProps;
}

const StyledList = styled(List)`
padding: 0;
gap: 0;
& .ds-load-more .ads-v2-listitem__title {
--color: var(--ads-v2-color-fg-subtle);
}
& .ads-v2-listitem__wrapper .ads-v2-listitem__idesc {
opacity: 0;
}
& .ads-v2-listitem__wrapper:hover .ads-v2-listitem__idesc {
opacity: 1;
}
`;

const Group: React.FC<GroupProps> = ({ group }) => {
const [visibleItems, setVisibleItems] = useState<number>(
DEFAULT_GROUP_LIST_SIZE,
);
const { className, groupTitle } = group;
const items = group.items.slice(0, visibleItems);
const hasMoreItems = group.items.length > visibleItems;

const handleLoadMore = () => {
setVisibleItems(group.items.length);
};

if (hasMoreItems) {
items.push({
title: "Load more...",
description: "",
descriptionType: "inline",
onClick: handleLoadMore,
className: "ds-load-more",
});
}

// TODO: try to avoid this
if (hasMoreItems && groupTitle === "Datasources") {
items.push(group.items[group.items.length - 1]);
}

return (
<Flex
borderBottom="1px solid var(--ads-v2-color-border-muted)"
className="groups-list-group"
flexDirection="column"
key={groupTitle}
pb="spaces-3"
>
{groupTitle ? (
<Text
className="pr-[var(--ads-v2-spaces-3)] py-[var(--ads-v2-spaces-1)]"
color="var(--ads-v2-color-fg-muted)"
kind="body-s"
>
{groupTitle}
</Text>
) : null}
<StyledList className={className} items={items} />
</Flex>
);
};

export { Group };
Loading

0 comments on commit 6ddf1c8

Please sign in to comment.