From 35da86f405245f701df13acf28d91d8195b7d086 Mon Sep 17 00:00:00 2001 From: Grayson Null Date: Fri, 10 Aug 2018 13:49:58 -0700 Subject: [PATCH] add action to fetch the applied overlay --- .../kustomize_overlay/KustomizeOverlay.jsx | 7 +++++ web/src/containers/KustomizeOverlay.js | 2 ++ .../redux/data/kustomizeOverlay/actions.js | 29 +++++++++++++++++++ web/src/redux/ui/main/reducer.js | 1 + 4 files changed, 39 insertions(+) diff --git a/web/src/components/kustomize/kustomize_overlay/KustomizeOverlay.jsx b/web/src/components/kustomize/kustomize_overlay/KustomizeOverlay.jsx index cf1173214..73c917d5c 100644 --- a/web/src/components/kustomize/kustomize_overlay/KustomizeOverlay.jsx +++ b/web/src/components/kustomize/kustomize_overlay/KustomizeOverlay.jsx @@ -163,6 +163,13 @@ export default class KustomizeOverlay extends React.Component { this.setState({ toastDetails }); } + async fetchAppliedOverlay() { + const payload = { + patch: this.state.patch + }; + await this.props.fetchAppliedOverlay(payload) + } + async handleKustomizeSave(closeOverlay) { const { selectedFile } = this.state; const contents = this.aceEditorOverlay.editor.getValue(); diff --git a/web/src/containers/KustomizeOverlay.js b/web/src/containers/KustomizeOverlay.js index 33c4823da..7f728b821 100644 --- a/web/src/containers/KustomizeOverlay.js +++ b/web/src/containers/KustomizeOverlay.js @@ -6,6 +6,7 @@ import { getHelmChartMetadata } from "../redux/data/kustomizeSettings/actions"; import { getFileContent, saveKustomizeOverlay, + fetchAppliedOverlay, finalizeKustomizeOverlay, generatePatch, applyPatch, @@ -26,6 +27,7 @@ const KustomizeOverlay = connect( getFileContent(payload) { return dispatch(getFileContent(payload)); }, getHelmChartMetadata() { return dispatch(getHelmChartMetadata()) }, saveKustomizeOverlay(payload) { return dispatch(saveKustomizeOverlay(payload)); }, + fetchAppliedOverlay(payload) { return dispatch(fetchAppliedOverlay(payload)); }, finalizeKustomizeOverlay() { return dispatch(finalizeKustomizeOverlay()); }, loadingData(key, isLoading) { return dispatch(loadingData(key, isLoading)); }, generatePatch(payload) { return dispatch(generatePatch(payload)); }, diff --git a/web/src/redux/data/kustomizeOverlay/actions.js b/web/src/redux/data/kustomizeOverlay/actions.js index fe32f2a61..54a55b37e 100644 --- a/web/src/redux/data/kustomizeOverlay/actions.js +++ b/web/src/redux/data/kustomizeOverlay/actions.js @@ -77,6 +77,35 @@ export function saveKustomizeOverlay(payload) { }; } +export function fetchAppliedOverlay(payload) { + return async (dispatch) => { + let response; + dispatch(loadingData("fetchAppliedOverlay", true)); + try { + const url = `${apiEndpoint}/kustomize/apply`; + response = await fetch(url, { + method: "POST", + headers: { + "Accept": "application/json", + "Content-Type": "application/json" + }, + body: JSON.stringify(payload) + }); + if (!response.ok) { + dispatch(loadingData("fetchAppliedOverlay", false)); + return; + } + await response.json(); + dispatch(loadingData("fetchAppliedOverlay", false)); + console.log(response) + } catch (error) { + dispatch(loadingData("fetchAppliedOverlay", false)); + console.log(error) + return; + } + }; +} + export function finalizeKustomizeOverlay() { return async (dispatch) => { let response; diff --git a/web/src/redux/ui/main/reducer.js b/web/src/redux/ui/main/reducer.js index cbf7854fe..90be31163 100644 --- a/web/src/redux/ui/main/reducer.js +++ b/web/src/redux/ui/main/reducer.js @@ -8,6 +8,7 @@ const loadingState = { submitActionLoading: false, fileContentLoading: false, saveKustomizeLoading: false, + fetchAppliedOverlayLoading: false, }; export function loading(state = loadingState, action = {}) {