Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
fakefeik committed Jan 7, 2023
1 parent 027eeab commit cff2166
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 20 deletions.
8 changes: 4 additions & 4 deletions DbViewer.TestApi/Controllers/DbViewerApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public DbViewerApiController(SchemaRegistryProvider schemaRegistryProvider)
[Route("{objectIdentifier}/count")]
public Task<CountResult> CountObjects(string objectIdentifier, [FromBody] ObjectSearchRequest query) => impl.CountObjects(objectIdentifier, query, IsSuperUser());

[HttpGet]
[Route("{objectIdentifier}/download/{queryString}")]
public async Task<IActionResult> DownloadObjects(string objectIdentifier, string queryString)
[HttpPost]
[Route("{objectIdentifier}/download")]
public async Task<IActionResult> 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -224,14 +218,21 @@ private static TypeScriptExpression GenerateConstructGetParams(IParameterInfo[]
private static TypeScriptInterfaceFunctionMember BuildApiInterfaceMember(IMethodInfo methodInfo, Func<ITypeInfo, TypeScriptType> 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<ITypeInfo, TypeScriptType> buildAndImportType)
{
var isUrlMethod = IsUrlMethod(methodInfo);
return methodInfo.GetParameters()
.Where(x => !isUrlMethod || !x.ParameterType.GetAttributes(TypeInfo.From<FromFormAttribute>()).Any())
.Select(x => new TypeScriptArgumentDeclaration
{
Name = x.Name,
Type = buildAndImportType(x.ParameterType)
})
.ToArray();
}
}
}
Original file line number Diff line number Diff line change
@@ -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 (
<form method="post" action={action} onSubmit={e => console.info(e)}>
<input
type="hidden"
name="data"
value={JSON.stringify({
conditions: conditions,
sorts: sorts,
excludedFields: hiddenColumns,
})}
/>
<Button
icon={downloading ? <Spinner /> : <DownloadIcon />}
disabled={downloading}
data-tid="DownloadLink"
use="link"
type="submit">
Выгрузить всё в Excel
</Button>
</form>
);
}
13 changes: 11 additions & 2 deletions db-viewer-ui/src/Containers/ObjectTableContainer.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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";
Expand Down Expand Up @@ -99,7 +100,7 @@ class ObjectTableContainerInternal extends React.Component<ObjectTableProps, Obj
loading,
objects,
metaInformation,
query: { offset, count, sorts },
query: { offset, count, sorts, conditions, hiddenColumns },
downloading,
showDownloadModal,
downloadCount,
Expand Down Expand Up @@ -139,6 +140,14 @@ class ObjectTableContainerInternal extends React.Component<ObjectTableProps, Obj
}
/>
<CommonLayout.Content>
{metaInformation && (
<DownloadButton
action={this.props.dbViewerApi.getDownloadObjectsUrl(metaInformation.identifier, "")}
conditions={conditions}
sorts={sorts}
hiddenColumns={hiddenColumns}
/>
)}
<Loader type="big" active={loading}>
<ColumnStack gap={4}>
<Fit>
Expand Down

0 comments on commit cff2166

Please sign in to comment.