Skip to content

Commit

Permalink
frontend: Prevent success pop-up on invalid operations
Browse files Browse the repository at this point in the history
Signed-off-by: Evangelos Skopelitis <[email protected]>

final changes

Signed-off-by: Evangelos Skopelitis <[email protected]>
  • Loading branch information
skoeva committed Jul 17, 2024
1 parent 6d5b487 commit 83d2b0f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions frontend/src/components/common/Resource/CreateButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function CreateButton(props: CreateButtonProps) {
);
};

function handleSave(newItemDefs: KubeObjectInterface[]) {
async function handleSave(newItemDefs: KubeObjectInterface[]) {
let massagedNewItemDefs = newItemDefs;
const cancelUrl = location.pathname;

Expand Down Expand Up @@ -84,8 +84,9 @@ export default function CreateButton(props: CreateButtonProps) {

const clusterName = getCluster() || '';

await applyFunc(massagedNewItemDefs, clusterName);
dispatch(
clusterAction(() => applyFunc(massagedNewItemDefs, clusterName), {
clusterAction(() => {}, {
startMessage: t('translation|Applying {{ newItemName }}…', {
newItemName: resourceNames.join(','),
}),
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/components/common/Resource/EditButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ export default function EditButton(props: EditButtonProps) {

const applyFunc = React.useCallback(updateFunc, [item]);

function handleSave(items: KubeObjectInterface[]) {
async function handleSave(items: KubeObjectInterface[]) {
const newItemDef = Array.isArray(items) ? items[0] : items;
const cancelUrl = location.pathname;
const itemName = item.metadata.name;

setOpenDialog(false);

await applyFunc(newItemDef);
dispatch(
clusterAction(() => applyFunc(newItemDef), {
clusterAction(() => {}, {
startMessage: t('translation|Applying changes to {{ itemName }}…', { itemName }),
cancelledMessage: t('translation|Cancelled changes to {{ itemName }}.', { itemName }),
successMessage: t('translation|Applied changes to {{ itemName }}.', { itemName }),
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/k8s/apiProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ export async function apply(body: KubeObjectInterface, clusterName?: string): Pr
// Preserve the resourceVersion if its an update request
bodyToApply.metadata.resourceVersion = resourceVersion;
// We had a conflict. Try a PUT
return apiEndpoint.put(bodyToApply, {}, cluster);
return await apiEndpoint.put(bodyToApply, {}, cluster);
}
}

Expand Down

0 comments on commit 83d2b0f

Please sign in to comment.