Skip to content

Commit

Permalink
Remove redux store usage from EditWidgetFrame.
Browse files Browse the repository at this point in the history
  • Loading branch information
linuspahl committed Nov 1, 2024
1 parent 6c42c6d commit e8f0fdf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import WidgetContext from 'views/components/contexts/WidgetContext';
import QueryEditModeContext from 'views/components/contexts/QueryEditModeContext';
import SaveOrCancelButtons from 'views/components/widgets/SaveOrCancelButtons';
import WidgetEditApplyAllChangesProvider from 'views/components/contexts/WidgetEditApplyAllChangesProvider';
import useViewType from 'views/hooks/useViewType';
import View from 'views/logic/views/View';
import type Widget from 'views/logic/widgets/Widget';

import WidgetQueryControls from '../WidgetQueryControls';
import WidgetOverrideElements from '../WidgetOverrideElements';
Expand All @@ -50,25 +49,25 @@ const Visualization = styled.div`

type Props = {
children: React.ReactNode,
displaySubmitActions?: boolean,
onCancel: () => void,
onSubmit: () => void,
displaySubmitActions?: boolean,
showQueryControls?: boolean,
onChange: (widgetId: string, newWidget: Widget) => Promise<void>,
};

const EditWidgetFrame = ({ children, onCancel, onSubmit, displaySubmitActions = true }: Props) => {
const EditWidgetFrame = ({ children, onCancel, onSubmit, displaySubmitActions = true, showQueryControls = true, onChange }: Props) => {
const widget = useContext(WidgetContext);
const viewType = useViewType();
const isDashboard = viewType === View.Type.Dashboard;

if (!widget) {
return <Spinner text="Loading widget ..." />;
}

return (
<WidgetEditApplyAllChangesProvider widget={widget}>
<WidgetEditApplyAllChangesProvider widget={widget} onChange={onChange}>
<DisableSubmissionStateProvider>
<Container>
{(isDashboard && !widget.returnsAllRecords) && (
{(showQueryControls && !widget.returnsAllRecords) && (
<QueryControls>
<QueryEditModeContext.Provider value="widget">
<WidgetQueryControls />
Expand Down
13 changes: 10 additions & 3 deletions graylog2-web-interface/src/views/components/widgets/Widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,14 @@ type EditWrapperProps = {
editing: boolean,
fields: FieldTypeMappingsList,
id: string,
onToggleEdit: () => void,
onCancelEdit: () => void,
onToggleEdit: () => void,
onWidgetConfigChange: (newWidgetConfig: WidgetConfig) => void,
showQueryControls?: boolean,
type: string,
};

const EditWrapper = ({
export const EditWrapper = ({
children,
config,
editing,
Expand All @@ -168,12 +169,17 @@ const EditWrapper = ({
onCancelEdit,
onWidgetConfigChange,
type,
showQueryControls,
}: EditWrapperProps) => {
const EditComponent = useMemo(() => _editComponentForType(type), [type]);
const hasOwnSubmitButton = _hasOwnEditSubmitButton(type);

return editing ? (
<EditWidgetFrame onSubmit={onToggleEdit} onCancel={onCancelEdit} displaySubmitActions={!hasOwnSubmitButton}>
<EditWidgetFrame onSubmit={onToggleEdit}
onCancel={onCancelEdit}
onChange={onWidgetConfigChange}
displaySubmitActions={!hasOwnSubmitButton}
showQueryControls={showQueryControls}>
<EditComponent config={config}
fields={fields}
editing={editing}
Expand Down Expand Up @@ -279,6 +285,7 @@ const Widget = ({ id, editing = false, widget, title, position, onPositionsChang
</InteractiveContext.Consumer>
<EditWrapper onToggleEdit={onToggleEdit}
onCancelEdit={onCancelEdit}
showQueryControls={isDashboard}
onWidgetConfigChange={onWidgetConfigChange}
config={config}
editing={editing}
Expand Down

0 comments on commit e8f0fdf

Please sign in to comment.