-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: alert history dropdown functionality (#5833)
* feat: alert history dropdown actions * chore: use query keys from react query key constant * fix: properly handle error states for alert rule APIs * fix: handle dropdown state using onOpenChange to fix clicking delete not closing the dropdown
- Loading branch information
1 parent
b20f906
commit 2e9cca5
Showing
10 changed files
with
244 additions
and
116 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 |
---|---|---|
@@ -1,26 +1,20 @@ | ||
import axios from 'api'; | ||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; | ||
import { AxiosError } from 'axios'; | ||
import { ErrorResponse, SuccessResponse } from 'types/api'; | ||
import { PayloadProps, Props } from 'types/api/alerts/create'; | ||
|
||
const create = async ( | ||
props: Props, | ||
): Promise<SuccessResponse<PayloadProps> | ErrorResponse> => { | ||
try { | ||
const response = await axios.post('/rules', { | ||
...props.data, | ||
}); | ||
const response = await axios.post('/rules', { | ||
...props.data, | ||
}); | ||
|
||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data.data, | ||
}; | ||
} catch (error) { | ||
return ErrorResponseHandler(error as AxiosError); | ||
} | ||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data.data, | ||
}; | ||
}; | ||
|
||
export default create; |
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 |
---|---|---|
@@ -1,24 +1,18 @@ | ||
import axios from 'api'; | ||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; | ||
import { AxiosError } from 'axios'; | ||
import { ErrorResponse, SuccessResponse } from 'types/api'; | ||
import { PayloadProps, Props } from 'types/api/alerts/delete'; | ||
|
||
const deleteAlerts = async ( | ||
props: Props, | ||
): Promise<SuccessResponse<PayloadProps> | ErrorResponse> => { | ||
try { | ||
const response = await axios.delete(`/rules/${props.id}`); | ||
const response = await axios.delete(`/rules/${props.id}`); | ||
|
||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data.data.rules, | ||
}; | ||
} catch (error) { | ||
return ErrorResponseHandler(error as AxiosError); | ||
} | ||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data.data.rules, | ||
}; | ||
}; | ||
|
||
export default deleteAlerts; |
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 |
---|---|---|
@@ -1,27 +1,16 @@ | ||
import axios from 'api'; | ||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; | ||
import { AxiosError } from 'axios'; | ||
import { ErrorResponse, SuccessResponse } from 'types/api'; | ||
import { PayloadProps, Props } from 'types/api/alerts/get'; | ||
|
||
const get = async ( | ||
props: Props, | ||
): Promise<SuccessResponse<PayloadProps> | ErrorResponse> => { | ||
try { | ||
const response = await axios.get(`/rules/${props.id}`); | ||
|
||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data, | ||
}; | ||
} catch (error) { | ||
if (window.location.href.includes('alerts/history')) { | ||
throw error as AxiosError; | ||
} | ||
return ErrorResponseHandler(error as AxiosError); | ||
} | ||
const response = await axios.get(`/rules/${props.id}`); | ||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data, | ||
}; | ||
}; | ||
|
||
export default get; |
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 |
---|---|---|
@@ -1,30 +1,20 @@ | ||
import axios from 'api'; | ||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; | ||
import { AxiosError } from 'axios'; | ||
import { ErrorResponse, SuccessResponse } from 'types/api'; | ||
import { PayloadProps, Props } from 'types/api/alerts/patch'; | ||
|
||
const patch = async ( | ||
props: Props, | ||
): Promise<SuccessResponse<PayloadProps> | ErrorResponse> => { | ||
try { | ||
const response = await axios.patch(`/rules/${props.id}`, { | ||
...props.data, | ||
}); | ||
const response = await axios.patch(`/rules/${props.id}`, { | ||
...props.data, | ||
}); | ||
|
||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data.data, | ||
}; | ||
} catch (error) { | ||
if (window.location.href.includes('alerts/history')) { | ||
throw error as AxiosError; | ||
} | ||
|
||
return ErrorResponseHandler(error as AxiosError); | ||
} | ||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data.data, | ||
}; | ||
}; | ||
|
||
export default patch; |
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 |
---|---|---|
@@ -1,26 +1,20 @@ | ||
import axios from 'api'; | ||
import { ErrorResponseHandler } from 'api/ErrorResponseHandler'; | ||
import { AxiosError } from 'axios'; | ||
import { ErrorResponse, SuccessResponse } from 'types/api'; | ||
import { PayloadProps, Props } from 'types/api/alerts/save'; | ||
|
||
const put = async ( | ||
props: Props, | ||
): Promise<SuccessResponse<PayloadProps> | ErrorResponse> => { | ||
try { | ||
const response = await axios.put(`/rules/${props.id}`, { | ||
...props.data, | ||
}); | ||
const response = await axios.put(`/rules/${props.id}`, { | ||
...props.data, | ||
}); | ||
|
||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data.data, | ||
}; | ||
} catch (error) { | ||
return ErrorResponseHandler(error as AxiosError); | ||
} | ||
return { | ||
statusCode: 200, | ||
error: null, | ||
message: response.data.status, | ||
payload: response.data.data, | ||
}; | ||
}; | ||
|
||
export default put; |
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
Oops, something went wrong.