Skip to content

Commit

Permalink
Merged react-router v6 to v7, and replaces flux with react-query
Browse files Browse the repository at this point in the history
Any UI changes that I have made were to aid debugging, so feel free to reverse.
Some code seemed "in process" and I tried to get it working the same way using re

------------- Pre Jan 8, 2025 comments -----------
First steps toward replacing flux with react-query. react-query looks like it will be much simpler to use and maintain.

This PR is not a full replacement for all the flux stores. This PR compiles, but many existing features do not fully work -- The existing flux based configuration Stores and Actions are not functional components so they have to still use AppObservableStore which is not logically connected to the new replacement ConnectAppContext.jsx Store -- Most of the functional components have been switched to the new useContext() ~ ConnectAppContext.jsx.

The Teams and FAQ pages display, and Login works. You can delete a team member. The Team and Person Store/Actions have been replaced enough for the Teams page to display.

All the code in Stores meant to manage cache is no longer needed -- react-cache does that automatically. I also found that apiCalming() is no longer needed, react-cache 'calms' api queries automatically too. You make the api request as often as you want on a page, and the request get served with cached data. There is a way to force a cache update if needed.

All the breaking changes from react-router 6 and 7 are resolved, this eliminates the need for the 'react-router-dom-v5 compat' library. This router upgrade also nicely simplifies App.jsx.

Some class functions need to be upgraded to functional components to work with useContext(), and more still need upgrading.

As a first step in switching over to useContext -- I replaced AppObservableStore with ConnectAppContext..jsx, which eliminates all the subscriptions that were needed to be created and destroyed for each component. So, many onAppObservableStoreChange() instances were replaced with useEffect(). ConnectAppContext.jsx is just a "modern" global key value store without specific setters/getters.

For all files that I touched, I cleared most of the lint errors.

To simplify this migration, lots of "not yet needed" code is commented out, since I rely heavily on lint errors. Not yet used "useState()" pairs were commented out, partially implemented useState() had the resulting errors "suppressed" with eslint no-unused-vars disables. Unused styled components were commented out.

Removed Storybook (until we actually need it), it had lots of unresolved version dependencies.

Minor note: Boolean props to StyledComponents now need a $ in front of the variable like $largeFont, due to the React upgrade.
  • Loading branch information
SailingSteve committed Jan 18, 2025
1 parent 0378b80 commit 1e33765
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/js/components/Drawers/EditTaskDefinitionDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import EditTaskDefinitionDrawerMainContent from '../Task/EditTaskDefinitionDrawe
const EditTaskDefinitionDrawer = () => {
renderLog('EditTaskDefinitionDrawer'); // Set LOG_RENDER_EVENTS to log all renders
const [headerTitleJsx, setHeaderTitleJsx] = React.useState(<></>);
const [headerFixedJsx, setHeaderFixedJsx] = React.useState(<></>);
const [headerFixedJsx] = React.useState(<></>);

const onAppObservableStoreChange = () => {
const questionnaireIdTemp = AppObservableStore.getGlobalVariableState('editTaskDefinitionDrawerTaskDefinitionId');
Expand Down
2 changes: 1 addition & 1 deletion src/js/components/Drawers/EditTaskGroupDrawer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import DrawerTemplateA from './DrawerTemplateA';

const EditTaskGroupDrawer = () => {
renderLog('EditTaskGroupDrawer'); // Set LOG_RENDER_EVENTS to log all renders
const { getAppContextValue, getAppContextData } = useConnectAppContext();
const { getAppContextValue } = useConnectAppContext();

const [headerTitleJsx, setHeaderTitleJsx] = useState(<></>);
const [headerFixedJsx] = useState(<></>);
Expand Down
4 changes: 2 additions & 2 deletions src/js/components/Person/AddPersonDrawerMainContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const AddPersonDrawerMainContent = ({ classes }) => {
const [allStaffList, setAllStaffList] = React.useState(getAppContextValue('allStaffList'));
const [thisTeamsCurrentMembersList, setThisTeamsCurrentMembersList] = React.useState([]);
const [teamId, setTeamId] = React.useState(getAppContextValue('teamId'));
const [teamName, setTeamName] = React.useState("");
const [teamName, setTeamName] = React.useState('');

// eslint-disable-next-line no-unused-vars
const [teamMemberPersonIdList, setTeamMemberPersonIdList] = React.useState([]);
Expand All @@ -37,7 +37,7 @@ const AddPersonDrawerMainContent = ({ classes }) => {

let memberList = [];
const teamListFromContext = getAppContextValue('teamListNested');
if (teamListFromContext && thisTeamsCurrentMembersList.length === 0 && teamName === "") {
if (teamListFromContext && thisTeamsCurrentMembersList.length === 0 && teamName === '') {
const oneTeam = teamListFromContext.find((team) => team.id === parseInt(teamId));
setTeamName(oneTeam.teamName);
setTeamId(oneTeam.id);
Expand Down
3 changes: 1 addition & 2 deletions src/js/components/Person/PersonProfile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ const PersonProfile = () => {
);
};
PersonProfile.propTypes = {
classes: PropTypes.object.isRequired,
personId: PropTypes.number,
classes: PropTypes.object,
};

const styles = () => ({
Expand Down
4 changes: 0 additions & 4 deletions src/js/components/Questionnaire/CopyQuestionnaireLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ const CopyQuestionnaireLink = () => {
</CopyQuestionnaireLinkWrapper>
);
};
CopyQuestionnaireLink.propTypes = {
personId: PropTypes.number,
questionnaireId: PropTypes.number,
};

const styles = () => ({
});
Expand Down
5 changes: 3 additions & 2 deletions src/js/components/Team/TeamHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ const TeamHeader = ({ classes, showHeaderLabels, showIcons, team }) => {
};
TeamHeader.propTypes = {
classes: PropTypes.object.isRequired,
// showHeaderLabels: PropTypes.bool,
// team: PropTypes.object.isRequired,
showHeaderLabels: PropTypes.bool,
team: PropTypes.object.isRequired,
showIcons: PropTypes.bool,
};

const styles = (theme) => ({
Expand Down
4 changes: 3 additions & 1 deletion src/js/react-query/TaskQueryProcessing.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// allCachedTasksDict: {}, // This is a dictionary key: personId, value: another dictionary key: taskDefinitionId, value: Task dict


export const personListRetrieve = (data, teamId) => {
const personListRetrieve = (data, teamId) => {
const personListRaw = data.personList;

const personList = [];
Expand All @@ -17,3 +17,5 @@ export const personListRetrieve = (data, teamId) => {
}
return personList;
};

export default personListRetrieve;

0 comments on commit 1e33765

Please sign in to comment.