Skip to content

Commit

Permalink
fix: fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasheartman committed Oct 8, 2024
1 parent e89bd86 commit 8337171
Showing 1 changed file with 82 additions and 25 deletions.
107 changes: 82 additions & 25 deletions frontend/src/component/personalDashboard/PersonalDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ import {
styled,
Typography,
} from '@mui/material';
import React, { type FC, useEffect, useState } from 'react';
import React, { type FC, useEffect } from 'react';
import LinkIcon from '@mui/icons-material/ArrowForward';
import { WelcomeDialog } from './WelcomeDialog';
import { useLocalStorageState } from 'hooks/useLocalStorageState';
import { usePersonalDashboard } from 'hooks/api/getters/usePersonalDashboard/usePersonalDashboard';
import { getFeatureTypeIcons } from 'utils/getFeatureTypeIcons';
import type {
PersonalDashboardSchema,
PersonalDashboardSchemaProjectsItem,
} from '../../openapi';
import type { PersonalDashboardSchemaProjectsItem } from '../../openapi';
import { FlagExposure } from 'component/feature/FeatureView/FeatureOverview/FeatureLifecycle/FlagExposure';
import { usePersonalDashboardProjectDetails } from 'hooks/api/getters/usePersonalDashboard/usePersonalDashboardProjectDetails';
import HelpOutline from '@mui/icons-material/HelpOutline';
Expand Down Expand Up @@ -55,15 +52,29 @@ export const StyledCardTitle = styled('div')<{ lines?: number }>(
wordBreak: 'break-word',
}),
);

const FlagListItem: FC<{
flag: { name: string; project: string; type: string };
selected: boolean;
onClick: () => void;
}> = ({ flag, selected, onClick }) => {
const activeFlagRef = useRef<HTMLLIElement>(null);

Check failure on line 60 in frontend/src/component/personalDashboard/PersonalDashboard.tsx

View workflow job for this annotation

GitHub Actions / build

Unhandled error

ReferenceError: useRef is not defined ❯ FlagListItem src/component/personalDashboard/PersonalDashboard.tsx:60:27 ❯ renderWithHooks node_modules/react-dom/cjs/react-dom.development.js:15486:18 ❯ mountIndeterminateComponent node_modules/react-dom/cjs/react-dom.development.js:20103:13 ❯ beginWork node_modules/react-dom/cjs/react-dom.development.js:21626:16 ❯ beginWork$1 node_modules/react-dom/cjs/react-dom.development.js:27465:14 ❯ performUnitOfWork node_modules/react-dom/cjs/react-dom.development.js:26599:12 ❯ workLoopSync node_modules/react-dom/cjs/react-dom.development.js:26505:5 ❯ renderRootSync node_modules/react-dom/cjs/react-dom.development.js:26473:7 ❯ recoverFromConcurrentError node_modules/react-dom/cjs/react-dom.development.js:25889:20 ❯ performSyncWorkOnRoot node_modules/react-dom/cjs/react-dom.development.js:26135:20 This error originated in "src/component/personalDashboard/PersonalDashboard.test.tsx" test file. It doesn't mean the error was thrown inside the file itself, but while it was running. The latest test that might've caused the error is "Render personal dashboard for a long running project". It might mean one of the following: - The error was thrown, while Vitest was running this test. - If the error occurred after the test had been completed, this was the last documented test before it was thrown.

useEffect(() => {
if (activeFlagRef.current) {
activeFlagRef.current.scrollIntoView({
block: 'nearest',
inline: 'start',
});
}
}, []);
const IconComponent = getFeatureTypeIcons(flag.type);
return (
<ListItem key={flag.name} disablePadding={true} sx={{ mb: 1 }}>
<ListItem
key={flag.name}
disablePadding={true}
sx={{ mb: 1 }}
ref={selected ? activeFlagRef : null}
>
<ListItemButton
sx={listItemStyle}
selected={selected}
Expand All @@ -88,18 +99,70 @@ const FlagListItem: FC<{
);
};

const useActiveProject = (projects: PersonalDashboardSchemaProjectsItem[]) => {
const [activeProject, setActiveProject] = useState(projects[0]?.id);
const useDashboardState = (
projects: PersonalDashboardSchemaProjectsItem[],
flags: PersonalDashboardSchemaFlagsItem[],
) => {
type State = {
activeProject: string | undefined;
activeFlag: PersonalDashboardSchemaFlagsItem | undefined;
};

const defaultState = {
activeProject: undefined,
activeFlag: undefined,
};

const [state, setState] = useLocalStorageState<State>(
'personal-dashboard:v1',
defaultState,
);

useEffect(() => {
if (!activeProject && projects.length > 0) {
setActiveProject(projects[0].id);
const setDefaultFlag =
flags.length &&
(!state.activeFlag ||
!flags.some((flag) => flag.name === state.activeFlag?.name));
const setDefaultProject =
projects.length &&
(!state.activeProject ||
!projects.some(
(project) => project.id === state.activeProject,
));

if (setDefaultFlag || setDefaultProject) {
setState({
activeFlag: setDefaultFlag ? flags[0] : state.activeFlag,
activeProject: setDefaultProject
? projects[0].id
: state.activeProject,
});
}
}, [JSON.stringify(projects)]);
});

return [activeProject, setActiveProject] as const;
};
const { activeFlag, activeProject } = state;

const setActiveFlag = (flag: PersonalDashboardSchemaFlagsItem) => {
setState({
...state,
activeFlag: flag,
});
};

const setActiveProject = (projectId: string) => {
setState({
...state,
activeProject: projectId,
});
};

return {
activeFlag,
setActiveFlag,
activeProject,
setActiveProject,
};
};
export const PersonalDashboard = () => {
const { user } = useAuthUser();

Expand All @@ -110,22 +173,16 @@ export const PersonalDashboard = () => {
refetch: refetchDashboard,
loading: personalDashboardLoading,
} = usePersonalDashboard();
const [activeFlag, setActiveFlag] = useState<
PersonalDashboardSchema['flags'][0] | null
>(null);
useEffect(() => {
if (personalDashboard?.flags.length) {
setActiveFlag(personalDashboard.flags[0]);
}
}, [JSON.stringify(personalDashboard?.flags)]);

const projects = personalDashboard?.projects || [];

const { activeProject, setActiveProject, activeFlag, setActiveFlag } =
useDashboardState(projects, personalDashboard?.flags ?? []);

const [welcomeDialog, setWelcomeDialog] = useLocalStorageState<
'open' | 'closed'
>('welcome-dialog:v1', 'open');

const projects = personalDashboard?.projects || [];
const [activeProject, setActiveProject] = useActiveProject(projects);

const {
personalDashboardProjectDetails,
loading: loadingDetails,
Expand Down

0 comments on commit 8337171

Please sign in to comment.