From cff2166f9a69eb2313ced10772e4f5a6d9e50651 Mon Sep 17 00:00:00 2001
From: Pavel Vostretsov
Date: Sun, 23 May 2021 15:38:29 +0500
Subject: [PATCH] WIP
---
.../Controllers/DbViewerApiController.cs | 8 ++--
.../InternalApiTypeBuildingContext.cs | 29 +++++++-------
.../DownloadButton.tsx | 40 +++++++++++++++++++
.../src/Containers/ObjectTableContainer.tsx | 13 +++++-
4 files changed, 70 insertions(+), 20 deletions(-)
create mode 100644 db-viewer-ui/src/Components/ObjectTableLayoutHeader/DownloadButton.tsx
diff --git a/DbViewer.TestApi/Controllers/DbViewerApiController.cs b/DbViewer.TestApi/Controllers/DbViewerApiController.cs
index 608fdc01..c1ba0131 100644
--- a/DbViewer.TestApi/Controllers/DbViewerApiController.cs
+++ b/DbViewer.TestApi/Controllers/DbViewerApiController.cs
@@ -32,11 +32,11 @@ public DbViewerApiController(SchemaRegistryProvider schemaRegistryProvider)
[Route("{objectIdentifier}/count")]
public Task CountObjects(string objectIdentifier, [FromBody] ObjectSearchRequest query) => impl.CountObjects(objectIdentifier, query, IsSuperUser());
- [HttpGet]
- [Route("{objectIdentifier}/download/{queryString}")]
- public async Task DownloadObjects(string objectIdentifier, string queryString)
+ [HttpPost]
+ [Route("{objectIdentifier}/download")]
+ public async Task DownloadObjects(string objectIdentifier, [FromForm] string data)
{
- var fileInfo = await impl.DownloadObjects(objectIdentifier, queryString, IsSuperUser()).ConfigureAwait(false);
+ var fileInfo = await impl.DownloadObjects(objectIdentifier, data, IsSuperUser()).ConfigureAwait(false);
return File(fileInfo.Content, fileInfo.ContentType, fileInfo.Name);
}
diff --git a/DbViewer.TestApi/TypeScriptConfiguration/InternalApiTypeBuildingContext.cs b/DbViewer.TestApi/TypeScriptConfiguration/InternalApiTypeBuildingContext.cs
index be97f708..6a652af7 100644
--- a/DbViewer.TestApi/TypeScriptConfiguration/InternalApiTypeBuildingContext.cs
+++ b/DbViewer.TestApi/TypeScriptConfiguration/InternalApiTypeBuildingContext.cs
@@ -81,13 +81,7 @@ private static TypeScriptClassMemberDefinition BuildApiImplMember(IMethodInfo me
Result = GetMethodResult(methodInfo, buildAndImportType),
Body = {isUrlMethod ? GenerateGetUrlCall(methodInfo) : CreateCall(methodInfo)}
};
- functionDefinition.Arguments.AddRange(
- methodInfo.GetParameters().Select(x => new TypeScriptArgumentDeclaration
- {
- Name = x.Name,
- Type = buildAndImportType(x.ParameterType)
- })
- );
+ functionDefinition.Arguments.AddRange(GetArguments(methodInfo, buildAndImportType));
return new TypeScriptClassMemberDefinition
{
Name = GetMethodName(methodInfo),
@@ -224,14 +218,21 @@ private static TypeScriptExpression GenerateConstructGetParams(IParameterInfo[]
private static TypeScriptInterfaceFunctionMember BuildApiInterfaceMember(IMethodInfo methodInfo, Func buildAndImportType)
{
var result = new TypeScriptInterfaceFunctionMember(GetMethodName(methodInfo), GetMethodResult(methodInfo, buildAndImportType));
- result.Arguments.AddRange(
- methodInfo.GetParameters().Select(x => new TypeScriptArgumentDeclaration
- {
- Name = x.Name,
- Type = buildAndImportType(x.ParameterType)
- })
- );
+ result.Arguments.AddRange(GetArguments(methodInfo, buildAndImportType));
return result;
}
+
+ private static TypeScriptArgumentDeclaration[] GetArguments(IMethodInfo methodInfo, Func buildAndImportType)
+ {
+ var isUrlMethod = IsUrlMethod(methodInfo);
+ return methodInfo.GetParameters()
+ .Where(x => !isUrlMethod || !x.ParameterType.GetAttributes(TypeInfo.From()).Any())
+ .Select(x => new TypeScriptArgumentDeclaration
+ {
+ Name = x.Name,
+ Type = buildAndImportType(x.ParameterType)
+ })
+ .ToArray();
+ }
}
}
\ No newline at end of file
diff --git a/db-viewer-ui/src/Components/ObjectTableLayoutHeader/DownloadButton.tsx b/db-viewer-ui/src/Components/ObjectTableLayoutHeader/DownloadButton.tsx
new file mode 100644
index 00000000..0a39e762
--- /dev/null
+++ b/db-viewer-ui/src/Components/ObjectTableLayoutHeader/DownloadButton.tsx
@@ -0,0 +1,40 @@
+import DownloadIcon from "@skbkontur/react-icons/Download";
+import { Button } from "@skbkontur/react-ui";
+import React from "react";
+
+import { Condition } from "../../Domain/Api/DataTypes/Condition";
+import { Sort } from "../../Domain/Api/DataTypes/Sort";
+
+import { Spinner } from "./Spinner";
+
+interface DownloadButtonProps {
+ action: string;
+ conditions: Condition[];
+ sorts: Sort[];
+ hiddenColumns: string[];
+}
+
+export function DownloadButton({ action, conditions, sorts, hiddenColumns }: DownloadButtonProps): JSX.Element {
+ const [downloading, setDownloading] = React.useState(false);
+ return (
+
+ );
+}
diff --git a/db-viewer-ui/src/Containers/ObjectTableContainer.tsx b/db-viewer-ui/src/Containers/ObjectTableContainer.tsx
index 29d29e5f..83b1a9de 100644
--- a/db-viewer-ui/src/Containers/ObjectTableContainer.tsx
+++ b/db-viewer-ui/src/Containers/ObjectTableContainer.tsx
@@ -1,5 +1,5 @@
import { ColumnStack, Fit, RowStack } from "@skbkontur/react-stack-layout";
-import { Link, Loader, Paging } from "@skbkontur/react-ui";
+import { Button, Link, Loader, Paging } from "@skbkontur/react-ui";
import isEqual from "lodash/isEqual";
import qs from "qs";
import React from "react";
@@ -8,6 +8,7 @@ import { RouteComponentProps, withRouter } from "react-router";
import { ErrorHandlingContainer } from "../Components/ErrorHandling/ErrorHandlingContainer";
import { CommonLayout } from "../Components/Layouts/CommonLayout";
import { ObjectTable } from "../Components/ObjectTable/ObjectTable";
+import { DownloadButton } from "../Components/ObjectTableLayoutHeader/DownloadButton";
import { ObjectTableLayoutHeader } from "../Components/ObjectTableLayoutHeader/ObjectTableLayoutHeader";
import { Condition } from "../Domain/Api/DataTypes/Condition";
import { CountResult } from "../Domain/Api/DataTypes/CountResult";
@@ -99,7 +100,7 @@ class ObjectTableContainerInternal extends React.Component
+ {metaInformation && (
+
+ )}