@@ -20,7 +20,9 @@ import { GridKeyEnum } from '../../../src/components/grid/enums/GridKey.enum'
2020import { ResponsiveContext , ResponsivePersonalSettings } from '../../context'
2121import { globals , useGlobalStyles } from '../../globalStyles'
2222import { useQuery , useSelectionService , useSnRoute } from '../../hooks'
23+ import { useRepositoryColumnSettings } from '../../hooks/use-repository-column-settings'
2324import { getPrimaryActionUrl , navigateToAction } from '../../services'
25+ import { ColumnSettingsSource , LegacyColumnSetting , LegacyColumnSettings } from '../../services/column-settings-service'
2426import { resolveContentLinkTarget } from '../../services/favorites'
2527import { ContentBreadcrumbs } from '../ContentBreadcrumbs'
2628import { DocumentViewer } from '../document-viewer'
@@ -51,19 +53,33 @@ const requiredGridLoadFields: ODataFieldParameter<GenericContent> = [
5153 'Locked' ,
5254]
5355
54- const getGridLoadChildrenSettings = ( colDef : ColDef [ ] ) : ODataParams < GenericContent > => {
55- const selectFields = new Set < keyof GenericContent > ( requiredGridLoadFields )
56+ const getGridLoadChildrenSettings = (
57+ colDef : ColDef [ ] ,
58+ columnSettings ?: LegacyColumnSetting [ ] ,
59+ ) : ODataParams < GenericContent > => {
60+ const selectFields = new Set < string > ( requiredGridLoadFields )
61+ const expandFields = new Set < string > ( [ 'CreatedBy' , 'ModifiedBy' ] )
5662
5763 colDef . forEach ( ( columnDefinition ) => {
5864 if ( columnDefinition . field && columnDefinition . field !== '0' ) {
59- selectFields . add ( columnDefinition . field as keyof GenericContent )
65+ selectFields . add ( columnDefinition . field )
66+ }
67+ } )
68+
69+ columnSettings ?. forEach ( ( { field } ) => {
70+ if ( ! field || field === 'Actions' ) {
71+ return
72+ }
73+ selectFields . add ( field )
74+ if ( field . includes ( '/' ) ) {
75+ expandFields . add ( field . split ( '/' ) [ 0 ] )
6076 }
6177 } )
6278
6379 return {
6480 orderby : [ [ 'DisplayName' , 'asc' ] ] ,
65- select : Array . from ( selectFields ) ,
66- expand : [ 'CreatedBy' , 'ModifiedBy' ] ,
81+ select : Array . from ( selectFields ) as ODataFieldParameter < GenericContent > ,
82+ expand : Array . from ( expandFields ) as ODataFieldParameter < GenericContent > ,
6783 onlyselectList : true ,
6884 }
6985}
@@ -222,13 +238,16 @@ export type ExploreProps = {
222238
223239type ExploreGridOrApplicationProps = {
224240 currentPath : string
225- fieldsToDisplay ?: Array < ColumnSetting < GenericContent > >
241+ fieldsToDisplay ?: LegacyColumnSetting [ ]
226242 schema ?: string
227243 disableColumnSettings ?: boolean
228244 colDef : ColDef [ ]
229245 gridKey : GridKeyEnum
230246 onNavigate : ( content : GenericContent ) => void
231247 onActivateItem : ( activeItem : GenericContent ) => Promise < void >
248+ onColumnSettingsChange : ( settings : LegacyColumnSettings , targetIdOrPath ?: string | number ) => Promise < void >
249+ columnSettingsSource ?: ColumnSettingsSource
250+ isColumnSettingsLoading : boolean
232251}
233252
234253const ActiveContentRouteSync : React . FC = ( ) => {
@@ -255,6 +274,9 @@ const ExploreGridOrApplication: React.FC<ExploreGridOrApplicationProps> = ({
255274 gridKey,
256275 onNavigate,
257276 onActivateItem,
277+ onColumnSettingsChange,
278+ columnSettingsSource,
279+ isColumnSettingsLoading,
258280} ) => {
259281 const selectionService = useSelectionService ( )
260282 const currentContent = useContext ( CurrentContentContext )
@@ -269,6 +291,9 @@ const ExploreGridOrApplication: React.FC<ExploreGridOrApplicationProps> = ({
269291 style = { { flexGrow : 7 , flexShrink : 0 , maxHeight : '100%' } }
270292 enableBreadcrumbs = { false }
271293 fieldsToDisplay = { fieldsToDisplay }
294+ onColumnSettingsChange = { onColumnSettingsChange }
295+ columnSettingsSource = { columnSettingsSource }
296+ isColumnSettingsLoading = { isColumnSettingsLoading }
272297 schema = { schema }
273298 onParentChange = { onNavigate }
274299 onActivateItem = { onActivateItem }
@@ -358,9 +383,19 @@ export function Explore({
358383 const pathFromUrl = useQuery ( ) . get ( 'path' )
359384 const snRoute = useSnRoute ( )
360385 const activeAction = snRoute . match ! . params . action
386+ const explicitColumnSettings = useMemo (
387+ ( ) =>
388+ fieldsToDisplay ?. map ( ( { field, title } ) => ( {
389+ field : String ( field ) ,
390+ title,
391+ } ) ) ,
392+ [ fieldsToDisplay ] ,
393+ )
394+ const { columnSettings, columnSettingsSource, isColumnSettingsLoading, saveColumnSettings } =
395+ useRepositoryColumnSettings ( currentPath , explicitColumnSettings )
361396 const currentChildrenLoadSettings = useMemo (
362- ( ) => loadChildrenSettings || getGridLoadChildrenSettings ( colDef ) ,
363- [ colDef , loadChildrenSettings ] ,
397+ ( ) => loadChildrenSettings || getGridLoadChildrenSettings ( colDef , columnSettings ) ,
398+ [ colDef , columnSettings , loadChildrenSettings ] ,
364399 )
365400 const onActivateItemOverride = async ( activeItem : GenericContent ) => {
366401 const contentToOpen = await resolveContentLinkTarget ( repository , activeItem )
@@ -434,7 +469,10 @@ export function Explore({
434469 < ContentInfo />
435470 < ExploreGridOrApplication
436471 disableColumnSettings = { disableColumnSettings }
437- fieldsToDisplay = { fieldsToDisplay }
472+ fieldsToDisplay = { columnSettings }
473+ onColumnSettingsChange = { saveColumnSettings }
474+ columnSettingsSource = { columnSettingsSource }
475+ isColumnSettingsLoading = { isColumnSettingsLoading }
438476 schema = { schema }
439477 onNavigate = { onNavigate }
440478 onActivateItem = { onActivateItemOverride }
0 commit comments