-
Notifications
You must be signed in to change notification settings - Fork 370
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
upcoming: [DI-19328] - Added capability to save & retrieve CloudPulse user preferences #10625
Changes from 9 commits
f8ee586
3b04a09
8a266d1
6b0dd47
6f6584c
afc40fc
44f0ebe
22693dd
20d8e78
10d5366
5d03d05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/api-v4": Upcoming Features | ||
--- | ||
|
||
Add ACLG Config and Widget to CloudPulse types ([#10625](https://github.com/linode/manager/pull/10625)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Upcoming Features | ||
--- | ||
|
||
Add capability to save & retrieve user preferences ([#10625](https://github.com/linode/manager/pull/10625)) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be able to use our React Query data layer for anything related to user preferences. ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To add to Banks, here's reference point in our docs: https://linode.github.io/manager/development-guide/05-fetching-data.html#react-query There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks!! for the suggestion. We will take this up as part of enhancements later to use React Query Data layer via https://track.akamai.com/jira/browse/DI-19503 as in Q3 we have a commitment for beta with minimum functionalities. Hope this is fine for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kmuddapo Use of React Query is something we'd need to see in this PR to get it merged, rather than later. Using direct api-v4 functions is rare in our codebase, and it may be acceptable on a one-off basis, but our best practice is to use RQ almost all the time -- this offers caching benefits, helps us manage states (loading, errors), as well as provides overall consistency in code. (See here for our section of documentation on this.) In this PR, even with debouncing, we'd be making several requests to @nikhagra Please update to use React Query here in place of the api-v4 functions, and let us know if you run into any questions on implementing that switch. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice to have: JSDocs comments are useful to include for custom hooks and utils. useRestrictedGlobalGrantCheck and usePagination are a couple examples of where we do this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* eslint-disable react-hooks/rules-of-hooks */ | ||
nikhagra-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { | ||
useMutatePreferences, | ||
usePreferences, | ||
} from 'src/queries/profile/preferences'; | ||
|
||
import type { AclpConfig } from '@linode/api-v4'; | ||
|
||
let userPreference: AclpConfig; | ||
let timerId: ReturnType<typeof setTimeout>; | ||
let mutateFn: any; | ||
|
||
export const loadUserPreferences = () => { | ||
nikhagra-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (userPreference) { | ||
return { isLoading: false }; | ||
} | ||
const { data: preferences, isError, isLoading } = usePreferences(); | ||
|
||
const { mutate } = useMutatePreferences(); | ||
|
||
if (isLoading) { | ||
return { isLoading }; | ||
} | ||
mutateFn = mutate; | ||
|
||
if (isError || !preferences) { | ||
userPreference = {} as AclpConfig; | ||
} else { | ||
userPreference = preferences.aclpPreference ?? {}; | ||
} | ||
|
||
return { isLoading }; | ||
}; | ||
|
||
export const getUserPreferenceObject = () => { | ||
return { ...userPreference }; | ||
}; | ||
|
||
const updateUserPreference = (updatedData: AclpConfig) => { | ||
nikhagra-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (mutateFn) { | ||
mutateFn({ aclpPreference: updatedData }); | ||
} | ||
}; | ||
|
||
export const updateGlobalFilterPreference = (data: {}) => { | ||
if (!userPreference) { | ||
userPreference = {} as AclpConfig; | ||
} | ||
userPreference = { ...userPreference, ...data }; | ||
|
||
debounce(userPreference); | ||
}; | ||
|
||
// to avoid frequent preference update calls within 500 ms interval | ||
const debounce = (updatedData: AclpConfig) => { | ||
if (timerId) { | ||
clearTimeout(timerId); | ||
} | ||
|
||
timerId = setTimeout(() => updateUserPreference(updatedData), 500); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const DASHBOARD_ID = 'dashboardId'; | ||
|
||
export const REGION = 'region'; | ||
|
||
export const RESOURCES = 'resources'; | ||
|
||
export const INTERVAL = 'interval'; | ||
|
||
export const TIME_DURATION = 'timeDuration'; | ||
|
||
export const AGGREGATE_FUNCTION = 'aggregateFunction'; | ||
|
||
export const SIZE = 'size'; | ||
|
||
export const LABEL = 'label'; | ||
|
||
export const REFRESH = 'refresh'; | ||
|
||
export const TIME_GRANULARITY = 'timeGranularity'; |
nikhagra-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's rename this file
utils.ts
to remain consistent with convention in the codebase.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed the case of file name to camel case because in future more util files will be added for different functionalities