-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2288 from posit-dev/dotnomad/secrets-view
Add Secrets view and deploy with Secrets to extension
- Loading branch information
Showing
11 changed files
with
265 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
extensions/vscode/webviews/homeView/src/components/SidebarInput.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<template> | ||
<input | ||
v-model="model" | ||
ref="input" | ||
class="sidebar-input" | ||
:aria-label="ariaLabel" | ||
@keydown.prevent.enter="$emit('submit')" | ||
@keydown.escape="$emit('cancel')" | ||
/> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, ref } from "vue"; | ||
const model = defineModel(); | ||
const props = defineProps<{ | ||
label: string; | ||
}>(); | ||
defineEmits(["submit", "cancel"]); | ||
const input = ref<HTMLInputElement | null>(null); | ||
const ariaLabel = computed( | ||
() => `${props.label}. Press Enter to confirm or Escape to cancel.`, | ||
); | ||
const select = () => { | ||
input.value?.select(); | ||
}; | ||
defineExpose({ select }); | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.sidebar-input { | ||
background-color: var(--vscode-input-background); | ||
border: 1px solid var(--vscode-input-border, transparent); | ||
color: var(--vscode-input-foreground); | ||
line-height: 20px; | ||
padding: 0; | ||
outline-color: var(--vscode-focusBorder); | ||
outline-offset: -1px; | ||
outline-style: solid; | ||
outline-width: 1px; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
extensions/vscode/webviews/homeView/src/components/views/secrets/Secret.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<template> | ||
<TreeItem | ||
:title="name" | ||
:actions="actions" | ||
codicon="codicon-lock-small" | ||
:list-style="secretValue || isEditing ? 'default' : 'deemphasized'" | ||
:tooltip="tooltip" | ||
align-icon-with-twisty | ||
> | ||
<template #description> | ||
<SidebarInput | ||
v-if="isEditing" | ||
ref="input" | ||
v-model="inputValue" | ||
class="w-full" | ||
label="Type secret value" | ||
@submit="updateSecret" | ||
@cancel="isEditing = false" | ||
/> | ||
<template v-else-if="secretValue">••••••</template> | ||
</template> | ||
</TreeItem> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed, ref, nextTick } from "vue"; | ||
import TreeItem from "src/components/tree/TreeItem.vue"; | ||
import SidebarInput from "src/components/SidebarInput.vue"; | ||
import { useHomeStore } from "src/stores/home"; | ||
import { ActionButton } from "src/components/ActionToolbar.vue"; | ||
interface Props { | ||
name: string; | ||
} | ||
const props = defineProps<Props>(); | ||
const input = ref<InstanceType<typeof SidebarInput> | null>(null); | ||
const isEditing = ref(false); | ||
const inputValue = ref<string>(); | ||
const home = useHomeStore(); | ||
const secretValue = computed(() => home.secrets.get(props.name)); | ||
const inputSecret = () => { | ||
// Update inputValue in case the secret value has changed or been cleared | ||
inputValue.value = secretValue.value; | ||
isEditing.value = true; | ||
// Wait for next tick to ensure the input is rendered | ||
nextTick(() => input.value?.select()); | ||
}; | ||
const updateSecret = () => { | ||
home.secrets.set(props.name, inputValue.value); | ||
isEditing.value = false; | ||
}; | ||
const tooltip = computed(() => { | ||
if (secretValue.value) { | ||
return "On the next deploy the new value will be set for the deployment."; | ||
} | ||
return "No value has been set. The value will not change on the next deploy."; | ||
}); | ||
const actions = computed<ActionButton[]>(() => { | ||
// Show no actions while the value is being edited | ||
if (isEditing.value) { | ||
return []; | ||
} | ||
const result = [ | ||
{ | ||
label: "Edit Value", | ||
codicon: "codicon-pencil", | ||
fn: inputSecret, | ||
}, | ||
]; | ||
if (secretValue.value) { | ||
result.push({ | ||
label: "Clear Value", | ||
codicon: "codicon-remove", | ||
fn: () => { | ||
home.secrets.set(props.name, undefined); | ||
}, | ||
}); | ||
} | ||
return result; | ||
}); | ||
</script> |
38 changes: 38 additions & 0 deletions
38
extensions/vscode/webviews/homeView/src/components/views/secrets/Secrets.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<template> | ||
<TreeSection | ||
title="Secrets" | ||
:actions="sectionActions" | ||
:count="home.secretsWithValueCount" | ||
> | ||
<template v-if="home.secrets.size"> | ||
<Secret v-for="[name] in home.secrets" :name="name" :key="name" /> | ||
</template> | ||
<WelcomeView v-else> | ||
<p>No secrets have been added to the configuration.</p> | ||
</WelcomeView> | ||
</TreeSection> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { computed } from "vue"; | ||
import { ActionButton } from "src/components/ActionToolbar.vue"; | ||
import TreeSection from "src/components/tree/TreeSection.vue"; | ||
import WelcomeView from "src/components/WelcomeView.vue"; | ||
import { useHomeStore } from "src/stores/home"; | ||
import Secret from "src/components/views/secrets/Secret.vue"; | ||
const home = useHomeStore(); | ||
const sectionActions = computed<ActionButton[]>(() => [ | ||
{ | ||
label: "Clear Values for all Secrets", | ||
codicon: "codicon-clear-all", | ||
fn: () => { | ||
home.secrets.forEach((_, key) => { | ||
home.secrets.set(key, undefined); | ||
}); | ||
}, | ||
}, | ||
]); | ||
</script> |
Oops, something went wrong.