2022-09-30 09:18:03 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
feat: Non auto height invisible widgets (#20118)
## Description
This PR adds another feature update we had planned for Auto Height
- [ ] For new applications, in View and Preview mode, any widget which
is invisible will let go of its space and collapse if it's either on the
main Canvas or a container-like widget which has Auto-height enabled.
- [ ] Widgets within a container-like Widget, say Tabs, that doesn't
have Auto-height enabled, will now let go of their space if they're
invisible.
- [ ] The experience in Edit mode has not changed.
TL;DR: In new applications, in the Preview and Published _AKA_ View
modes, if a widget is invisible and within an Auto-height-enabled
container like a Tab, a Modal, a Form, or the main Canvas, it will fully
collapse, allowing widgets below it to move up and take its space. This
changes the behavior today prior to the release of this PR for
Auto-height-enabled widgets.
Fixes #19983
Fixes #18681
2023-02-14 13:36:19 +00:00
|
|
|
import { GridDefaults, WidgetHeightLimits } from "constants/WidgetConstants";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
2022-01-21 10:19:10 +00:00
|
|
|
import { BlueprintOperationTypes } from "widgets/constants";
|
|
|
|
|
import IconSVG from "./icon.svg";
|
|
|
|
|
import Widget from "./widget";
|
2021-09-09 15:10:22 +00:00
|
|
|
|
|
|
|
|
export const CONFIG = {
|
|
|
|
|
type: Widget.getWidgetType(),
|
|
|
|
|
name: "Tabs",
|
|
|
|
|
iconSVG: IconSVG,
|
|
|
|
|
needsMeta: true,
|
|
|
|
|
isCanvas: true,
|
2022-11-23 09:48:23 +00:00
|
|
|
// TODO(abhinav): Default config like these are not serializable
|
|
|
|
|
// So they will not work with Redux state and they might break
|
|
|
|
|
// evaluations. One way to handle these types of properties is to
|
|
|
|
|
// define them in a Map which the platform understands to have
|
|
|
|
|
// them stored only in the WidgetFactory.
|
feat: Non auto height invisible widgets (#20118)
## Description
This PR adds another feature update we had planned for Auto Height
- [ ] For new applications, in View and Preview mode, any widget which
is invisible will let go of its space and collapse if it's either on the
main Canvas or a container-like widget which has Auto-height enabled.
- [ ] Widgets within a container-like Widget, say Tabs, that doesn't
have Auto-height enabled, will now let go of their space if they're
invisible.
- [ ] The experience in Edit mode has not changed.
TL;DR: In new applications, in the Preview and Published _AKA_ View
modes, if a widget is invisible and within an Auto-height-enabled
container like a Tab, a Modal, a Form, or the main Canvas, it will fully
collapse, allowing widgets below it to move up and take its space. This
changes the behavior today prior to the release of this PR for
Auto-height-enabled widgets.
Fixes #19983
Fixes #18681
2023-02-14 13:36:19 +00:00
|
|
|
canvasHeightOffset: (props: WidgetProps): number => {
|
|
|
|
|
let offset =
|
|
|
|
|
props.borderWidth && props.borderWidth > 1
|
|
|
|
|
? Math.ceil(
|
|
|
|
|
(2 * parseInt(props.borderWidth, 10) || 0) /
|
|
|
|
|
GridDefaults.DEFAULT_GRID_ROW_HEIGHT,
|
|
|
|
|
)
|
|
|
|
|
: 0;
|
|
|
|
|
|
|
|
|
|
if (props.shouldShowTabs === true) {
|
|
|
|
|
offset += 4;
|
|
|
|
|
}
|
|
|
|
|
return offset;
|
|
|
|
|
},
|
2022-11-23 09:48:23 +00:00
|
|
|
features: {
|
2022-11-24 18:40:06 +00:00
|
|
|
dynamicHeight: {
|
|
|
|
|
sectionIndex: 1,
|
|
|
|
|
active: true,
|
|
|
|
|
},
|
2022-11-23 09:48:23 +00:00
|
|
|
},
|
2021-09-09 15:10:22 +00:00
|
|
|
defaults: {
|
2022-11-27 17:12:00 +00:00
|
|
|
rows: WidgetHeightLimits.MIN_CANVAS_HEIGHT_IN_ROWS + 5,
|
2022-01-21 10:19:10 +00:00
|
|
|
columns: 24,
|
2021-09-09 15:10:22 +00:00
|
|
|
shouldScrollContents: false,
|
|
|
|
|
widgetName: "Tabs",
|
2021-12-14 07:55:58 +00:00
|
|
|
animateLoading: true,
|
2022-09-30 09:18:03 +00:00
|
|
|
borderWidth: 1,
|
|
|
|
|
borderColor: Colors.GREY_5,
|
|
|
|
|
backgroundColor: Colors.WHITE,
|
2022-11-27 17:12:00 +00:00
|
|
|
minDynamicHeight: WidgetHeightLimits.MIN_CANVAS_HEIGHT_IN_ROWS + 5,
|
2021-09-09 15:10:22 +00:00
|
|
|
tabsObj: {
|
|
|
|
|
tab1: {
|
|
|
|
|
label: "Tab 1",
|
|
|
|
|
id: "tab1",
|
|
|
|
|
widgetId: "",
|
|
|
|
|
isVisible: true,
|
|
|
|
|
index: 0,
|
|
|
|
|
},
|
|
|
|
|
tab2: {
|
|
|
|
|
label: "Tab 2",
|
|
|
|
|
id: "tab2",
|
|
|
|
|
widgetId: "",
|
|
|
|
|
isVisible: true,
|
|
|
|
|
index: 1,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
shouldShowTabs: true,
|
|
|
|
|
defaultTab: "Tab 1",
|
|
|
|
|
blueprint: {
|
2021-09-21 07:55:56 +00:00
|
|
|
view: [
|
|
|
|
|
{
|
|
|
|
|
type: "CANVAS_WIDGET",
|
|
|
|
|
position: { left: 0, top: 0 },
|
|
|
|
|
props: {
|
|
|
|
|
detachFromLayout: true,
|
|
|
|
|
canExtend: true,
|
|
|
|
|
isVisible: true,
|
|
|
|
|
isDisabled: false,
|
|
|
|
|
shouldScrollContents: false,
|
|
|
|
|
tabId: "tab1",
|
|
|
|
|
tabName: "Tab 1",
|
|
|
|
|
children: [],
|
|
|
|
|
version: 1,
|
2022-11-27 17:12:00 +00:00
|
|
|
bottomRow: WidgetHeightLimits.MIN_CANVAS_HEIGHT_IN_ROWS,
|
2021-09-21 07:55:56 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
type: "CANVAS_WIDGET",
|
|
|
|
|
position: { left: 0, top: 0 },
|
|
|
|
|
props: {
|
|
|
|
|
detachFromLayout: true,
|
|
|
|
|
canExtend: true,
|
|
|
|
|
isVisible: true,
|
|
|
|
|
isDisabled: false,
|
|
|
|
|
shouldScrollContents: false,
|
|
|
|
|
tabId: "tab2",
|
|
|
|
|
tabName: "Tab 2",
|
|
|
|
|
children: [],
|
|
|
|
|
version: 1,
|
2022-11-27 17:12:00 +00:00
|
|
|
bottomRow: WidgetHeightLimits.MIN_CANVAS_HEIGHT_IN_ROWS,
|
2021-09-21 07:55:56 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
2021-09-09 15:10:22 +00:00
|
|
|
operations: [
|
|
|
|
|
{
|
|
|
|
|
type: BlueprintOperationTypes.MODIFY_PROPS,
|
|
|
|
|
fn: (widget: WidgetProps & { children?: WidgetProps[] }) => {
|
|
|
|
|
const tabs = Object.values({ ...widget.tabsObj });
|
2021-09-21 07:55:56 +00:00
|
|
|
const tabIds: Record<string, string> = (
|
|
|
|
|
widget.children || []
|
|
|
|
|
).reduce((idsObj, eachChild) => {
|
|
|
|
|
idsObj = { ...idsObj, [eachChild.tabId]: eachChild.widgetId };
|
|
|
|
|
return idsObj;
|
|
|
|
|
}, {});
|
2021-09-09 15:10:22 +00:00
|
|
|
const tabsObj = tabs.reduce((obj: any, tab: any) => {
|
|
|
|
|
const newTab = { ...tab };
|
2021-09-21 07:55:56 +00:00
|
|
|
newTab.widgetId = tabIds[newTab.id];
|
2021-09-09 15:10:22 +00:00
|
|
|
obj[newTab.id] = newTab;
|
|
|
|
|
return obj;
|
|
|
|
|
}, {});
|
|
|
|
|
const updatePropertyMap = [
|
|
|
|
|
{
|
|
|
|
|
widgetId: widget.widgetId,
|
|
|
|
|
propertyName: "tabsObj",
|
|
|
|
|
propertyValue: tabsObj,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
return updatePropertyMap;
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
version: 3,
|
|
|
|
|
},
|
|
|
|
|
properties: {
|
|
|
|
|
derived: Widget.getDerivedPropertiesMap(),
|
|
|
|
|
default: Widget.getDefaultPropertiesMap(),
|
|
|
|
|
meta: Widget.getMetaPropertiesMap(),
|
|
|
|
|
config: Widget.getPropertyPaneConfig(),
|
2022-08-09 13:05:15 +00:00
|
|
|
contentConfig: Widget.getPropertyPaneContentConfig(),
|
|
|
|
|
styleConfig: Widget.getPropertyPaneStyleConfig(),
|
2022-11-28 04:44:31 +00:00
|
|
|
stylesheetConfig: Widget.getStylesheetConfig(),
|
2021-09-09 15:10:22 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Widget;
|