Skip to content

Commit

Permalink
Fix for single user field sync #1267
Browse files Browse the repository at this point in the history
  • Loading branch information
olemp committed Oct 17, 2023
1 parent 97a08e9 commit 354551b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const EditPropertiesPanel: FC = () => {
const submit = useEditPropertiesPanelSubmit()
return (
<CustomEditPanel
debug={true}
isOpen={context.state.activePanel === 'EditPropertiesPanel'}
headerText={strings.EditProjectInformationText}
fieldValues={context.state.data.fieldValues}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FluentProvider, mergeClasses, webLightTheme } from '@fluentui/react-components'
import { FluentProvider, webLightTheme } from '@fluentui/react-components'
import { Alert } from '@fluentui/react-components/unstable'
import { WebPartTitle } from 'pp365-shared-library'
import { Fluent, WebPartTitle } from 'pp365-shared-library'
import { ConfirmDialog } from 'pzl-spfx-components/lib/components/ConfirmDialog'
import React, { FC } from 'react'
import { Actions } from './Actions'
Expand Down Expand Up @@ -44,12 +44,7 @@ export const ProjectInformation: FC<IProjectInformationProps> = (props) => {

return (
<ProjectInformationContextProvider value={context}>
<FluentProvider
id={fluentProviderId}
theme={webLightTheme}
className={mergeClasses(styles.root, props.className)}
style={{ background: 'transparent' }}
>
<Fluent transparent>
<WebPartTitle title={props.title} />
<div className={styles.container}>
{context.state.error && (
Expand All @@ -73,7 +68,7 @@ export const ProjectInformation: FC<IProjectInformationProps> = (props) => {
<EditPropertiesPanel />
<CreateParentDialog />
</div>
</FluentProvider>
</Fluent>
{context.state.confirmActionProps && <ConfirmDialog {...context.state.confirmActionProps} />}
</ProjectInformationContextProvider>
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import { FluentProvider, useId, webLightTheme } from '@fluentui/react-components'
import { PortalCompatProvider } from '@fluentui/react-portal-compat'
import React, { FC, useMemo } from 'react'
import { IFluentProps } from './types'

export const Fluent: FC = ({ children }) => {
export const Fluent: FC<IFluentProps> = ({ children, transparent }) => {
const fluentProviderId = useId('fluent-provider')
return useMemo(
() => (
<FluentProvider id={fluentProviderId} theme={webLightTheme}>
<FluentProvider
id={fluentProviderId}
theme={webLightTheme}
style={transparent && { background: 'transparent' }}
>
<PortalCompatProvider>{children}</PortalCompatProvider>
</FluentProvider>
),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface IFluentProps {
transparent?: boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,28 +399,33 @@ export class SPDataAdapterBase<
break
case 'User':
{
const sourceUserId = fieldValues.get<number>(`${field.InternalName}Id`, {
const userFieldName = `${field.InternalName}Id`
const sourceUserId = fieldValues.get<number>(userFieldName, {
format: 'user_id'
})
if (sourceWeb.toUrl() === destinationWeb.toUrl()) {
properties[`${field.InternalName}Id`] = sourceUserId
properties[userFieldName] = sourceUserId
return properties
}
const user = siteUsers.find((u) => u.Id === sourceUserId)
if (!user) return properties
if (!user) {
properties[userFieldName] = null
return properties
}
const destinationUserId =
(await destinationWeb.ensureUser(user.LoginName))?.data?.Id ?? null
properties[`${field.InternalName}Id`] = destinationUserId
properties[userFieldName] = destinationUserId
}
break
case 'UserMulti':
{
const sourceUserIds = fieldValues.get<number[]>(`${field.InternalName}Id`, {
const userFieldName = `${field.InternalName}Id`
const sourceUserIds = fieldValues.get<number[]>(userFieldName, {
format: 'user_id',
defaultValue: []
})
if (sourceWeb.toUrl() === destinationWeb.toUrl()) {
properties[`${field.InternalName}Id`] = sourceUserIds
properties[userFieldName] = sourceUserIds
return properties
}
const users = siteUsers.filter(({ Id }) => sourceUserIds.indexOf(Id) !== -1)
Expand All @@ -429,7 +434,7 @@ export class SPDataAdapterBase<
users.map(({ LoginName }) => destinationWeb.ensureUser(LoginName))
)
).map(({ data }) => data.Id)
properties[`${field.InternalName}Id`] = options.wrapMultiValuesInResultsArray
properties[userFieldName] = options.wrapMultiValuesInResultsArray
? { results: destinationUserIds }
: destinationUserIds
}
Expand Down

0 comments on commit 354551b

Please sign in to comment.