Skip to content

Commit

Permalink
Adding hardcoded object based on generated schema from db
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelandert committed Jul 31, 2024
1 parent fb38420 commit c6fa675
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
1 change: 0 additions & 1 deletion apps/app/src/lib/components/HominioDB.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@
</div>
<Properties
properties={selectedItem.json.properties}
required={selectedItem.json.required || []}
{expandedProperties}
on:toggleProperty={handleToggleProperty}
/>
Expand Down
18 changes: 6 additions & 12 deletions apps/app/src/lib/components/Properties.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const dispatch = createEventDispatcher();
export let properties: any;
export let required: string[] = [];
export let path: string[] = [];
export let expandedProperties: string[] = [];
Expand All @@ -18,12 +17,11 @@
return expandedProperties.includes(propertyPath);
}
function renderProperties(properties: any, required: string[] = [], path: string[] = []) {
function renderProperties(properties: any, path: string[] = []) {
return Object.entries(properties).map(([key, value]) => ({
key,
value,
isObj: typeof value === 'object' && value !== null && value.type === 'object',
isRequired: required.includes(key),
isObj: typeof value === 'object' && value !== null,
path: [...path, key].join('.')
}));
}
Expand All @@ -33,7 +31,7 @@
$: {
console.log('Properties: Rendered properties changed', properties);
console.log('Properties: Current expandedProperties', expandedProperties);
renderedProperties = renderProperties(properties, required, path);
renderedProperties = renderProperties(properties, path);
}
</script>

Expand All @@ -43,14 +41,11 @@
<div class="flex flex-col mb-2">
<div class="flex items-center">
<span class="px-1 text-white rounded-sm text-2xs bg-surface-700 dark:bg-surface-600">
{prop.isObj ? 'object' : prop.value.type}
{typeof prop.value}
</span>
<span class="ml-1 text-sm font-semibold truncate text-surface-700 dark:text-surface-300">
{prop.key}
</span>
{#if prop.isRequired}
<span class="px-1 ml-1 text-red-500 border border-red-500 rounded text-2xs">*</span>
{/if}
{#if prop.isObj}
<button
class="ml-1 text-xs text-blue-500 hover:text-blue-600 dark:text-blue-400 dark:hover:text-blue-300"
Expand All @@ -61,16 +56,15 @@
{/if}
</div>
<span class="text-xs truncate text-surface-600 dark:text-surface-400">
{prop.value.description}
{prop.isObj ? '' : JSON.stringify(prop.value)}
</span>
</div>
{/each}
</div>
{#each renderedProperties as prop (prop.path)}
{#if prop.isObj && isExpanded(prop.path)}
<svelte:self
properties={prop.value.properties}
required={prop.value.required || []}
properties={prop.value}
path={prop.path.split('.')}
{expandedProperties}
on:toggleProperty
Expand Down

0 comments on commit c6fa675

Please sign in to comment.