@@ -46,7 +46,14 @@ export const getUserPreferences = async (): Promise<UserPreferencesType> => {
46
46
parsedResult . computedAppTheme === 'system-dark' || parsedResult . computedAppTheme === 'system-light'
47
47
? THEME_PREFERENCE_MAP . auto
48
48
: parsedResult . computedAppTheme ,
49
- resources : parsedResult . resources ,
49
+ resources : {
50
+ [ ResourceKindType . devtronApplication ] : {
51
+ [ UserPreferenceResourceActions . RECENTLY_VISITED ] :
52
+ parsedResult . resources ?. [ ResourceKindType . devtronApplication ] ?. [
53
+ UserPreferenceResourceActions . RECENTLY_VISITED
54
+ ] || ( [ ] as BaseAppMetaData [ ] ) ,
55
+ } ,
56
+ } ,
50
57
}
51
58
}
52
59
@@ -69,31 +76,36 @@ const resourcesObj = (recentlyVisited: BaseAppMetaData[]): UserPreferenceResourc
69
76
* @throws Will throw an error if `shouldThrowError` is true and the request fails.
70
77
*/
71
78
79
+ export type UpdateUserPreferencesProps =
80
+ | { type : 'updateTheme' ; value : ThemePreferenceType | null ; appTheme : ThemeConfigType [ 'appTheme' ] }
81
+ | { type : 'updatePipelineRBACView' ; value : ViewIsPipelineRBACConfiguredRadioTabs }
82
+ | { type : 'updateRecentlyVisitedApps' ; value : BaseAppMetaData [ ] }
83
+
72
84
export const updateUserPreferences = async (
73
85
updatedUserPreferences ?: UpdatedUserPreferencesType ,
74
86
recentlyVisitedDevtronApps ?: BaseAppMetaData [ ] ,
75
87
shouldThrowError : boolean = false ,
76
88
) : Promise < boolean > => {
77
89
try {
78
- let value : UserPreferencesPayloadValueType = null
90
+ let data : UserPreferencesPayloadValueType = null
79
91
if ( updatedUserPreferences ) {
80
92
const { themePreference, appTheme, pipelineRBACViewSelectedTab } = updatedUserPreferences
81
93
82
- value = {
94
+ data = {
83
95
viewPermittedEnvOnly : pipelineRBACViewSelectedTab === ViewIsPipelineRBACConfiguredRadioTabs . ACCESS_ONLY ,
84
96
computedAppTheme : themePreference === THEME_PREFERENCE_MAP . auto ? `system-${ appTheme } ` : appTheme ,
85
97
}
86
98
}
87
99
88
100
if ( recentlyVisitedDevtronApps ?. length ) {
89
- value = {
101
+ data = {
90
102
resources : resourcesObj ( recentlyVisitedDevtronApps ) ,
91
103
}
92
104
}
93
105
94
106
const payload : UpdateUserPreferencesPayloadType = {
95
107
key : USER_PREFERENCES_ATTRIBUTE_KEY ,
96
- value : JSON . stringify ( value ) ,
108
+ value : JSON . stringify ( data ) ,
97
109
}
98
110
99
111
await patch ( `${ ROUTES . ATTRIBUTES_USER } /${ ROUTES . PATCH } ` , payload )
@@ -107,8 +119,3 @@ export const updateUserPreferences = async (
107
119
return false
108
120
}
109
121
}
110
-
111
- export type UserPreferencesUpdateType =
112
- | { type : 'updateTheme' ; value : ThemePreferenceType | null ; appTheme : ThemeConfigType [ 'appTheme' ] }
113
- | { type : 'updatePipelineRBACView' ; value : ViewIsPipelineRBACConfiguredRadioTabs }
114
- | { type : 'updateRecentlyVisitedApps' ; value : BaseAppMetaData [ ] }
0 commit comments