Skip to content

Commit cff2166

Browse files
committed
WIP
1 parent 027eeab commit cff2166

File tree

4 files changed

+70
-20
lines changed

4 files changed

+70
-20
lines changed

DbViewer.TestApi/Controllers/DbViewerApiController.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public DbViewerApiController(SchemaRegistryProvider schemaRegistryProvider)
3232
[Route("{objectIdentifier}/count")]
3333
public Task<CountResult> CountObjects(string objectIdentifier, [FromBody] ObjectSearchRequest query) => impl.CountObjects(objectIdentifier, query, IsSuperUser());
3434

35-
[HttpGet]
36-
[Route("{objectIdentifier}/download/{queryString}")]
37-
public async Task<IActionResult> DownloadObjects(string objectIdentifier, string queryString)
35+
[HttpPost]
36+
[Route("{objectIdentifier}/download")]
37+
public async Task<IActionResult> DownloadObjects(string objectIdentifier, [FromForm] string data)
3838
{
39-
var fileInfo = await impl.DownloadObjects(objectIdentifier, queryString, IsSuperUser()).ConfigureAwait(false);
39+
var fileInfo = await impl.DownloadObjects(objectIdentifier, data, IsSuperUser()).ConfigureAwait(false);
4040
return File(fileInfo.Content, fileInfo.ContentType, fileInfo.Name);
4141
}
4242

DbViewer.TestApi/TypeScriptConfiguration/InternalApiTypeBuildingContext.cs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,7 @@ private static TypeScriptClassMemberDefinition BuildApiImplMember(IMethodInfo me
8181
Result = GetMethodResult(methodInfo, buildAndImportType),
8282
Body = {isUrlMethod ? GenerateGetUrlCall(methodInfo) : CreateCall(methodInfo)}
8383
};
84-
functionDefinition.Arguments.AddRange(
85-
methodInfo.GetParameters().Select(x => new TypeScriptArgumentDeclaration
86-
{
87-
Name = x.Name,
88-
Type = buildAndImportType(x.ParameterType)
89-
})
90-
);
84+
functionDefinition.Arguments.AddRange(GetArguments(methodInfo, buildAndImportType));
9185
return new TypeScriptClassMemberDefinition
9286
{
9387
Name = GetMethodName(methodInfo),
@@ -224,14 +218,21 @@ private static TypeScriptExpression GenerateConstructGetParams(IParameterInfo[]
224218
private static TypeScriptInterfaceFunctionMember BuildApiInterfaceMember(IMethodInfo methodInfo, Func<ITypeInfo, TypeScriptType> buildAndImportType)
225219
{
226220
var result = new TypeScriptInterfaceFunctionMember(GetMethodName(methodInfo), GetMethodResult(methodInfo, buildAndImportType));
227-
result.Arguments.AddRange(
228-
methodInfo.GetParameters().Select(x => new TypeScriptArgumentDeclaration
229-
{
230-
Name = x.Name,
231-
Type = buildAndImportType(x.ParameterType)
232-
})
233-
);
221+
result.Arguments.AddRange(GetArguments(methodInfo, buildAndImportType));
234222
return result;
235223
}
224+
225+
private static TypeScriptArgumentDeclaration[] GetArguments(IMethodInfo methodInfo, Func<ITypeInfo, TypeScriptType> buildAndImportType)
226+
{
227+
var isUrlMethod = IsUrlMethod(methodInfo);
228+
return methodInfo.GetParameters()
229+
.Where(x => !isUrlMethod || !x.ParameterType.GetAttributes(TypeInfo.From<FromFormAttribute>()).Any())
230+
.Select(x => new TypeScriptArgumentDeclaration
231+
{
232+
Name = x.Name,
233+
Type = buildAndImportType(x.ParameterType)
234+
})
235+
.ToArray();
236+
}
236237
}
237238
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import DownloadIcon from "@skbkontur/react-icons/Download";
2+
import { Button } from "@skbkontur/react-ui";
3+
import React from "react";
4+
5+
import { Condition } from "../../Domain/Api/DataTypes/Condition";
6+
import { Sort } from "../../Domain/Api/DataTypes/Sort";
7+
8+
import { Spinner } from "./Spinner";
9+
10+
interface DownloadButtonProps {
11+
action: string;
12+
conditions: Condition[];
13+
sorts: Sort[];
14+
hiddenColumns: string[];
15+
}
16+
17+
export function DownloadButton({ action, conditions, sorts, hiddenColumns }: DownloadButtonProps): JSX.Element {
18+
const [downloading, setDownloading] = React.useState(false);
19+
return (
20+
<form method="post" action={action} onSubmit={e => console.info(e)}>
21+
<input
22+
type="hidden"
23+
name="data"
24+
value={JSON.stringify({
25+
conditions: conditions,
26+
sorts: sorts,
27+
excludedFields: hiddenColumns,
28+
})}
29+
/>
30+
<Button
31+
icon={downloading ? <Spinner /> : <DownloadIcon />}
32+
disabled={downloading}
33+
data-tid="DownloadLink"
34+
use="link"
35+
type="submit">
36+
Выгрузить всё в Excel
37+
</Button>
38+
</form>
39+
);
40+
}

db-viewer-ui/src/Containers/ObjectTableContainer.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ColumnStack, Fit, RowStack } from "@skbkontur/react-stack-layout";
2-
import { Link, Loader, Paging } from "@skbkontur/react-ui";
2+
import { Button, Link, Loader, Paging } from "@skbkontur/react-ui";
33
import isEqual from "lodash/isEqual";
44
import qs from "qs";
55
import React from "react";
@@ -8,6 +8,7 @@ import { RouteComponentProps, withRouter } from "react-router";
88
import { ErrorHandlingContainer } from "../Components/ErrorHandling/ErrorHandlingContainer";
99
import { CommonLayout } from "../Components/Layouts/CommonLayout";
1010
import { ObjectTable } from "../Components/ObjectTable/ObjectTable";
11+
import { DownloadButton } from "../Components/ObjectTableLayoutHeader/DownloadButton";
1112
import { ObjectTableLayoutHeader } from "../Components/ObjectTableLayoutHeader/ObjectTableLayoutHeader";
1213
import { Condition } from "../Domain/Api/DataTypes/Condition";
1314
import { CountResult } from "../Domain/Api/DataTypes/CountResult";
@@ -99,7 +100,7 @@ class ObjectTableContainerInternal extends React.Component<ObjectTableProps, Obj
99100
loading,
100101
objects,
101102
metaInformation,
102-
query: { offset, count, sorts },
103+
query: { offset, count, sorts, conditions, hiddenColumns },
103104
downloading,
104105
showDownloadModal,
105106
downloadCount,
@@ -139,6 +140,14 @@ class ObjectTableContainerInternal extends React.Component<ObjectTableProps, Obj
139140
}
140141
/>
141142
<CommonLayout.Content>
143+
{metaInformation && (
144+
<DownloadButton
145+
action={this.props.dbViewerApi.getDownloadObjectsUrl(metaInformation.identifier, "")}
146+
conditions={conditions}
147+
sorts={sorts}
148+
hiddenColumns={hiddenColumns}
149+
/>
150+
)}
142151
<Loader type="big" active={loading}>
143152
<ColumnStack gap={4}>
144153
<Fit>

0 commit comments

Comments
 (0)