-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
404 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
<script setup lang="ts"> | ||
import { ref } from 'vue'; | ||
import { Button } from '@/components/ui/button'; | ||
import { Share, AlertCircle, Copy, Check } from 'lucide-vue-next'; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from '@/components/ui/dialog'; | ||
import { Alert, AlertDescription } from '@/components/ui/alert'; | ||
import { useToast } from '@/components/ui/toast'; | ||
const props = defineProps<{ | ||
resources: any[]; | ||
onShare?: () => void; | ||
}>(); | ||
const { toast } = useToast(); | ||
const showDialog = ref(false); | ||
const copied = ref(false); | ||
const shareUrl = ref<string>(''); | ||
const urlTooLong = ref(false); | ||
// Import these from your sharing utilities | ||
import { encodeResources, checkUrlLength } from '@/lib/sharing'; | ||
const generateShareUrl = () => { | ||
try { | ||
console.debug('Generating share URL...'); | ||
const encoded = encodeResources(props.resources); | ||
const baseUrl = `${window.location.origin}${window.location.pathname}`; | ||
const { valid } = checkUrlLength(baseUrl, encoded); | ||
urlTooLong.value = !valid; | ||
shareUrl.value = valid ? `${baseUrl}?resources=${encoded}` : ''; | ||
return valid; | ||
} catch (err) { | ||
console.error('Failed to generate share URL:', err); | ||
return false; | ||
} | ||
}; | ||
const copyToClipboard = async () => { | ||
if (!shareUrl.value) return; | ||
try { | ||
await navigator.clipboard.writeText(shareUrl.value); | ||
copied.value = true; | ||
setTimeout(() => { | ||
copied.value = false; | ||
}, 2000); | ||
toast({ | ||
description: "Share URL copied to clipboard!", | ||
}); | ||
showDialog.value = false; | ||
} catch (err) { | ||
toast({ | ||
variant: "destructive", | ||
description: "Failed to copy URL. Please try again.", | ||
}); | ||
} | ||
}; | ||
// Generate URL when dialog opens | ||
const handleDialogOpen = () => { | ||
console.debug('Dialog opened'); | ||
generateShareUrl(); | ||
}; | ||
</script> | ||
|
||
<template> | ||
<Dialog v-model:open="showDialog" @update:open="handleDialogOpen"> | ||
<DialogTrigger asChild> | ||
<Button | ||
variant="outline" | ||
size="sm" | ||
class="gap-1.5 text-sm" | ||
:disabled="resources.length === 0" | ||
> | ||
<Share class="size-3.5" /> | ||
Share | ||
</Button> | ||
</DialogTrigger> | ||
|
||
<DialogContent class="sm:max-w-md"> | ||
<DialogHeader> | ||
<DialogTitle>Share Project</DialogTitle> | ||
<DialogDescription> | ||
Share your Kubernetes resources with others using this URL | ||
</DialogDescription> | ||
</DialogHeader> | ||
|
||
<div class="flex items-center space-x-2"> | ||
<div v-if="urlTooLong" class="flex-1"> | ||
<Alert variant="destructive"> | ||
<AlertCircle class="size-4" /> | ||
<AlertDescription> | ||
Project is too large to share via URL. Try reducing the number of resources. | ||
</AlertDescription> | ||
</Alert> | ||
</div> | ||
<div v-else-if="shareUrl" class="grid flex-1 gap-4"> | ||
<div class="flex items-center"> | ||
<input | ||
class="flex-1 truncate rounded-md border px-3 py-2 text-sm" | ||
:value="shareUrl" | ||
readonly | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<DialogFooter className="sm:justify-start"> | ||
<Button | ||
v-if="!urlTooLong && shareUrl" | ||
type="button" | ||
variant="secondary" | ||
size="sm" | ||
class="gap-1.5" | ||
@click="copyToClipboard" | ||
> | ||
<span v-if="!copied"> | ||
<Copy class="size-3.5" /> | ||
Copy URL | ||
</span> | ||
<span v-else> | ||
<Check class="size-3.5" /> | ||
Copied! | ||
</span> | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
</template> |
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,16 @@ | ||
<script setup lang="ts"> | ||
import type { HTMLAttributes } from 'vue' | ||
import { cn } from '@/lib/utils' | ||
import { type AlertVariants, alertVariants } from '.' | ||
const props = defineProps<{ | ||
class?: HTMLAttributes['class'] | ||
variant?: AlertVariants['variant'] | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<div :class="cn(alertVariants({ variant }), props.class)" role="alert"> | ||
<slot /> | ||
</div> | ||
</template> |
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,14 @@ | ||
<script setup lang="ts"> | ||
import type { HTMLAttributes } from 'vue' | ||
import { cn } from '@/lib/utils' | ||
const props = defineProps<{ | ||
class?: HTMLAttributes['class'] | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<div :class="cn('text-sm [&_p]:leading-relaxed', props.class)"> | ||
<slot /> | ||
</div> | ||
</template> |
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,14 @@ | ||
<script setup lang="ts"> | ||
import type { HTMLAttributes } from 'vue' | ||
import { cn } from '@/lib/utils' | ||
const props = defineProps<{ | ||
class?: HTMLAttributes['class'] | ||
}>() | ||
</script> | ||
|
||
<template> | ||
<h5 :class="cn('mb-1 font-medium leading-none tracking-tight', props.class)"> | ||
<slot /> | ||
</h5> | ||
</template> |
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,23 @@ | ||
import { cva, type VariantProps } from 'class-variance-authority' | ||
|
||
export { default as Alert } from './Alert.vue' | ||
export { default as AlertDescription } from './AlertDescription.vue' | ||
export { default as AlertTitle } from './AlertTitle.vue' | ||
|
||
export const alertVariants = cva( | ||
'relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground', | ||
{ | ||
variants: { | ||
variant: { | ||
default: 'bg-background text-foreground', | ||
destructive: | ||
'border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive', | ||
}, | ||
}, | ||
defaultVariants: { | ||
variant: 'default', | ||
}, | ||
}, | ||
) | ||
|
||
export type AlertVariants = VariantProps<typeof alertVariants> |
Oops, something went wrong.