-
-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4450 from kobotoolbox/4234-remove-x-button-from-p…
…roject-route split top tabs from `formViewTabs` file and remove x button
- Loading branch information
Showing
9 changed files
with
183 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
import classnames from 'classnames'; | ||
import React, {useEffect, useState} from 'react'; | ||
import {useNavigate} from 'react-router-dom'; | ||
import {ROUTES} from 'js/router/routerConstants'; | ||
import {userCan, userCanPartially} from 'js/components/permissions/utils'; | ||
import { | ||
getRouteAssetUid, | ||
isAnyFormDataRoute, | ||
isFormLandingRoute, | ||
isAnyFormSettingsRoute, | ||
isFormSummaryRoute, | ||
} from 'js/router/routerUtils'; | ||
import assetStore from 'js/assetStore'; | ||
import sessionStore from 'js/stores/session'; | ||
import type {AssetResponse} from 'js/dataInterface'; | ||
import styles from './projectTopTabs.module.scss'; | ||
|
||
export default function ProjectTopTabs() { | ||
// First check if uid is available | ||
const assetUid = getRouteAssetUid(); | ||
if (assetUid === null) { | ||
return null; | ||
} | ||
|
||
// Setup navigation | ||
const navigate = useNavigate(); | ||
|
||
const [asset, setAsset] = useState<AssetResponse | undefined>(undefined); | ||
|
||
useEffect(() => { | ||
assetStore.whenLoaded(assetUid, setAsset); | ||
}, []); | ||
|
||
const isDataTabEnabled = | ||
asset?.deployment__identifier != undefined && | ||
asset?.has_deployment && | ||
asset?.deployment__submission_count > 0 && | ||
(userCan('view_submissions', asset) || | ||
userCanPartially('view_submissions', asset)); | ||
|
||
const isSettingsTabEnabled = | ||
sessionStore.isLoggedIn && | ||
(userCan('change_asset', asset) || userCan('change_metadata_asset', asset)); | ||
|
||
return ( | ||
<nav className={styles.root}> | ||
<ul className={styles.tabs}> | ||
<li | ||
onClick={() => | ||
navigate(ROUTES.FORM_SUMMARY.replace(':uid', assetUid)) | ||
} | ||
className={classnames({ | ||
[styles.tab]: true, | ||
[styles.disabled]: !sessionStore.isLoggedIn, | ||
[styles.active]: isFormSummaryRoute(assetUid), | ||
})} | ||
> | ||
{t('Summary')} | ||
</li> | ||
|
||
<li | ||
onClick={() => | ||
navigate(ROUTES.FORM_LANDING.replace(':uid', assetUid)) | ||
} | ||
className={classnames({ | ||
[styles.tab]: true, | ||
[styles.active]: isFormLandingRoute(assetUid), | ||
})} | ||
> | ||
{t('Form')} | ||
</li> | ||
|
||
<li | ||
onClick={() => navigate(ROUTES.FORM_DATA.replace(':uid', assetUid))} | ||
className={classnames({ | ||
[styles.tab]: true, | ||
[styles.disabled]: !isDataTabEnabled, | ||
[styles.active]: isAnyFormDataRoute(assetUid), | ||
})} | ||
> | ||
{t('Data')} | ||
</li> | ||
|
||
<li | ||
onClick={() => | ||
navigate(ROUTES.FORM_SETTINGS.replace(':uid', assetUid)) | ||
} | ||
className={classnames({ | ||
[styles.tab]: true, | ||
[styles.disabled]: !isSettingsTabEnabled, | ||
[styles.active]: isAnyFormSettingsRoute(assetUid), | ||
})} | ||
> | ||
{t('Settings')} | ||
</li> | ||
</ul> | ||
</nav> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
@use 'scss/sizes'; | ||
@use '~kobo-common/src/styles/colors'; | ||
|
||
@media print { | ||
.root { | ||
display: none; | ||
} | ||
} | ||
|
||
.root { | ||
width: 100%; | ||
} | ||
|
||
.tabs { | ||
background: colors.$kobo-white; | ||
border-bottom: sizes.$x1 solid colors.$kobo-gray-92; | ||
text-align: center; | ||
height: sizes.$x48; | ||
position: relative; | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: center; | ||
align-items: stretch; | ||
} | ||
|
||
.tab { | ||
background: transparent; | ||
border: none; | ||
border-bottom: sizes.$x2 solid transparent; | ||
text-transform: uppercase; | ||
line-height: sizes.$x48; | ||
margin: 0 sizes.$x30; | ||
font-size: sizes.$x15; | ||
cursor: pointer; | ||
position: relative; | ||
color: colors.$kobo-gray-40; | ||
font-weight: normal; | ||
|
||
&:hover, | ||
&.active { | ||
color: colors.$kobo-gray-24; | ||
} | ||
|
||
&.active { | ||
font-weight: 700; | ||
border-bottom: sizes.$x4 solid colors.$kobo-teal; | ||
} | ||
|
||
&.disabled { | ||
pointer-events: none; | ||
opacity: 0.5; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.