Skip to content

Commit

Permalink
Merge pull request #5536 from gooddata/ine-lx-588
Browse files Browse the repository at this point in the history
feat: add D&D of nested layout
  • Loading branch information
xMort authored Nov 5, 2024
2 parents 69e09c9 + 6160681 commit 942ed0c
Show file tree
Hide file tree
Showing 51 changed files with 842 additions and 72 deletions.
85 changes: 81 additions & 4 deletions libs/sdk-ui-dashboard/api/sdk-ui-dashboard.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ import { IDashboardInsightProps as IDashboardInsightProps_2 } from './types.js';
import { IDashboardKpiProps as IDashboardKpiProps_2 } from './types.js';
import { IDashboardLayout } from '@gooddata/sdk-model';
import { IDashboardLayoutItem } from '@gooddata/sdk-model';
import { IDashboardLayoutProps as IDashboardLayoutProps_2 } from './types.js';
import { IDashboardLayoutSection } from '@gooddata/sdk-model';
import { IDashboardLayoutSectionHeader } from '@gooddata/sdk-model';
import { IDashboardLayoutSizeByScreenSize } from '@gooddata/sdk-model';
Expand Down Expand Up @@ -1226,6 +1227,9 @@ export type CustomDashboardKpiComponent = ComponentType<IDashboardKpiProps>;
// @alpha (undocumented)
export type CustomDashboardLayoutComponent = ComponentType<IDashboardLayoutProps>;

// @alpha (undocumented)
export type CustomDashboardNestedLayoutComponent = ComponentType<IDashboardNestedLayoutProps>;

// @public (undocumented)
export type CustomDashboardRichTextComponent = ComponentType<IDashboardRichTextProps>;

