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
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';
|
|
import { pageLayoutEditingWidgetIdComponentState } from '@/page-layout/states/pageLayoutEditingWidgetIdComponentState';
|
|
import { useRecoilComponentCallbackState } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentCallbackState';
|
|
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
|
|
import { useRecoilCallback } from 'recoil';
|
|
import type { PageLayoutWidget } from '~/generated/graphql';
|
|
|
|
export const useUpdateCurrentWidgetConfig = (pageLayoutIdFromProps: string) => {
|
|
const pageLayoutDraftCallbackState = useRecoilComponentCallbackState(
|
|
pageLayoutDraftComponentState,
|
|
pageLayoutIdFromProps,
|
|
);
|
|
|
|
const currentlyEditingWidgetId = useRecoilComponentValue(
|
|
pageLayoutEditingWidgetIdComponentState,
|
|
pageLayoutIdFromProps,
|
|
);
|
|
|
|
const updateCurrentWidgetConfig = useRecoilCallback(
|
|
({ set }) =>
|
|
({
|
|
objectMetadataId,
|
|
configToUpdate,
|
|
}: {
|
|
objectMetadataId?: string | null;
|
|
configToUpdate?: Partial<PageLayoutWidget['configuration']>;
|
|
}) => {
|
|
set(pageLayoutDraftCallbackState, (prev) => ({
|
|
...prev,
|
|
tabs: prev.tabs.map((tab) => ({
|
|
...tab,
|
|
widgets: tab.widgets.map((widget) =>
|
|
widget.id === currentlyEditingWidgetId
|
|
? {
|
|
...widget,
|
|
objectMetadataId:
|
|
objectMetadataId ?? widget.objectMetadataId,
|
|
configuration: {
|
|
...(widget.configuration ?? {}),
|
|
...configToUpdate,
|
|
} as PageLayoutWidget['configuration'],
|
|
}
|
|
: widget,
|
|
),
|
|
})),
|
|
}));
|
|
},
|
|
[pageLayoutDraftCallbackState, currentlyEditingWidgetId],
|
|
);
|
|
|
|
return { updateCurrentWidgetConfig };
|
|
};
|