|
30 | 30 | $: env = $page.params.env;
|
31 | 31 | $: team = $page.params.team;
|
32 | 32 |
|
33 |
| - $: applicationManifest = `spec: |
34 |
| - envFrom: |
35 |
| - - secret: ${secretName}`; |
36 |
| -
|
37 | 33 | let changes: operation[] = [];
|
38 | 34 | let deleteSecretOpen = false;
|
39 | 35 |
|
| 36 | + const applicationManifest = (secretName: string) => `spec: |
| 37 | + envFrom: |
| 38 | + - secret: ${secretName}`; |
| 39 | +
|
40 | 40 | const discardChanges = () => {
|
41 | 41 | changes = [];
|
42 | 42 | Secret.fetch();
|
|
64 | 64 | }
|
65 | 65 | `);
|
66 | 66 | const updateSecret = async () => {
|
67 |
| - if (!secret) return; |
| 67 | + if (!secret || changes.length == 0) return; |
68 | 68 |
|
69 | 69 | let data: VariableInput[] = changes.reduce(mergeChanges, secret.data);
|
70 | 70 |
|
|
75 | 75 | team: team
|
76 | 76 | });
|
77 | 77 |
|
| 78 | + if ($updateSecretMutation.errors) { |
| 79 | + return; |
| 80 | + } |
| 81 | +
|
78 | 82 | changes = [];
|
79 |
| - await Secret.fetch(); |
80 | 83 | };
|
81 | 84 |
|
82 | 85 | const deleteSecretMutation = graphql(`
|
|
91 | 94 | team: team,
|
92 | 95 | env: env
|
93 | 96 | });
|
| 97 | +
|
| 98 | + if ($deleteSecretMutation.errors) { |
| 99 | + return; |
| 100 | + } |
| 101 | +
|
94 | 102 | await goto('/team/' + team + '/secrets');
|
95 | 103 | };
|
96 | 104 |
|
97 |
| - const toggleDeleteSecretOpen = () => { |
98 |
| - deleteSecretOpen = !deleteSecretOpen; |
| 105 | + const openDeleteSecretModal = () => { |
| 106 | + deleteSecretOpen = true; |
99 | 107 | };
|
100 | 108 | </script>
|
101 | 109 |
|
102 | 110 | <svelte:head><title>{team} - Console</title></svelte:head>
|
103 | 111 |
|
104 |
| -{#if secretName} |
105 |
| - <h3> |
106 |
| - <a href="/team/{team}">{team}</a> / |
107 |
| - <a href="/team/{team}/secrets">secrets</a> / |
108 |
| - {env} / |
109 |
| - <i><a href="/team/{team}/{env}/secret/{secretName}">{secretName}</a></i> |
110 |
| - </h3> |
111 |
| -{:else} |
112 |
| - <h3> |
113 |
| - <a href="/team/{team}">{team}</a> / <a href="/team/{team}/secrets">secrets</a> / {env} |
114 |
| - </h3> |
115 |
| -{/if} |
| 112 | +<h3> |
| 113 | + <a href="/team/{team}">{team}</a> / |
| 114 | + <a href="/team/{team}/secrets">secrets</a> / |
| 115 | + {env} / |
| 116 | + <i><a href="/team/{team}/{env}/secret/{secretName}">{secretName}</a></i> |
| 117 | +</h3> |
116 | 118 |
|
117 | 119 | {#if $Secret.errors}
|
118 | 120 | <Alert variant="error">
|
|
131 | 133 | <HelpText title="Secret data" placement="right">
|
132 | 134 | A secret contains a set of key-value pairs.<br />
|
133 | 135 | <br />
|
134 |
| - Changes are not persisted until the "Confirm" button is clicked.<br /> |
| 136 | + Changes are not persisted until the "Save" button is clicked.<br /> |
135 | 137 | Applications using the secret will automatically restart to pick up any changes.
|
136 | 138 | <br />
|
137 | 139 | </HelpText>
|
|
141 | 143 | class="delete-secret"
|
142 | 144 | variant="danger"
|
143 | 145 | size="small"
|
144 |
| - on:click={toggleDeleteSecretOpen} |
| 146 | + on:click={openDeleteSecretModal} |
145 | 147 | >
|
146 | 148 | Delete
|
147 | 149 | </Button>
|
|
166 | 168 | <Tbody>
|
167 | 169 | <div class="secret-content">
|
168 | 170 | <div class="secret-edit">
|
| 171 | + {#if secret.data.length === 0 && filterAddKvs(changes).length === 0} |
| 172 | + <Alert variant="info" size="small"> |
| 173 | + No data found. Add a new row to get started. |
| 174 | + </Alert> |
| 175 | + {/if} |
169 | 176 | {#each secret.data as data (data.name)}
|
170 | 177 | <SecretKv key={data.name} value={data.value} bind:changes />
|
171 | 178 | {/each}
|
|
175 | 182 | <AddSecretKv bind:changes existingKeys={secret.data.map((d) => d.name)} />
|
176 | 183 | </div>
|
177 | 184 | <div class="secret-edit-buttons">
|
178 |
| - {#if changes.length > 0} |
179 |
| - <Tooltip content="Persist all changes" arrow={false}> |
180 |
| - <Button variant="primary" size="small" on:click={updateSecret}>Confirm</Button> |
181 |
| - </Tooltip> |
182 |
| - <Tooltip content="Discard all changes" arrow={false}> |
183 |
| - <Button variant="secondary" size="small" on:click={discardChanges}>Cancel</Button> |
184 |
| - </Tooltip> |
185 |
| - {/if} |
| 185 | + <Tooltip content="Persist all changes" arrow={false}> |
| 186 | + <Button variant="primary" size="small" on:click={updateSecret}>Save</Button> |
| 187 | + </Tooltip> |
| 188 | + <Tooltip content="Discard all changes" arrow={false}> |
| 189 | + <Button variant="secondary" size="small" on:click={discardChanges}>Cancel</Button> |
| 190 | + </Tooltip> |
186 | 191 | </div>
|
187 | 192 | {#if $updateSecretMutation.errors}
|
188 |
| - <Alert variant="error">{$updateSecretMutation.errors[0]?.message}</Alert> |
| 193 | + <Alert variant="error"> |
| 194 | + {#each $updateSecretMutation.errors as error} |
| 195 | + {error.message} |
| 196 | + {/each} |
| 197 | + </Alert> |
| 198 | + {/if} |
| 199 | + {#if $deleteSecretMutation.errors} |
| 200 | + <Alert variant="error"> |
| 201 | + {#each $deleteSecretMutation.errors as error} |
| 202 | + {error.message} |
| 203 | + {/each} |
| 204 | + </Alert> |
189 | 205 | {/if}
|
190 | 206 | </div>
|
191 | 207 | </Tbody>
|
|
242 | 258 | as environment variables.
|
243 | 259 | </HelpText>
|
244 | 260 | </h4>
|
245 |
| - <pre class="manifest">{applicationManifest}</pre> |
| 261 | + <pre class="manifest">{applicationManifest(secretName)}</pre> |
246 | 262 | <Tooltip content="Copy manifest to clipboard">
|
247 | 263 | <CopyButton
|
248 | 264 | text="Copy manifest"
|
249 | 265 | activeText="Manifest copied"
|
250 | 266 | variant="action"
|
251 |
| - copyText={applicationManifest} |
| 267 | + copyText={applicationManifest(secretName)} |
252 | 268 | ></CopyButton>
|
253 | 269 | </Tooltip>
|
254 | 270 | </Card>
|
|
301 | 317 | }
|
302 | 318 |
|
303 | 319 | .secret-edit-buttons {
|
304 |
| - margin: 16px 0 0 16px; |
| 320 | + margin: 32px 0 0 16px; |
305 | 321 | padding: 32px 0;
|
306 | 322 | }
|
307 | 323 |
|
|
0 commit comments