|
31 | 31 | $: team = $page.params.team;
|
32 | 32 |
|
33 | 33 | let changes: operation[] = [];
|
| 34 | + let saved = false; |
34 | 35 | let deleteSecretOpen = false;
|
| 36 | + let discardChangesOpen = false; |
35 | 37 |
|
36 | 38 | const workloadManifest = (secretName: string) => `spec:
|
37 | 39 | envFrom:
|
38 | 40 | - secret: ${secretName}`;
|
39 | 41 |
|
40 | 42 | const discardChanges = () => {
|
| 43 | + saved = false; |
41 | 44 | changes = [];
|
42 | 45 | Secret.fetch();
|
43 | 46 | };
|
44 | 47 |
|
45 | 48 | const updateSecretMutation = graphql(`
|
46 |
| - mutation updateSecret( |
47 |
| - $name: String! |
48 |
| - $team: Slug! |
49 |
| - $env: String! |
50 |
| - $data: [VariableInput!]! |
51 |
| - ) { |
| 49 | + mutation updateSecret($name: String!, $team: Slug!, $env: String!, $data: [VariableInput!]!) { |
52 | 50 | updateSecret(name: $name, team: $team, env: $env, data: $data) {
|
53 | 51 | id
|
54 | 52 | data {
|
|
64 | 62 | }
|
65 | 63 | `);
|
66 | 64 | const updateSecret = async () => {
|
| 65 | + saved = false; |
67 | 66 | if (!secret || changes.length == 0) return;
|
68 | 67 |
|
69 | 68 | let data: VariableInput[] = changes.reduce(mergeChanges, secret.data);
|
|
80 | 79 | }
|
81 | 80 |
|
82 | 81 | changes = [];
|
| 82 | + saved = true; |
83 | 83 | };
|
84 | 84 |
|
85 | 85 | const deleteSecretMutation = graphql(`
|
|
105 | 105 | const openDeleteSecretModal = () => {
|
106 | 106 | deleteSecretOpen = true;
|
107 | 107 | };
|
| 108 | +
|
| 109 | + const openDiscardChangesModal = () => { |
| 110 | + saved = false; |
| 111 | + if (changes.length === 0) return; |
| 112 | + discardChangesOpen = true; |
| 113 | + }; |
108 | 114 | </script>
|
109 | 115 |
|
110 | 116 | <svelte:head><title>{team} - Console</title></svelte:head>
|
|
125 | 131 | {:else if $Secret.fetching}
|
126 | 132 | <Loader />
|
127 | 133 | {:else if secret}
|
| 134 | + <div class="alerts"> |
| 135 | + {#if saved && changes.length === 0} |
| 136 | + <Alert variant="success" size="small">Changes saved!</Alert> |
| 137 | + {/if} |
| 138 | + {#if $updateSecretMutation.errors} |
| 139 | + <Alert variant="error"> |
| 140 | + {#each $updateSecretMutation.errors as error} |
| 141 | + {error.message} |
| 142 | + {/each} |
| 143 | + </Alert> |
| 144 | + {:else if $deleteSecretMutation.errors} |
| 145 | + <Alert variant="error"> |
| 146 | + {#each $deleteSecretMutation.errors as error} |
| 147 | + {error.message} |
| 148 | + {/each} |
| 149 | + </Alert> |
| 150 | + {/if} |
| 151 | + </div> |
| 152 | + <Confirm |
| 153 | + confirmText="Delete" |
| 154 | + variant="danger" |
| 155 | + bind:open={deleteSecretOpen} |
| 156 | + on:confirm={deleteSecret} |
| 157 | + > |
| 158 | + <svelte:fragment slot="header"> |
| 159 | + <Heading>Delete secret</Heading> |
| 160 | + </svelte:fragment> |
| 161 | + <p> |
| 162 | + This will permanently delete the secret named <b>{secret.name}</b> from <b>{env}</b>. |
| 163 | + </p> |
| 164 | + |
| 165 | + Are you sure you want to delete this secret? |
| 166 | + </Confirm> |
| 167 | + <Confirm |
| 168 | + confirmText="Reset" |
| 169 | + variant="danger" |
| 170 | + bind:open={discardChangesOpen} |
| 171 | + on:confirm={discardChanges} |
| 172 | + > |
| 173 | + <svelte:fragment slot="header"> |
| 174 | + <Heading>Reset all changes</Heading> |
| 175 | + </svelte:fragment> |
| 176 | + <p>You have unsaved changes which will be lost on reset.</p> |
| 177 | + |
| 178 | + Are you sure you want to reset? |
| 179 | + </Confirm> |
128 | 180 | <div class="grid">
|
129 | 181 | <Card columns={8} rows={3}>
|
130 | 182 | <div class="header">
|
131 | 183 | <h4>
|
132 | 184 | Secret Data
|
133 | 185 | <HelpText title="Secret data" placement="right">
|
134 |
| - A secret contains a set of key-value pairs.<br /> |
135 |
| - <br /> |
136 |
| - Changes are not persisted until the "Save" button is clicked.<br /> |
137 |
| - Applications using the secret will automatically restart to pick up any changes. |
138 |
| - <br /> |
| 186 | + A secret contains a set of key-value pairs. |
139 | 187 | </HelpText>
|
140 | 188 | </h4>
|
141 | 189 | <Tooltip content="Delete secret from environment" arrow={false}>
|
|
148 | 196 | Delete
|
149 | 197 | </Button>
|
150 | 198 | </Tooltip>
|
151 |
| - <Confirm |
152 |
| - confirmText="Delete" |
153 |
| - variant="danger" |
154 |
| - bind:open={deleteSecretOpen} |
155 |
| - on:confirm={deleteSecret} |
156 |
| - > |
157 |
| - <svelte:fragment slot="header"> |
158 |
| - <Heading>Delete secret</Heading> |
159 |
| - </svelte:fragment> |
160 |
| - <p> |
161 |
| - This will permanently delete the secret named <b>{secret.name}</b> from <b>{env}</b>. |
162 |
| - </p> |
163 |
| - |
164 |
| - Are you sure you want to delete this secret? |
165 |
| - </Confirm> |
166 | 199 | </div>
|
167 | 200 | <Table size="small" style="margin-top: 2rem">
|
168 | 201 | <Tbody>
|
|
183 | 216 | </div>
|
184 | 217 | <div class="secret-edit-buttons">
|
185 | 218 | <Tooltip content="Discard all changes" arrow={false}>
|
186 |
| - <Button variant="secondary" size="small" on:click={discardChanges}>Cancel</Button> |
| 219 | + <Button variant="secondary" size="small" on:click={openDiscardChangesModal} |
| 220 | + >Reset</Button |
| 221 | + > |
187 | 222 | </Tooltip>
|
188 | 223 | <Tooltip content="Persist all changes" arrow={false}>
|
189 |
| - <Button variant="primary" size="small" on:click={updateSecret}>Save</Button> |
| 224 | + <Button |
| 225 | + variant="primary" |
| 226 | + size="small" |
| 227 | + on:click={updateSecret} |
| 228 | + loading={$updateSecretMutation.fetching}>Save</Button |
| 229 | + > |
190 | 230 | </Tooltip>
|
| 231 | + <HelpText title="Save changes" placement="top"> |
| 232 | + Changes are not persisted until the "Save" button is clicked. |
| 233 | + </HelpText> |
191 | 234 | </div>
|
192 |
| - {#if $updateSecretMutation.errors} |
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> |
205 |
| - {/if} |
206 | 235 | </div>
|
207 | 236 | </Tbody>
|
208 | 237 | </Table>
|
|
252 | 281 | <h4>
|
253 | 282 | Use secret in workload
|
254 | 283 | <HelpText title="How to use this secret in a workload" placement="bottom">
|
255 |
| - To use this secret in your workload, you will need to reference it in your |
256 |
| - workload's manifest.<br /> |
257 |
| - <br /> |
258 |
| - The snippet below injects the secret into your workload. Each key-value pair is then available |
259 |
| - as environment variables. |
| 284 | + Reference the secret in your workload manifest with the snippet below. |
260 | 285 | </HelpText>
|
261 | 286 | </h4>
|
262 | 287 | <pre class="manifest">{workloadManifest(secretName)}</pre>
|
|
313 | 338 | margin-bottom: 1rem;
|
314 | 339 | }
|
315 | 340 |
|
| 341 | + .alerts { |
| 342 | + margin-bottom: 1rem; |
| 343 | + } |
| 344 | +
|
316 | 345 | .secret-content {
|
317 | 346 | padding: 8px;
|
318 | 347 | }
|
319 | 348 |
|
320 | 349 | .secret-edit-buttons {
|
| 350 | + display: flex; |
321 | 351 | margin: 32px 0 0 16px;
|
322 | 352 | padding: 32px 0;
|
323 | 353 | }
|
|
0 commit comments