Skip to content

Commit

Permalink
Fix schemas browser and remove type from metadata api again
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Oct 26, 2024
1 parent d92f801 commit 35b169d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 31 deletions.
8 changes: 4 additions & 4 deletions daiquiri/metadata/assets/js/components/Schemas.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const Schemas = ({ schemas, activeItem, setActiveItem, getTooltip, onDoubleClick

const handleClick = (type, item) => {
if (item != activeItem) {
setActiveItem(item)
setActiveItem({ type, ...item })
}
if (type == 'schema' && item != openSchema) {
setOpenSchema(item)
Expand Down Expand Up @@ -62,7 +62,7 @@ const Schemas = ({ schemas, activeItem, setActiveItem, getTooltip, onDoubleClick
{
visibleSchemas.map((schema, index) => (
<li key={index}>
<Tooltip tooltip={getTooltip(schema)}>
<Tooltip tooltip={getTooltip('schema', schema)}>
<button
className={classNames('btn btn-link d-flex', {'active': isActive('schema', schema)})}
onClick={() => handleClick('schema', schema)}
Expand All @@ -89,7 +89,7 @@ const Schemas = ({ schemas, activeItem, setActiveItem, getTooltip, onDoubleClick
{
visibleTables.map((table, index) => (
<li key={index}>
<Tooltip tooltip={getTooltip(table)}>
<Tooltip tooltip={getTooltip('table', table)}>
<button
className={classNames('btn btn-link d-flex', {'active': isActive('table', table)})}
onClick={() => handleClick('table', table)}
Expand All @@ -116,7 +116,7 @@ const Schemas = ({ schemas, activeItem, setActiveItem, getTooltip, onDoubleClick
{
visibleColumns.map((column, index) => (
<li key={index}>
<Tooltip tooltip={getTooltip(column)}>
<Tooltip tooltip={getTooltip('column', column)}>
<button
className={classNames('btn btn-link', {'active': isActive('column', column)})}
onClick={() => handleClick('column', column)}
Expand Down
8 changes: 4 additions & 4 deletions daiquiri/metadata/assets/js/hooks/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export const useMetadataQuery = ({ type, id }) => {
queryFn: () => {
switch (type) {
case 'schema':
return MetadataApi.fetchSchema(id)
return MetadataApi.fetchSchema(id).then(response => ({ type, ...response }))
case 'table':
return MetadataApi.fetchTable(id)
return MetadataApi.fetchTable(id).then(response => ({ type, ...response }))
case 'column':
return MetadataApi.fetchColumn(id)
return MetadataApi.fetchColumn(id).then(response => ({ type, ...response }))
case 'function':
return MetadataApi.fetchFunction(id)
return MetadataApi.fetchFunction(id).then(response => ({ type, ...response }))
}
},
placeholderData: keepPreviousData,
Expand Down
5 changes: 0 additions & 5 deletions daiquiri/metadata/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class Meta:

class FunctionSerializer(serializers.ModelSerializer):

type = serializers.CharField(default='function')
label = serializers.CharField(source='__str__', read_only=True)
admin_url = serializers.CharField(read_only=True)

Expand All @@ -29,7 +28,6 @@ class Meta:

class ColumnSerializer(serializers.ModelSerializer):

type = serializers.CharField(default='column')
label = serializers.CharField(source='__str__', read_only=True)
admin_url = serializers.CharField(read_only=True)

Expand All @@ -43,7 +41,6 @@ class Meta:
else:
fields = (
'id',
'type',
'label',
'order',
'name',
Expand All @@ -64,7 +61,6 @@ class Meta:

class TableSerializer(serializers.ModelSerializer):

type = serializers.CharField(default='table')
label = serializers.CharField(source='__str__', read_only=True)

related_identifiers = JSONListField(required=False)
Expand All @@ -80,7 +76,6 @@ class Meta:

class SchemaSerializer(serializers.ModelSerializer):

type = serializers.CharField(default='schema')
label = serializers.CharField(source='__str__', read_only=True)

related_identifiers = JSONListField(required=False)
Expand Down
18 changes: 4 additions & 14 deletions daiquiri/metadata/serializers/management.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,31 @@

class ColumnSerializer(serializers.ModelSerializer):

type = serializers.CharField(default='column')

class Meta:
model = Column
fields = ('id', 'type', 'name')
fields = ('id', 'name')


class TableSerializer(serializers.ModelSerializer):

type = serializers.CharField(default='table')

columns = ColumnSerializer(many=True, read_only=True)



class Meta:
model = Table
fields = ('id', 'type', 'name', 'columns')
fields = ('id', 'name', 'columns')


class SchemaSerializer(serializers.ModelSerializer):

type = serializers.CharField(default='schema')

tables = TableSerializer(many=True, read_only=True)

class Meta:
model = Schema
fields = ('id', 'type', 'name', 'tables')
fields = ('id', 'name', 'tables')


class FunctionSerializer(serializers.ModelSerializer):

type = serializers.CharField(default='function')

class Meta:
model = Function
fields = ('id', 'type', 'name')
fields = ('id', 'name')
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ const SchemasDropdown = ({ onDoubleClick }) => {

const [activeItem, setActiveItem] = useState(null)

const getTooltip = (item) => ({
title: item.description + isEmpty(item.unit) ? '' : `</br><b>Unit:</b> ${item.unit}`,
placement: 'left'
})
const getTooltip = (type, item) => {
return {
title: item.description + (isEmpty(item.unit) ? '' : `</br><b>Unit:</b> ${item.unit}`),
placement: 'left'
}
}

return !isUndefined(schemas) && !isUndefined(userSchema) && (
<div>
Expand Down

0 comments on commit 35b169d

Please sign in to comment.