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

Display all image previews in reference picker #1524

Merged
merged 16 commits into from
Sep 27, 2023
Merged
28 changes: 28 additions & 0 deletions apps/sensenet/cypress/e2e/ui/referencePicker.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { PATHS, resolvePathParams } from '../../../src/application-paths'
import { pathWithQueryParams } from '../../../src/services/query-string-builder'

describe('Batch operations: ', () => {
beforeEach(() => {
cy.login()
cy.visit(pathWithQueryParams({ path: '/', newParams: { repoUrl: Cypress.env('repoUrl') } }))
})

it('it should render a preview in reference picker if it is an image', () => {
cy.visit(
pathWithQueryParams({
path: resolvePathParams({ path: PATHS.content.appPath, params: { browseType: 'explorer' } }),
newParams: { repoUrl: Cypress.env('repoUrl'), path: '/SampleWorkspace/Blog' },
}),
)

cy.get('[data-test="table-cell-6-ways-to-unlock-true-collaboration-with-a-headless-cms"]').rightclick({
force: true,
})
cy.get('[data-test="content-context-menu-edit"]').click({ force: true })
cy.get('[for="LeadImage"]').siblings('ul').find('li:last-of-type button').click()
cy.get('[placeholder="Search"]').type('teamwork')
cy.get(
'.MuiDialogContent-root img[src="https://daily.test.sensenet.cloud/Root/Content/SampleWorkspace/Blog/Images/teamwork.gif"]',
).should('be.visible')
})
})
14 changes: 13 additions & 1 deletion apps/sensenet/src/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
} from '@material-ui/icons'
import { Repository } from '@sensenet/client-core'
import { Injector, LogLevel, PathHelper } from '@sensenet/client-utils'
import { File, GenericContent, User } from '@sensenet/default-content-types'
import { File, GenericContent, Image, User } from '@sensenet/default-content-types'
import { useInjector, useRepository } from '@sensenet/hooks-react'
import { InlineIcon } from '@iconify/react'
import circleciIcon from '@iconify-icons/logos/circleci'
Expand Down Expand Up @@ -223,6 +223,18 @@ export const defaultContentResolvers: Array<IconResolver<GenericContent>> = [
/>
) : null,
},
{
get: (item, options) =>
options.repo.schemas.isContentFromType<Image>(item, 'Image') && (!item.PageCount || item.PageCount <= 0) ? (
<img
width={options.style?.width || 32}
height={options.style?.width || 32}
alt=""
src={PathHelper.joinPaths(options.repo.configuration.repositoryUrl, item.Path)}
style={options.style}
/>
) : null,
},
{
get: (item, options) => getIconByName(item.Icon, options),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const ReferencePicker: React.FC<ReferencePickerProps<GenericContentWithIs
return isFolder ? 'folder' : 'insert_drive_file'
}

const renderIcon = (item: GenericContentWithIsParent) =>
const renderIcon = (item: GenericContentWithIsParent | User) =>
props.repository.schemas.isContentFromType<User>(item, 'User') ? (
(item as User).Avatar?.Url ? (
<Avatar
Expand Down
2 changes: 1 addition & 1 deletion packages/sn-controls-react/test/reference-grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ describe('Reference grid field control', () => {
)
await sleepAsync(0)

wrapper.find(ReferencePicker).prop('handleSubmit')([{ Path: '/', Name: 'Jane Doe', Id: 1234, Type: 'User' }])
wrapper.find(ReferencePicker).prop('handleSubmit')!([{ Path: '/', Name: 'Jane Doe', Id: 1234, Type: 'User' }])

// Jane Doe + add reference
expect(wrapper.update().find(DefaultItemTemplate)).toHaveLength(2)
Expand Down
Loading