d10ab5f67c
This PR is the first part of the creation of the Chart editor. https://github.com/user-attachments/assets/8b0af8ea-be41-4506-84cb-e40f5521cbf0 Done: - Bar chart settings (except filters) - Line chart settings (except filters) In progress: - Pie chart settings - Number chart settings - Gauge chart settings Left to do: - Loosen the backend validation to allow the user to save a partial configuration, validate the graph configuration in the frontend and display a error friendly message in the graph if the config is not completed yet - Implement the filter edition - Finish the other graph types settings
57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import { useCallback } from 'react';
|
|
|
|
import { CommandMenuPages } from '@/command-menu/types/CommandMenuPages';
|
|
import { useSetRecoilComponentState } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentState';
|
|
|
|
import { useNavigatePageLayoutCommandMenu } from '@/command-menu/pages/page-layout/hooks/useNavigatePageLayoutCommandMenu';
|
|
import { PageLayoutComponentInstanceContext } from '@/page-layout/states/contexts/PageLayoutComponentInstanceContext';
|
|
import { pageLayoutEditingWidgetIdComponentState } from '@/page-layout/states/pageLayoutEditingWidgetIdComponentState';
|
|
import { useAvailableComponentInstanceIdOrThrow } from '@/ui/utilities/state/component-state/hooks/useAvailableComponentInstanceIdOrThrow';
|
|
import { t } from '@lingui/core/macro';
|
|
import { WidgetType } from '~/generated/graphql';
|
|
|
|
export const useEditPageLayoutWidget = (pageLayoutIdFromProps?: string) => {
|
|
const pageLayoutId = useAvailableComponentInstanceIdOrThrow(
|
|
PageLayoutComponentInstanceContext,
|
|
pageLayoutIdFromProps,
|
|
);
|
|
|
|
const setPageLayoutEditingWidgetId = useSetRecoilComponentState(
|
|
pageLayoutEditingWidgetIdComponentState,
|
|
pageLayoutId,
|
|
);
|
|
|
|
const { navigatePageLayoutCommandMenu } = useNavigatePageLayoutCommandMenu();
|
|
|
|
const handleEditWidget = useCallback(
|
|
({
|
|
widgetId,
|
|
widgetType,
|
|
}: {
|
|
widgetId: string;
|
|
widgetType: WidgetType;
|
|
}) => {
|
|
setPageLayoutEditingWidgetId(widgetId);
|
|
|
|
if (widgetType === WidgetType.IFRAME) {
|
|
navigatePageLayoutCommandMenu({
|
|
commandMenuPage: CommandMenuPages.PageLayoutIframeConfig,
|
|
pageTitle: t`Edit iFrame`,
|
|
});
|
|
}
|
|
|
|
if (widgetType === WidgetType.GRAPH) {
|
|
navigatePageLayoutCommandMenu({
|
|
commandMenuPage: CommandMenuPages.PageLayoutGraphTypeSelect,
|
|
pageTitle: t`Edit Graph`,
|
|
});
|
|
}
|
|
},
|
|
[setPageLayoutEditingWidgetId, navigatePageLayoutCommandMenu],
|
|
);
|
|
|
|
return {
|
|
handleEditWidget,
|
|
};
|
|
};
|