Skip to content

Commit

Permalink
Make isProjectView prop optional
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesrkiger committed Jun 12, 2024
1 parent 47722d5 commit b9e39b3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
5 changes: 1 addition & 4 deletions jsapp/js/projects/myProjectsRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,7 @@ function MyProjectsRoute() {

{selectedAssets.length === 1 && (
<div className={styles.actions}>
<ProjectQuickActions
asset={selectedAssets[0]}
isProjectView={false}
/>
<ProjectQuickActions asset={selectedAssets[0]} />
</div>
)}

Expand Down
36 changes: 19 additions & 17 deletions jsapp/js/projects/projectsTable/projectQuickActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,38 @@ import customViewStore from 'js/projects/customViewStore';

interface ProjectQuickActionsProps {
asset: AssetResponse | ProjectViewAsset;
isProjectView: boolean;
isProjectView?: boolean;
}

/**
* Quick Actions (Archive, Share, Delete) buttons. Use these when a single
* project is selected in the Project Table.
*/
export default function ProjectQuickActions(props: ProjectQuickActionsProps) {
const ProjectQuickActions = ({asset, isProjectView = false}: ProjectQuickActionsProps) => {
// The `userCan` method requires `permissions` property to be present in the
// `asset` object. For performance reasons `ProjectViewAsset` doesn't have
// that property, and it is fine, as we don't expect Project View to have
// a lot of options available.
const isChangingPossible = userCan('change_asset', props.asset);
const isManagingPossible = userCan('manage_asset', props.asset);
const isChangingPossible = userCan('change_asset', asset);
const isManagingPossible = userCan('manage_asset', asset);

return (
<div className={styles.root}>
{/* Archive / Unarchive */}
{/* Archive a deployed project */}
{props.asset.deployment_status === 'deployed' && (
{asset.deployment_status === 'deployed' && (
<Button
isDisabled={
!isChangingPossible ||
props.asset.asset_type !== ASSET_TYPES.survey.id ||
!props.asset.has_deployment
asset.asset_type !== ASSET_TYPES.survey.id ||
!asset.has_deployment
}
type='bare'
color='storm'
size='s'
startIcon='archived'
onClick={() =>
archiveAsset(props.asset, (response: DeploymentResponse) => {
archiveAsset(asset, (response: DeploymentResponse) => {
customViewStore.handleAssetChanged(response.asset);
})
}
Expand All @@ -59,19 +59,19 @@ export default function ProjectQuickActions(props: ProjectQuickActionsProps) {
/>
)}
{/* Un-archive a deployed project */}
{props.asset.deployment_status === 'archived' && (
{asset.deployment_status === 'archived' && (
<Button
isDisabled={
!isChangingPossible ||
props.asset.asset_type !== ASSET_TYPES.survey.id ||
!props.asset.has_deployment
asset.asset_type !== ASSET_TYPES.survey.id ||
!asset.has_deployment
}
type='bare'
color='storm'
size='s'
startIcon='archived'
onClick={() =>
unarchiveAsset(props.asset, (response: DeploymentResponse) => {
unarchiveAsset(asset, (response: DeploymentResponse) => {
customViewStore.handleAssetChanged(response.asset);
})
}
Expand All @@ -80,7 +80,7 @@ export default function ProjectQuickActions(props: ProjectQuickActionsProps) {
/>
)}
{/* Show tooltip, since drafts can't be archived/unarchived */}
{props.asset.deployment_status === 'draft' && (
{asset.deployment_status === 'draft' && (
<Button
isDisabled
type='bare'
Expand All @@ -94,12 +94,12 @@ export default function ProjectQuickActions(props: ProjectQuickActionsProps) {

{/* Share */}
<Button
isDisabled={!isManagingPossible && !props.isProjectView}
isDisabled={!isManagingPossible && !isProjectView}
type='bare'
color='storm'
size='s'
startIcon='user-share'
onClick={() => manageAssetSharing(props.asset.uid)}
onClick={() => manageAssetSharing(asset.uid)}
tooltip={t('Share project')}
tooltipPosition='right'
/>
Expand All @@ -113,8 +113,8 @@ export default function ProjectQuickActions(props: ProjectQuickActionsProps) {
startIcon='trash'
onClick={() =>
deleteAsset(
props.asset,
getAssetDisplayName(props.asset).final,
asset,
getAssetDisplayName(asset).final,
(deletedAssetUid: string) => {
customViewStore.handleAssetsDeleted([deletedAssetUid]);
}
Expand All @@ -128,3 +128,5 @@ export default function ProjectQuickActions(props: ProjectQuickActionsProps) {
</div>
);
}

export default ProjectQuickActions

0 comments on commit b9e39b3

Please sign in to comment.