26e2fe349f
With the new side panel, we are able to delete a widget with the side panel still open. This caused the app to crash because we threw when the widget id wasn't defined. This PR fixes this by closing the side panel in the delete action and by returning null instead of throwing. ## Before https://github.com/user-attachments/assets/092bfe62-82dc-4d83-9967-1cc753ecf55e ## After https://github.com/user-attachments/assets/8bed6cc5-961b-4112-8cf5-e587865d14da
53 lines
2.0 KiB
TypeScript
53 lines
2.0 KiB
TypeScript
import { ChartSettings } from '@/command-menu/pages/page-layout/components/ChartSettings';
|
|
import { WidgetSettingsFooter } from '@/command-menu/pages/page-layout/components/WidgetSettingsFooter';
|
|
import { usePageLayoutIdFromContextStoreTargetedRecord } from '@/command-menu/pages/page-layout/hooks/usePageLayoutFromContextStoreTargetedRecord';
|
|
import { pageLayoutDraftComponentState } from '@/page-layout/states/pageLayoutDraftComponentState';
|
|
import { pageLayoutEditingWidgetIdComponentState } from '@/page-layout/states/pageLayoutEditingWidgetIdComponentState';
|
|
import { GraphWidgetComponentInstanceContext } from '@/page-layout/widgets/graph/states/contexts/GraphWidgetComponentInstanceContext';
|
|
import { useRecoilComponentValue } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValue';
|
|
import styled from '@emotion/styled';
|
|
import { isDefined } from 'twenty-shared/utils';
|
|
|
|
const StyledContainer = styled.div`
|
|
display: flex;
|
|
flex-direction: column;
|
|
height: 100%;
|
|
`;
|
|
|
|
export const CommandMenuPageLayoutChartSettings = () => {
|
|
const { pageLayoutId } = usePageLayoutIdFromContextStoreTargetedRecord();
|
|
|
|
const draftPageLayout = useRecoilComponentValue(
|
|
pageLayoutDraftComponentState,
|
|
pageLayoutId,
|
|
);
|
|
|
|
const pageLayoutEditingWidgetId = useRecoilComponentValue(
|
|
pageLayoutEditingWidgetIdComponentState,
|
|
pageLayoutId,
|
|
);
|
|
|
|
const widgetInEditMode = draftPageLayout.tabs
|
|
.flatMap((tab) => tab.widgets)
|
|
.find((widget) => widget.id === pageLayoutEditingWidgetId);
|
|
|
|
if (
|
|
!isDefined(widgetInEditMode) ||
|
|
!isDefined(widgetInEditMode.configuration) ||
|
|
!('graphType' in widgetInEditMode.configuration)
|
|
) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<StyledContainer>
|
|
<GraphWidgetComponentInstanceContext.Provider
|
|
value={{ instanceId: widgetInEditMode.id }}
|
|
>
|
|
<ChartSettings widget={widgetInEditMode} />
|
|
<WidgetSettingsFooter />
|
|
</GraphWidgetComponentInstanceContext.Provider>
|
|
</StyledContainer>
|
|
);
|
|
};
|