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

SWC-6800 - Remove feature flag and unnecessary props #1122

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,6 @@ const routes: NestedRoute = {
synapseConfigArray: [
{
name: 'DownloadCartPage',
props: {
onViewSharingSettingsClicked: benefactorEntityId => {
window.open(
`https://www.synapse.org/Synapse:${benefactorEntityId}`,
'_blank',
)
},
},
isOutsideContainer: true,
},
],
Expand Down
5 changes: 2 additions & 3 deletions apps/synapse-portal-framework/src/types/portal-config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
CardContainerLogicProps,
ChallengeDataDownloadProps,
DownloadCartPageProps,
DatasetJsonLdScriptProps,
ExternalFileHandleLinkProps,
FeaturedDataTabsProps,
GoalsProps,
Expand All @@ -21,7 +21,6 @@ import {
TableFeedCardsProps,
ThemesPlotProps,
TimelinePlotProps,
DatasetJsonLdScriptProps,
UpsetPlotProps,
UserCardListGroupsProps,
UserCardListRotateProps,
Expand Down Expand Up @@ -132,7 +131,7 @@ type HomePageCardContainer = {

type DownloadCartPage = {
name: 'DownloadCartPage'
props: DownloadCartPageProps
props?: undefined
}

type Ecosystem = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import useTrackTransientListItems from '../../utils/hooks/useTrackTransientListI

export type EntityActionsRequiredProps = {
entityId: string
onViewSharingSettingsClicked?: (benefactorId: string) => void
}

export const EntityActionsRequired: React.FunctionComponent<
EntityActionsRequiredProps
> = props => {
const { entityId, onViewSharingSettingsClicked } = props
const { entityId } = props
const { data: actionRequiredList } = useGetEntityActionsRequired(entityId)
const actions = actionRequiredList?.actions

Expand All @@ -26,13 +25,7 @@ export const EntityActionsRequired: React.FunctionComponent<
<div className="EntityActionsRequired">
{allCompleteAndIncompleteActions.map((action: Action, index) => {
if (action) {
return (
<ActionRequiredListItem
key={index}
action={action}
onViewSharingSettingsClicked={onViewSharingSettingsClicked}
/>
)
return <ActionRequiredListItem key={index} action={action} />
} else return false
})}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ import { EnableTwoFaRequirementCard } from './EnableTwoFaRequirementCard'
export type ActionRequiredListItemProps = {
action: Action
count?: number
/** Invoked when a user clicks "View Sharing Settings" for a set of files that require the Download permission*/
onViewSharingSettingsClicked?: (benefactorId: string) => void
}

export function ActionRequiredListItem(props: ActionRequiredListItemProps) {
const { action, count, onViewSharingSettingsClicked } = props
const { action, count } = props
switch (action.concreteType) {
case 'org.sagebionetworks.repo.model.download.MeetAccessRequirement': {
return (
Expand All @@ -29,7 +27,6 @@ export function ActionRequiredListItem(props: ActionRequiredListItemProps) {
key={action.benefactorId}
entityId={`syn${action.benefactorId}`}
count={count}
onViewSharingSettingsClicked={onViewSharingSettingsClicked}
/>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
import React from 'react'
import { useEffect, useState } from 'react'
import React, { useEffect, useState } from 'react'
import AvailableForDownloadTable from './AvailableForDownloadTable'
import DownloadListStats from './DownloadListStats'
import { useGetDownloadListStatistics } from '../../synapse-queries/download/useDownloadList'
import {
DownloadListActionsRequired,
DownloadListActionsRequiredProps,
} from './DownloadListActionsRequired'
import { useSynapseContext } from '../../utils/context/SynapseContext'
import { useGetDownloadListStatistics } from '../../synapse-queries'
import { DownloadListActionsRequired } from './DownloadListActionsRequired'
import { useSynapseContext } from '../../utils'
import SynapseClient from '../../synapse-client'
import IconSvg from '../IconSvg/IconSvg'
import { CreatePackageV2 } from './CreatePackageV2'
import FullWidthAlert from '../FullWidthAlert/FullWidthAlert'
import { ErrorBanner } from '../error/ErrorBanner'
import { ErrorBanner } from '../error'
import { Button, Tooltip, Typography } from '@mui/material'
import { HelpPopover } from '../HelpPopover/HelpPopover'
import { HelpPopover } from '../HelpPopover'
import { ProgrammaticInstructionsModal } from '../ProgrammaticInstructionsModal/ProgrammaticInstructionsModal'
import { DeleteTwoTone } from '@mui/icons-material'
import { PYTHON_CLIENT_IMPORT_AND_LOGIN } from './DirectProgrammaticDownload'
Expand All @@ -27,9 +23,7 @@ const cliDownloadCode = `synapse get-download-list`
/**
* Show the Download Cart page.
*/
export const DownloadCartPage: React.FunctionComponent<
DownloadListActionsRequiredProps
> = props => {
export function DownloadCartPage() {
const { accessToken } = useSynapseContext()
const [selectedTabIndex, setSelectedTabIndex] = useState<number>(0)
const [isShowingCreatePackageUI, setIsShowingCreatePackageUI] =
Expand Down Expand Up @@ -151,7 +145,7 @@ export const DownloadCartPage: React.FunctionComponent<
// In the typical case where the download cart is cleared, unmounting the component ensures that the actions are cleared out.
<div>
<div className="actionsRequiredContainer container">
<DownloadListActionsRequired {...props} />
<DownloadListActionsRequired />
</div>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,7 @@ import { ActionRequiredListItem } from './ActionRequiredListItem'
import useTrackTransientListItems from '../../utils/hooks/useTrackTransientListItems'
import { times } from 'lodash-es'

export type DownloadListActionsRequiredProps = {
/** Invoked when a user clicks "View Sharing Settings" for a set of files that require the Download permission*/
onViewSharingSettingsClicked?: (benefactorId: string) => void
}

export function DownloadListActionsRequired(
props: DownloadListActionsRequiredProps,
) {
const { onViewSharingSettingsClicked } = props

export function DownloadListActionsRequired() {
// This component will track all completed actions, based on which actions are omitted from the ActionsRequiredResponse as the user performs required tasks
// For accurate tracking, we must make sure we have all data. So we will fetch all pages instead of one page at a time.
const { data: currentActionsRequired, isLoading } =
Expand All @@ -38,7 +29,6 @@ export function DownloadListActionsRequired(
key={index}
action={item.action}
count={item.count}
onViewSharingSettingsClicked={onViewSharingSettingsClicked}
/>
)
} else return false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen } from '@testing-library/react'
import { render, screen, waitFor, within } from '@testing-library/react'
import React from 'react'
import { createWrapper } from '../../testutils/TestingLibraryUtils'
import { SynapseContextType } from '../../utils'
Expand All @@ -11,15 +11,19 @@ import {
RequestDownloadCardProps,
} from './RequestDownloadCard'
import userEvent from '@testing-library/user-event'
import { EntityBundle, ErrorResponse } from '@sage-bionetworks/synapse-types'
import {
ACCESS_TYPE,
EntityBundle,
ErrorResponse,
} from '@sage-bionetworks/synapse-types'
import mockFileEntity from '../../mocks/entity/mockFileEntity'
import { MOCK_USER_ID_2 } from '../../mocks/user/mock_user_profile'
import { AUTHENTICATED_PRINCIPAL_ID } from '../../utils/SynapseConstants'

const ENTITY_ID = 'syn29218'
const onViewSharingSettingsClicked = jest.fn()
const defaultProps: RequestDownloadCardProps = {
entityId: ENTITY_ID,
count: 10,
onViewSharingSettingsClicked,
}

const setupEntityBundleResponse = (canDownload: boolean) => {
Expand All @@ -28,6 +32,19 @@ const setupEntityBundleResponse = (canDownload: boolean) => {
...mockFileEntity.entity,
id: ENTITY_ID,
},
benefactorAcl: {
id: ENTITY_ID,
resourceAccess: [
{
principalId: MOCK_USER_ID_2,
accessType: [ACCESS_TYPE.CHANGE_PERMISSIONS],
},
{
principalId: AUTHENTICATED_PRINCIPAL_ID,
accessType: [ACCESS_TYPE.READ],
},
],
},
permissions: {
canDownload: canDownload,
canView: false,
Expand Down Expand Up @@ -80,7 +97,18 @@ describe('RequestDownloadCard tests', () => {
name: 'View Sharing Settings',
})
await userEvent.click(viewSharingSettingsButton)
expect(onViewSharingSettingsClicked).toHaveBeenLastCalledWith(ENTITY_ID)

const dialog = await screen.findByRole('dialog')
within(dialog).getByText('Sharing Settings', { exact: false })

const closeSharingSettingsButton = within(dialog).getByRole('button', {
name: 'close',
})
await userEvent.click(closeSharingSettingsButton)

await waitFor(() =>
expect(screen.queryByRole('dialog')).not.toBeInTheDocument(),
)
})

it('Indicates the action is complete if the user can download the entity', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
import React from 'react'
import React, { useState } from 'react'
import { useGetEntityBundle } from '../../synapse-queries'
import { DOWNLOAD_PERMISSION_REQUIRED } from '../../utils/SynapseConstants'
import { Alert, Button, Typography } from '@mui/material'
import { ActionRequiredCard } from './ActionRequiredCard/ActionRequiredCard'
import EntityAclEditorModal from '../EntityAclEditor/EntityAclEditorModal'

export type RequestDownloadCardProps = {
entityId: string
count?: number
/** Invoked when a user clicks "View Sharing Settings" for a set of files that require the Download permission*/
onViewSharingSettingsClicked?: (benefactorId: string) => void
}

const DEFAULT_ON_VIEW_SHARING_SETTINGS_CLICKED: RequestDownloadCardProps['onViewSharingSettingsClicked'] =
benefactorEntityId =>
window.open(
`https://www.synapse.org/Synapse:${benefactorEntityId}`,
'_blank',
)

export const REQUEST_DOWNLOAD_TITLE = 'Download Permission Required'
export const RequestDownloadCard: React.FunctionComponent<
RequestDownloadCardProps
> = ({
entityId,
count,
onViewSharingSettingsClicked = DEFAULT_ON_VIEW_SHARING_SETTINGS_CLICKED,
}: RequestDownloadCardProps) => {
> = ({ entityId, count }: RequestDownloadCardProps) => {
const {
data: entityBundle,
isLoading,
Expand All @@ -36,6 +24,8 @@ export const RequestDownloadCard: React.FunctionComponent<
includePermissions: true,
})

const [showSharingSettings, setShowSharingSettings] = useState(false)

const hasDownloadPermission = Boolean(entityBundle?.permissions.canDownload)

if (isError) {
Expand All @@ -59,10 +49,15 @@ export const RequestDownloadCard: React.FunctionComponent<
<Typography variant="smallText1" sx={{ mb: 1, color: 'grey.700' }}>
Contact an administrator to request download permission
</Typography>
<EntityAclEditorModal
entityId={entityId}
open={showSharingSettings}
onClose={() => setShowSharingSettings(false)}
/>
<Button
variant="outlined"
onClick={() => {
onViewSharingSettingsClicked(entityId)
setShowSharingSettings(true)
}}
disabled={hasDownloadPermission}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import type { DownloadListActionsRequiredProps as DownloadCartPageProps } from './DownloadListActionsRequired'
import { DownloadCartPage } from './DownloadCartPage'
import { ShowDownloadV2 } from './ShowDownloadV2'
import type { ShowDownloadV2Props } from './ShowDownloadV2'
import { ShowDownloadV2 } from './ShowDownloadV2'

export {
DownloadCartPage,
DownloadCartPageProps,
ShowDownloadV2,
ShowDownloadV2Props,
}
export { DownloadCartPage, ShowDownloadV2, ShowDownloadV2Props }
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ export type QueryContextType<
/** Returns true iff the current request has resettable filters applied via facet filters or additionalFilters. Excludes filters applied to a locked column */
hasResettableFilters: boolean
getColumnModel: (columnName: string) => ColumnModel | null
// Either open benefactor entity page in a new window or open the sharing settings dialog (in Synapse.org)
onViewSharingSettingsClicked?: (benefactorId: string) => void
/** Combines two faceted columns into a single inclusive range selector */
combineRangeFacetConfig?: ReadonlyDeep<CombineRangeFacetConfig>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ export type QueryWrapperProps = React.PropsWithChildren<{
onQueryChange?: (newQueryJson: string) => void
onQueryResultBundleChange?: (newQueryResultBundleJson: string) => void
lockedColumn?: LockedColumn
onViewSharingSettingsClicked?: (benefactorId: string) => void
isRowSelectionVisible?: boolean
/** The set of columns that defines a uniqueness constraint on the table for the purposes of filtering based on row selection.
* Note that Synapse tables have no internal concept of a primary key.
Expand Down Expand Up @@ -100,7 +99,6 @@ function _QueryWrapper(props: QueryWrapperProps) {
lockedColumn,
componentIndex,
shouldDeepLink,
onViewSharingSettingsClicked,
isRowSelectionVisible: isRowSelectionVisibleFromProps = false,
isRowSelectionUIFloating: isRowSelectionUIFloatingFromProps = true,
rowSelectionPrimaryKey: rowSelectionPrimaryKeyFromProps,
Expand Down Expand Up @@ -267,7 +265,6 @@ function _QueryWrapper(props: QueryWrapperProps) {
removeQueryFilter,
removeValueFromQueryFilter,
getColumnModel,
onViewSharingSettingsClicked,
addValueToSelectedFacet,
combineRangeFacetConfig,
setRangeFacetValue,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
import React, { useMemo } from 'react'
import { ErrorBanner } from './error/ErrorBanner'
import { useQueryContext } from './QueryContext/QueryContext'
import { ErrorBanner } from './error'
import { useQueryContext } from './QueryContext'
import { EntityActionsRequired } from './AccessRequirement/EntityActionsRequired'
import { useSynapseContext } from '../utils'

/**
* Error banner that automatically pulls the error from QueryContext. If 403, shows entity actions required
*/
export const QueryWrapperErrorBanner = () => {
const { error, getCurrentQueryRequest, onViewSharingSettingsClicked } =
useQueryContext()
const { error, getCurrentQueryRequest } = useQueryContext()
const { entityId } = useMemo(
() => getCurrentQueryRequest(),
[getCurrentQueryRequest],
)
const { accessToken } = useSynapseContext()

if (error?.status == 403 && accessToken) {
return (
<EntityActionsRequired
entityId={entityId}
onViewSharingSettingsClicked={onViewSharingSettingsClicked}
/>
)
return <EntityActionsRequired entityId={entityId} />
} else {
return <ErrorBanner error={error} />
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,19 +331,6 @@ export const TableWithNoDownloadAccess: Story = {
name: 'No Table Download Access',
hideSqlEditorControl: false,
shouldDeepLink: false,
// onViewSharingSettingsClicked: undefined
onViewSharingSettingsClicked: benefactorEntityId => {
displayToast(
`Open the ${benefactorEntityId} Sharing Settings dialog. If undefined, send to the entity page.`,
'info',
{
primaryButtonConfig: {
text: 'Open Entity Page',
href: `https://www.synapse.org/Synapse:${benefactorEntityId}`,
},
},
)
},
},
}

Expand Down
Loading
Loading