Skip to content

Commit

Permalink
Better version
Browse files Browse the repository at this point in the history
  • Loading branch information
Heenawter committed Feb 2, 2024
1 parent 9d6790b commit 03fa8d3
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,34 @@

import '../control_group.scss';

import {
arrayMove,
SortableContext,
rectSortingStrategy,
sortableKeyboardCoordinates,
} from '@dnd-kit/sortable';
import {
closestCenter,
DndContext,
DragEndEvent,
DragOverlay,
KeyboardSensor,
LayoutMeasuringStrategy,
PointerSensor,
useSensor,
useSensors,
LayoutMeasuringStrategy,
} from '@dnd-kit/core';
import {
arrayMove,
rectSortingStrategy,
SortableContext,
sortableKeyboardCoordinates,
} from '@dnd-kit/sortable';
import { EuiButtonIcon, EuiFlexGroup, EuiFlexItem, EuiPanel, EuiTourStep } from '@elastic/eui';
import classNames from 'classnames';
import React, { useEffect, useMemo, useState } from 'react';
import { TypedUseSelectorHook, useSelector } from 'react-redux';
import { EuiButtonIcon, EuiFlexGroup, EuiFlexItem, EuiPanel, EuiTourStep } from '@elastic/eui';

import { ViewMode } from '@kbn/embeddable-plugin/public';

import { ControlGroupReduxState } from '../types';
import { ControlGroupStrings } from '../control_group_strings';
import { ControlClone, SortableControl } from './control_group_sortable_item';
import { useControlGroupContainer } from '../embeddable/control_group_container';
import { ControlGroupReduxState } from '../types';
import { ControlClone, SortableControl } from './control_group_sortable_item';

const contextSelect = useSelector as TypedUseSelectorHook<ControlGroupReduxState>;

Expand All @@ -51,29 +51,36 @@ export const ControlGroup = () => {
(state) => state.componentState.invalidSelectionsControlId
);

const [renderTourStep, setRenderTourStep] = useState(false);
useEffect(() => {
console.log('HEREEE', invalidSelectionsControlId);
/**
* This forces the tour step to get unmounted so that it can attach to the new
* control - otherwise, the anchor will remain attached to the old invalid control
*/
setRenderTourStep(false);
setTimeout(() => setRenderTourStep(true), 100);
}, [invalidSelectionsControlId]);

// const tourStep = useMemo(() => {
// return (
// <EuiTourStep
// anchor={`#controlFrame--${invalidSelectionsControlId}`}
// content={'this is some content'}
// isStepOpen={Boolean(invalidSelectionsControlId)}
// minWidth={300}
// onFinish={() => {}}
// step={1}
// stepsTotal={1}
// repositionOnScroll
// maxWidth={300}
// panelPaddingSize="m"
// display="block"
// title="React ref as anchor location"
// anchorPosition="downCenter"
// />
// );
// }, [invalidSelectionsControlId]);
const tourStep = useMemo(() => {
if (!renderTourStep || !invalidSelectionsControlId) return null;
return (
<EuiTourStep
anchor={`#controlFrame--${invalidSelectionsControlId}`}
content={'this is some content'}
isStepOpen={Boolean(invalidSelectionsControlId)}
minWidth={300}
onFinish={() => {}}
step={1}
stepsTotal={1}
repositionOnScroll
maxWidth={300}
panelPaddingSize="m"
display="block"
title="React ref as anchor location"
anchorPosition="downCenter"
/>
);
}, [invalidSelectionsControlId, renderTourStep]);

const isEditable = viewMode === ViewMode.EDIT;

Expand Down Expand Up @@ -144,21 +151,24 @@ export const ControlGroup = () => {
alignItems="center"
data-test-subj="controls-group"
>
<EuiTourStep
anchor={`#controlFrame--${invalidSelectionsControlId}`}
content={'this is some content'}
isStepOpen={Boolean(invalidSelectionsControlId)}
minWidth={300}
onFinish={() => {}}
step={1}
stepsTotal={1}
repositionOnScroll
maxWidth={300}
panelPaddingSize="m"
display="block"
title="React ref as anchor location"
anchorPosition="downCenter"
/>
{tourStep}
{/* {debouncedInvalidControlId && (
<EuiTourStep
anchor={`#controlFrame--${debouncedInvalidControlId}`}
content={'this is some content'}
isStepOpen={Boolean(invalidSelectionsControlId)}
minWidth={300}
onFinish={() => {}}
step={1}
stepsTotal={1}
repositionOnScroll
maxWidth={300}
panelPaddingSize="m"
display="block"
title="React ref as anchor location"
anchorPosition="downCenter"
/>
)} */}
<EuiFlexItem>
<DndContext
onDragStart={({ active }) => setDraggingId(active.id)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,29 +213,21 @@ export class ControlGroupContainer extends Container<
})
);

this.subscriptions.add(
this.getAnyChildOutputChange$()
.pipe(debounceTime(100))
.subscribe(() => {
const childrenWithInvalidSelections = cachedChildEmbeddableOrder(
this.getInput().panels
).idsInOrder.filter((childId) => {
return this.invalidSelectionsState[childId];
});
if (childrenWithInvalidSelections.length > 0) {
this.dispatch.setInvalidSelectionsControlId(childrenWithInvalidSelections[0]);
} else {
this.dispatch.setInvalidSelectionsControlId(undefined);
}
})
);

/**
* debounce output recalculation
*/
this.subscriptions.add(
this.recalculateFilters$.pipe(debounceTime(10)).subscribe(() => {
this.recalculateFilters();
console.log('HERE!!!');
const childrenWithInvalidSelections = cachedChildEmbeddableOrder(
this.getInput().panels
).idsInOrder.filter((childId) => {
return this.invalidSelectionsState[childId];
});
this.dispatch.setInvalidSelectionsControlId(
childrenWithInvalidSelections.length > 0 ? childrenWithInvalidSelections[0] : undefined
);
})
);
};
Expand All @@ -246,6 +238,7 @@ export class ControlGroupContainer extends Container<
} = this.getState();
if (!persistableControlGroupInputIsEqual(this.getPersistableInput(), lastSavedInput)) {
this.updateInput(lastSavedInput);
this.reload(); // this forces the children to update their inputs + perform validation as necessary
}
}

Expand Down

0 comments on commit 03fa8d3

Please sign in to comment.