-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7168 from ashanthamara/actions
Add getActionByActionId API call in the Action UI
- Loading branch information
Showing
8 changed files
with
193 additions
and
28 deletions.
There are no files selected for viewing
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,6 @@ | ||
--- | ||
"@wso2is/admin.actions.v1": minor | ||
"@wso2is/i18n": patch | ||
--- | ||
|
||
Add getActionByActionId api to actions ui |
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,64 @@ | ||
/** | ||
* Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import useRequest, { | ||
RequestConfigInterface, | ||
RequestErrorInterface, | ||
RequestResultInterface | ||
} from "@wso2is/admin.core.v1/hooks/use-request"; | ||
import { store } from "@wso2is/admin.core.v1/store"; | ||
import { HttpMethods } from "@wso2is/core/models"; | ||
import isEmpty from "lodash-es/isEmpty"; | ||
import { ActionResponseInterface } from "../models/actions"; | ||
|
||
/** | ||
* Hook to get the action configurations by id. | ||
* | ||
* @param actionType - Type of the action. | ||
* @param actionId - ID of the action. | ||
* @returns SWR response object containing the data, error, isLoading, isValidating, mutate. | ||
*/ | ||
const useGetActionById = <Data = ActionResponseInterface, Error = RequestErrorInterface> | ||
(actionType: string, actionId: string): RequestResultInterface<Data, Error> => { | ||
|
||
const requestConfig: RequestConfigInterface = { | ||
headers: { | ||
Accept: "application/json", | ||
"Content-Type": "application/json" | ||
}, | ||
method: HttpMethods.GET, | ||
url: `${ store.getState().config.endpoints.actions }/${ actionType }/${ actionId }` | ||
}; | ||
|
||
const shouldFetch: boolean = !isEmpty(actionId); | ||
|
||
const { data, error, isLoading, isValidating, mutate } = useRequest<Data, Error>( | ||
shouldFetch ? requestConfig : null, | ||
{ shouldRetryOnError: false } | ||
); | ||
|
||
return { | ||
data, | ||
error, | ||
isLoading, | ||
isValidating, | ||
mutate | ||
}; | ||
}; | ||
|
||
export default useGetActionById; |
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
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