Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use search module instead of shell for search #753

Merged
merged 20 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
144f2b3
chore: update submodule
beawar Nov 13, 2024
f531fe7
build(deps): update ds, preview and styled-components deps
beawar Nov 13, 2024
9615856
fix: remove types.d.ts, allow js in tsconfig and fix types
beawar Nov 13, 2024
1c65b76
refactor: add $ prefix on styled components custom props
beawar Nov 13, 2024
832a668
Merge remote-tracking branch 'origin/devel' into CO-1608-upgrade-styl…
beawar Nov 22, 2024
4ac36ef
build(deps): update shell dep
beawar Dec 2, 2024
002e122
Merge remote-tracking branch 'origin/devel' into CO-1608-upgrade-styl…
beawar Dec 2, 2024
93bdddf
build(deps-dev): add missing @types/react-dom dep
beawar Dec 2, 2024
3bc7071
refactor: use search module instead of shell for search
beawar Dec 5, 2024
1135f3f
refactor: move use-run-search to common
beawar Dec 9, 2024
61489ec
Merge remote-tracking branch 'origin/devel' into CO-1741-separate-sea…
beawar Dec 10, 2024
ce64d4d
Merge remote-tracking branch 'origin/devel' into CO-1741-separate-sea…
beawar Dec 16, 2024
2044748
Merge remote-tracking branch 'origin/CO-1608-upgrade-styled-component…
beawar Dec 16, 2024
492023d
fix: set integration type
beawar Dec 16, 2024
c9284d6
Merge remote-tracking branch 'origin/devel' into CO-1741-separate-sea…
beawar Dec 16, 2024
6db7c63
refactor: use component to register search
beawar Dec 16, 2024
74d25cc
Merge remote-tracking branch 'origin/devel' into CO-1741-separate-sea…
beawar Dec 19, 2024
88eb53d
style: add override keyword to class method
beawar Dec 19, 2024
b6e7ae3
Merge branch 'devel' into CO-1741-separate-search-module
giuliano176 Dec 27, 2024
978730d
fix(extra-window): restore timeout in MutationObserver
giuliano176 Dec 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
308 changes: 255 additions & 53 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"@types/react-router-dom": "^5.3.3",
"@types/styled-components": "^5.1.26",
"@types/uuid": "^10.0.0",
"@zextras/carbonio-ui-configs": "^1.0.0",
"@zextras/carbonio-search-ui": "github:zextras/carbonio-search-ui#devel",
"@zextras/carbonio-ui-configs": "^2.0.1",
"@zextras/carbonio-ui-sdk": "^1.7.7",
"babel-plugin-styled-components": "^2.0.7",
"babel-plugin-transform-import-meta": "^2.2.0",
Expand All @@ -74,7 +75,7 @@
"msw": "^2.2.3",
"npm": "^10.5.0",
"ts-node": "^10.9.1",
"typescript": "^4.9.5"
"typescript": "^5.7.2"
},
"dependencies": {
"@emotion/react": "^11.11.4",
Expand Down
2 changes: 1 addition & 1 deletion src/api/errors/create-mountpoint-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { GenericSoapApiError } from '../../carbonio-ui-commons/soap/errors/gener
export class CreateMountpointError extends GenericSoapApiError {
public static readonly FOLDER_ALREADY_EXISTS = 'mail.ALREADY_EXISTS';

getLocalizedMessage(t: TFunction): string {
override getLocalizedMessage(t: TFunction): string {
if (this.fault.Detail.Error.Code === CreateMountpointError.FOLDER_ALREADY_EXISTS) {
return t(
'api.error.CreateMountpoint.folder_already_exists',
Expand Down
23 changes: 0 additions & 23 deletions src/app-utils/add-shell-components.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ import React, { Suspense, lazy } from 'react';
import { ModalManager } from '@zextras/carbonio-design-system';
import {
addRoute,
addSearchView,
addBoardView,
addSettingsView,
SearchViewProps,
t,
SecondaryBarComponentProps,
upsertApp
Expand Down Expand Up @@ -39,10 +37,6 @@ const LazySettingsView = lazy(
() => import(/* webpackChunkName: "mail-setting-view" */ '../views/settings/settings-view')
);

const LazySearchView = lazy(
() => import(/* webpackChunkName: "mail-search-view" */ '../views/search/search-view')
);

const LazySidebarView = lazy(
() => import(/* webpackChunkName: "mail-sidebar-view" */ '../views/sidebar/sidebar')
);
Expand Down Expand Up @@ -79,18 +73,6 @@ const SettingsView = (): React.JSX.Element => (
</Suspense>
);

const SearchView = (props: SearchViewProps): React.JSX.Element => (
<Suspense fallback={<Spinner />}>
<StoreProvider>
<ExtraWindowsManager>
<ModalManager>
<LazySearchView {...props} />
</ModalManager>
</ExtraWindowsManager>
</StoreProvider>
</Suspense>
);

const SidebarView = (props: SecondaryBarComponentProps): React.JSX.Element => (
<Suspense fallback={<Spinner />}>
<StoreProvider>
Expand All @@ -112,11 +94,6 @@ export const addComponentsToShell = async (): Promise<void> => {
secondaryBar: SidebarView,
appView: AppView
});
addSearchView({
route: MAILS_ROUTE,
component: SearchView,
label
});
addBoardView({
id: MAILS_BOARD_VIEW_ID,
component: EditView
Expand Down
3 changes: 0 additions & 3 deletions src/app-utils/register-shell-integrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export const registerShellIntegrations = (): void => {
registerFunctions(
{
id: 'compose',
// TOFIX-SHELL: fix the function type definition
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
fn: openComposerSharedFunction
},
{
Expand Down
12 changes: 12 additions & 0 deletions src/app-utils/search-registration.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* SPDX-FileCopyrightText: 2024 Zextras <https://www.zextras.com>
*
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { useSearchRegisterer } from './use-search-registerer';

export const SearchRegistration = (): null => {
useSearchRegisterer();
return null;
};
19 changes: 4 additions & 15 deletions src/app-utils/test/add-shell-components.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { addRoute, addSearchView, addSettingsView, upsertApp } from '@zextras/carbonio-shell-ui';
import { addBoardView, addRoute, addSettingsView, upsertApp } from '@zextras/carbonio-shell-ui';
import { HttpResponse } from 'msw';

import { createAPIInterceptor } from '../../carbonio-ui-commons/test/mocks/network/msw/create-api-interceptor';
import { MAIL_APP_ID } from '../../constants';
import { MAIL_APP_ID, MAILS_BOARD_VIEW_ID } from '../../constants';
import { mockAdvancedAccountAPI } from '../../tests/utils';
import { addComponentsToShell } from '../add-shell-components';

Expand All @@ -33,23 +33,12 @@ describe('addShellComponents', () => {
})
);
});
it('should call addSearchView with the correct parameters', async () => {
await addComponentsToShell();

expect(addSearchView).toHaveBeenCalledWith(
expect.objectContaining({
route: 'mails',
component: expect.anything(),
label
})
);
});
it('should call addBoardView with the correct parameters', async () => {
await addComponentsToShell();

expect(addSearchView).toHaveBeenCalledWith(
expect(addBoardView).toHaveBeenCalledWith(
expect.objectContaining({
route: 'mails',
id: MAILS_BOARD_VIEW_ID,
component: expect.anything()
})
);
Expand Down
67 changes: 67 additions & 0 deletions src/app-utils/test/use-search-registerer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* SPDX-FileCopyrightText: 2024 Zextras <https://www.zextras.com>
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import * as Shell from '@zextras/carbonio-shell-ui';

import { setupHook } from '../../carbonio-ui-commons/test/test-setup';
import { MAIL_APP_ID, MAILS_ROUTE } from '../../constants';
import { useSearchRegisterer } from '../use-search-registerer';

describe('useSearchView', () => {
it('should add search view if integration is available', () => {
const addSearchViewFn = jest.fn();
jest.spyOn(Shell, 'useIntegratedFunction').mockImplementation((id) => {
if (id === 'search-add-view') {
return [addSearchViewFn, true];
}
return [(): void => undefined, false];
});

setupHook(useSearchRegisterer);

expect(addSearchViewFn).toHaveBeenCalledWith({
id: MAIL_APP_ID,
app: MAIL_APP_ID,
icon: 'MailModOutline',
route: MAILS_ROUTE,
component: expect.anything(),
label: 'Mails',
position: 100
});
});

it('should remove search view on unmount', () => {
const addSearchViewFn = jest.fn();
const removeSearchViewFn = jest.fn();
jest.spyOn(Shell, 'useIntegratedFunction').mockImplementation((id) => {
if (id === 'search-add-view') {
return [addSearchViewFn, true];
}
if (id === 'search-remove-view') {
return [removeSearchViewFn, true];
}
return [(): void => undefined, false];
});

const { unmount } = setupHook(useSearchRegisterer);

unmount();
expect(removeSearchViewFn).toHaveBeenCalledWith(MAIL_APP_ID);
});

it('should not call addSearchView if integration is not available', () => {
const addSearchViewFn = jest.fn();
jest.spyOn(Shell, 'useIntegratedFunction').mockImplementation((id) => {
if (id === 'search-add-view') {
return [addSearchViewFn, false];
}
return [(): void => undefined, false];
});

setupHook(useSearchRegisterer);

expect(addSearchViewFn).not.toHaveBeenCalled();
});
});
60 changes: 60 additions & 0 deletions src/app-utils/use-search-registerer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* SPDX-FileCopyrightText: 2024 Zextras <https://www.zextras.com>
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import React, { lazy, Suspense, useEffect } from 'react';

import { ModalManager } from '@zextras/carbonio-design-system';
import type * as Search from '@zextras/carbonio-search-ui';
import { useIntegratedFunction } from '@zextras/carbonio-shell-ui';
import { useTranslation } from 'react-i18next';

import { Spinner } from '../assets/spinner';
import { MAIL_APP_ID, MAILS_ROUTE } from '../constants';
import { StoreProvider } from '../store/redux';
import { ExtraWindowsManager } from '../views/app/extra-windows/extra-window-manager';

const LazySearchView = lazy(
() => import(/* webpackChunkName: "mail-search-view" */ '../views/search/search-view')
);

const SearchView = (props: Search.SearchViewProps): React.JSX.Element => (
<Suspense fallback={<Spinner />}>
<StoreProvider>
<ExtraWindowsManager>
<ModalManager>
<LazySearchView {...props} />
</ModalManager>
</ExtraWindowsManager>
</StoreProvider>
</Suspense>
);

export const useSearchRegisterer = (): void => {
const [t] = useTranslation();
const [addSearchView, isAddSearchViewAvailable] =
useIntegratedFunction<typeof Search.addSearchView>('search-add-view');
const [removeSearchView, isRemoveSearchViewAvailable] =
useIntegratedFunction<typeof Search.removeSearchView>('search-remove-view');

useEffect(() => {
if (isAddSearchViewAvailable) {
addSearchView({
id: MAIL_APP_ID,
app: MAIL_APP_ID,
icon: 'MailModOutline',
route: MAILS_ROUTE,
component: SearchView,
label: t('label.app_name', 'Mails'),
position: 100
});
}

return () => {
if (isRemoveSearchViewAvailable) {
removeSearchView(MAIL_APP_ID);
}
};
}, [addSearchView, isAddSearchViewAvailable, isRemoveSearchViewAvailable, removeSearchView, t]);
};
7 changes: 7 additions & 0 deletions src/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import App from './app';
import * as addComponentsToShell from './app-utils/add-shell-components';
import * as registerShellActions from './app-utils/register-shell-actions';
import * as registerShellIntegrations from './app-utils/register-shell-integrations';
import * as useSearchRegisterer from './app-utils/use-search-registerer';
import { generateFolder } from './carbonio-ui-commons/test/mocks/folders/folders-generator';
import {
createAPIInterceptor,
Expand Down Expand Up @@ -83,6 +84,12 @@ describe('App', () => {
expect(registerShellIntegrationsSpy).toHaveBeenCalled();
});

it('should register the search', () => {
const useSearchRegistererSpy = jest.spyOn(useSearchRegisterer, 'useSearchRegisterer');
setupTest(<App />);
expect(useSearchRegistererSpy).toHaveBeenCalled();
});

it('should add the backup search route when the backup search messages are present', () => {
updateBackupSearchStoreWith([aDeletedMessage()]);

Expand Down
2 changes: 2 additions & 0 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import React from 'react';

import { BackupSearchComponentToggler } from './app-utils/backup-search-component-toggler';
import { SearchRegistration } from './app-utils/search-registration';
import { ShellRegistrations } from './app-utils/shell-registrations';
import { AuthGuard } from './auth-guard';
import { StoreProvider } from './store/redux';
Expand All @@ -21,6 +22,7 @@ const App = (): React.JSX.Element => (
<AuthGuard>
<ShellRegistrations />
<BackupSearchComponentToggler />
<SearchRegistration />

<StoreProvider>
<GlobalModalManager>
Expand Down
2 changes: 1 addition & 1 deletion src/commons/gap-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ const GapRow = React.forwardRef<HTMLDivElement, GapRowProps>(function GapRowFn(
);
});

export { GapContainer, GapRow, GapContainerProps, GapRowProps };
export { GapContainer, GapRow, type GapContainerProps, type GapRowProps };
6 changes: 3 additions & 3 deletions src/helpers/identities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,9 @@ export function getExtraAccountsIds(): Array<string> {
}

export {
IdentityDescriptor,
MatchingReplyIdentity,
RecipientWeight,
type IdentityDescriptor,
type MatchingReplyIdentity,
type RecipientWeight,
getNoIdentityPlaceholder,
getDefaultIdentity,
checkMatchingAddress,
Expand Down
10 changes: 7 additions & 3 deletions src/hooks/use-get-tags-accordions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import {
Tooltip,
useModal
} from '@zextras/carbonio-design-system';
import { runSearch, t, QueryChip } from '@zextras/carbonio-shell-ui';
import type { QueryChip } from '@zextras/carbonio-search-ui';
import { t } from '@zextras/carbonio-shell-ui';
import { reduce } from 'lodash';

import { ZIMBRA_STANDARD_COLORS } from '../carbonio-ui-commons/constants/utils';
import { useRunSearchIntegration } from '../carbonio-ui-commons/integrations/search/use-run-search';
import { useTags } from '../carbonio-ui-commons/store/zustand/tags';
import type { TagsAccordionItems } from '../carbonio-ui-commons/types/tags';
import type { ItemType } from '../types';
Expand All @@ -31,9 +33,11 @@ type ItemProps = {
const CustomComp: FC<ItemProps> = (props) => {
const actions = useGetTagsActions({ tag: props?.item });

const runSearch = useRunSearchIntegration();

const triggerSearch = useCallback(
() =>
runSearch(
runSearch?.(
[
// TODO: add a new type for query chips
{
Expand All @@ -49,7 +53,7 @@ const CustomComp: FC<ItemProps> = (props) => {
],
'mails'
),
[props?.item?.color, props?.item?.name]
[props?.item?.color, props?.item?.name, runSearch]
);

return (
Expand Down
2 changes: 1 addition & 1 deletion src/tests/generators/generateConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ const generateConversation = ({
};
};

export { ConversationGenerationParams, generateConversation };
export { type ConversationGenerationParams, generateConversation };
2 changes: 1 addition & 1 deletion src/tests/generators/generateMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,4 @@ const generateMessage = ({
messageIsFromDistributionList: false
});

export { MessageGenerationParams, generateMessage };
export { type MessageGenerationParams, generateMessage };
2 changes: 1 addition & 1 deletion src/tests/generators/getMsgResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ const generateGetMsgResponse = ({
return result;
};

export { GetMsgResponseGenerationParams, generateGetMsgResponse };
export { type GetMsgResponseGenerationParams, generateGetMsgResponse };
Loading