2021-09-09 15:10:22 +00:00
|
|
|
import Widget from "./widget";
|
|
|
|
|
import IconSVG from "./icon.svg";
|
|
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
|
|
|
|
import {
|
|
|
|
|
BlueprintOperationTypes,
|
|
|
|
|
GRID_DENSITY_MIGRATION_V1,
|
|
|
|
|
} from "widgets/constants";
|
|
|
|
|
|
|
|
|
|
export const CONFIG = {
|
|
|
|
|
type: Widget.getWidgetType(),
|
|
|
|
|
name: "Tabs",
|
|
|
|
|
iconSVG: IconSVG,
|
|
|
|
|
needsMeta: true,
|
|
|
|
|
isCanvas: true,
|
|
|
|
|
defaults: {
|
2021-09-20 10:43:44 +00:00
|
|
|
rows: 10 * GRID_DENSITY_MIGRATION_V1,
|
|
|
|
|
columns: 6 * GRID_DENSITY_MIGRATION_V1,
|
2021-09-09 15:10:22 +00:00
|
|
|
shouldScrollContents: false,
|
|
|
|
|
widgetName: "Tabs",
|
|
|
|
|
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(),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default Widget;
|