diff --git a/app/client/src/mockResponses/WidgetSidebarResponse.tsx b/app/client/src/mockResponses/WidgetSidebarResponse.tsx index f831424f04..b63b7b0016 100644 --- a/app/client/src/mockResponses/WidgetSidebarResponse.tsx +++ b/app/client/src/mockResponses/WidgetSidebarResponse.tsx @@ -2,106 +2,92 @@ import { WidgetCardProps } from "widgets/BaseWidget"; import { generateReactKey } from "utils/generators"; /* eslint-disable no-useless-computed-key */ -const WidgetSidebarResponse: { - [id: string]: WidgetCardProps[]; -} = { - ["Form Widgets"]: [ - { - type: "FORM_WIDGET", - widgetCardName: "Form", - key: generateReactKey(), - }, - { - type: "INPUT_WIDGET", - widgetCardName: "Input", - key: generateReactKey(), - }, - { - type: "DROP_DOWN_WIDGET", - widgetCardName: "Dropdown", - key: generateReactKey(), - }, - { - type: "BUTTON_WIDGET", - widgetCardName: "Button", - key: generateReactKey(), - }, - { - type: "CHECKBOX_WIDGET", - widgetCardName: "Checkbox", - key: generateReactKey(), - }, - { - type: "RADIO_GROUP_WIDGET", - widgetCardName: "Radio", - key: generateReactKey(), - }, - // { - // type: "SWITCH_WIDGET", - // icon: "icon-switch", - // widgetCardName: "Switch", - // key: generateReactKey(), - // }, - { - type: "DATE_PICKER_WIDGET", - widgetCardName: "DatePicker", - key: generateReactKey(), - }, - { - type: "RICH_TEXT_EDITOR_WIDGET", - widgetCardName: "Rich Text Editor", - key: generateReactKey(), - }, - { - type: "FILE_PICKER_WIDGET", - widgetCardName: "FilePicker", - key: generateReactKey(), - }, - ], - ["Display widgets"]: [ - { - type: "IMAGE_WIDGET", - widgetCardName: "Image", - key: generateReactKey(), - }, - { - type: "TEXT_WIDGET", - widgetCardName: "Text", - key: generateReactKey(), - }, - { - type: "TABLE_WIDGET", - widgetCardName: "Table", - key: generateReactKey(), - }, - { - type: "VIDEO_WIDGET", - widgetCardName: "Video", - key: generateReactKey(), - }, - { - type: "MAP_WIDGET", - widgetCardName: "Map", - key: generateReactKey(), - }, - { - type: "CHART_WIDGET", - widgetCardName: "Chart", - key: generateReactKey(), - }, - ], - ["Layout widgets"]: [ - { - type: "TABS_WIDGET", - widgetCardName: "Tabs", - key: generateReactKey(), - }, - { - type: "CONTAINER_WIDGET", - widgetCardName: "Container", - key: generateReactKey(), - }, - ], -}; +const WidgetSidebarResponse: WidgetCardProps[] = [ + { + type: "BUTTON_WIDGET", + widgetCardName: "Button", + key: generateReactKey(), + }, + { + type: "CHART_WIDGET", + widgetCardName: "Chart", + key: generateReactKey(), + }, + { + type: "CHECKBOX_WIDGET", + widgetCardName: "Checkbox", + key: generateReactKey(), + }, + { + type: "CONTAINER_WIDGET", + widgetCardName: "Container", + key: generateReactKey(), + }, + { + type: "DATE_PICKER_WIDGET", + widgetCardName: "DatePicker", + key: generateReactKey(), + }, + { + type: "DROP_DOWN_WIDGET", + widgetCardName: "Dropdown", + key: generateReactKey(), + }, + { + type: "FILE_PICKER_WIDGET", + widgetCardName: "FilePicker", + key: generateReactKey(), + }, + { + type: "FORM_WIDGET", + widgetCardName: "Form", + key: generateReactKey(), + }, + { + type: "IMAGE_WIDGET", + widgetCardName: "Image", + key: generateReactKey(), + }, + { + type: "INPUT_WIDGET", + widgetCardName: "Input", + key: generateReactKey(), + }, + { + type: "MAP_WIDGET", + widgetCardName: "Map", + key: generateReactKey(), + }, + { + type: "RADIO_GROUP_WIDGET", + widgetCardName: "Radio", + key: generateReactKey(), + }, + { + type: "RICH_TEXT_EDITOR_WIDGET", + widgetCardName: "Rich Text Editor", + key: generateReactKey(), + }, + { + type: "TABLE_WIDGET", + widgetCardName: "Table", + key: generateReactKey(), + }, + { + type: "TABS_WIDGET", + widgetCardName: "Tabs", + key: generateReactKey(), + }, + { + type: "TEXT_WIDGET", + widgetCardName: "Text", + key: generateReactKey(), + }, + { + type: "VIDEO_WIDGET", + widgetCardName: "Video", + key: generateReactKey(), + }, +]; export default WidgetSidebarResponse; diff --git a/app/client/src/pages/Editor/WidgetSidebar.tsx b/app/client/src/pages/Editor/WidgetSidebar.tsx index c97a579d59..31bac8d4d7 100644 --- a/app/client/src/pages/Editor/WidgetSidebar.tsx +++ b/app/client/src/pages/Editor/WidgetSidebar.tsx @@ -84,17 +84,11 @@ const WidgetSidebar = (props: IPanelProps) => { let filteredCards = cards; if (keyword.trim().length > 0) { filteredCards = produce(cards, draft => { - for (const [key, value] of Object.entries(cards)) { - value.forEach((card, index) => { - if (card.widgetCardName.toLowerCase().indexOf(keyword) === -1) { - delete draft[key][index]; - } - }); - draft[key] = draft[key].filter(Boolean); - if (draft[key].length === 0) { - delete draft[key]; + cards.forEach((card, index) => { + if (card.widgetCardName.toLowerCase().indexOf(keyword) === -1) { + delete draft[index]; } - } + }); }); } setFilteredCards(filteredCards); @@ -119,7 +113,6 @@ const WidgetSidebar = (props: IPanelProps) => { el?.removeEventListener("cleared", search); }; }, [searchInputRef, search]); - const groups = Object.keys(filteredCards); return ( <> { onClick={props.closePanel} /> - {groups.map((group: string) => ( - -
{group}
- - {filteredCards[group].map((card: WidgetCardProps) => ( - - ))} - -
- ))} + + {filteredCards.map((card: WidgetCardProps) => ( + + ))} + ); diff --git a/app/client/src/reducers/uiReducers/widgetSidebarReducer.ts b/app/client/src/reducers/uiReducers/widgetSidebarReducer.ts index 4b93649d06..8db2c0b8b9 100644 --- a/app/client/src/reducers/uiReducers/widgetSidebarReducer.ts +++ b/app/client/src/reducers/uiReducers/widgetSidebarReducer.ts @@ -9,7 +9,7 @@ import { import { EditorReduxState } from "./editorReducer"; export interface WidgetSidebarReduxState { - cards: { [id: string]: WidgetCardProps[] }; + cards: WidgetCardProps[]; } const initialState: WidgetSidebarReduxState = { diff --git a/app/client/src/selectors/editorSelectors.tsx b/app/client/src/selectors/editorSelectors.tsx index 9eb2c1086d..c82fb4fad7 100644 --- a/app/client/src/selectors/editorSelectors.tsx +++ b/app/client/src/selectors/editorSelectors.tsx @@ -96,14 +96,17 @@ export const getWidgetCards = createSelector( widgetConfigs: WidgetConfigReducerState, ) => { const cards = widgetCards.cards; - const groups: string[] = Object.keys(cards); - groups.forEach((group: string) => { - cards[group] = cards[group].map((widget: WidgetCardProps) => { + return cards + .map((widget: WidgetCardProps) => { const { rows, columns } = widgetConfigs.config[widget.type]; return { ...widget, rows, columns }; - }); - }); - return cards; + }) + .sort( + ( + { widgetCardName: widgetACardName }: WidgetCardProps, + { widgetCardName: widgetBCardName }: WidgetCardProps, + ) => widgetACardName.localeCompare(widgetBCardName), + ); }, );