import * as React from "react"; import { IBadgeProps } from "react-badger"; import { IPerspective } from "./perspective"; import { IPerspectiveStorage } from "./storage"; import { Workbench } from "../workbench"; /** * Props of the perspective bar component. */ export interface IPerspectiveBarProps { /** * Whether reordering of perspectives is allowed within the perspective bar * by dragging and dropping. */ allowReordering?: boolean; /** * Props of the badge to show on buttons corresponding to perspectives when * the perspective is modified. */ badgeProps?: Partial; /** * Whether the perspective bar is editable. Editable bars show buttons for * adding a new perspective or saving the current one. Non-editable bars * do not show these buttons, but of course you may still modify the * perspectives from other components. */ editable?: boolean; /** * Error message to show on the perspective bar when the perspectives cannot * be loaded from the storage. */ errorMessage?: string; /** * Fallback component to show in the perspective bar when the perspectives * are being loaded. */ fallback?: React.ReactNode; /** * Function to call when the selected perspective is about to be changed. * * The function will be called with the new perspective ID that is about * to become active. The function must return true if it wishes to * _prevent_ the default behaviour of the perspective bar, which is to * load the perspective that the user has selected. */ onChange?: (id: string) => boolean | void; /** * Prop that allows the user to control the selected perspective ID from * the outside. */ selectedPerspectiveId?: string | undefined; /** * The perspective storage that the perspective bar uses to store * perspectives. */ storage?: IPerspectiveStorage; /** * The workbench that the perspective bar is associated to. */ workbench: Workbench; } /** * State of the perspective bar component. */ export interface IPerspectiveBarState { /** * Dummy counter that can be used to force updates to the perspective bar. */ counter: number; /** * Whether the last loading attempt ended with an error. */ error: boolean; /** * Array containing all the perspectives that were loaded by the previous * attempt. undefined if the perspectives have not been loaded yet or if the * loading attempt ended with an error. */ perspectives: Array<[string, IPerspective]> | undefined; /** * A promise that will eventually resolve to the list of perspectives in the * perspective bar. When undefined, the perspective bar is not loading * anything. */ promise: Promise> | undefined; /** * ID of the selected perspective that the user is currently editing if * the component is not controlled from the outside via props. */ selectedPerspectiveId: string | undefined; } export declare class PerspectiveBar extends React.Component { /** * Unique identifier for the droppable area of the current perspective bar. */ private _droppableId; /** * When this variable is positive, the next state change event from the * workbench will be ignored and the variable will be decremented by one. * When this variable is zero or negative, the state change event from * the workbench will update the perspectiveChanged state * variable of the bar. */ private _ignoreStateChangeCounter; /** * The last known state of the workbench. */ private _lastState; private _storage; private _workbench; static getDerivedStateFromProps(props: IPerspectiveBarProps): { selectedPerspectiveId: string | undefined; } | null; constructor(props: IPerspectiveBarProps); componentDidMount(): void; componentDidUpdate(): void; componentWillUnmount(): void; render(): React.JSX.Element; /** * Cancels the current attempt to load the list of perspectives. */ private _cancelLoading; /** * Returns whether the buttons in the perspective bar can be reordered by * dragging and dropping. */ private _canReorder; private _createNewPerspective; /** * Determines whether the state of the current perspective needs to be saved * after a `stateChanged` event. * * The problem we are solving here is that `stateChanged` is fired not only * for item creations / rearrangements but also when the user changes the * selection in the perspective. We want to ignore selection changes but save * the perspective state whenever an actual change happens. * * @param {IPerspective} newState the new state of the workbench * @return {boolean} if the new state of the workbench is different from the * state of the current perspective in the perspective storage, * ignoring selection changes */ private _currentPerspectiveNeedsSavingAfterChange; /** * Forces the component to reload the current list of perspectives from * the storage backend. */ private _forceReload; private _loadPerspectiveById; private _onPerspectiveButtonClicked; private _onStorageChanged; private _onWorkbenchChanged; private _persistModificationsOfCurrentPerspective; private _revertModificationsOfCurrentPerspective; /** * Requests the component to change the selected perspective ID. If the * component is uncontrolled, the change will happen immediately. If the * component is controlled, the change is propagated to the parent via the * `onChange()` handler, which has the opportunity to prevent the change * by returning `true`. * * @param id the new perspective ID * @return true if the perspective ID is allowed to change, false otherwise */ private _requestSelectedPerspectiveIdChange; private _setStorage; private _setWorkbench; /** * Starts loading the list of perspectives if needed. */ private _startLoadingIfNeeded; private _updateCurrentPerspective; private _updateCurrentPerspectiveWith; } /** * Props for the button that allows the user to load a perspective. */ export interface ILoadPerspectiveButtonProps { /** * Props of the badge to show on the button when the perspective is modified. */ badgeProps?: Partial; /** * Label of the button to show. */ label?: React.ReactNode; /** * Whether the perspective was modified by the user compared to its last * stored base state in the perspective storage. */ modified?: boolean; /** * Handler to call when the user clicks on the button in order to load the * perspective. */ onClick?: (event: React.SyntheticEvent) => void; /** * Whether the perspective is currently selected. */ selected?: boolean; } /** * Props for the button that allows the user to create a new perspective. */ export interface INewPerspectiveButtonProps { /** * Handler to call when the user clicks on the button in order to save the * current configuration as a new perspective. */ onClick?: (event: React.SyntheticEvent) => void; } /** * Props for the button that allows the user to reload the list of perspectives * in case of an error. */ export interface IReloadPerspectivesButtonProps { /** * Label to use on the button. */ label?: string; /** * Handler to call when the user clicks on the button in order to reload the * list of perspectives. */ onClick?: (event: React.SyntheticEvent) => void; } /** * Props for the button that allows the user to save a perspective. */ export interface ISavePerspectiveButtonProps { /** * Whether the button is enabled. */ disabled?: boolean; /** * Handler to call when the user clicks on the button in order to save the * current configuration as a perspective. */ onClick?: (event: React.SyntheticEvent) => void; }