2021-05-18 18:29:39 +00:00
|
|
|
import React, { CSSProperties, ReactNode, useCallback, useMemo } from "react";
|
2019-11-13 07:00:25 +00:00
|
|
|
import { BaseStyle } from "widgets/BaseWidget";
|
2020-03-06 09:33:20 +00:00
|
|
|
import { WIDGET_PADDING } from "constants/WidgetConstants";
|
2020-03-27 09:02:11 +00:00
|
|
|
import { generateClassName } from "utils/generators";
|
2020-06-10 17:31:20 +00:00
|
|
|
import styled from "styled-components";
|
2021-03-29 15:47:22 +00:00
|
|
|
import { useClickOpenPropPane } from "utils/hooks/useClickOpenPropPane";
|
2021-05-18 18:29:39 +00:00
|
|
|
import { stopEventPropagation } from "utils/AppsmithUtils";
|
|
|
|
|
import { Layers } from "constants/Layers";
|
2020-06-10 17:31:20 +00:00
|
|
|
|
2021-06-17 13:26:54 +00:00
|
|
|
const PositionedWidget = styled.div`
|
|
|
|
|
&:hover {
|
|
|
|
|
z-index: ${Layers.positionedWidget + 1} !important;
|
|
|
|
|
}
|
|
|
|
|
`;
|
2019-11-13 07:00:25 +00:00
|
|
|
type PositionedContainerProps = {
|
|
|
|
|
style: BaseStyle;
|
2020-03-27 09:02:11 +00:00
|
|
|
children: ReactNode;
|
|
|
|
|
widgetId: string;
|
2020-05-21 06:15:12 +00:00
|
|
|
widgetType: string;
|
2021-05-27 06:41:38 +00:00
|
|
|
selected?: boolean;
|
|
|
|
|
focused?: boolean;
|
|
|
|
|
resizeDisabled?: boolean;
|
2019-11-13 07:00:25 +00:00
|
|
|
};
|
|
|
|
|
|
2021-04-28 10:28:39 +00:00
|
|
|
export function PositionedContainer(props: PositionedContainerProps) {
|
2020-03-04 08:10:40 +00:00
|
|
|
const x = props.style.xPosition + (props.style.xPositionUnit || "px");
|
2020-03-27 09:02:11 +00:00
|
|
|
const y = props.style.yPosition + (props.style.yPositionUnit || "px");
|
|
|
|
|
const padding = WIDGET_PADDING;
|
2021-03-29 15:47:22 +00:00
|
|
|
const openPropertyPane = useClickOpenPropPane();
|
2021-04-23 05:43:13 +00:00
|
|
|
// memoized classname
|
|
|
|
|
const containerClassName = useMemo(() => {
|
|
|
|
|
return (
|
|
|
|
|
generateClassName(props.widgetId) +
|
|
|
|
|
" positioned-widget " +
|
|
|
|
|
`t--widget-${props.widgetType
|
|
|
|
|
.split("_")
|
|
|
|
|
.join("")
|
|
|
|
|
.toLowerCase()}`
|
|
|
|
|
);
|
|
|
|
|
}, [props.widgetType, props.widgetId]);
|
|
|
|
|
const containerStyle: CSSProperties = useMemo(() => {
|
|
|
|
|
return {
|
|
|
|
|
position: "absolute",
|
|
|
|
|
left: x,
|
|
|
|
|
top: y,
|
|
|
|
|
height: props.style.componentHeight + (props.style.heightUnit || "px"),
|
|
|
|
|
width: props.style.componentWidth + (props.style.widthUnit || "px"),
|
|
|
|
|
padding: padding + "px",
|
2021-05-27 06:41:38 +00:00
|
|
|
zIndex:
|
|
|
|
|
props.selected || props.focused
|
|
|
|
|
? Layers.selectedWidget
|
|
|
|
|
: Layers.positionedWidget,
|
2021-05-18 18:29:39 +00:00
|
|
|
backgroundColor: "inherit",
|
2021-04-23 05:43:13 +00:00
|
|
|
};
|
|
|
|
|
}, [props.style]);
|
|
|
|
|
|
2021-05-18 18:29:39 +00:00
|
|
|
const openPropPane = useCallback((e) => openPropertyPane(e, props.widgetId), [
|
|
|
|
|
props.widgetId,
|
|
|
|
|
openPropertyPane,
|
|
|
|
|
]);
|
|
|
|
|
|
2019-11-13 07:00:25 +00:00
|
|
|
return (
|
2020-06-10 17:31:20 +00:00
|
|
|
<PositionedWidget
|
2021-04-28 10:28:39 +00:00
|
|
|
className={containerClassName}
|
2021-05-18 18:29:39 +00:00
|
|
|
data-testid="test-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
|
|
|
id={props.widgetId}
|
2021-07-08 06:30:19 +00:00
|
|
|
key={`positioned-container-${props.widgetId}`}
|
2021-05-18 18:29:39 +00:00
|
|
|
onClick={stopEventPropagation}
|
|
|
|
|
// Positioned Widget is the top enclosure for all widgets and clicks on/inside the widget should not be propogated/bubbled out of this Container.
|
|
|
|
|
onClickCapture={openPropPane}
|
2020-03-27 09:02:11 +00:00
|
|
|
//Before you remove: This is used by property pane to reference the element
|
2021-04-28 10:28:39 +00:00
|
|
|
style={containerStyle}
|
2019-11-13 07:00:25 +00:00
|
|
|
>
|
|
|
|
|
{props.children}
|
2020-06-10 17:31:20 +00:00
|
|
|
</PositionedWidget>
|
2019-11-13 07:00:25 +00:00
|
|
|
);
|
2021-04-28 10:28:39 +00:00
|
|
|
}
|
2019-11-13 07:00:25 +00:00
|
|
|
|
2020-01-16 11:46:21 +00:00
|
|
|
PositionedContainer.padding = WIDGET_PADDING;
|
2019-11-13 07:00:25 +00:00
|
|
|
|
|
|
|
|
export default PositionedContainer;
|