From 84f6c97a43e933985a5c1c7f924782a7dde64b95 Mon Sep 17 00:00:00 2001 From: Marniks7 <9289172+marniks7@users.noreply.github.com> Date: Sat, 14 Jan 2023 22:45:14 -0500 Subject: [PATCH] Add loading spinner and useEffect --- src/api/pipelineRuns.test.js | 10 ++- .../CreatePipelineRun/CreatePipelineRun.js | 12 +++- .../CreatePipelineRun/YAMLEditor.js | 65 +++++++++++-------- .../CreatePipelineRun/YAMLEditor.test.js | 14 ++++ 4 files changed, 67 insertions(+), 34 deletions(-) diff --git a/src/api/pipelineRuns.test.js b/src/api/pipelineRuns.test.js index 4160d619a6..df20acc1bc 100644 --- a/src/api/pipelineRuns.test.js +++ b/src/api/pipelineRuns.test.js @@ -370,9 +370,8 @@ it('generate new pipeline run maximum', () => { metadata: { annotations: { keya: 'valuea', - 'kubectl.kubernetes.io/last-applied-configuration': { - keya: 'valuea' - } + 'kubectl.kubernetes.io/last-applied-configuration': + '{"apiVersion": "tekton.dev/v1beta1", "keya": "valuea"}' }, labels: { keyl: 'valuel', @@ -418,9 +417,8 @@ it('generate new pipeline run last applied configuration should be removed', () kind: 'PipelineRun', metadata: { annotations: { - 'kubectl.kubernetes.io/last-applied-configuration': { - keya: 'valuea' - } + 'kubectl.kubernetes.io/last-applied-configuration': + '{"apiVersion": "tekton.dev/v1beta1", "keya": "valuea"}' }, name: 'test', namespace: 'test2' diff --git a/src/containers/CreatePipelineRun/CreatePipelineRun.js b/src/containers/CreatePipelineRun/CreatePipelineRun.js index 632d1bc004..e9a4f83f3e 100644 --- a/src/containers/CreatePipelineRun/CreatePipelineRun.js +++ b/src/containers/CreatePipelineRun/CreatePipelineRun.js @@ -486,8 +486,18 @@ function CreatePipelineRun() { ); payloadYaml = yaml.dump(payload); } + const loadingMessage = intl.formatMessage({ + id: 'dashboard.loading.pipelineRun', + defaultMessage: 'Loading PipelineRun…' + }); - return ; + return ( + + ); } const pipelineRun = getPipelineRunPayload({ labels: labels.reduce((acc, { key, value }) => { diff --git a/src/containers/CreatePipelineRun/YAMLEditor.js b/src/containers/CreatePipelineRun/YAMLEditor.js index d9648c3172..19e2d4b877 100644 --- a/src/containers/CreatePipelineRun/YAMLEditor.js +++ b/src/containers/CreatePipelineRun/YAMLEditor.js @@ -16,39 +16,40 @@ import { Button, Form, FormGroup, - InlineNotification + InlineNotification, + Loading } from 'carbon-components-react'; import yaml from 'js-yaml'; -import React, { useState } from 'react'; +import React, { useEffect, useState } from 'react'; import CodeMirror from '@uiw/react-codemirror'; import { StreamLanguage } from '@codemirror/language'; import { yaml as codeMirrorYAML } from '@codemirror/legacy-modes/mode/yaml'; import { useNavigate } from 'react-router-dom-v5-compat'; import { createPipelineRunRaw, useSelectedNamespace } from '../../api'; -export function CreateYAMLEditor({ code: initialCode, loading = false }) { +export function CreateYAMLEditor({ + code: initialCode, + loading = false, + loadingMessage = '' +}) { const intl = useIntl(); const navigate = useNavigate(); const { selectedNamespace } = useSelectedNamespace(); - const [ - { isCreating, prevLoading, submitError, validationErrorMessage, code }, - setState - ] = useState({ - isCreating: false, - prevLoading: loading, - submitError: '', - validationErrorMessage: '', - code: initialCode - }); + const [{ isCreating, submitError, validationErrorMessage, code }, setState] = + useState({ + isCreating: false, + submitError: '', + validationErrorMessage: '', + code: initialCode + }); - if (prevLoading !== loading) { + useEffect(() => { setState(state => ({ ...state, - code: initialCode, - prevLoading: loading + code: initialCode })); - } + }, [loading]); function validateNamespace(obj) { if (!obj?.metadata?.namespace) { @@ -187,15 +188,25 @@ export function CreateYAMLEditor({ code: initialCode, loading = false }) { lowContrast /> )} - - + + <> + {loading && ( +
+ + {loadingMessage} +
+ )} + {!loading && ( + + )} +