@ -42,11 +42,9 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
const { addUndo , defineViewScope } = useUndoRedo ( )
const { addUndo , defineViewScope } = useUndoRedo ( )
const isLocalMode = computed (
const isLocalMode = computed ( ( ) = > isPublic || ! isUIAllowed ( 'viewFieldEdit' ) || isSharedBase . value )
( ) = > isPublic || ! isUIAllowed ( 'viewFieldEdit' ) || ! isUIAllowed ( 'viewFieldEdit' ) || isSharedBase . value ,
)
const localChanges = ref < Field [ ] > ( [ ] )
const localChanges = ref < Record < string , Field > > ( { } )
const isColumnViewEssential = ( column : ColumnType ) = > {
const isColumnViewEssential = ( column : ColumnType ) = > {
// TODO: consider at some point ti delegate this via a cleaner design pattern to view specific check logic
// TODO: consider at some point ti delegate this via a cleaner design pattern to view specific check logic
@ -71,6 +69,7 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
const loadViewColumns = async ( ) = > {
const loadViewColumns = async ( ) = > {
if ( ! meta || ! view ) return
if ( ! meta || ! view ) return
let order = 1
let order = 1
if ( view . value ? . id ) {
if ( view . value ? . id ) {
@ -103,15 +102,19 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
aggregation : currentColumnField?.aggregation ? ? CommonAggregations . None ,
aggregation : currentColumnField?.aggregation ? ? CommonAggregations . None ,
system : isSystemColumn ( metaColumnById ? . value ? . [ currentColumnField . fk_column_id ! ] ) ,
system : isSystemColumn ( metaColumnById ? . value ? . [ currentColumnField . fk_column_id ! ] ) ,
isViewEssentialField : isColumnViewEssential ( column ) ,
isViewEssentialField : isColumnViewEssential ( column ) ,
initialShow :
currentColumnField . show ||
isColumnViewEssential ( currentColumnField ) ||
( currentColumnField as GridColumnType ) ? . group_by ,
}
}
} )
} )
. sort ( ( a : Field , b : Field ) = > a . order - b . order )
. sort ( ( a : Field , b : Field ) = > a . order - b . order )
if ( isLocalMode . value && fields . value ) {
if ( isLocalMode . value && fields . value ) {
for ( const field of localChanges . value ) {
for ( const key in localChanges . value ) {
const fieldIndex = fields . value . findIndex ( ( f ) = > f . fk_column_id === field . fk_column_id )
const fieldIndex = fields . value . findIndex ( ( f ) = > f . fk_column_id === key )
if ( fieldIndex !== undefined && fieldIndex > - 1 ) {
if ( fieldIndex !== undefined && fieldIndex > - 1 ) {
fields . value [ fieldIndex ] = field
fields . value [ fieldIndex ] = localChanges . value [ key ]
fields . value = fields . value . sort ( ( a : Field , b : Field ) = > a . order - b . order )
fields . value = fields . value . sort ( ( a : Field , b : Field ) = > a . order - b . order )
}
}
}
}
@ -133,16 +136,20 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
if ( isLocalMode . value ) {
if ( isLocalMode . value ) {
const fieldById = ( fields . value || [ ] ) . reduce < Record < string , any > > ( ( acc , curr ) = > {
const fieldById = ( fields . value || [ ] ) . reduce < Record < string , any > > ( ( acc , curr ) = > {
if ( curr . fk_column_id ) {
if ( curr . fk_column_id ) {
curr . show = true
curr . show = curr . initialShow ? true : fals e
acc [ curr . fk_column_id ] = curr
acc [ curr . fk_column_id ] = curr
}
}
return acc
return acc
} , { } )
} , { } )
fields . value = fields . value ? . map ( ( field : Field ) = > ( {
fields . value = ( fields . value || [ ] ) ? . map ( ( field : Field ) = > {
. . . field ,
const updateField = {
show : fieldById [ field . fk_column_id ! ] ? . show ,
. . . field ,
} ) )
show : fieldById [ field . fk_column_id ! ] ? . show ,
}
localChanges . value [ field . fk_column_id ! ] = field
return updateField
} )
meta . value ! . columns = meta . value ! . columns ? . map ( ( column : ColumnType ) = > {
meta . value ! . columns = meta . value ! . columns ? . map ( ( column : ColumnType ) = > {
if ( fieldById [ column . id ! ] ) {
if ( fieldById [ column . id ! ] ) {
@ -177,16 +184,20 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
if ( isLocalMode . value ) {
if ( isLocalMode . value ) {
const fieldById = ( fields . value || [ ] ) . reduce < Record < string , any > > ( ( acc , curr ) = > {
const fieldById = ( fields . value || [ ] ) . reduce < Record < string , any > > ( ( acc , curr ) = > {
if ( curr . fk_column_id ) {
if ( curr . fk_column_id ) {
curr . show = ! ! curr . isViewEssentialField
curr . show = ! ! metaColumnById ? . value ? . [ curr . fk_column_id ! ] ? . pv || ! ! curr . isViewEssentialField
acc [ curr . fk_column_id ] = curr
acc [ curr . fk_column_id ] = curr
}
}
return acc
return acc
} , { } )
} , { } )
fields . value = fields . value ? . map ( ( field : Field ) = > ( {
fields . value = ( fields . value || [ ] ) ? . map ( ( field : Field ) = > {
. . . field ,
const updateField = {
show : fieldById [ field . fk_column_id ! ] ? . show ,
. . . field ,
} ) )
show : fieldById [ field . fk_column_id ! ] ? . show ,
}
localChanges . value [ field . fk_column_id ! ] = field
return updateField
} )
meta . value ! . columns = meta . value ! . columns ? . map ( ( column : ColumnType ) = > {
meta . value ! . columns = meta . value ! . columns ? . map ( ( column : ColumnType ) = > {
if ( fieldById [ column . id ! ] ) {
if ( fieldById [ column . id ! ] ) {
@ -237,7 +248,7 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
return column
return column
} )
} )
localChanges . value . push ( field )
localChanges . value [ field . fk_column_id ] = field
}
}
if ( isUIAllowed ( 'viewFieldEdit' ) ) {
if ( isUIAllowed ( 'viewFieldEdit' ) ) {
@ -284,6 +295,10 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
const filteredFieldList = computed ( ( ) = > {
const filteredFieldList = computed ( ( ) = > {
return (
return (
fields . value ? . filter ( ( field : Field ) = > {
fields . value ? . filter ( ( field : Field ) = > {
if ( ! field . initialShow && isLocalMode . value ) {
return false
}
if (
if (
metaColumnById ? . value ? . [ field . fk_column_id ! ] ? . pv &&
metaColumnById ? . value ? . [ field . fk_column_id ! ] ? . pv &&
( ! filterQuery . value || field . title . toLowerCase ( ) . includes ( filterQuery . value . toLowerCase ( ) ) )
( ! filterQuery . value || field . title . toLowerCase ( ) . includes ( filterQuery . value . toLowerCase ( ) ) )
@ -305,6 +320,27 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
)
)
} )
} )
const numberOfHiddenFields = computed ( ( ) = > {
return ( fields . value || [ ] )
? . filter ( ( field : Field ) = > {
if ( ! field . initialShow && isLocalMode . value ) {
return false
}
if ( metaColumnById ? . value ? . [ field . fk_column_id ! ] ? . pv ) {
return true
}
// hide system columns if not enabled
if ( ! showSystemFields . value && isSystemColumn ( metaColumnById ? . value ? . [ field . fk_column_id ! ] ) ) {
return false
}
return true
} )
. filter ( ( field ) = > ! field . show ) ? . length
} )
const sortedAndFilteredFields = computed < ColumnType [ ] > ( ( ) = > {
const sortedAndFilteredFields = computed < ColumnType [ ] > ( ( ) = > {
return ( fields ? . value
return ( fields ? . value
? . filter ( ( field : Field ) = > {
? . filter ( ( field : Field ) = > {
@ -432,6 +468,7 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
fieldsMap ,
fieldsMap ,
loadViewColumns ,
loadViewColumns ,
filteredFieldList ,
filteredFieldList ,
numberOfHiddenFields ,
filterQuery ,
filterQuery ,
showAll ,
showAll ,
hideAll ,
hideAll ,
@ -445,6 +482,7 @@ const [useProvideViewColumns, useViewColumns] = useInjectionState(
updateGridViewColumn ,
updateGridViewColumn ,
gridViewCols ,
gridViewCols ,
resizingColOldWith ,
resizingColOldWith ,
isLocalMode ,
}
}
} ,
} ,
'useViewColumnsOrThrow' ,
'useViewColumnsOrThrow' ,