2022-09-30 09:18:03 +00:00
|
|
|
import { Colors } from "constants/Colors";
|
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.
|
|
|
|
|
canvasHeightOffset: (props: WidgetProps): number =>
|
|
|
|
|
props.shouldShowTabs === true ? 4 : 0,
|
|
|
|
|
features: {
|
|
|
|
|
dynamicHeight: true,
|
|
|
|
|
},
|
2021-09-09 15:10:22 +00:00
|
|
|
defaults: {
|
2022-01-21 10:19:10 +00:00
|
|
|
rows: 40,
|
|
|
|
|
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,
|
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,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
],
|
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(),
|
2021-09-09 15:10:22 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Widget;
|