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

Scix 314 Fix bugs related to visualization page #345

Merged
merged 3 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/components/ResultList/Item/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const Item = (props: IItemProps): ReactElement => {
const formattedPubDate = getFomattedNumericPubdate(pubdate);
const isClient = useIsClient();
const truncatedPub =
pub.length > APP_DEFAULTS.RESULT_ITEM_PUB_CUTOFF ? pub.slice(0, APP_DEFAULTS.RESULT_ITEM_PUB_CUTOFF) + '...' : pub;
pub?.length > APP_DEFAULTS.RESULT_ITEM_PUB_CUTOFF ? pub.slice(0, APP_DEFAULTS.RESULT_ITEM_PUB_CUTOFF) + '...' : pub;

// memoize the isSelected callback on bibcode
const isChecked = useStore(useCallback((state) => state.isDocSelected(bibcode), [bibcode]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ interface IAuthorNetworkPageState {
type AuthorNetworkPageAction =
| { type: 'CHANGE_PAPER_LIMIT'; payload: number }
| { type: 'SET_SELECTED'; payload: { node: IADSApiAuthorNetworkNode; dict: IBibcodeDict } }
| { type: 'DESELECT' }
| { type: 'ADD_FILTER'; payload: IAuthorNetworkNodeDetails }
| { type: 'REMOVE_FILTER'; payload: IAuthorNetworkNodeDetails }
| { type: 'REMOVE_FILTER_TAG'; payload: ITagItem }
Expand All @@ -60,6 +61,8 @@ const reducer: Reducer<IAuthorNetworkPageState, AuthorNetworkPageAction> = (stat
return { ...state, selected: null, filters: [], rowsToFetch: action.payload };
case 'SET_SELECTED':
return { ...state, selected: getAuthorNetworkNodeDetails(action.payload.node, action.payload.dict) };
case 'DESELECT':
return { ...state, selected: null };
case 'ADD_FILTER':
return { ...state, filters: uniq([...state.filters, action.payload]) };
case 'REMOVE_FILTER':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { IDocsEntity } from '@api';
import { Flex, Tab, TabList, TabPanel, TabPanels, Tabs } from '@chakra-ui/react';
import { IAuthor } from '@components/FeedbackForms';
import { Item } from '@components/ResultList/Item';
import { ILineGraph } from '@components/Visualizations/types';
import { ReactElement, useEffect, useState } from 'react';
import { equals } from 'ramda';
import { memo, ReactElement, useEffect, useRef, useState } from 'react';
import { NodeDetailPane } from './NodeDetailsPane';
import { SummaryPane } from './SummaryPane';

Expand Down Expand Up @@ -34,9 +36,15 @@ export const AuthorNetworkDetailsPane = ({
}: AuthorNetworkDetailsProps): ReactElement => {
const [tabIndex, setTabIndex] = useState(0);

// prevent tab switching during re-render
const prevNode = useRef<IAuthorNetworkNodeDetails>(null);

// when selected node changes, change tab to node details
useEffect(() => {
setTabIndex(node ? 1 : 0);
if (!equals(node, prevNode.current)) {
setTabIndex(node ? 1 : 0);
prevNode.current = node;
}
}, [node]);

const handleTabIndexChange = (index: number) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Visualizations/VisualizationTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const VisualizationsTabs = ({ selectedSection }: { selectedSection: VizSe
const index = sections.findIndex((section) => section.id === selectedSection);

const onPageChange = (index: number) => {
void router.push({ pathname: sections[index].path, query: router.query }, null, { shallow: true });
void router.push({ pathname: sections[index].path, query: router.query }, null);
};

return (
Expand Down
Loading