Skip to content

Commit

Permalink
[IMPROVE] Upgrade nivo and React Query (#26338)
Browse files Browse the repository at this point in the history
  • Loading branch information
tassoevan authored and carlosrodrigues94 committed Aug 3, 2022
1 parent d7012b4 commit 90cbdca
Show file tree
Hide file tree
Showing 37 changed files with 293 additions and 645 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const renderRow = ({ _id, name, email }: any) => (
);

export const Default: ComponentStory<typeof GenericTable> = (args) => (
<GenericTable {...args} header={header} renderFilter={renderFilter} renderRow={renderRow} height='100vh' />
<GenericTable {...args} header={header} renderFilter={renderFilter} renderRow={renderRow} />
);
Default.storyName = 'GenericTable';
Default.args = {
Expand Down
10 changes: 5 additions & 5 deletions apps/meteor/client/components/GenericTable/GenericTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ const defaultSetParamsValue = (): void => undefined;

export type GenericTableParams = {
text?: string;
current?: number;
itemsPerPage?: 25 | 50 | 100;
current: number;
itemsPerPage: 25 | 50 | 100;
};

type GenericTableProps<FilterProps extends { onChange?: (params: GenericTableParams) => void }, ResultProps extends { _id?: Key }> = {
type GenericTableProps<FilterProps extends { onChange?: (params: GenericTableParams) => void }, ResultProps extends { _id?: Key } | {}> = {
fixed?: boolean;
header?: ReactNode;
params?: GenericTableParams;
Expand All @@ -34,7 +34,7 @@ type GenericTableProps<FilterProps extends { onChange?: (params: GenericTablePar

const GenericTable = forwardRef(function GenericTable<
FilterProps extends { onChange?: (params: GenericTableParams) => void },
ResultProps extends { _id?: Key },
ResultProps extends { _id?: Key } | {},
>(
{
children,
Expand Down Expand Up @@ -83,7 +83,7 @@ const GenericTable = forwardRef(function GenericTable<
<GenericTableBody>
{isLoading && <GenericTableLoadingTable headerCells={headerCells} />}
{!isLoading &&
((RenderRow && results?.map((props, index: number) => <RenderRow key={props._id || index} {...props} />)) ||
((RenderRow && results?.map((props, index: number) => <RenderRow key={'_id' in props ? props._id : index} {...props} />)) ||
(children && results?.map(children)))}
</GenericTableBody>
</GenericTableV2>
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/components/PlanTag.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Box, Tag } from '@rocket.chat/fuselage';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import React, { ReactElement, useEffect, useState } from 'react';
import { useQuery } from 'react-query';

import { isTruthy } from '../../lib/isTruthy';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { MultiSelectFiltered, Icon, Box, Chip } from '@rocket.chat/fuselage';
import type { Options } from '@rocket.chat/fuselage';
import { useDebouncedValue } from '@rocket.chat/fuselage-hooks';
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import React, { memo, ReactElement, useState, ComponentProps } from 'react';
import { useQuery } from 'react-query';

import UserAvatar from '../avatar/UserAvatar';
import AutocompleteOptions, { OptionsContext } from './UserAutoCompleteMultipleOptions';
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/lib/queryClient.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { QueryClient } from 'react-query';
import { QueryClient } from '@tanstack/react-query';

export const queryClient = new QueryClient();
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { forwardRef, ReactElement } from 'react';

import ScrollableContentWrapper from '../../components/ScrollableContentWrapper';

export default forwardRef<HTMLElement>(function ScrollerWithCustomProps(props, ref): ReactElement {
export default forwardRef<HTMLDivElement>(function ScrollerWithCustomProps(props, ref): ReactElement {
return (
<ScrollableContentWrapper
{...props}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { forwardRef, ReactElement } from 'react';

import ScrollableContentWrapper from '../../components/ScrollableContentWrapper';

const ScrollerWithCustomProps = forwardRef(function ScrollerWithCustomProps(props, ref: React.Ref<HTMLElement>) {
const ScrollerWithCustomProps = forwardRef(function ScrollerWithCustomProps(props, ref: React.Ref<HTMLDivElement>) {
return (
<ScrollableContentWrapper
{...props}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { QueryCache, QueryClient, QueryClientProvider } from '@tanstack/react-query';
import React, { FC } from 'react';
import { QueryCache, QueryClient, QueryClientProvider } from 'react-query';

const queryCache = new QueryCache();

Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/views/admin/rooms/RoomsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import FilterByTypeAndText from './FilterByTypeAndText';
type RoomParamsType = {
text?: string;
types?: string[];
current?: number;
itemsPerPage?: 25 | 50 | 100;
current: number;
itemsPerPage: 25 | 50 | 100;
};

const style: CSSProperties = { whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden' };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const VoipExtensionsPage: FC = () => {
const t = useTranslation();
const setModal = useSetModal();

const [params, setParams] = useState<{ current?: number; itemsPerPage?: 25 | 50 | 100 }>({
const [params, setParams] = useState<{ current: number; itemsPerPage: 25 | 50 | 100 }>({
current: 0,
itemsPerPage: 25,
});
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/views/hooks/useUpgradeTabParams.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSetting, useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import { format } from 'date-fns';
import { useQuery } from 'react-query';

import { UpgradeTabVariant, getUpgradeTabType } from '../../../lib/getUpgradeTabType';

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/views/invite/InvitePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
useSetting,
useTranslation,
} from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import React, { ReactElement } from 'react';
import { useQuery } from 'react-query';

import { APIClient } from '../../../app/utils/client';
import LoginPage from '../root/MainLayout/LoginPage';
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/views/invite/SecretURLPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useSessionDispatch, useRouteParameter, useSetting, useTranslation } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import React, { ReactElement } from 'react';
import { useQuery } from 'react-query';

import { KonchatNotification } from '../../../app/ui';
import { call } from '../../lib/utils/call';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const useQuery = (
current,
}: {
text?: string;
itemsPerPage?: 25 | 50 | 100;
current?: number;
itemsPerPage: 25 | 50 | 100;
current: number;
},
[column, direction]: string[],
userIdLoggedIn: string | null,
Expand All @@ -54,7 +54,7 @@ const useQuery = (
);

const CallTable: FC = () => {
const [params, setParams] = useState<{ text?: string; current?: number; itemsPerPage?: 25 | 50 | 100 }>({
const [params, setParams] = useState<{ text?: string; current: number; itemsPerPage: 25 | 50 | 100 }>({
text: '',
current: 0,
itemsPerPage: 25,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type QueueListPagePropsParamsType = {
servedBy: string;
status: string;
departmentId: string;
itemsPerPage: number;
itemsPerPage: 25 | 50 | 100;
current: number;
};

Expand Down Expand Up @@ -41,7 +41,7 @@ export const QueueListPage = ({ title, header, data, renderRow, params, setParam
results={data?.queue}
total={data?.total}
params={params}
setParams={setParams}
setParams={setParams as (params: Pick<QueueListPagePropsParamsType, 'itemsPerPage' | 'current'>) => void}
/>
</Page.Content>
</Page>
Expand Down
8 changes: 7 additions & 1 deletion apps/meteor/client/views/omnichannel/queueList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,13 @@ const QueueList = (): ReactElement => {
[mediaQuery, t],
);

const [params, setParams] = useState({
const [params, setParams] = useState<{
servedBy: string;
status: string;
departmentId: string;
itemsPerPage: 25 | 50 | 100;
current: number;
}>({
servedBy: '',
status: '',
departmentId: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IMessage, IRoom } from '@rocket.chat/core-typings';
import { useEndpoint, useTranslation, useToastMessageDispatch } from '@rocket.chat/ui-contexts';
import { useQuery, useQueryClient } from '@tanstack/react-query';
import React, { ReactElement } from 'react';
import { useQuery, useQueryClient } from 'react-query';

import GenericModal from '../../../components/GenericModal';
import MapView from '../../location/MapView';
Expand All @@ -17,7 +17,7 @@ type ShareLocationModalProps = {
const ShareLocationModal = ({ rid, tmid, onClose }: ShareLocationModalProps): ReactElement => {
const t = useTranslation();
const dispatchToast = useToastMessageDispatch();
const { data: permissionData, isLoading: permissionLoading } = useQuery('geolocationPermission', getGeolocationPermission);
const { data: permissionData, isLoading: permissionLoading } = useQuery(['geolocationPermission'], getGeolocationPermission);
const { data: positionData } = useQuery(['geolocationPosition', permissionData], async () => {
if (permissionLoading || permissionData === 'prompt' || permissionData === 'denied') {
return;
Expand Down Expand Up @@ -55,9 +55,9 @@ const ShareLocationModal = ({ rid, tmid, onClose }: ShareLocationModalProps): Re
try {
const position = await getGeolocationPosition();
queryClient.setQueryData(['geolocationPosition', 'granted'], position);
queryClient.setQueryData('geolocationPermission', 'granted');
queryClient.setQueryData(['geolocationPermission'], 'granted');
} catch (e) {
queryClient.setQueryData('geolocationPermission', () => getGeolocationPermission);
queryClient.setQueryData(['geolocationPermission'], () => getGeolocationPermission);
}
};

Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/client/views/root/AppRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { QueryClientProvider } from '@tanstack/react-query';
import React, { FC, lazy, Suspense } from 'react';
import { QueryClientProvider } from 'react-query';

import { OmnichannelRoomIconProvider } from '../../components/RoomIcon/OmnichannelRoomIcon/provider/OmnichannelRoomIconProvider';
import { queryClient } from '../../lib/queryClient';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ISetting } from '@rocket.chat/core-typings';
import { useMethod } from '@rocket.chat/ui-contexts';
import { useQuery, UseQueryResult } from 'react-query';
import { useQuery, UseQueryResult } from '@tanstack/react-query';

type SetupWizardParameters = {
settings: ISetting[];
Expand Down
4 changes: 2 additions & 2 deletions apps/meteor/client/views/teams/ChannelDesertionTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ChannelDesertionTableProps = {
lastOwnerWarning: boolean | undefined;
rooms: (Serialized<IRoom> & { isLastOwner?: string })[] | undefined;
eligibleRoomsLength: number | undefined;
params?: {};
params?: { current: number; itemsPerPage: 25 | 50 | 100 };
onChangeParams?: () => void;
onChangeRoomSelection: (room: Serialized<IRoom>) => void;
selectedRooms: { [key: string]: Serialized<IRoom> };
Expand Down Expand Up @@ -66,7 +66,7 @@ const ChannelDesertionTable: FC<ChannelDesertionTableProps> = ({
formatDate={formatDate}
room={room}
onChange={onChangeRoomSelection}
selected={!!selectedRooms[room._id]}
selected={'_id' in room && room._id ? !!selectedRooms[room._id] : false}
lastOwnerWarning={lastOwnerWarning}
/>
)}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/ee/client/lib/onToggledFeature.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { QueryObserver } from 'react-query';
import { QueryObserver } from '@tanstack/react-query';

import { queryClient } from '../../../client/lib/queryClient';
import type { BundleFeature } from '../../app/license/server/bundles';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import Page from '../../../../client/components/Page';
export type CannedResponsesPageProps = {
data: any;
header: ReactElement[];
setParams: Dispatch<SetStateAction<{ current?: number; itemsPerPage?: 25 | 50 | 100 }>>;
params: { current?: number; itemsPerPage?: 25 | 50 | 100 };
setParams: Dispatch<SetStateAction<{ current: number; itemsPerPage: 25 | 50 | 100 }>>;
params: { current: number; itemsPerPage: 25 | 50 | 100 };
title: string;
renderFilter?: (props: any) => ReactElement;
renderRow?: (props: any) => ReactElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const CannedResponsesRoute: FC = () => {
const { sharing, createdBy, text } = values as CannedResponseFilterValues;
const { handleSharing, handleCreatedBy, handleText } = handlers;

const [params, setParams] = useState<{ current?: number; itemsPerPage?: 25 | 50 | 100 }>({
const [params, setParams] = useState<{ current: number; itemsPerPage: 25 | 50 | 100 }>({
current: 0,
itemsPerPage: 25,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Box } from '@rocket.chat/fuselage';
import colors from '@rocket.chat/fuselage-tokens/colors.json';
import { useEndpoint, useTranslation } from '@rocket.chat/ui-contexts';
import { useQuery } from '@tanstack/react-query';
import React, { ReactElement } from 'react';
import { useQuery } from 'react-query';

export const SidebarFooterWatermark = (): ReactElement | null => {
const t = useTranslation();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from 'react-query';
import { useQuery } from '@tanstack/react-query';

import { getPeriodRange, Period } from '../dataView/periods';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from 'react-query';
import { useQuery } from '@tanstack/react-query';

import { getPeriodRange, Period } from '../dataView/periods';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from 'react-query';
import { useQuery } from '@tanstack/react-query';

import { getPeriodRange, Period } from '../dataView/periods';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useEndpoint } from '@rocket.chat/ui-contexts';
import { useQuery } from 'react-query';
import { useQuery } from '@tanstack/react-query';

import { getPeriodRange, Period } from '../dataView/periods';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ const ActiveUsersSection = ({ timezone }: ActiveUsersSectionProps): ReactElement
format: (date): string => moment(date).format(dauValues.length === 7 ? 'dddd' : 'L'),
}}
animate={true}
motionStiffness={90}
motionDamping={15}
motionConfig='stiff'
theme={{
// TODO: Get it from theme
axis: {
Expand Down
Loading

0 comments on commit 90cbdca

Please sign in to comment.