Skip to content

Commit

Permalink
feat(dbt): show source and compiled code in the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
hsheth2 committed Mar 12, 2024
1 parent 2a6ad21 commit a876291
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ private void mapViewProperties(@Nonnull Dataset dataset, @Nonnull DataMap dataMa
graphqlProperties.setMaterialized(properties.isMaterialized());
graphqlProperties.setLanguage(properties.getViewLanguage());
graphqlProperties.setLogic(properties.getViewLogic());
graphqlProperties.setFormattedLogic(properties.getFormattedViewLogic());
dataset.setViewProperties(graphqlProperties);
}

Expand Down
6 changes: 6 additions & 0 deletions datahub-graphql-core/src/main/resources/entity.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3186,6 +3186,12 @@ type ViewProperties {
"""
logic: String!

"""
A formatted version of the logic associated with the view.
For dbt, this contains the compiled SQL.
"""
formattedLogic: String

"""
The language in which the view logic is written, for example SQL
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Typography } from 'antd';
import React from 'react';
import { Radio, Typography } from 'antd';
import React, { useState } from 'react';
import styled from 'styled-components';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { GetDatasetQuery } from '../../../../../../graphql/dataset.generated';
Expand All @@ -23,9 +23,14 @@ const InfoItemContent = styled.div`
padding-top: 8px;
`;

const FormattingSelector = styled.div`
margin-top: 10px;
`;

const QueryText = styled(Typography.Paragraph)`
margin-top: 20px;
margin-top: 15px;
background-color: ${ANTD_GRAY[2]};
border-radius: 5px;
`;

// NOTE: Yes, using `!important` is a shame. However, the SyntaxHighlighter is applying styles directly
Expand All @@ -38,9 +43,15 @@ const NestedSyntax = styled(SyntaxHighlighter)`
export default function ViewDefinitionTab() {
const baseEntity = useBaseEntity<GetDatasetQuery>();
const logic = baseEntity?.dataset?.viewProperties?.logic || 'UNKNOWN';
const formattedLogic = baseEntity?.dataset?.viewProperties?.formattedLogic;
const materialized = (baseEntity?.dataset?.viewProperties?.materialized && true) || false;
const language = baseEntity?.dataset?.viewProperties?.language || 'UNKNOWN';

const isDbt = baseEntity?.dataset?.platform?.name?.toLowerCase() === 'dbt';
const canShowFormatted = formattedLogic && true;
const [showFormatted, setShowFormatted] = useState(false);
const formatOptions = isDbt ? ['Source', 'Compiled'] : ['Raw', 'Formatted'];

return (
<>
<InfoSection>
Expand All @@ -56,8 +67,21 @@ export default function ViewDefinitionTab() {
</InfoSection>
<InfoSection>
<Typography.Title level={5}>Logic</Typography.Title>
{canShowFormatted && (
<FormattingSelector>
<Radio.Group
options={[
{ label: formatOptions[0], value: false },
{ label: formatOptions[1], value: true },
]}
onChange={(e) => setShowFormatted(e.target.value)}
value={showFormatted}
optionType="button"
/>
</FormattingSelector>
)}
<QueryText>
<NestedSyntax language="sql">{logic}</NestedSyntax>
<NestedSyntax language="sql">{showFormatted ? formattedLogic : logic}</NestedSyntax>
</QueryText>
</InfoSection>
</>
Expand Down
1 change: 1 addition & 0 deletions datahub-web-react/src/graphql/dataset.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ fragment viewProperties on Dataset {
viewProperties {
materialized
logic
formattedLogic
language
}
}
Expand Down

0 comments on commit a876291

Please sign in to comment.