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

Feat/tup 700 core components node pkg use pkg fixes #272

12 changes: 8 additions & 4 deletions react/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
* https://jestjs.io/docs/configuration
*/

// https://stackoverflow.com/questions/73504569/syntaxerror-unexpected-token-export-from-react-leaflet-while-using-jest
const esModules = ['@react-leaflet', 'react-leaflet'].join('|');
const esModules = [
'@react-leaflet',
'react-leaflet',
'@tacc/core-components',
].join('|');

module.exports = {
// All imported modules in your tests should be mocked automatically
Expand Down Expand Up @@ -85,6 +88,7 @@ module.exports = {
'^utils(.*)$': '<rootDir>/src/utils$1',
'^hooks(.*)$': '<rootDir>/src/hooks$1',
'^react-leaflet$': require.resolve('react-leaflet'),
'^@hazmapper/(.*)$': '<rootDir>/src/$1',
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
Expand Down Expand Up @@ -178,10 +182,10 @@ module.exports = {
// timers: "real",

// A map from regular expressions to paths to transformers
transform: { '^.+\\.(js|jsx)?$': 'babel-jest' },
transform: { '^.+\\.(js|jsx|mjs)?$': 'babel-jest' },

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
transformIgnorePatterns: [`/node_modules/(?!${esModules})`],
transformIgnorePatterns: [`/node_modules/(?!(${esModules}))`],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,
Expand Down
18,098 changes: 9,987 additions & 8,111 deletions react/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@babel/preset-typescript": "^7.21.0",
"@changey/react-leaflet-markercluster": "^4.0.0-rc1",
"@reduxjs/toolkit": "^1.8.4",
"@tacc/core-components": "file:../../tacc-core-components-0.0.1.tgz",
"@tacc/core-components": "^0.0.3-beta.0",
"@tacc/core-styles": "^2.24.1",
"@testing-library/react": "^13.4.0",
"@turf/turf": "^6.5.0",
Expand All @@ -62,7 +62,7 @@
"react-leaflet": "^4.2.0",
"react-query": "^3.39.3",
"react-redux": "^8.0.2",
"react-resize-detector": "^9.1.1",
"react-resize-detector": "^7.1.2",
"react-router-dom": "^6.3.0",
"react-table": "^7.8.0",
"reactstrap": "^9.2.1",
Expand Down
4 changes: 2 additions & 2 deletions react/src/components/CreateMapModal/CreateMapModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { BrowserRouter as Router } from 'react-router-dom';
import { act } from 'react-dom/test-utils';
import { QueryClient, QueryClientProvider } from 'react-query';

jest.mock('../../hooks/user/useAuthenticatedUser', () => ({
jest.mock('@hazmapper/hooks/user/useAuthenticatedUser', () => ({
__esModule: true,
default: () => ({
data: { username: 'mockUser' },
Expand All @@ -21,7 +21,7 @@ jest.mock('../../hooks/user/useAuthenticatedUser', () => ({
}),
}));

jest.mock('../../hooks/projects/useCreateProject', () => ({
jest.mock('@hazmapper/hooks/projects/useCreateProject', () => ({
__esModule: true,
default: () => ({
mutate: jest.fn((data, { onSuccess, onError }) => {
Expand Down
11 changes: 3 additions & 8 deletions react/src/components/CreateMapModal/CreateMapModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@ import { Button } from '@tacc/core-components';
import styles from './CreateMapModal.module.css';
import { Formik, Form, Field } from 'formik';
import * as Yup from 'yup';
import useCreateProject from '../../hooks/projects/useCreateProject';
import useAuthenticatedUser from '../../hooks/user/useAuthenticatedUser';
import useCreateProject from '@hazmapper/hooks/projects/useCreateProject';
import useAuthenticatedUser from '@hazmapper/hooks/user/useAuthenticatedUser';
import { useNavigate } from 'react-router-dom';
import { ProjectRequest } from '../../types';
import { ProjectRequest } from '@hazmapper/types';
import {
FormikInput,
FormikTextarea,
FormikCheck,
} from '@tacc/core-components';
// import {
// FormikInput,
// FormikTextarea,
// FormikCheck,
// } from '../../core-wrappers';

type CreateMapModalProps = {
isOpen: boolean;
Expand Down
2 changes: 1 addition & 1 deletion react/src/components/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from 'react-leaflet';
import { TiledMapLayer } from 'react-esri-leaflet';
import MarkerClusterGroup from '@changey/react-leaflet-markercluster';
import { TileServerLayer, FeatureCollection } from '../../types';
import { TileServerLayer, FeatureCollection } from '@hazmapper/types';
import * as L from 'leaflet';
import * as turf from '@turf/turf';
import { LatLngTuple, MarkerCluster } from 'leaflet';
Expand Down
4 changes: 3 additions & 1 deletion react/src/components/MapProjectNavBar/MapProjectNavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import React from 'react';
import { useLocation } from 'react-router-dom';
import styles from './MapProjectNavBar.module.css';
import { QueryNavItem } from '@tacc/core-components';
import { queryPanelKey, Panel } from '../../utils/panels';
import { queryPanelKey, Panel } from '@hazmapper/utils/panels';
// TODO:not needed but can help illustate the `error useLocation() in the context of a <Router>` and how its in the tacc/core-components lib
//import { QueryNavItem } from './QueryNavItem';

import assetsImage from '../../assets/assets.png';
import pointCloudImage from '../../assets/point-clouds.png';
Expand Down
58 changes: 58 additions & 0 deletions react/src/components/MapProjectNavBar/QueryNavItem.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@import url('@tacc/core-styles/src/lib/_imports/tools/media-queries.css');

.nav-link {
text-decoration: none !important;
min-width: var(--min-width);
border: none;
padding-left: var(--horizontal-buffer);
color: #707070;
cursor: pointer;
display: block;
}

.nav-content {
height: 34px;
text-decoration: none;
padding-left: 1.5em;
padding-right: 1.5em;
display: flex;
align-items: center;
}

.nav-content:hover {
background: var(--global-color-accent--weak);
}

.nav-active {
background: var(--global-color-accent--weak);
}

.nav-text {
font-size: 1.2rem;
font-weight: 500;
pointer-events: none;
color: var(--global-color-primary--x-dark);
text-decoration: none;
}

.nav-icon {
margin-right: 1rem;
}

@media (--narrow-and-below) {
.nav-icon {
margin-right: unset;
margin: 0.25em;
}

.nav-content {
text-align: center;
flex-direction: column;
height: unset;
padding-block: 0.25em;
}

.nav-content > span {
width: min-content;
}
}
29 changes: 29 additions & 0 deletions react/src/components/MapProjectNavBar/QueryNavItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import { NavLink } from 'react-router-dom';
import { Icon } from '@tacc/core-components';
import styles from './QueryNavItem.module.css';

// Alternate nav item with active state set by a prop
export const QueryNavItem: React.FC<
React.PropsWithChildren<{
to: string;
icon?: string;
end?: boolean;
active: boolean;
className?: string;
}>
> = ({ to, icon, end, className, active, children }) => {
return (
<NavLink to={to} end={end} className={`${styles['nav-link']} ${className}`}>
<div
className={`${styles['nav-content']} ${
active ? styles['nav-active'] : ''
}`}
>
{icon && <Icon name={icon} size="xs" className={styles['nav-icon']} />}
{/* we'll want to set name based on the app */}
<span className={styles['nav-text']}>{children}</span>
</div>
</NavLink>
);
};
77 changes: 37 additions & 40 deletions react/src/components/Projects/ProjectListing.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import React, { useState } from 'react';
import { Project, DesignSafeProject } from '../../types';
import {
useDsProjects,
useProjects,
mergeDesignSafeProject,
} from '../../hooks';
import { Button, LoadingSpinner } from '@tacc/core-components';
import { useProjectsWithDesignSafeInformation } from '@hazmapper/hooks';
import { Button, LoadingSpinner, Icon } from '@tacc/core-components';
import CreateMapModal from '../CreateMapModal/CreateMapModal';
import { useNavigate } from 'react-router-dom';

Expand All @@ -21,15 +16,7 @@ export const ProjectListing: React.FC = () => {
setIsModalOpen(!isModalOpen);
};

const { data, isLoading, isError } = useProjects();
let projectsData: Array<Project> = [];
let dsData: Array<DesignSafeProject> = [];
const resp = useDsProjects();
dsData = resp?.data?.projects ?? [];
projectsData = data ?? [];

const combinedProj = mergeDesignSafeProject(projectsData, dsData);
projectsData = combinedProj;
const { data, isLoading, isError } = useProjectsWithDesignSafeInformation();

if (isLoading) {
return <LoadingSpinner />;
Expand All @@ -40,30 +27,40 @@ export const ProjectListing: React.FC = () => {
}

return (
<table>
<thead>
<tr>
<th>Map</th>
<th>Project</th>
<th>
<CreateMapModal isOpen={isModalOpen} toggle={toggleModal} />
<Button onClick={toggleModal} size="small">
Create a New Map
</Button>
</th>
</tr>
</thead>
<tbody>
{projectsData?.map((proj) => (
<tr key={proj.id} onClick={() => navigateToProject(proj.uuid)}>
<td>{proj.name}</td>
<td>
{proj.ds_project_id} {proj.ds_project_title}
</td>
<td></td>
<>
<table>
<thead>
<tr>
<th>Map</th>
<th>Project</th>
<th>
<CreateMapModal isOpen={isModalOpen} toggle={toggleModal} />
<Button onClick={toggleModal} size="small">
Create a New Map
</Button>
</th>
</tr>
))}
</tbody>
</table>
</thead>
<tbody>
{data?.map((proj) => (
<tr key={proj.id} onClick={() => navigateToProject(proj.uuid)}>
<td>{proj.name}</td>
<td>
{proj.ds_project?.value.projectId}{' '}
{proj.ds_project?.value.title}
</td>
<td>
<Button>
<Icon name="edit-document"></Icon>
</Button>
<Button>
<Icon name="trash"></Icon>
</Button>
</td>
</tr>
))}
</tbody>
</table>
</>
);
};
2 changes: 1 addition & 1 deletion react/src/components/Systems/SystemSelect.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, screen, fireEvent } from '@testing-library/react';
import { SystemSelect } from './SystemSelect';
import systemsFixture from './Systems.fixture';

jest.mock('../../hooks', () => {
jest.mock('@hazmapper/hooks', () => {
return {
useSystems: () => {
return {
Expand Down
4 changes: 2 additions & 2 deletions react/src/components/Systems/SystemSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react';
import { useSystems } from '../../hooks';
import { System } from '../../types';
import { useSystems } from '@hazmapper/hooks';
import { System } from '@hazmapper/types';

interface SystemSelectProps {
onSystemSelect: (selectedSystem: string) => void;
Expand Down
2 changes: 1 addition & 1 deletion react/src/hooks/environment/useAppConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
MapillaryConfiguration,
GeoapiBackendEnvironment,
DesignSafePortalEnvironment,
} from '../../types';
} from '@hazmapper/types';
import useBasePath from './useBasePath';

/**
Expand Down
2 changes: 1 addition & 1 deletion react/src/hooks/features/useFeatures.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UseQueryResult } from 'react-query';
import { FeatureCollection } from '../../types';
import { FeatureCollection } from '@hazmapper/types';
import { useGet } from '../../requests';

interface UseFeaturesParams {
Expand Down
6 changes: 5 additions & 1 deletion react/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
export { useProjects, useProject } from './projects/useProjects';
export {
useProjects,
useProject,
useProjectsWithDesignSafeInformation,
} from './projects/useProjects';
export { default as useFeatures } from './features/useFeatures';
export { useTileServers } from './tileServers/useTileServers';
export { default as useSystems } from './systems/useSystems';
Expand Down
2 changes: 1 addition & 1 deletion react/src/hooks/projects/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export {
mergeDesignSafeProject,
useProjectsWithDesignSafeInformation,
useProjects,
useDsProjects,
} from './useProjects';
2 changes: 1 addition & 1 deletion react/src/hooks/projects/useCreateProject.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { usePost } from '../../requests';
import { ApiService, Project, ProjectRequest } from '../../types';
import { ApiService, Project, ProjectRequest } from '@hazmapper/types';

const useCreateProject = () => {
const endpoint = '/projects/';
Expand Down
Loading
Loading