Skip to content

Commit b40c396

Browse files
committed
permission fix, missing localization, avatar fixes
1 parent d121663 commit b40c396

File tree

12 files changed

+97
-18
lines changed

12 files changed

+97
-18
lines changed

apps/sensenet/src/components/UserAvatar.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ export const UserAvatar: FC<{
2222
)
2323
}
2424
return (
25-
<Avatar style={props.style}>
26-
{(props.user?.DisplayName && props.user.DisplayName[0]) || (props.user?.Name && props.user.Name[0]) || 'U'}
25+
<Avatar
26+
style={{
27+
...props.style,
28+
}}>
29+
{(props.user?.DisplayName && props.user.DisplayName[0])?.toUpperCase() ||
30+
(props.user?.Name && props.user.Name[0])?.toUpperCase() ||
31+
'U'}
2732
</Avatar>
2833
)
2934
}

apps/sensenet/src/components/dialogs/logout.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ export function LogoutDialog() {
2222
<Icon
2323
style={{
2424
margin: '0 1em 0 0',
25-
transition: 'filter linear 1s, opacity linear 1.5s',
26-
width: '1.5em',
2725
}}
2826
item={user}
2927
/>

apps/sensenet/src/components/field-controls/reference-grid.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export const ReferenceGrid: React.FC<ReactClientFieldSetting> = (props) => {
1010
<SnReferenceGrid
1111
{...props}
1212
dialogProps={{ classes: { paper: clsx(globalClasses.dialog, globalClasses.pickerDialog) } }}
13-
renderPickerIcon={(item) => <Icon item={item} />}
13+
renderPickerIcon={(item) => (
14+
<Icon item={item} style={{ width: 'auto', height: 'auto', marginTop: 1, paddingTop: 1 }} />
15+
)}
1416
pickerClasses={{ cancelButton: globalClasses.cancelButton }}
1517
/>
1618
)

apps/sensenet/src/components/grid/Cols/ColumnDefs..tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export const userColumnDefs: ColDef[] = [
195195
width: 110,
196196
minWidth: 110,
197197
maxWidth: 110,
198-
cellRendererFramework: (params: any) => {
198+
cellRenderer: (params: any) => {
199199
const roles = params.data.AllRoles.length ? params.data.AllRoles : []
200200
const directRoles = params.data.DirectRoles?.length ? params.data.DirectRoles : []
201201
return <RolesField user={params.data} roles={roles} directRoles={directRoles} />
@@ -240,7 +240,7 @@ export const groupColumnDefs: ColDef[] = [
240240
width: 110,
241241
minWidth: 110,
242242
maxWidth: 110,
243-
cellRendererFramework: (params: any) => {
243+
cellRenderer: (params: any) => {
244244
return <ReferenceField content={params.data} fieldName={'Members'} parent={params.data} showIcon={true} />
245245
},
246246
},

apps/sensenet/src/components/tree/StyledTreeItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const StyledTreeItem = ({
111111
const getLabel = () => (
112112
<>
113113
<ListItemIcon>
114-
<Icon item={contentvalue} style={{ height: 20, width: 20, fontSize: 18 }} />
114+
<Icon item={contentvalue} style={{ height: 20, width: 20, fontSize: 15 }} />
115115
</ListItemIcon>
116116
<ListItemText style={{ fontSize: '11px', color: isDisabled ? 'grey' : undefined }} primary={contentvalue.Name} />
117117
</>

apps/sensenet/src/hooks/use-drawer-items.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export const useDrawerItems = () => {
201201
for (const permission of item.permissions) {
202202
const actions = await repo.getActions({ idOrPath: permission.path })
203203
const action = actions.d.results.find((a) => a.Name === permission.action)
204-
if (!action || action.Forbidden) return false
204+
if (!action) return false
205205
}
206206
} catch (error) {
207207
logger.debug({

packages/sn-hooks-react/src/context/current-content.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { PathHelper } from '@sensenet/client-utils'
33
import { GenericContent } from '@sensenet/default-content-types'
44
import React, { createContext, FunctionComponent, useCallback, useEffect, useState } from 'react'
55
import Semaphore from 'semaphore-async-await'
6-
import { useRepository, useRepositoryEvents } from '../hooks'
6+
import { useLogger, useRepository, useRepositoryEvents } from '../hooks'
7+
import { useLocalization } from '../hooks/use-localization'
78

89
/**
910
* Returns a given content as current content
@@ -43,6 +44,8 @@ export const CurrentContentProvider: FunctionComponent<CurrentContentProviderPro
4344
const reload = () => setReloadToken(Math.random())
4445
const repo = useRepository()
4546
const events = useRepositoryEvents()
47+
const logger = useLogger('CurrentContent')
48+
const localization = useLocalization()
4649

4750
const onDeleteContent = useCallback(
4851
async (deleted: Content[]) => {
@@ -99,10 +102,14 @@ export const CurrentContentProvider: FunctionComponent<CurrentContentProviderPro
99102
}, [repo, props.idOrPath, reloadToken, loadLock])
100103

101104
if (errorState?.error) {
102-
if (errorState?.status === 404) {
103-
throw errorState
104-
}
105-
throw errorState.error
105+
console.log(errorState)
106+
logger.error({
107+
message: localization.currentContextError,
108+
data: {
109+
error: errorState.error,
110+
},
111+
})
112+
setErrorState({})
106113
}
107114

108115
return (
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { deepMerge, DeepPartial } from '@sensenet/client-utils'
2+
import React, { createContext, FC, useEffect, useState } from 'react'
3+
4+
export const defaultLocalization = {
5+
currentContextError: 'There was an unexpected error while fetching content!',
6+
}
7+
8+
export const LocalizationContext = createContext(defaultLocalization)
9+
10+
export type LocalizationType = DeepPartial<typeof defaultLocalization>
11+
12+
interface LocalizationProviderProps {
13+
localization?: Partial<LocalizationType>
14+
}
15+
16+
export const LocalizationProvider: FC<LocalizationProviderProps> = (props) => {
17+
const [currentValue, setCurrentValue] = useState(deepMerge(defaultLocalization, props.localization))
18+
19+
useEffect(() => {
20+
setCurrentValue(deepMerge(defaultLocalization, props.localization))
21+
}, [props.localization])
22+
23+
return <LocalizationContext.Provider value={currentValue}>{props.children}</LocalizationContext.Provider>
24+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { useContext } from 'react'
2+
import { LocalizationContext } from '../context/localizatzion-context'
3+
4+
export const useLocalization = () => {
5+
return useContext(LocalizationContext)
6+
}

packages/sn-pickers-react/src/components/picker-advanced.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Query, QueryExpression, QueryOperators } from '@sensenet/query'
1010
import { ColDef } from 'ag-grid-community'
1111
import { AgGridReact } from 'ag-grid-react'
1212
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
13+
import { useLocalization } from '../hooks/use-localization'
1314
import { GenericContentWithIsParent } from '../types'
1415

1516
// Icons
@@ -152,6 +153,7 @@ const useStyles = makeStyles(() =>
152153
wordBreak: 'break-all',
153154
},
154155
treeIcon: {
156+
width: '22px',
155157
'& span': {
156158
display: 'flex',
157159
},
@@ -338,6 +340,8 @@ export const PickerAdvanced: React.FC<PickerAdvancedProps> = ({
338340
const [rootElement, setRootElement] = useState<GenericContent>()
339341
const [searchTerm, setSearchTerm] = useState<string>('')
340342

343+
const localization = useLocalization()
344+
341345
const searchFieldRef = useRef<HTMLInputElement | null>(null)
342346

343347
//Grid Columns
@@ -555,7 +559,7 @@ export const PickerAdvanced: React.FC<PickerAdvancedProps> = ({
555559
<TextField
556560
ref={searchFieldRef}
557561
fullWidth={true}
558-
placeholder={'Search'}
562+
placeholder={localization.search}
559563
onChange={(ev) => {
560564
onSearchFieldChange(ev.target.value)
561565
}}
@@ -607,15 +611,15 @@ export const PickerAdvanced: React.FC<PickerAdvancedProps> = ({
607611
<div className={classes.errorMsg}>
608612
{selectionRoots &&
609613
!selectionRoots.some((root) => currentPath === root || currentPath.startsWith(`${root}/`)) && (
610-
<div>Disabled Path</div>
614+
<div>{localization.disabledPath}</div>
611615
)}
612616
</div>
613617
<Button
614618
type="button"
615619
onClick={() => {
616620
onCancel?.()
617621
}}>
618-
Cancel
622+
{localization.cancel}
619623
</Button>
620624
<Button
621625
type="button"
@@ -627,7 +631,7 @@ export const PickerAdvanced: React.FC<PickerAdvancedProps> = ({
627631
onClick={() => {
628632
onSubmit?.(selectedItems)
629633
}}>
630-
Submit
634+
{localization.submit}
631635
</Button>
632636
</div>
633637
</div>

0 commit comments

Comments
 (0)