Skip to content
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
13 changes: 13 additions & 0 deletions frontend/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { Link, useNavigate, useLocation } from 'react-router-dom';
import Popup from 'reactjs-popup';
import { FormattedMessage } from 'react-intl';
import { useProjectSummaryQuery } from '../../api/projects';

import messages from './messages';
import { ORG_URL, ORG_NAME, ORG_LOGO, SERVICE_DESK } from '../../config';
Expand Down Expand Up @@ -35,6 +36,13 @@
const organisations = useSelector((state) => state.auth.organisations);
const showOrgBar = useSelector((state) => state.orgBarVisibility.isVisible);

// Matches URLs containing '/projects/' followed by digits (the project ID), like '/projects/130' or '/manage/projects/130'
const match = location.pathname.match(/\/projects\/(\d+)/);
const projectId = match ? match[1] : null;
const { data: project } = useProjectSummaryQuery(projectId, {
enabled: !!projectId,
});

const linkCombo = 'link mh3 barlow-condensed blue-dark f4 ttu lh-solid nowrap pv2';

const isActive = ({ isPartiallyCurrent }) => {
Expand Down Expand Up @@ -125,6 +133,11 @@
/>
<span className="barlow-condensed f3 fw6 ml2 blue-dark nowrap">Tasking Manager</span>
</Link>
{project && project.sandbox && (

Check warning on line 136 in frontend/src/components/header/index.js

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer using an optional chain expression instead, as it's more concise and easier to read.

See more on https://sonarcloud.io/project/issues?id=hotosm_tasking-manager&issues=AZ4WnlamxCDtB74JbxDx&open=AZ4WnlamxCDtB74JbxDx&pullRequest=7243
<div className="tc br1 f7 ttu ba b--red red pv1 ph2 ml3 v-mid dib nowrap">
<FormattedMessage {...messages.sandbox} />
</div>
)}
<HorizontalScroll
className={'dn dib-l ml5-l mr4-l pl6-xl'}
style={{ flexGrow: 1 }}
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/components/header/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,8 @@ export default defineMessages({
id: 'serviceWorker.dialog.remindMeLater',
defaultMessage: 'Remind me later',
},
sandbox: {
id: 'project.detail.sandbox',
defaultMessage: 'Sandbox Mode',
},
});
8 changes: 5 additions & 3 deletions frontend/src/components/header/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ describe('Header', () => {
const setup = () => {
return {
...renderWithRouter(
<ReduxIntlProviders>
<Header />
</ReduxIntlProviders>,
<QueryClientProviders>
<ReduxIntlProviders>
<Header />
</ReduxIntlProviders>
</QueryClientProviders>,
),
};
};
Expand Down
Loading