2020-09-02 06:44:01 +00:00
|
|
|
import React, { useRef, useEffect, useState } from "react";
|
2021-10-04 15:34:37 +00:00
|
|
|
import { useSelector } from "react-redux";
|
2019-10-18 08:16:26 +00:00
|
|
|
import WidgetCard from "./WidgetCard";
|
2021-10-18 14:03:44 +00:00
|
|
|
import { getWidgetCards } from "selectors/editorSelectors";
|
2021-10-04 15:34:37 +00:00
|
|
|
import { IPanelProps } from "@blueprintjs/core";
|
2020-09-02 06:44:01 +00:00
|
|
|
import ExplorerSearch from "./Explorer/ExplorerSearch";
|
|
|
|
|
import { debounce } from "lodash";
|
|
|
|
|
import produce from "immer";
|
2021-11-23 08:01:46 +00:00
|
|
|
import { useLocation } from "react-router";
|
|
|
|
|
|
2021-03-13 14:24:45 +00:00
|
|
|
import { createMessage, WIDGET_SIDEBAR_CAPTION } from "constants/messages";
|
2021-10-18 14:03:44 +00:00
|
|
|
import { matchBuilderPath } from "constants/routes";
|
2021-10-04 15:34:37 +00:00
|
|
|
import { AppState } from "reducers";
|
2020-09-02 06:44:01 +00:00
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
function WidgetSidebar(props: IPanelProps) {
|
2021-08-10 14:56:56 +00:00
|
|
|
const location = useLocation();
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
const cards = useSelector(getWidgetCards);
|
2020-09-02 06:44:01 +00:00
|
|
|
const [filteredCards, setFilteredCards] = useState(cards);
|
|
|
|
|
const searchInputRef = useRef<HTMLInputElement | null>(null);
|
2020-09-03 14:22:08 +00:00
|
|
|
const filterCards = (keyword: string) => {
|
2020-09-02 06:44:01 +00:00
|
|
|
let filteredCards = cards;
|
|
|
|
|
if (keyword.trim().length > 0) {
|
2020-12-24 04:32:25 +00:00
|
|
|
filteredCards = produce(cards, (draft) => {
|
2020-12-23 11:32:30 +00:00
|
|
|
cards.forEach((card, index) => {
|
2021-09-09 15:10:22 +00:00
|
|
|
if (card.displayName.toLowerCase().indexOf(keyword) === -1) {
|
2020-12-23 11:32:30 +00:00
|
|
|
delete draft[index];
|
2020-09-02 06:44:01 +00:00
|
|
|
}
|
2020-12-23 11:32:30 +00:00
|
|
|
});
|
2020-09-02 06:44:01 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
setFilteredCards(filteredCards);
|
2020-09-03 14:22:08 +00:00
|
|
|
};
|
2021-11-23 08:01:46 +00:00
|
|
|
const isForceOpenWidgetPanel = useSelector(
|
|
|
|
|
(state: AppState) => state.ui.onBoarding.forceOpenWidgetPanel,
|
|
|
|
|
);
|
2020-09-03 14:22:08 +00:00
|
|
|
|
2021-10-18 14:03:44 +00:00
|
|
|
const onCanvas = matchBuilderPath(window.location.pathname);
|
2021-10-04 15:34:37 +00:00
|
|
|
|
2021-02-11 06:36:07 +00:00
|
|
|
useEffect(() => {
|
2022-01-25 13:56:52 +00:00
|
|
|
if (!onCanvas || isForceOpenWidgetPanel === false) {
|
2021-02-11 06:36:07 +00:00
|
|
|
props.closePanel();
|
|
|
|
|
}
|
2022-01-25 13:56:52 +00:00
|
|
|
}, [onCanvas, location, isForceOpenWidgetPanel]);
|
2021-02-11 06:36:07 +00:00
|
|
|
|
2021-11-23 08:01:46 +00:00
|
|
|
/**
|
|
|
|
|
* filter widgets
|
|
|
|
|
*/
|
2020-09-03 14:22:08 +00:00
|
|
|
const search = debounce((e: any) => {
|
|
|
|
|
filterCards(e.target.value.toLowerCase());
|
2020-09-02 06:44:01 +00:00
|
|
|
}, 300);
|
|
|
|
|
|
2021-11-23 08:01:46 +00:00
|
|
|
/**
|
|
|
|
|
* clear the search input
|
|
|
|
|
*/
|
|
|
|
|
const clearSearchInput = () => {
|
|
|
|
|
if (searchInputRef.current) {
|
|
|
|
|
searchInputRef.current.value = "";
|
|
|
|
|
}
|
|
|
|
|
filterCards("");
|
2022-02-09 04:00:56 +00:00
|
|
|
searchInputRef.current?.focus();
|
2021-11-23 08:01:46 +00:00
|
|
|
};
|
2021-02-11 06:36:07 +00:00
|
|
|
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
return (
|
2021-11-23 08:01:46 +00:00
|
|
|
<div className="flex flex-col overflow-hidden">
|
2022-01-25 13:56:52 +00:00
|
|
|
<ExplorerSearch
|
|
|
|
|
autoFocus
|
|
|
|
|
clear={clearSearchInput}
|
|
|
|
|
onChange={search}
|
|
|
|
|
placeholder="Search widgets..."
|
|
|
|
|
ref={searchInputRef}
|
|
|
|
|
/>
|
2021-11-23 08:01:46 +00:00
|
|
|
<div className="flex-grow px-3 overflow-y-scroll">
|
|
|
|
|
<p className="px-3 py-3 text-sm leading-relaxed text-trueGray-400 t--widget-sidebar">
|
|
|
|
|
{createMessage(WIDGET_SIDEBAR_CAPTION)}
|
|
|
|
|
</p>
|
|
|
|
|
<div className="grid items-stretch grid-cols-3 gap-3 justify-items-stretch">
|
2021-09-09 15:10:22 +00:00
|
|
|
{filteredCards.map((card) => (
|
2022-01-25 13:56:52 +00:00
|
|
|
<WidgetCard details={card} key={card.key} />
|
2020-12-23 11:32:30 +00:00
|
|
|
))}
|
2021-11-23 08:01:46 +00:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-10-18 08:16:26 +00:00
|
|
|
|
Feature/entity browse (#220)
# New Feature: Entity Explorer
- Entities are actions (apis and queries), datasources, pages, and widgets
- With this new feature, all entities in the application will be available
to view in the new entity explorer sidebar
- All existing application features from the api sidebar, query sidebar, datasource sidebar and pages sidebar
now are avialable on the entity explorer sidebar
- Users are now able to quickly switch to any entity in the application from the entity explorer sidebar.
- Users can also search all entities in the application from the new sidebar. Use cmd + f or ctrl + f to focus on the search input
- Users can rename entities from the new sidebar
- Users can also perform contextual actions on these entities like set a page as home page, copy/move actions, delete entity, etc from the context menu available alongside the entities in the sidebar
- Users can view the properties of the entities in the sidebar, as well as copy bindings to use in the application.
2020-08-10 08:52:45 +00:00
|
|
|
WidgetSidebar.displayName = "WidgetSidebar";
|
|
|
|
|
|
|
|
|
|
export default WidgetSidebar;
|