Skip to content

Commit

Permalink
chore: stop importing action manager as global (#29766)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo authored Jul 11, 2023
1 parent cadec3a commit 54579fb
Show file tree
Hide file tree
Showing 29 changed files with 407 additions and 312 deletions.
56 changes: 0 additions & 56 deletions apps/meteor/app/ui-message/client/ActionButtonSyncer.ts

This file was deleted.

21 changes: 6 additions & 15 deletions apps/meteor/app/ui-message/client/ActionManager.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { UIKitIncomingInteractionType } from '@rocket.chat/apps-engine/definition/uikit';
import { Meteor } from 'meteor/meteor';
import { Random } from '@rocket.chat/random';
import { Emitter } from '@rocket.chat/emitter';
import { UIKitInteractionTypes } from '@rocket.chat/core-typings';
import { lazy } from 'react';

import Notifications from '../../notifications/client/lib/Notifications';
import { CachedCollectionManager } from '../../ui-cached-collection/client';
import { t } from '../../utils/client';
import { t } from '../../utils/lib/i18n';
import * as banners from '../../../client/lib/banners';
import { dispatchToastMessage } from '../../../client/lib/toast';
import { imperativeModal } from '../../../client/lib/imperativeModal';
import UiKitModal from '../../../client/views/modal/uikit/UiKitModal';
import { sdk } from '../../utils/client/lib/SDKClient';
import { router } from '../../../client/providers/RouterProvider';
import { imperativeModal } from '../../../client/lib/imperativeModal';

const UiKitModal = lazy(() => import('../../../client/views/modal/uikit/UiKitModal'));

const events = new Emitter();

Expand Down Expand Up @@ -45,7 +44,7 @@ export const generateTriggerId = (appId) => {
return triggerId;
};

const handlePayloadUserInteraction = (type, { /* appId,*/ triggerId, ...data }) => {
export const handlePayloadUserInteraction = (type, { /* appId,*/ triggerId, ...data }) => {
if (!triggersId.has(triggerId)) {
return;
}
Expand Down Expand Up @@ -256,11 +255,3 @@ export const getUserInteractionPayloadByViewId = (viewId) => {

return instance.payload;
};

Meteor.startup(() =>
CachedCollectionManager.onLogin(() =>
Notifications.onUser('uiInteraction', ({ type, ...data }) => {
handlePayloadUserInteraction(type, data);
}),
),
);
28 changes: 0 additions & 28 deletions apps/meteor/app/ui-message/client/actionButtons/dropdownAction.ts

This file was deleted.

33 changes: 0 additions & 33 deletions apps/meteor/app/ui-message/client/actionButtons/messageAction.ts

This file was deleted.

42 changes: 0 additions & 42 deletions apps/meteor/app/ui-message/client/actionButtons/messageBox.ts

This file was deleted.

33 changes: 0 additions & 33 deletions apps/meteor/app/ui-message/client/actionButtons/tabbar.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/meteor/app/ui-utils/client/lib/MessageAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export type MessageActionConfig = {
chat,
autoTranslateOptions,
}: {
message?: IMessage & Partial<ITranslatedMessage>;
message: IMessage & Partial<ITranslatedMessage>;
tabbar: ToolboxContextValue;
room?: IRoom;
chat: ContextType<typeof ChatContext>;
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/app/ui-utils/client/lib/messageBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { TranslationKey } from '@rocket.chat/ui-contexts';

import type { ChatAPI } from '../../../../client/lib/chats/ChatAPI';

type MessageBoxAction = {
export type MessageBoxAction = {
label: TranslationKey;
id: string;
icon?: string;
Expand Down
11 changes: 7 additions & 4 deletions apps/meteor/client/UIKit/hooks/useUIKitHandleAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import { UIKitIncomingInteractionContainerType } from '@rocket.chat/apps-engine/
// import React, { Context, FC, useMemo } from 'react';
import type { UiKitPayload, UIKitActionEvent } from '@rocket.chat/core-typings';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';

import { useUiKitActionManager } from '../../hooks/useUiKitActionManager';
// import { UIKitIncomingInteractionContainerType } from '@rocket.chat/apps-engine/definition/uikit/UIKitIncomingInteractionContainer';

// import { useEndpoint } from '@rocket.chat/ui-contexts';
import * as ActionManager from '../../../app/ui-message/client/ActionManager';

const useUIKitHandleAction = <S extends UiKitPayload>(state: S): ((event: UIKitActionEvent) => Promise<void>) =>
useMutableCallback(async ({ blockId, value, appId, actionId }) => {
const useUIKitHandleAction = <S extends UiKitPayload>(state: S): ((event: UIKitActionEvent) => Promise<void>) => {
const actionManager = useUiKitActionManager();
return useMutableCallback(async ({ blockId, value, appId, actionId }) => {
if (!appId) {
throw new Error('useUIKitHandleAction - invalid appId');
}
return ActionManager.triggerBlockAction({
return actionManager.triggerBlockAction({
container: {
type: UIKitIncomingInteractionContainerType.VIEW,
id: state.viewId || state.appId,
Expand All @@ -26,5 +28,6 @@ const useUIKitHandleAction = <S extends UiKitPayload>(state: S): ((event: UIKitA
blockId,
});
});
};

export { useUIKitHandleAction };
26 changes: 14 additions & 12 deletions apps/meteor/client/UIKit/hooks/useUIKitHandleClose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,30 @@ import type { UIKitInteractionType } from '@rocket.chat/apps-engine/definition/u
import type { UiKitPayload } from '@rocket.chat/core-typings';
import { useMutableCallback } from '@rocket.chat/fuselage-hooks';
import { useToastMessageDispatch } from '@rocket.chat/ui-contexts';

import { useUiKitActionManager } from '../../hooks/useUiKitActionManager';
// import { UIKitIncomingInteractionContainerType } from '@rocket.chat/apps-engine/definition/uikit/UIKitIncomingInteractionContainer';

// import { useEndpoint } from '@rocket.chat/ui-contexts';

import * as ActionManager from '../../../app/ui-message/client/ActionManager';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const emptyFn = (_error: any, _result: UIKitInteractionType | void): void => undefined;

const useUIKitHandleClose = <S extends UiKitPayload>(state: S, fn = emptyFn): (() => Promise<void | UIKitInteractionType>) => {
const actionManager = useUiKitActionManager();
const dispatchToastMessage = useToastMessageDispatch();
return useMutableCallback(() =>
ActionManager.triggerCancel({
appId: state.appId,
viewId: state.viewId,
view: {
...state,
id: state.viewId,
// state: groupStateByBlockId(values),
},
isCleared: true,
})
actionManager
.triggerCancel({
appId: state.appId,
viewId: state.viewId,
view: {
...state,
id: state.viewId,
// state: groupStateByBlockId(values),
},
isCleared: true,
})
.then((result) => fn(undefined, result))
.catch((error) => {
dispatchToastMessage({ type: 'error', message: error });
Expand Down
7 changes: 4 additions & 3 deletions apps/meteor/client/UIKit/hooks/useUIKitStateManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { isErrorType } from '@rocket.chat/core-typings';
import { useSafely } from '@rocket.chat/fuselage-hooks';
import { useEffect, useState } from 'react';

import * as ActionManager from '../../../app/ui-message/client/ActionManager';
import { useUiKitActionManager } from '../../hooks/useUiKitActionManager';

const useUIKitStateManager = <S extends UiKitPayload>(initialState: S): S => {
const actionManager = useUiKitActionManager();
const [state, setState] = useSafely(useState(initialState));

const { viewId } = state;
Expand All @@ -22,10 +23,10 @@ const useUIKitStateManager = <S extends UiKitPayload>(initialState: S): S => {
setState(rest as any);
};

ActionManager.on(viewId, handleUpdate);
actionManager.on(viewId, handleUpdate);

return (): void => {
ActionManager.off(viewId, handleUpdate);
actionManager.off(viewId, handleUpdate);
};
}, [setState, viewId]);

Expand Down
Loading

0 comments on commit 54579fb

Please sign in to comment.