Expand Down Expand Up @@ -2404,6 +2408,28 @@ export interface DashboardLayoutChangedPayload {
// @beta (undocumented)
export type DashboardLayoutCommands = AddLayoutSection | MoveLayoutSection | RemoveLayoutSection | ChangeLayoutSectionHeader | AddSectionItems | MoveSectionItem | RemoveSectionItem | RemoveSectionItemByWidgetRef | ResizeHeight;

// @alpha (undocumented)
export type DashboardLayoutComponentProvider = (widget: IDashboardLayout) => CustomDashboardNestedLayoutComponent;

// @internal (undocumented)
export type DashboardLayoutDraggableComponent = {
DraggingComponent?: DashboardLayoutDraggingComponent;
type: "dashboardLayout";
};

// @internal (undocumented)
export type DashboardLayoutDraggableItem = BaseDraggableMovingItem & {
type: "dashboardLayout";
};

// @internal (undocumented)
export type DashboardLayoutDraggableListItem = BaseDraggableLayoutItem & {
type: "dashboardLayoutListItem";
};

// @internal (undocumented)
export type DashboardLayoutDraggingComponent = ComponentType<IDashboardLayoutDraggingComponentProps>;

// @beta
export interface DashboardLayoutSectionAdded extends IDashboardEvent {
// (undocumented)
Expand Down Expand Up @@ -2530,6 +2556,9 @@ export interface DashboardLayoutSectionRemovedPayload {
readonly stashIdentifier?: StashedDashboardItemsId;
}

// @internal
export type DashboardLayoutWidgetComponentSet = CustomComponentBase<IDashboardNestedLayoutProps, Parameters<DashboardLayoutComponentProvider>> & DraggableComponent & Partial<CreatableByDragComponent> & Partial<CreatablePlaceholderComponent<IDashboardNestedLayoutProps>> & ConfigurableWidget<IDashboardLayout>;

// @beta (undocumented)
export interface DashboardMetaState {
descriptor?: DashboardDescriptor;
Expand Down Expand Up @@ -3062,9 +3091,15 @@ export const DefaultDashboardKpiPlaceholderWidget: CustomDashboardWidgetComponen
// @alpha (undocumented)
export const DefaultDashboardLayout: (props: IDashboardLayoutProps) => JSX.Element;

// @internal (undocumented)
export function DefaultDashboardLayoutComponentSetFactory(dashboardLayoutComponentProvider: DashboardLayoutComponentProvider): DashboardLayoutWidgetComponentSet;

// @internal (undocumented)
export const DefaultDashboardMainContent: (_: IDashboardProps) => React_2.JSX.Element;

// @public
export const DefaultDashboardNestedLayout: ComponentType<IDashboardLayoutProps_2>;

// @public
export const DefaultDashboardRichText: ComponentType<IDashboardRichTextProps_2>;

Expand Down Expand Up @@ -3202,14 +3237,14 @@ export function dispatchAndWaitFor<TCommand extends DashboardCommands, TResult>(

// @internal
export type DraggableComponent = {
dragging: AttributeFilterDraggableComponent | DateFilterDraggableComponent | KpiDraggableComponent | InsightDraggableComponent | RichTextDraggableComponent | VisualizationSwitcherDraggableComponent | CustomDraggableComponent;
dragging: AttributeFilterDraggableComponent | DateFilterDraggableComponent | KpiDraggableComponent | InsightDraggableComponent | RichTextDraggableComponent | VisualizationSwitcherDraggableComponent | DashboardLayoutDraggableComponent | CustomDraggableComponent;
};

// @internal (undocumented)
export type DraggableContentItem = AttributeFilterDraggableItem | AttributeFilterPlaceholderDraggableItem | DateFilterDraggableItem | InsightDraggableItem | InsightDraggableListItem | InsightPlaceholderDraggableItem | KpiDraggableItem | KpiPlaceholderDraggableItem | RichTextDraggableItem | RichTextDraggableListItem | VisualizationSwitcherDraggableItem | VisualizationSwitcherDraggableListItem | CustomWidgetDraggableItem | CustomDraggableItem;
export type DraggableContentItem = AttributeFilterDraggableItem | AttributeFilterPlaceholderDraggableItem | DateFilterDraggableItem | InsightDraggableItem | InsightDraggableListItem | InsightPlaceholderDraggableItem | KpiDraggableItem | KpiPlaceholderDraggableItem | RichTextDraggableItem | RichTextDraggableListItem | VisualizationSwitcherDraggableItem | VisualizationSwitcherDraggableListItem | DashboardLayoutDraggableItem | DashboardLayoutDraggableListItem | CustomWidgetDraggableItem | CustomDraggableItem;

// @internal (undocumented)
export type DraggableContentItemType = "attributeFilter" | "dateFilter" | "attributeFilter-placeholder" | "insightListItem" | "insight" | "insight-placeholder" | "kpi" | "kpi-placeholder" | "richText" | "richTextListItem" | "visualizationSwitcher" | "visualizationSwitcherListItem" | "custom";
export type DraggableContentItemType = "attributeFilter" | "dateFilter" | "attributeFilter-placeholder" | "insightListItem" | "insight" | "insight-placeholder" | "kpi" | "kpi-placeholder" | "richText" | "richTextListItem" | "visualizationSwitcher" | "visualizationSwitcherListItem" | "dashboardLayout" | "dashboardLayoutListItem" | "custom";

// @internal (undocumented)
export const DraggableCreatePanelItem: React_2.FC<IDraggableCreatePanelItemProps>;
Expand Down Expand Up @@ -3237,6 +3272,8 @@ export type DraggableItemComponentTypeMapping = {
richTextListItem: RichTextDraggableListItem;
visualizationSwitcher: VisualizationSwitcherDraggableItem;
visualizationSwitcherListItem: VisualizationSwitcherDraggableListItem;
dashboardLayout: DashboardLayoutDraggableItem;
dashboardLayoutListItem: DashboardLayoutDraggableListItem;
custom: CustomDraggableItem;
};

Expand All @@ -3253,7 +3290,7 @@ export type DraggableItemType = DraggableContentItemType | DraggableInternalItem
export type DraggableItemTypeMapping = DraggableItemComponentTypeMapping & DraggableItemInternalTypeMapping;

// @internal (undocumented)
export type DraggableLayoutItem = InsightDraggableItem | KpiDraggableItem | RichTextDraggableItem | VisualizationSwitcherDraggableItem | CustomWidgetDraggableItem;
export type DraggableLayoutItem = InsightDraggableItem | KpiDraggableItem | RichTextDraggableItem | VisualizationSwitcherDraggableItem | DashboardLayoutDraggableItem | CustomWidgetDraggableItem;

// @internal (undocumented)
export interface DraggingComponentProps {
Expand Down Expand Up @@ -4012,6 +4049,7 @@ export interface IDashboardCustomComponentProps {
DashboardContentComponentProvider?: OptionalDashboardContentComponentProvider;
// @alpha
DashboardDateFilterComponentProvider?: OptionalDateFilterComponentProvider;
DashboardLayoutComponentProvider?: OptionalDashboardLayoutComponentProvider;
// @internal
EmptyLayoutDropZoneBodyComponent?: CustomEmptyLayoutDropZoneBodyComponent;
// @alpha
Expand Down Expand Up @@ -4296,6 +4334,12 @@ export interface IDashboardLayoutCustomizer {
customizeFluidLayout(fun: FluidLayoutCustomizationFn): IDashboardLayoutCustomizer;
}

// @internal (undocumented)
export type IDashboardLayoutDraggingComponentProps = {
itemType: "dashboardLayout";
item: DashboardLayoutDraggableItem;
};

// @alpha (undocumented)
export interface IDashboardLayoutProps {
// (undocumented)
Expand All @@ -4308,6 +4352,28 @@ export interface IDashboardLayoutProps {
onFiltersChange?: (filters: (IDashboardFilter | FilterContextItem)[], resetOthers?: boolean) => void;
}

// @alpha (undocumented)
export interface IDashboardNestedLayoutProps {
backend?: IAnalyticalBackend;
clientHeight?: number;
clientWidth?: number;
// (undocumented)
ErrorComponent?: React.ComponentType<IErrorProps>;
// (undocumented)
layout?: IDashboardLayout<ExtendedDashboardWidget>;
// (undocumented)
onDrill?: OnFiredDashboardDrillEvent;
// (undocumented)
onError?: OnError;
// (undocumented)
onFiltersChange?: (filters: (IDashboardFilter | FilterContextItem)[], resetOthers?: boolean) => void;
// (undocumented)
parentLayoutItemSize?: IDashboardLayoutSizeByScreenSize;
// (undocumented)
screen?: ScreenSize;
workspace?: string;
}

// @public
export interface IDashboardPluginContract_V1 extends DashboardPluginDescriptor {
onPluginLoaded?(ctx: DashboardContext, parameters?: string): Promise<void> | void;
Expand Down Expand Up @@ -5397,6 +5463,12 @@ export const isDashboardKpiWidgetMeasureChanged: (obj: unknown) => obj is Dashbo
// @beta
export const isDashboardLayoutChanged: (obj: unknown) => obj is DashboardLayoutChanged;

// @internal (undocumented)
export function isDashboardLayoutDraggableItem(item: any): item is DashboardLayoutDraggableItem;

// @internal (undocumented)
export function isDashboardLayoutDraggableListItem(item: any): item is DashboardLayoutDraggableListItem;

// @beta
export const isDashboardLayoutSectionAdded: (obj: unknown) => obj is DashboardLayoutSectionAdded;

Expand Down Expand Up @@ -5552,6 +5624,8 @@ export interface ISidebarProps {
// @internal
AttributeFilterComponentSet?: AttributeFilterComponentSet;
configurationPanelClassName?: string;
// @internal
DashboardLayoutWidgetComponentSet?: DashboardLayoutWidgetComponentSet;
DefaultSidebar: ComponentType<ISidebarProps>;
// @internal
DeleteDropZoneComponent?: React.ComponentType;
Expand Down Expand Up @@ -6151,6 +6225,9 @@ export type OptionalAttributeFilterComponentProvider = OptionalProvider<Attribut
// @alpha (undocumented)
export type OptionalDashboardContentComponentProvider = OptionalProvider<DashboardContentComponentProvider>;

// @alpha (undocumented)
export type OptionalDashboardLayoutComponentProvider = OptionalProvider<DashboardLayoutComponentProvider>;

// @public (undocumented)
export type OptionalDateFilterComponentProvider = OptionalProvider<DateFilterComponentProvider>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import {
IDashboardRichTextProps,
IDashboardVisualizationSwitcherProps,
IDashboardWidgetProps,
IDashboardNestedLayoutProps,
} from "../widget/types.js";
import {
AttributeFilterDraggableItem,
CustomDraggableItem,
DashboardLayoutDraggableItem,
DateFilterDraggableItem,
DraggableContentItemType,
IWrapCreatePanelItemWithDragComponent,
Expand All @@ -31,8 +33,10 @@ import {
RichTextComponentProvider,
WidgetComponentProvider,
VisualizationSwitcherComponentProvider,
DashboardLayoutComponentProvider,
} from "../dashboardContexts/types.js";
import {
IDashboardLayout,
IInsightWidget,
IKpiWidget,
IRichTextWidget,
Expand Down Expand Up @@ -114,6 +118,14 @@ export type IVisualizationSwitcherDraggingComponentProps = {
item: VisualizationSwitcherDraggableItem;
};

/**
* @internal
*/
export type IDashboardLayoutDraggingComponentProps = {
itemType: "dashboardLayout";
item: DashboardLayoutDraggableItem;
};

/**
* @internal
*/
Expand Down Expand Up @@ -153,6 +165,11 @@ export type RichTextDraggingComponent = ComponentType<IRichTextDraggingComponent
export type VisualizationSwitcherDraggingComponent =
ComponentType<IVisualizationSwitcherDraggingComponentProps>;

/**
* @internal
*/
export type DashboardLayoutDraggingComponent = ComponentType<IDashboardLayoutDraggingComponentProps>;

/**
* @internal
*/
Expand Down Expand Up @@ -206,6 +223,14 @@ export type VisualizationSwitcherDraggableComponent = {
type: "visualizationSwitcher";
};

/**
* @internal
*/
export type DashboardLayoutDraggableComponent = {
DraggingComponent?: DashboardLayoutDraggingComponent;
type: "dashboardLayout";
};

/**
* @internal
*/
Expand All @@ -226,6 +251,7 @@ export type DraggableComponent = {
| InsightDraggableComponent
| RichTextDraggableComponent
| VisualizationSwitcherDraggableComponent
| DashboardLayoutDraggableComponent
| CustomDraggableComponent;
};

Expand Down Expand Up @@ -396,6 +422,19 @@ export type VisualizationSwitcherWidgetComponentSet = CustomComponentBase<
Partial<CreatablePlaceholderComponent<IDashboardWidgetProps>> &
ConfigurableWidget<IVisualizationSwitcherWidget>;

/**
* Definition of Dashboard layout widget
* @internal
*/
export type DashboardLayoutWidgetComponentSet = CustomComponentBase<
IDashboardNestedLayoutProps,
Parameters<DashboardLayoutComponentProvider>
> &
DraggableComponent &
Partial<CreatableByDragComponent> &
Partial<CreatablePlaceholderComponent<IDashboardNestedLayoutProps>> &
ConfigurableWidget<IDashboardLayout>;

/**
* Definition of widget
* @internal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
selectEnableKDRichText,
selectSupportsRichTextWidgets,
selectEnableVisualizationSwitcher,
selectEnableFlexibleLayout,
} from "../../../model/index.js";
import cx from "classnames";
import {
Expand All @@ -27,6 +28,7 @@ import {
KpiWidgetComponentSet,
RichTextWidgetComponentSet,
VisualizationSwitcherWidgetComponentSet,
DashboardLayoutWidgetComponentSet,
} from "../../componentDefinition/index.js";

interface ICreationPanelProps {
Expand All @@ -38,6 +40,7 @@ interface ICreationPanelProps {
InsightWidgetComponentSet?: InsightWidgetComponentSet;
RichTextWidgetComponentSet?: RichTextWidgetComponentSet;
VisualizationSwitcherWidgetComponentSet?: VisualizationSwitcherWidgetComponentSet;
DashboardLayoutWidgetComponentSet?: DashboardLayoutWidgetComponentSet;
}

export const CreationPanel: React.FC<ICreationPanelProps> = (props) => {
Expand All @@ -46,6 +49,7 @@ export const CreationPanel: React.FC<ICreationPanelProps> = (props) => {
const supportsRichText = useDashboardSelector(selectSupportsRichTextWidgets);
const enableRichText = useDashboardSelector(selectEnableKDRichText);
const enableVisualizationSwitcher = useDashboardSelector(selectEnableVisualizationSwitcher);
const enableFlexibleLayout = useDashboardSelector(selectEnableFlexibleLayout);
const isAnalyticalDesignerEnabled = useDashboardSelector(selectIsAnalyticalDesignerEnabled);
const isNewDashboard = useDashboardSelector(selectIsNewDashboard);
const settings = useDashboardSelector(selectSettings);
Expand All @@ -54,12 +58,14 @@ export const CreationPanel: React.FC<ICreationPanelProps> = (props) => {
const InsightWidgetComponentSet = props.InsightWidgetComponentSet!;
const RichTextWidgetComponentSet = props.RichTextWidgetComponentSet!;
const VisualizationSwitcherWidgetComponentSet = props.VisualizationSwitcherWidgetComponentSet!;
const DashboardLayoutWidgetComponentSet = props.DashboardLayoutWidgetComponentSet!;

const addItemPanelItems = useMemo(() => {
const items = compact([
InsightWidgetComponentSet.creating,
supportsKpis && KpiWidgetComponentSet.creating,
AttributeFilterComponentSet.creating,
InsightWidgetComponentSet.creating,
enableFlexibleLayout && DashboardLayoutWidgetComponentSet.creating,
enableVisualizationSwitcher && VisualizationSwitcherWidgetComponentSet.creating,
supportsRichText && enableRichText && RichTextWidgetComponentSet.creating,
]);
Expand All @@ -78,10 +84,12 @@ export const CreationPanel: React.FC<ICreationPanelProps> = (props) => {
InsightWidgetComponentSet,
RichTextWidgetComponentSet,
VisualizationSwitcherWidgetComponentSet,
DashboardLayoutWidgetComponentSet,
supportsKpis,
supportsRichText,
enableRichText,
enableVisualizationSwitcher,
enableFlexibleLayout,
WrapCreatePanelItemWithDragComponent,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const DashboardSidebar = (props: ISidebarProps): JSX.Element => {
InsightWidgetComponentSet,
RichTextWidgetComponentSet,
VisualizationSwitcherWidgetComponentSet,
DashboardLayoutWidgetComponentSet,
} = useDashboardComponentsContext();

return (
Expand All @@ -27,6 +28,7 @@ export const DashboardSidebar = (props: ISidebarProps): JSX.Element => {
InsightWidgetComponentSet={InsightWidgetComponentSet}
RichTextWidgetComponentSet={RichTextWidgetComponentSet}
VisualizationSwitcherWidgetComponentSet={VisualizationSwitcherWidgetComponentSet}
DashboardLayoutWidgetComponentSet={DashboardLayoutWidgetComponentSet}
WrapCreatePanelItemWithDragComponent={WrapCreatePanelItemWithDragComponent}
WrapInsightListItemWithDragComponent={WrapInsightListItemWithDragComponent}
DeleteDropZoneComponent={DeleteDropZoneComponent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const SidebarConfigurationPanel: React.FC<Omit<ISidebarProps, "DefaultSid
InsightWidgetComponentSet,
RichTextWidgetComponentSet,
VisualizationSwitcherWidgetComponentSet,
DashboardLayoutWidgetComponentSet,
} = props;
const { deselectWidgets } = useWidgetSelection();
const DeleteDropZoneComponent = props.DeleteDropZoneComponent!;
Expand All @@ -35,6 +36,7 @@ export const SidebarConfigurationPanel: React.FC<Omit<ISidebarProps, "DefaultSid
InsightWidgetComponentSet={InsightWidgetComponentSet}
RichTextWidgetComponentSet={RichTextWidgetComponentSet}
VisualizationSwitcherWidgetComponentSet={VisualizationSwitcherWidgetComponentSet}
DashboardLayoutWidgetComponentSet={DashboardLayoutWidgetComponentSet}
/>
</div>
<DeleteDropZoneComponent />
Expand Down
Loading

0 comments on commit 942ed0c

Please sign in to comment.