WIP - more progress with permissions
This commit is contained in:
@@ -12,6 +12,8 @@ import {
|
||||
CollapsibleTrigger,
|
||||
} from '@/components/ui/collapsible'
|
||||
|
||||
console.log('[EditView] COMPONENT MOUNTING')
|
||||
|
||||
interface Props {
|
||||
config: EditViewConfig
|
||||
data?: any
|
||||
@@ -25,6 +27,8 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
saving: false,
|
||||
})
|
||||
|
||||
console.log('[EditView] Props received on mount:', JSON.stringify(props, null, 2))
|
||||
|
||||
const emit = defineEmits<{
|
||||
'save': [data: any]
|
||||
'cancel': []
|
||||
@@ -35,10 +39,16 @@ const emit = defineEmits<{
|
||||
const formData = ref<Record<string, any>>({ ...props.data })
|
||||
const errors = ref<Record<string, string>>({})
|
||||
|
||||
console.log('[EditView] Initial props.data:', JSON.stringify(props.data, null, 2))
|
||||
console.log('[EditView] props.data.id:', props.data?.id)
|
||||
|
||||
// Watch for data changes (useful for edit mode)
|
||||
watch(() => props.data, (newData) => {
|
||||
console.log('[EditView] Data changed:', JSON.stringify(newData, null, 2))
|
||||
console.log('[EditView] newData.id:', newData?.id)
|
||||
console.log('[EditView] Keys in newData:', Object.keys(newData))
|
||||
formData.value = { ...newData }
|
||||
}, { deep: true })
|
||||
}, { deep: true, immediate: true })
|
||||
|
||||
// Organize fields into sections
|
||||
const sections = computed<FieldSection[]>(() => {
|
||||
@@ -137,7 +147,11 @@ const validateForm = (): boolean => {
|
||||
|
||||
const handleSave = () => {
|
||||
if (validateForm()) {
|
||||
emit('save', { ...formData.value })
|
||||
// Preserve id and other system fields from original data when saving
|
||||
emit('save', {
|
||||
id: props.data?.id, // Preserve the record ID for updates
|
||||
...formData.value
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,11 +45,16 @@ const errors = ref<Record<string, string>>({})
|
||||
|
||||
// Watch for data changes (useful for edit mode)
|
||||
watch(() => props.data, (newData) => {
|
||||
console.log('[EditViewEnhanced] Data changed:', newData)
|
||||
console.log('[EditViewEnhanced] Data has id?', newData?.id)
|
||||
formData.value = { ...newData }
|
||||
}, { deep: true })
|
||||
}, { deep: true, immediate: true })
|
||||
|
||||
// Fetch page layout if objectId is provided
|
||||
onMounted(async () => {
|
||||
console.log('[EditViewEnhanced] Component mounted')
|
||||
console.log('[EditViewEnhanced] Props:', props)
|
||||
|
||||
if (props.objectId) {
|
||||
try {
|
||||
loadingLayout.value = true
|
||||
@@ -159,13 +164,27 @@ const validateForm = (): boolean => {
|
||||
}
|
||||
|
||||
const handleSave = () => {
|
||||
console.log('[EditViewEnhanced] handleSave called')
|
||||
console.log('[EditViewEnhanced] props.data:', props.data)
|
||||
console.log('[EditViewEnhanced] props.data?.id:', props.data?.id)
|
||||
console.log('[EditViewEnhanced] formData before processing:', { ...formData.value })
|
||||
|
||||
if (validateForm()) {
|
||||
// Filter out system fields from save data
|
||||
// Preserve the id from props.data if it exists (needed for updates)
|
||||
// Filter out other system fields that are auto-managed
|
||||
const saveData = { ...formData.value }
|
||||
const systemFields = ['id', 'tenantId', 'ownerId', 'created_at', 'updated_at', 'createdAt', 'updatedAt', 'createdBy', 'updatedBy']
|
||||
for (const field of systemFields) {
|
||||
const systemFieldsToRemove = ['tenantId', 'ownerId', 'created_at', 'updated_at', 'createdAt', 'updatedAt', 'createdBy', 'updatedBy']
|
||||
for (const field of systemFieldsToRemove) {
|
||||
delete saveData[field]
|
||||
}
|
||||
|
||||
// Explicitly preserve id if it exists in the original data
|
||||
if (props.data?.id) {
|
||||
saveData.id = props.data.id
|
||||
console.log('[EditViewEnhanced] Preserved id from props:', saveData.id)
|
||||
}
|
||||
|
||||
console.log('[EditViewEnhanced] Final saveData:', saveData)
|
||||
emit('save', saveData)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ interface Props {
|
||||
loading?: boolean
|
||||
selectable?: boolean
|
||||
baseUrl?: string
|
||||
canCreate?: boolean
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
@@ -29,6 +30,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
loading: false,
|
||||
selectable: false,
|
||||
baseUrl: '/runtime/objects',
|
||||
canCreate: true,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -145,7 +147,7 @@ const handleAction = (actionId: string) => {
|
||||
</Button>
|
||||
|
||||
<!-- Create -->
|
||||
<Button size="sm" @click="emit('create')">
|
||||
<Button v-if="props.canCreate" size="sm" @click="emit('create')">
|
||||
<Plus class="h-4 w-4 mr-2" />
|
||||
New
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user