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/preservation journey #913

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
34 changes: 32 additions & 2 deletions src/components/TreeView/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
} from './style';
import Spinner from '../Spinner';
import { KeyboardArrowDown, KeyboardArrowRight } from '@mui/icons-material';
import { Link, useLocation } from 'react-router-dom';
import { Link, useLocation, useNavigate } from 'react-router-dom';
import { useLibraryContext } from '@procosys/modules/PlantConfig/views/Library/LibraryTreeview/LibraryTreeview';

/**
* @param id Unique identifier across all nodes in the tree (number or string).
Expand Down Expand Up @@ -56,6 +57,29 @@ const TreeView = ({
const [isNodeExpanded, setIsNodeExpanded] = useState(false);
const [executionCount, setExecutionCount] = useState(0);
const { pathname } = useLocation();
const navigate = useNavigate();

const { newJourney } = useLibraryContext();

// useEffect(() => {
// const getBasePath = (pathname: string): string => {
// const segments = pathname.split('/').filter(Boolean);
// if (segments.length < 2) return '';
// return `/${segments[0]}/${segments[1]}`;
// };

// const baseLibraryPath = getBasePath(pathname);

// if (newJourney?.project?.description && newJourney?.title) {
// const updatedPath = `${baseLibraryPath}/Preservation%20journeys/${encodeURIComponent(
// newJourney.project.description
// )}/${encodeURIComponent(newJourney.title)}`;

// if (pathname !== updatedPath) {
// navigate(updatedPath, { replace: true });
// }
// }
// }, [newJourney, pathname, navigate]);

const getNodeChildCountAndCollapse = (
parentNodeId: string | number
Expand Down Expand Up @@ -307,6 +331,7 @@ const TreeView = ({
handleOnClick(node);
}}
isSelected={node.isSelected ? true : false}
title={node.name}
>
{node.name}
</NodeLink>
Expand All @@ -319,7 +344,12 @@ const TreeView = ({
return (
<Link
to={finalPath}
style={{ textDecoration: 'none', color: 'inherit' }}
title={node.name}
style={{
textDecoration: 'none',
color: 'inherit',
width: '100%',
}}
>
{linkContent}
</Link>
Expand Down
3 changes: 3 additions & 0 deletions src/components/TreeView/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { tokens } from '@equinor/eds-tokens';
export const TreeContainer = styled.div`
display: flex;
flex-direction: column;
max-width: 100%;
`;

interface NodeContainerProps {
Expand All @@ -17,6 +18,8 @@ export const NodeContainer = styled.div<NodeContainerProps>`

margin-left: ${(props): string =>
`calc(var(--grid-unit) * ${props.indentMultiplier} - 4px)`};
margin-left: ${(props): string =>
`calc(var(--grid-unit) * ${props.indentMultiplier} - 4px)`};
`;

interface ExpandCollapseIconProps {
Expand Down
83 changes: 46 additions & 37 deletions src/modules/PlantConfig/views/Library/Library.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import React, { useEffect, useReducer, useState } from 'react';
import { Helmet } from 'react-helmet';
//import withAccessControl from '../../../../core/security/withAccessControl';
import LibraryItemDetails from './LibraryItemDetails';
import LibraryTreeview from './LibraryTreeview/LibraryTreeview';
import LibraryTreeview, {
LibraryProvider,
} from './LibraryTreeview/LibraryTreeview';
import { hot } from 'react-hot-loader';

import { Route, Routes } from 'react-router-dom';
Expand Down Expand Up @@ -111,43 +113,50 @@ const Library = (): JSX.Element => {
};

return (
<Container>
{selectedLibraryType && (
<Helmet>
<title>{` - ${selectedLibraryType}`}</title>
</Helmet>
)}
<LibraryTreeview
forceUpdate={forceUpdate}
setSelectedLibraryType={setSelectedLibraryType}
setSelectedLibraryItem={setSelectedLibraryItem}
dirtyLibraryType={dirtyLibraryType}
resetDirtyLibraryType={(): void => setDirtyLibraryType('')}
/>

<Divider />
<Routes>
<Route
path="/"
element={
<LibraryItemContainer
addPaddingRight={
selectedLibraryType !== LibraryType.TAG_FUNCTION
}
>
<LibraryItemDetails
forceUpdate={update}
libraryType={selectedLibraryType}
libraryItem={selectedLibraryItem}
setSelectedLibraryType={setSelectedLibraryType}
setSelectedLibraryItem={setSelectedLibraryItem}
setDirtyLibraryType={setDirtyLibraryType}
/>
</LibraryItemContainer>
}
<LibraryProvider>
<Container>
{selectedLibraryType && (
<Helmet>
<title>{` - ${selectedLibraryType}`}</title>
</Helmet>
)}
<LibraryTreeview
forceUpdate={forceUpdate}
setSelectedLibraryType={setSelectedLibraryType}
setSelectedLibraryItem={setSelectedLibraryItem}
dirtyLibraryType={dirtyLibraryType}
resetDirtyLibraryType={(): void => setDirtyLibraryType('')}
/>
</Routes>
</Container>

<Divider />
<Routes>
<Route
path="/"
element={
<LibraryItemContainer
addPaddingRight={
selectedLibraryType !==
LibraryType.TAG_FUNCTION
}
>
<LibraryItemDetails
forceUpdate={update}
libraryType={selectedLibraryType}
libraryItem={selectedLibraryItem}
setSelectedLibraryType={
setSelectedLibraryType
}
setSelectedLibraryItem={
setSelectedLibraryItem
}
setDirtyLibraryType={setDirtyLibraryType}
/>
</LibraryItemContainer>
}
/>
</Routes>
</Container>
</LibraryProvider>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export const Container = styled.div`
padding-top: var(--margin-module--top);
padding-right: calc(var(--grid-unit) * 5);
padding-left: calc(var(--grid-unit) * 5);
width: 20vw;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import TreeView, {

import { Container } from './LibraryTreeview.style';
import { LibraryType } from '../Library';
import React from 'react';
import React, { createContext, useContext, useState } from 'react';
import { showSnackbarNotification } from '../../../../../core/services/NotificationService';
import { usePlantConfigContext } from '../../../context/PlantConfigContext';
import {
Expand Down Expand Up @@ -282,3 +282,39 @@ const LibraryTreeview = (props: LibraryTreeviewProps): JSX.Element => {
};

export default LibraryTreeview;

interface LibraryContextType {
newJourney: Journey;
setNewJourney: (journey: Journey) => void;
}

const LibraryContext = createContext<LibraryContextType | undefined>(undefined);

export const LibraryProvider: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const [newJourney, setNewJourney] = useState<Journey>({
id: -1,
title: '',
isVoided: false,
isInUse: false,
steps: [],
rowVersion: '',
});

return (
<LibraryContext.Provider value={{ newJourney, setNewJourney }}>
{children}
</LibraryContext.Provider>
);
};

export const useLibraryContext = (): LibraryContextType => {
const context = useContext(LibraryContext);
if (!context) {
throw new Error(
'useLibraryContext must be used within a LibraryProvider'
);
}
return context;
};
Loading