Skip to content

Commit

Permalink
try again button in update service alert is not correct (#944)
Browse files Browse the repository at this point in the history
  • Loading branch information
WangLiNaruto committed Jul 2, 2024
1 parent d5ca050 commit 7ffc0fc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
22 changes: 19 additions & 3 deletions src/components/content/catalog/services/update/UpdateResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { Alert, Button } from 'antd';
import React from 'react';
import catalogStyles from '../../../../../styles/catalog.module.css';
import errorAlertStyles from '../../../../../styles/error-alert.module.css';
import { Ocl } from '../../../../../xpanse-api/generated';
import { convertStringArrayToUnorderedList } from '../../../../utils/generateUnorderedList';

Expand All @@ -14,11 +15,15 @@ function UpdateResult({
updateRequestStatus,
updateResult,
onRemove,
retryRequest,
tryNewFile,
}: {
ocl: Ocl;
updateRequestStatus: string;
updateResult: string[];
onRemove: () => void;
retryRequest: () => void;
tryNewFile: () => void;
}): React.JSX.Element {
if (updateRequestStatus === 'success') {
return (
Expand Down Expand Up @@ -46,9 +51,20 @@ function UpdateResult({
onClose={onRemove}
className={catalogStyles.catalogServiceUpdateResult}
action={
<Button size='small' type='primary' onClick={onRemove} danger={true}>
Try Again
</Button>
<>
<Button
className={errorAlertStyles.tryAgainBtnInAlertClass}
size='small'
type='primary'
onClick={retryRequest}
danger={true}
>
Try Again
</Button>
<Button size='small' type='primary' onClick={tryNewFile} danger={true}>
Try New File
</Button>
</>
}
/>
);
Expand Down
21 changes: 20 additions & 1 deletion src/components/content/catalog/services/update/UpdateService.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,17 @@ function UpdateService({
updateServiceRequest.reset();
};

const tryNewFile = () => {
files.current.pop();
ocl.current = undefined;
yamlValidationResult.current = '';
updateResult.current = [];
setYamlSyntaxValidationStatus('notStarted');
setOclValidationStatus('notStarted');
oclDisplayData.current = <></>;
updateServiceRequest.reset();
};

function validateAndLoadYamlFile(uploadedFiles: UploadFile[]) {
if (uploadedFiles.length > 0) {
const reader = new FileReader();
Expand Down Expand Up @@ -126,6 +137,12 @@ function UpdateService({
}
};

const retryRequest = () => {
if (ocl.current) {
updateServiceRequest.mutate(ocl.current);
}
};

const setFileData = (file: RcFile): boolean => {
files.current.pop();
files.current.push(file);
Expand Down Expand Up @@ -166,6 +183,8 @@ function UpdateService({
updateRequestStatus={updateServiceRequest.status}
updateResult={updateResult.current}
onRemove={handleCancel}
tryNewFile={tryNewFile}
retryRequest={retryRequest}
/>
) : null}
<div className={registerStyles.registerButtons}>
Expand All @@ -175,7 +194,7 @@ function UpdateService({
beforeUpload={setFileData}
maxCount={1}
fileList={files.current}
onRemove={handleCancel}
onRemove={tryNewFile}
accept={'.yaml, .yml'}
showUploadList={{
showRemoveIcon: true,
Expand Down

0 comments on commit 7ffc0fc

Please sign in to comment.