Skip to content
Snippets Groups Projects

Resolve "Add UI for parameter translation layer"

Merged Daniel Göbel requested to merge feature/105-add-ui-for-parameter-translation-layer into main
4 files
+ 108
17
Compare changes
  • Side-by-side
  • Inline
Files
4
<script setup lang="ts">
<script setup lang="ts">
import { computed, type PropType, reactive, watch } from "vue";
import { computed, onMounted, type PropType, reactive, watch } from "vue";
import { useS3ObjectStore } from "@/stores/s3objects";
import { useS3ObjectStore } from "@/stores/s3objects";
import { useBucketStore } from "@/stores/buckets";
import { useBucketStore } from "@/stores/buckets";
import type { SizeModifierType } from "@/types/PropTypes";
import type { SizeModifierType } from "@/types/PropTypes";
const model = defineModel<string | undefined>({ required: true });
const model = defineModel<string | undefined>({ required: true });
 
const s3Regex = /s3:\/\/(\S*)\/(\S*)/g;
const props = defineProps({
const props = defineProps({
parameter: {
parameter: {
@@ -50,6 +51,33 @@ const inputDynamicClass = computed<string[]>(() => {
@@ -50,6 +51,33 @@ const inputDynamicClass = computed<string[]>(() => {
return cssClasses;
return cssClasses;
});
});
 
watch(model, (newVal, oldVal) => {
 
if (
 
newVal != oldVal &&
 
newVal !== translateToModel(s3Path.bucket, s3Path.key)
 
) {
 
parseModel(newVal);
 
}
 
});
 
 
function parseModel(val?: string) {
 
if (val == undefined) {
 
s3Path.bucket = "";
 
s3Path.key = undefined;
 
return;
 
}
 
const match = s3Regex.exec(val ?? "");
 
if (match) {
 
s3Path.bucket = match[1];
 
s3Path.key = match[2];
 
if (bucketRepository.bucketMapping[s3Path.bucket] == undefined) {
 
console.log("Missing bucket");
 
}
 
} else {
 
console.log("Not S3 Path");
 
}
 
}
 
const s3Path = reactive<{
const s3Path = reactive<{
bucket: string;
bucket: string;
key?: string;
key?: string;
@@ -104,23 +132,27 @@ watch(
@@ -104,23 +132,27 @@ watch(
() => s3Path.key,
() => s3Path.key,
(newVal, oldVal) => {
(newVal, oldVal) => {
if (newVal !== oldVal) {
if (newVal !== oldVal) {
updateModel(s3Path.bucket, newVal);
model.value = translateToModel(s3Path.bucket, newVal);
}
}
},
},
);
);
function updateBucket(bucket: string) {
function updateBucket(bucket: string) {
s3Path.bucket = bucket;
s3Path.bucket = bucket;
updateModel(bucket, s3Path.key);
model.value = translateToModel(bucket, s3Path.key);
s3ObjectRepository.fetchS3Objects(
s3ObjectRepository.fetchS3Objects(
bucket,
bucket,
bucketRepository.ownPermissions[bucket]?.file_prefix ?? undefined,
bucketRepository.ownPermissions[bucket]?.file_prefix ?? undefined,
);
);
}
}
function updateModel(bucket: string, key?: string) {
function translateToModel(bucket: string, key?: string): string | undefined {
model.value = !bucket ? undefined : `s3://${bucket}${key ? "/" + key : ""}`;
return !bucket ? undefined : `s3://${bucket}${key ? "/" + key : ""}`;
}
}
 
 
onMounted(() => {
 
parseModel(model.value);
 
});
</script>
</script>
<template>
<template>
Loading