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";
|
2020-12-30 07:31:20 +00:00
|
|
|
import Boxed from "components/editorComponents/Onboarding/Boxed";
|
|
|
|
|
import { OnboardingStep } from "constants/OnboardingConstants";
|
2021-08-10 14:56:56 +00:00
|
|
|
import {
|
|
|
|
|
getCurrentStep,
|
|
|
|
|
getCurrentSubStep,
|
|
|
|
|
inOnboarding,
|
|
|
|
|
} from "sagas/OnboardingSagas";
|
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";
|
2021-11-23 08:01:46 +00:00
|
|
|
import OnboardingIndicator from "components/editorComponents/Onboarding/Indicator";
|
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-02-11 06:36:07 +00:00
|
|
|
// For onboarding
|
2021-08-10 14:56:56 +00:00
|
|
|
const isInOnboarding = useSelector(inOnboarding);
|
2021-02-11 06:36:07 +00:00
|
|
|
const currentStep = useSelector(getCurrentStep);
|
|
|
|
|
const currentSubStep = useSelector(getCurrentSubStep);
|
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(() => {
|
2021-08-10 14:56:56 +00:00
|
|
|
if (
|
2021-10-04 15:34:37 +00:00
|
|
|
((currentStep === OnboardingStep.DEPLOY || !isInOnboarding) &&
|
|
|
|
|
!onCanvas) ||
|
|
|
|
|
isForceOpenWidgetPanel === false
|
2021-08-10 14:56:56 +00:00
|
|
|
) {
|
2021-02-11 06:36:07 +00:00
|
|
|
props.closePanel();
|
|
|
|
|
}
|
2021-10-04 15:34:37 +00:00
|
|
|
}, [currentStep, onCanvas, isInOnboarding, 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("");
|
|
|
|
|
};
|
2021-02-11 06:36:07 +00:00
|
|
|
|
|
|
|
|
const showTableWidget = currentStep >= OnboardingStep.RUN_QUERY_SUCCESS;
|
|
|
|
|
const showInputWidget = currentStep >= OnboardingStep.ADD_INPUT_WIDGET;
|
|
|
|
|
|
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">
|
2021-02-11 06:36:07 +00:00
|
|
|
<Boxed step={OnboardingStep.DEPLOY}>
|
|
|
|
|
<ExplorerSearch
|
2021-04-28 10:28:39 +00:00
|
|
|
autoFocus
|
2021-02-11 06:36:07 +00:00
|
|
|
clear={clearSearchInput}
|
2021-11-23 08:01:46 +00:00
|
|
|
onChange={search}
|
2021-02-11 06:36:07 +00:00
|
|
|
placeholder="Search widgets..."
|
2021-04-28 10:28:39 +00:00
|
|
|
ref={searchInputRef}
|
2021-02-11 06:36:07 +00:00
|
|
|
/>
|
|
|
|
|
</Boxed>
|
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) => (
|
2020-12-30 07:31:20 +00:00
|
|
|
<Boxed
|
2021-04-28 10:28:39 +00:00
|
|
|
key={card.key}
|
2021-02-11 06:36:07 +00:00
|
|
|
show={
|
|
|
|
|
(card.type === "TABLE_WIDGET" && showTableWidget) ||
|
2022-01-18 07:52:24 +00:00
|
|
|
(card.type === "INPUT_WIDGET_V2" && showInputWidget)
|
2021-02-11 06:36:07 +00:00
|
|
|
}
|
2021-04-28 10:28:39 +00:00
|
|
|
step={OnboardingStep.DEPLOY}
|
2020-12-30 07:31:20 +00:00
|
|
|
>
|
2021-02-11 06:36:07 +00:00
|
|
|
<OnboardingIndicator
|
2021-02-15 05:14:42 +00:00
|
|
|
className="onboarding-widget-menu"
|
2021-04-28 10:28:39 +00:00
|
|
|
hasButton={false}
|
2021-02-11 06:36:07 +00:00
|
|
|
show={
|
|
|
|
|
(card.type === "TABLE_WIDGET" &&
|
|
|
|
|
currentStep === OnboardingStep.RUN_QUERY_SUCCESS) ||
|
2022-01-18 07:52:24 +00:00
|
|
|
(card.type === "INPUT_WIDGET_V2" &&
|
2021-02-11 06:36:07 +00:00
|
|
|
currentSubStep === 0 &&
|
|
|
|
|
currentStep === OnboardingStep.ADD_INPUT_WIDGET)
|
|
|
|
|
}
|
2021-04-28 10:28:39 +00:00
|
|
|
step={
|
|
|
|
|
OnboardingStep.RUN_QUERY_SUCCESS ||
|
|
|
|
|
OnboardingStep.ADD_INPUT_WIDGET
|
|
|
|
|
}
|
|
|
|
|
width={100}
|
2021-02-11 06:36:07 +00:00
|
|
|
>
|
|
|
|
|
<WidgetCard details={card} />
|
|
|
|
|
</OnboardingIndicator>
|
2020-12-30 07:31:20 +00:00
|
|
|
</Boxed>
|
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;
|