From 580cb976a6b07c110847c7ea8ed207d98339dc62 Mon Sep 17 00:00:00 2001 From: andreashimin Date: Fri, 10 May 2024 16:24:52 +0800 Subject: [PATCH] feat(wren-ui): integrate preview to model metadata drawer --- .../apollo/client/graphql/model.generated.ts | 40 ++++++++++++++++- wren-ui/src/apollo/client/graphql/model.ts | 6 +++ .../pages/modeling/metadata/ModelMetadata.tsx | 45 ++++++++++++++----- .../pages/modeling/metadata/ViewMetadata.tsx | 19 +++----- 4 files changed, 86 insertions(+), 24 deletions(-) diff --git a/wren-ui/src/apollo/client/graphql/model.generated.ts b/wren-ui/src/apollo/client/graphql/model.generated.ts index f5f4689ef..2db21774f 100644 --- a/wren-ui/src/apollo/client/graphql/model.generated.ts +++ b/wren-ui/src/apollo/client/graphql/model.generated.ts @@ -43,6 +43,13 @@ export type DeleteModelMutationVariables = Types.Exact<{ export type DeleteModelMutation = { __typename?: 'Mutation', deleteModel: boolean }; +export type PreviewModelDataMutationVariables = Types.Exact<{ + where: Types.WhereIdInput; +}>; + + +export type PreviewModelDataMutation = { __typename?: 'Mutation', previewModelData: any }; + export const CommonColumnFragmentDoc = gql` fragment CommonColumn on DetailedColumn { displayName @@ -271,4 +278,35 @@ export function useDeleteModelMutation(baseOptions?: Apollo.MutationHookOptions< } export type DeleteModelMutationHookResult = ReturnType; export type DeleteModelMutationResult = Apollo.MutationResult; -export type DeleteModelMutationOptions = Apollo.BaseMutationOptions; \ No newline at end of file +export type DeleteModelMutationOptions = Apollo.BaseMutationOptions; +export const PreviewModelDataDocument = gql` + mutation PreviewModelData($where: WhereIdInput!) { + previewModelData(where: $where) +} + `; +export type PreviewModelDataMutationFn = Apollo.MutationFunction; + +/** + * __usePreviewModelDataMutation__ + * + * To run a mutation, you first call `usePreviewModelDataMutation` within a React component and pass it any options that fit your needs. + * When your component renders, `usePreviewModelDataMutation` returns a tuple that includes: + * - A mutate function that you can call at any time to execute the mutation + * - An object with fields that represent the current status of the mutation's execution + * + * @param baseOptions options that will be passed into the mutation, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options-2; + * + * @example + * const [previewModelDataMutation, { data, loading, error }] = usePreviewModelDataMutation({ + * variables: { + * where: // value for 'where' + * }, + * }); + */ +export function usePreviewModelDataMutation(baseOptions?: Apollo.MutationHookOptions) { + const options = {...defaultOptions, ...baseOptions} + return Apollo.useMutation(PreviewModelDataDocument, options); + } +export type PreviewModelDataMutationHookResult = ReturnType; +export type PreviewModelDataMutationResult = Apollo.MutationResult; +export type PreviewModelDataMutationOptions = Apollo.BaseMutationOptions; \ No newline at end of file diff --git a/wren-ui/src/apollo/client/graphql/model.ts b/wren-ui/src/apollo/client/graphql/model.ts index 2a9fd3636..5ba002ed6 100644 --- a/wren-ui/src/apollo/client/graphql/model.ts +++ b/wren-ui/src/apollo/client/graphql/model.ts @@ -104,3 +104,9 @@ export const DELETE_MODEL = gql` deleteModel(where: $where) } `; + +export const PREVIEW_MODEL_DATA = gql` + mutation PreviewModelData($where: WhereIdInput!) { + previewModelData(where: $where) + } +`; diff --git a/wren-ui/src/components/pages/modeling/metadata/ModelMetadata.tsx b/wren-ui/src/components/pages/modeling/metadata/ModelMetadata.tsx index e50b29edc..ed271d8a4 100644 --- a/wren-ui/src/components/pages/modeling/metadata/ModelMetadata.tsx +++ b/wren-ui/src/components/pages/modeling/metadata/ModelMetadata.tsx @@ -1,21 +1,16 @@ -import { Col, Row, Typography } from 'antd'; +import { Col, Row, Typography, Button } from 'antd'; import FieldTable from '@/components/table/FieldTable'; import CalculatedFieldTable from '@/components/table/CalculatedFieldTable'; import RelationTable from '@/components/table/RelationTable'; +import PreviewData from '@/components/dataPreview/PreviewData'; +import { DiagramModel } from '@/utils/data'; +import { usePreviewModelDataMutation } from '@/apollo/client/graphql/model.generated'; -export interface Props { - displayName: string; - referenceName: string; - sourceTableName: string; - fields: any[]; - calculatedFields: any[]; - relationFields: any[]; - description: string; - properties: Record; -} +export type Props = DiagramModel; export default function ModelMetadata(props: Props) { const { + modelId, displayName, referenceName, fields = [], @@ -24,6 +19,15 @@ export default function ModelMetadata(props: Props) { description, } = props || {}; + const [previewModelData, previewModelDataResult] = + usePreviewModelDataMutation({ + onError: (error) => console.error(error), + }); + + const onPreviewData = () => { + previewModelData({ variables: { where: { id: modelId } } }); + }; + return ( <> @@ -71,6 +75,25 @@ export default function ModelMetadata(props: Props) { )} + +
+ + Data preview (100 rows) + + +
+ +
+
); } diff --git a/wren-ui/src/components/pages/modeling/metadata/ViewMetadata.tsx b/wren-ui/src/components/pages/modeling/metadata/ViewMetadata.tsx index c27b4f669..222dee779 100644 --- a/wren-ui/src/components/pages/modeling/metadata/ViewMetadata.tsx +++ b/wren-ui/src/components/pages/modeling/metadata/ViewMetadata.tsx @@ -17,15 +17,12 @@ export default function ViewMetadata(props: Props) { viewId, } = props || {}; - const [previewViewDataMutation, previewViewDataResult] = - usePreviewViewDataMutation({ - onError: (error) => console.error(error), - }); + const [previewViewData, previewViewDataResult] = usePreviewViewDataMutation({ + onError: (error) => console.error(error), + }); const onPreviewData = () => { - previewViewDataMutation({ - variables: { where: { id: viewId } }, - }); + previewViewData({ variables: { where: { id: viewId } } }); }; // View only can input Name (alias), so it should show alias as Name in metadata. @@ -70,11 +67,9 @@ export default function ViewMetadata(props: Props) {