forked from linode/manager
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upcoming: [DI-20204] - Added Interface type setup, query updates and …
…enhanced preferences type for upcoming Cloudpulsecustomselect component (linode#10769) Co-authored-by: vmangalr <vmangalr@akamai.com>
- Loading branch information
1 parent
dd19e75
commit 9f0138e
Showing
10 changed files
with
187 additions
and
21 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/api-v4/.changeset/pr-10769-upcoming-features-1723465718778.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/api-v4": Upcoming Features | ||
--- | ||
|
||
Update the type for AclpConfig ([#10769](https://github.com/linode/manager/pull/10769)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-10769-upcoming-features-1723465772614.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/manager": Upcoming Features | ||
--- | ||
|
||
Enhance support for passing Xfilters in existing databases fetch all instances query and Add a new query method for supporting custom filter using inbuilt API-V4 query factories for services like linode, dbaas etc., for upcoming CloudpulseCustomSelection component ([#10769](https://github.com/linode/manager/pull/10769)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import type { Filter, Params } from '@linode/api-v4'; | ||
import type { CloudPulseServiceTypeFiltersOptions } from 'src/features/CloudPulse/Utils/models'; | ||
import type { QueryFunctionAndKey } from 'src/features/CloudPulse/Utils/models'; | ||
import type { | ||
QueryFunctionNonArrayType, | ||
QueryFunctionType, | ||
} from 'src/features/CloudPulse/Utils/models'; | ||
|
||
/** | ||
* Interface that has the parameters required for making custom filter query call | ||
*/ | ||
interface CustomFilterQueryProps { | ||
/** | ||
* The Built in API-V4 query factory functions like databaseQueries.types, databaseQueries.engines etc., makes use of existing query key and optimises cache | ||
*/ | ||
apiV4QueryKey: QueryFunctionAndKey; | ||
/** | ||
* This indicates whether or not to enable the query | ||
*/ | ||
enabled: boolean; | ||
/** | ||
* The xFilter that is used to filter the results in API | ||
*/ | ||
filter?: Filter; | ||
/** | ||
* The id field to consider from the response of the custom filter call | ||
*/ | ||
idField: string; | ||
/** | ||
* The label field to consider from the response of the custom filter call | ||
*/ | ||
labelField: string; | ||
|
||
/** | ||
* The params like pagination information to be passed to the API | ||
*/ | ||
params?: Params; | ||
} | ||
|
||
/** | ||
* This functions queries the API-V4 URL and returns the filter value list like db engines, node types, region and resources etc., | ||
* @param queryProps - The parameters required for making custom filter query call | ||
*/ | ||
export const useGetCustomFiltersQuery = ( | ||
queryProps: CustomFilterQueryProps | ||
) => { | ||
const { apiV4QueryKey, enabled, idField, labelField } = queryProps; | ||
return useQuery< | ||
QueryFunctionType, | ||
unknown, | ||
CloudPulseServiceTypeFiltersOptions[] | ||
>({ | ||
// receive filters and return only id and label | ||
enabled, | ||
...apiV4QueryKey, | ||
select: ( | ||
filters: QueryFunctionType | ||
): CloudPulseServiceTypeFiltersOptions[] => { | ||
// whatever field we receive, just return id and label | ||
return filters | ||
.map( | ||
(filter): CloudPulseServiceTypeFiltersOptions => { | ||
return { | ||
id: getStringValue(filter, idField) ?? '', | ||
label: getStringValue(filter, labelField) ?? '', | ||
}; | ||
} | ||
) | ||
.filter(({ id, label }) => id.length && label.length); | ||
}, | ||
}); | ||
}; | ||
|
||
/** | ||
* | ||
* @param filter The queried filters like DatabaseEngine , DatabaseType | ||
* @param fieldKey The id and label field that needs to be fetched from the filter | ||
* @returns String value of the fieldKey in the filter object | ||
*/ | ||
const getStringValue = ( | ||
filter: QueryFunctionNonArrayType, | ||
fieldKey: string | ||
): string | undefined => { | ||
if (fieldKey in filter) { | ||
const value = filter[fieldKey as keyof typeof filter]; // since we already checked fieldKey is present in filterObj like (DatabaseEngine, DatabaseType) we can fetch it by considering fieldKey as key of filter | ||
if (value) { | ||
return String(value); | ||
} | ||
} | ||
return undefined; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters