Skip to content

Commit 1aa7c8a

Browse files
Devesh0129Logende
andauthored
Add DateProperty and EmailProperty components (#961)
* Files added * apply formatting changes * Date and email property components * EmailProperty.vue Removed * simplify code * apply formatting changes --------- Co-authored-by: Devesh0129 <Devesh0129@users.noreply.github.com> Co-authored-by: Felix Neubauer <felix@neuby.de> Co-authored-by: Logende <Logende@users.noreply.github.com> Co-authored-by: Felix Neubauer <33369081+Logende@users.noreply.github.com>
1 parent 9e72ad4 commit 1aa7c8a

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!-- Date picker for string properties with date format -->
2+
<script setup lang="ts">
3+
import {ref, watch} from 'vue';
4+
import DatePicker from 'primevue/datepicker';
5+
import type {JsonSchemaWrapper} from '@/schema/jsonSchemaWrapper';
6+
import type {PathElement} from '@/utility/path';
7+
import type {ValidationResult} from '@/schema/validationService';
8+
import {isReadOnly} from '@/components/panels/gui-editor/configTreeNodeReadingUtils';
9+
10+
const props = defineProps<{
11+
propertyName: PathElement;
12+
propertyData: string | undefined;
13+
propertySchema: JsonSchemaWrapper;
14+
validationResults: ValidationResult;
15+
}>();
16+
17+
const emit = defineEmits<{
18+
(e: 'update:propertyData', newValue: string | undefined): void;
19+
}>();
20+
21+
// convert string to Date for the picker
22+
const dateValue = ref<Date | undefined>(
23+
props.propertyData ? new Date(props.propertyData) : undefined
24+
);
25+
26+
watch(
27+
() => props.propertyData,
28+
newVal => {
29+
dateValue.value = newVal ? new Date(newVal) : undefined;
30+
}
31+
);
32+
33+
function updateValue(newDate: Date | undefined) {
34+
if (!newDate) {
35+
emit('update:propertyData', undefined);
36+
return;
37+
}
38+
// convert Date back to ISO date string (YYYY-MM-DD)
39+
const isoString = newDate.toISOString().split('T')[0];
40+
emit('update:propertyData', isoString);
41+
}
42+
</script>
43+
44+
<template>
45+
<DatePicker
46+
:class="{'underline decoration-wavy decoration-red-600': !props.validationResults.valid}"
47+
class="h-8"
48+
v-model="dateValue"
49+
dateFormat="yy-mm-dd"
50+
:disabled="isReadOnly(props.propertySchema)"
51+
@update:modelValue="updateValue" />
52+
</template>

meta_configurator/src/components/panels/gui-editor/resolveCorrespondingComponent.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import StringProperty from '@/components/panels/gui-editor/properties/StringProp
44
import NumberProperty from '@/components/panels/gui-editor/properties/NumberProperty.vue';
55
import SimpleObjectProperty from '@/components/panels/gui-editor/properties/SimpleObjectProperty.vue';
66
import SimpleArrayProperty from '@/components/panels/gui-editor/properties/SimpleArrayProperty.vue';
7+
import DateProperty from '@/components/panels/gui-editor/properties/DateProperty.vue';
78
import type {
89
AddItemTreeNodeData,
910
ConfigTreeNodeData,
@@ -75,6 +76,20 @@ export function resolveCorrespondingComponent(
7576
...propsObject,
7677
});
7778
}
79+
if (nodeData.schema.hasType('string') && nodeData.schema.format === 'date') {
80+
// @ts-ignore
81+
return h(DateProperty, propsObject);
82+
}
83+
84+
if (nodeData.schema.hasType('string') && nodeData.schema.format === 'email') {
85+
if (!nodeData.schema.examples || nodeData.schema.examples.length === 0) {
86+
// if there is no example e-mail provided, add one directly to the schema
87+
const underlyingSchema = nodeData.schema.jsonSchema;
88+
if (underlyingSchema) {
89+
underlyingSchema.examples = ['example@email.com'];
90+
}
91+
}
92+
}
7893

7994
if (nodeData.schema.hasType('string')) {
8095
// @ts-ignore

0 commit comments

Comments
 (0)