Skip to content

Commit

Permalink
feat(addTeamProjectHeaderToAnalysisApps): Changed all instances of va…
Browse files Browse the repository at this point in the history
…riable name showButton to isEditable
  • Loading branch information
jarvisraymond-uchicago committed Nov 6, 2023
1 parent f18faef commit 140e5d3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/Analysis/Analysis.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Analysis extends React.Component {
{CheckForTeamProjectApplication(analysisApps) && (
<Col flex='1 0 auto'>
<QueryClientProvider client={new QueryClient()} contextSharing>
<TeamProjectHeader showButton />
<TeamProjectHeader isEditable />
</QueryClientProvider>
</Col>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/Analysis/AnalysisApp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ class AnalysisApp extends React.Component {
client={new QueryClient()}
contextSharing
>
<TeamProjectHeader showButton={false} />
<TeamProjectHeader isEditable={false} />
</QueryClientProvider>
</Col>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import isEnterOrSpace from '../../IsEnterOrSpace';
import TeamProjectModal from '../TeamProjectModal/TeamProjectModal';
import './TeamProjectHeader.css';

const TeamProjectHeader = ({ showButton }) => {
const TeamProjectHeader = ({ isEditable }) => {
const [isModalOpen, setIsModalOpen] = useState(false);
const [bannerText, setBannerText] = useState('- -');
const showModal = () => {
Expand All @@ -18,19 +18,19 @@ const TeamProjectHeader = ({ showButton }) => {
const storedTeamProject = localStorage.getItem('teamProject');
if (storedTeamProject) {
setBannerText(storedTeamProject);
} else if (showButton) {
} else if (isEditable) {
showModal();
} else if (!showButton && !storedTeamProject) {
} else if (!isEditable && !storedTeamProject) {
// non-editable view should redirect to app selection if user doesn't have a storedTeamProject
history.push('/analysis');
}
}, [history, showButton]);
}, [history, isEditable]);

return (
<React.Fragment>
<div className='team-project-header'>
<strong>Team Project</strong> / {bannerText}
{showButton && (
{isEditable && (
<span
className='team-project-header_modal-button'
tabIndex='0'
Expand All @@ -47,7 +47,7 @@ const TeamProjectHeader = ({ showButton }) => {
</span>
)}
</div>
{showButton && (
{isEditable && (
<TeamProjectModal
isModalOpen={isModalOpen}
setIsModalOpen={setIsModalOpen}
Expand All @@ -59,11 +59,11 @@ const TeamProjectHeader = ({ showButton }) => {
};

TeamProjectHeader.propTypes = {
showButton: PropTypes.bool,
isEditable: PropTypes.bool,
};

TeamProjectHeader.defaultProps = {
showButton: false,
isEditable: false,
};

export default TeamProjectHeader;
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const Template = (args) => (

export const withButton = Template.bind({});
withButton.args = {
showButton: true,
isEditable: true,
};

export const withNoButton = Template.bind({});
withNoButton.args = {
showButton: false,
isEditable: false,
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@ beforeEach(() => {
});
});

test('renders TeamProjectHeader with default props when showButton is true and no local storage', () => {
test('renders TeamProjectHeader with default props when isEditable is true and no local storage', () => {
localStorageMock.getItem.mockReturnValueOnce(null);
render(
<QueryClientProvider client={new QueryClient()} contextSharing>
<TeamProjectHeader showButton />
<TeamProjectHeader isEditable />
</QueryClientProvider>,
);
// Assert that the component renders without crashing without button
expect(screen.getByText('Team Project')).toBeInTheDocument();
expect(screen.getByText('/ - -')).toBeInTheDocument();
});

test(`Calls useHistory for redirect to analysis page when showButton is
test(`Calls useHistory for redirect to analysis page when isEditable is
false and teamProject is not set in local storage`, () => {
localStorageMock.getItem.mockReturnValueOnce(null);
const history = createMemoryHistory();

render(
<Router history={history}>
<QueryClientProvider client={new QueryClient()} contextSharing>
<TeamProjectHeader showButton={false} />
<TeamProjectHeader isEditable={false} />
</QueryClientProvider>
</Router>,
);

expect(history.location.pathname).toBe('/analysis');
});

test('renders TeamProjectHeader with edit button when showButton is true and can open modal', () => {
test('renders TeamProjectHeader with edit button when isEditable is true and can open modal', () => {
render(
<QueryClientProvider client={new QueryClient()} contextSharing>
<TeamProjectHeader showButton />
<TeamProjectHeader isEditable />
</QueryClientProvider>,
);

Expand Down

0 comments on commit 140e5d3

Please sign in to comment.