Skip to content

Commit

Permalink
Get rid of useHooks in components
Browse files Browse the repository at this point in the history
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix'
  • Loading branch information
Heenawter committed Aug 23, 2022
1 parent f4d9f85 commit 9c26a01
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ export const ControlFrame = ({
const controlStyle = select((state) => state.explicitInput.controlStyle);

// Controls Services Context
const { overlays } = pluginServices.getHooks();
const { openConfirm } = overlays.useService();
const {
overlays: { openConfirm },
} = pluginServices.getServices();

const embeddable = useChildEmbeddable({ untilEmbeddableLoaded, embeddableId, embeddableType });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ export const ControlEditor = ({
getRelevantDataViewId,
setLastUsedDataViewId,
}: EditControlProps) => {
const { dataViews, controls } = pluginServices.getHooks();
const { getIdsWithTitle, getDefaultId, get } = dataViews.useService();
const { getControlTypes, getControlFactory } = controls.useService();
const {
dataViews: { getIdsWithTitle, getDefaultId, get },
controls: { getControlTypes, getControlFactory },
} = pluginServices.getServices();
const [state, setState] = useState<ControlEditorState>({
dataViewListItems: [],
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ export const CreateControlButton = ({
updateDefaultGrow,
}: CreateControlButtonProps) => {
// Controls Services Context
const { overlays, controls, theme } = pluginServices.getHooks();
const { getControlTypes, getControlFactory } = controls.useService();
const { openFlyout, openConfirm } = overlays.useService();
const themeService = theme.useService();
const {
overlays: { openFlyout, openConfirm },
controls: { getControlTypes, getControlFactory },
theme,
} = pluginServices.getServices();

const createNewControl = async () => {
const ControlsServicesProvider = pluginServices.getContextProvider();
Expand Down Expand Up @@ -115,7 +116,7 @@ export const CreateControlButton = ({
}
/>
</ControlsServicesProvider>,
{ theme$: themeService.theme$ }
{ theme$: theme.theme$ }
),
{
'aria-label': ControlGroupStrings.manageControl.getFlyoutCreateTitle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ interface EditControlResult {

export const EditControlButton = ({ embeddableId }: { embeddableId: string }) => {
// Controls Services Context
const { overlays, controls, theme } = pluginServices.getHooks();
const { getControlFactory } = controls.useService();
const { openFlyout, openConfirm } = overlays.useService();
const themeService = theme.useService();

const {
overlays: { openFlyout, openConfirm },
controls: { getControlFactory },
theme,
} = pluginServices.getServices();
// Redux embeddable container Context
const reduxContainerContext = useReduxContainerContext<
ControlGroupReduxState,
Expand Down Expand Up @@ -161,7 +161,7 @@ export const EditControlButton = ({ embeddableId }: { embeddableId: string }) =>
}}
/>
</ControlsServicesProvider>,
{ theme$: themeService.theme$ }
{ theme$: theme.theme$ }
),
{
'aria-label': ControlGroupStrings.manageControl.getFlyoutEditTitle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ export const EditControlGroup = ({
controlGroupContainer,
closePopover,
}: EditControlGroupButtonProps) => {
const { overlays, theme } = pluginServices.getHooks();
const { openConfirm, openFlyout } = overlays.useService();
const themeService = theme.useService();
const {
overlays: { openConfirm, openFlyout },
theme,
} = pluginServices.getServices();

const editControlGroup = () => {
const onDeleteAll = (ref: OverlayRef) => {
Expand All @@ -55,7 +56,7 @@ export const EditControlGroup = ({
onDeleteAll={() => onDeleteAll(flyoutInstance)}
onClose={() => flyoutInstance.close()}
/>,
{ theme$: themeService.theme$ }
{ theme$: theme.theme$ }
),
{
outsideClickCloses: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ export const RangeSliderPopover: FC = () => {
const rangeRef = useRef<EuiDualRange | null>(null);

// Controls Services Context
const { dataViews } = pluginServices.getHooks();
const { get: getDataViewById } = dataViews.useService();
const {
dataViews: { get: getDataViewById },
} = pluginServices.getServices();
const {
useEmbeddableDispatch,
useEmbeddableSelector: select,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/controls/public/services/data/data.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import { of, Observable } from 'rxjs';
import { of } from 'rxjs';
import { PluginServiceFactory } from '@kbn/presentation-util-plugin/public';
import { DataPublicPluginStart } from '@kbn/data-plugin/public';
import { ControlsDataService } from './types';
Expand Down

0 comments on commit 9c26a01

Please sign in to comment.