Skip to content

Commit

Permalink
Merge branch 'main' into features/2534_wellbore_uid_mapping
Browse files Browse the repository at this point in the history
# Conflicts:
#	Src/WitsmlExplorer.Frontend/components/ContextMenus/FluidContextMenu.tsx
#	Src/WitsmlExplorer.Frontend/components/ContextMenus/LogCurveInfoContextMenu.tsx
#	Src/WitsmlExplorer.Frontend/components/ContextMenus/LogsContextMenu.tsx
#	Src/WitsmlExplorer.Frontend/components/ContextMenus/ObjectMenuItems.tsx
#	Src/WitsmlExplorer.Frontend/components/ContextMenus/ObjectsSidebarContextMenu.tsx
#	Src/WitsmlExplorer.Frontend/components/ContextMenus/TrajectoryStationContextMenu.tsx
#	Src/WitsmlExplorer.Frontend/components/ContextMenus/TubularComponentContextMenu.tsx
#	Src/WitsmlExplorer.Frontend/components/ContextMenus/WbGeometrySectionContextMenu.tsx
#	Src/WitsmlExplorer.Frontend/components/ContextMenus/WellContextMenu.tsx
#	Src/WitsmlExplorer.Frontend/components/ContextMenus/WellboreContextMenu.tsx
  • Loading branch information
vaclavbasniar committed Nov 19, 2024
2 parents 5fb7d74 + 340b341 commit c9f5f9a
Show file tree
Hide file tree
Showing 61 changed files with 919 additions and 533 deletions.
23 changes: 23 additions & 0 deletions Src/WitsmlExplorer.Api/HttpHandlers/JobHandler.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -120,5 +121,27 @@ public static IResult GetReport(string jobId, IJobCache jobCache, HttpRequest ht
}
return TypedResults.Ok(job.Report);
}

[Produces("application/octet-stream")]
public static IResult DownloadFile(string jobId, IJobCache jobCache, HttpRequest httpRequest, IConfiguration configuration, ICredentialsService credentialsService)
{
EssentialHeaders eh = new(httpRequest);
bool useOAuth2 = StringHelpers.ToBoolean(configuration[ConfigConstants.OAuth2Enabled]);
string userName = useOAuth2 ? credentialsService.GetClaimFromToken(eh.GetBearerToken(), "upn") : eh.TargetUsername;
if (!useOAuth2)
{
credentialsService.VerifyUserIsLoggedIn(eh, ServerType.Target);
}
JobInfo job = jobCache.GetJobInfoById(jobId);
if (job.Username != userName && (!useOAuth2 || !IsAdminOrDeveloper(eh.GetBearerToken())))
{
return TypedResults.Forbid();
}
BaseReport report = job.Report;
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(report.FileData.FileContent);
var stream = new MemoryStream(byteArray);
httpRequest.HttpContext.Response.Headers["Access-Control-Expose-Headers"] = "Content-Disposition";
return TypedResults.File(stream, "application/octet-stream", report.FileData.FileName);
}
}
}
2 changes: 1 addition & 1 deletion Src/WitsmlExplorer.Api/Jobs/JobInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ReportType ReportType
{
return ReportType.None;
}
if (Report?.DownloadImmediately == true)
if (Report?.HasFile == true)
{
return ReportType.File;
}
Expand Down
1 change: 1 addition & 0 deletions Src/WitsmlExplorer.Api/Models/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public Connection(Server server)
CredentialIds = server.CredentialIds;
Id = server.Id;
DepthLogDecimals = server.DepthLogDecimals;
IsPriority = server.IsPriority;
}

[JsonPropertyName("usernames")]
Expand Down
13 changes: 10 additions & 3 deletions Src/WitsmlExplorer.Api/Models/Reports/BaseReport.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace WitsmlExplorer.Api.Models.Reports
{
Expand All @@ -8,9 +9,15 @@ public class BaseReport
public string Summary { get; init; }
public IEnumerable<object> ReportItems { get; init; }
public string WarningMessage { get; init; }
public bool DownloadImmediately { get; init; } = false;
public string ReportHeader { get; init; }
public bool HasFile { get; init; } = false;
public string JobDetails { get; init; }
public string ReportBody { get; init; }
[JsonIgnore]
public ReportFileData FileData { get; init; }
}

public class ReportFileData
{
public string FileName { get; init; }
public string FileContent { get; init; }
}
}
2 changes: 2 additions & 0 deletions Src/WitsmlExplorer.Api/Models/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public Server() : base(Guid.NewGuid())
public IList<string> CredentialIds { get; init; }
[JsonPropertyName("depthLogDecimals")]
public int DepthLogDecimals { get; init; }
[JsonPropertyName("isPriority")]
public bool IsPriority { get; init; }

public override string ToString()
{
Expand Down
1 change: 1 addition & 0 deletions Src/WitsmlExplorer.Api/Routes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public static void ConfigureApi(this WebApplication app, IConfiguration configur
app.MapGet("/jobs/alljobinfos", JobHandler.GetAllJobInfos, useOAuth2, AuthorizationPolicyRoles.ADMINORDEVELOPER);
app.MapPost("/jobs/cancel/{jobId}", JobHandler.CancelJob, useOAuth2);
app.MapGet("/jobs/report/{jobId}", JobHandler.GetReport, useOAuth2);
app.MapGet("/jobs/download/{jobId}", JobHandler.DownloadFile, useOAuth2);

app.MapGet("/credentials/authorize", AuthorizeHandler.Authorize, useOAuth2);
app.MapGet("/credentials/deauthorize", AuthorizeHandler.Deauthorize, useOAuth2);
Expand Down
24 changes: 15 additions & 9 deletions Src/WitsmlExplorer.Api/Workers/DownloadLogDataWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,33 @@ public DownloadLogDataWorker(
private (WorkerResult, RefreshAction) DownloadLogDataResult(DownloadLogDataJob job, ICollection<Dictionary<string, LogDataValue>> reportItems, ICollection<CurveSpecification> curveSpecifications)
{
Logger.LogInformation("Download of all data is done. {jobDescription}", job.Description());
var reportHeader = GetReportHeader(curveSpecifications);
var reportBody = GetReportBody(reportItems, curveSpecifications);
job.JobInfo.Report = DownloadLogDataReport(reportItems, job.LogReference, reportHeader, reportBody);
string content = GetCsvFileContent(reportItems, curveSpecifications);
job.JobInfo.Report = DownloadLogDataReport(job.LogReference, content, "csv");
WorkerResult workerResult = new(GetTargetWitsmlClientOrThrow().GetServerHostname(), true, $"Download of all data is ready, jobId: ", jobId: job.JobInfo.Id);
return (workerResult, null);
}

private DownloadLogDataReport DownloadLogDataReport(ICollection<Dictionary<string, LogDataValue>> reportItems, LogObject logReference, string reportHeader, string reportBody)
private DownloadLogDataReport DownloadLogDataReport(LogObject logReference, string fileContent, string fileExtension)
{
return new DownloadLogDataReport
{
Title = $"{logReference.WellboreName} - {logReference.Name}",
Summary = "You can download the report as csv file",
Summary = "The download will start automatically. You can also access the download link in the Jobs view.",
LogReference = logReference,
ReportItems = reportItems,
DownloadImmediately = true,
ReportHeader = reportHeader,
ReportBody = reportBody
HasFile = true,
FileData = new ReportFileData
{
FileName = $"{logReference.WellboreName}-{logReference.Name}.{fileExtension}",
FileContent = fileContent
}
};
}

private string GetCsvFileContent(ICollection<Dictionary<string, LogDataValue>> reportItems, ICollection<CurveSpecification> curveSpecifications)
{
return $"{GetReportHeader(curveSpecifications)}\n{GetReportBody(reportItems, curveSpecifications)}";
}

private string GetReportHeader(ICollection<CurveSpecification> curveSpecifications)
{
var listOfHeaders = new List<string>();
Expand Down
2 changes: 1 addition & 1 deletion Src/WitsmlExplorer.Desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"electron-builder": "^24.13.3",
"electron-playwright-helpers": "^1.7.1",
"electron-vite": "^2.1.0",
"lint-staged": "^13.0.3",
"lint-staged": "^15.2.4",
"vite-tsconfig-paths": "^4.3.2"
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions Src/WitsmlExplorer.Frontend/__testUtils__/testUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export function getServer(overrides?: Partial<Server>): Server {
roles: [],
credentialIds: [],
depthLogDecimals: 0,
isPriority: false,
...overrides
};
}
Expand Down Expand Up @@ -209,8 +210,7 @@ export function getReport(overrides?: Partial<BaseReport>): BaseReport {
summary: "testSummary",
reportItems: [],
warningMessage: "",
downloadImmediately: false,
reportHeader: "",
hasFile: false,
...overrides
};
}
Expand Down
11 changes: 7 additions & 4 deletions Src/WitsmlExplorer.Frontend/components/Alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,13 @@ const Alerts = (): React.ReactElement => {
?.toString()
.toLowerCase();
const shouldNotify =
connectedServerUrl &&
(notificationServerUrl === null ||
connectedServerUrl === notificationServerUrl ||
connectedServerUrl === notificationSourceServerUrl);
(!connectedServerUrl &&
!notificationServerUrl &&
!notificationSourceServerUrl) ||
(connectedServerUrl &&
(notificationServerUrl === null ||
connectedServerUrl === notificationServerUrl ||
connectedServerUrl === notificationSourceServerUrl));
if (!shouldNotify) {
return;
}
Expand Down
19 changes: 13 additions & 6 deletions Src/WitsmlExplorer.Frontend/components/Breadcrumbs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export function Breadcrumbs() {
color="inherit"
aria-label="breadcrumb"
wrap={false}
isCompact={theme === UserTheme.Compact}
$isCompact={theme === UserTheme.Compact}
>
{breadcrumbContent.map((breadCrumb, index: number) => (
<EdsBreadcrumbs.Breadcrumb
Expand Down Expand Up @@ -400,13 +400,20 @@ const StyledNavLink = styled(NavLink)`
text-decoration: none;
`;

const StyledBreadcrumbs = styled(EdsBreadcrumbs)<{ isCompact: boolean }>`
padding-top: 0.2em;
height: 1.5rem;
const StyledBreadcrumbs = styled(EdsBreadcrumbs)<{ $isCompact: boolean }>`
overflow: clip;
display: flex;
justify-content: flex-start;
align-items: center;
height: fit-content;
li > span {
display: inline-flex;
line-height: 16px;
}
${({ isCompact }) =>
!isCompact
${({ $isCompact }) =>
!$isCompact
? ""
: css`
li > span {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import OperationType from "contexts/operationType";
import { refreshJobInfoQuery } from "hooks/query/queryRefreshHelpers";
import { useGetJobInfo } from "hooks/query/useGetJobInfo";
import { useGetServers } from "hooks/query/useGetServers";
import useExport from "hooks/useExport";
import { useOperationState } from "hooks/useOperationState";
import JobStatus from "models/jobStatus";
import JobInfo from "models/jobs/jobInfo";
Expand Down Expand Up @@ -49,8 +48,6 @@ export const JobsView = (): React.ReactElement => {
? new Date(dataUpdatedAt).toLocaleTimeString()
: "";

const { exportData } = useExport();

const [cancellingJobs, setCancellingJobs] = useState<string[]>([]);

const onContextMenu = (
Expand Down Expand Up @@ -94,8 +91,8 @@ export const JobsView = (): React.ReactElement => {
};
const onClickReport = async (jobId: string) => {
const report = await JobService.getReport(jobId);
if (report.downloadImmediately === true) {
exportData(report.title, report.reportHeader, report.reportBody);
if (report.hasFile === true) {
await JobService.downloadFile(jobId);
} else {
const reportModalProps = { report };
dispatchOperation({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,11 @@ const getExpandedRowsFromQuery = (
const StyledTextField = styled(TextField)`
display: flex;
align-items: center;
div {
background-color: transparent;
}
width: 100%;
height: 100%;
`;
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Icon from "styles/Icons";
import { Box } from "@mui/material";
import QueryDataGrid from "components/ContentViews/QueryDataGrid";
import { QueryEditorTypes } from "components/ContentViews/QueryView/components/QueryOptions/QueryOptions";
import ResultMeta from "components/ContentViews/QueryView/components/ResultMeta";
import QueryOptions from "./components/QueryOptions";

const QueryView = (): React.ReactElement => {
Expand Down Expand Up @@ -56,7 +57,7 @@ const QueryView = (): React.ReactElement => {
activeTab={tabIndex}
onChange={onTabChange}
scrollable
style={{ overflowX: "auto", whiteSpace: "nowrap" }}
style={{ whiteSpace: "nowrap" }}
>
<Tabs.List>
{queries.map((query) => (
Expand Down Expand Up @@ -85,13 +86,14 @@ const QueryView = (): React.ReactElement => {
<Box
display="grid"
gridTemplateRows="auto 1fr auto"
gap="1rem"
gap="0.5rem"
height="100%"
pr="2px"
>
<QueryOptions
onQueryChange={onQueryChange}
onChangeEditorType={setEditorType}
editorType={editorType}
/>
{editorType === QueryEditorTypes.DataGrid ? (
<QueryDataGrid />
Expand All @@ -103,9 +105,16 @@ const QueryView = (): React.ReactElement => {
/>
)}
</Box>
<div>
<Box
display="grid"
gridTemplateRows="auto 1fr"
gap="1rem"
height="100%"
pr="2px"
>
<ResultMeta />
<QueryEditor value={result} readonly />
</div>
</Box>
</div>
</Layout>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React, { ChangeEventHandler, FC } from "react";
import { Stack } from "@mui/material";
import { Switch } from "@equinor/eds-core-react";
import { useOperationState } from "../../../../../../hooks/useOperationState.tsx";
import { UserTheme } from "../../../../../../contexts/operationStateReducer.tsx";
import styled from "styled-components";
import { Colors } from "../../../../../../styles/Colors.tsx";

type DataGridSwitchProps = {
onClick: ChangeEventHandler<HTMLInputElement>;
dataGridActive: boolean;
};

const DataGridSwitch: FC<DataGridSwitchProps> = ({
onClick,
dataGridActive
}) => {
const { theme, colors } = useOperationState().operationState;
const isCompact = theme === UserTheme.Compact;

return (
<Stack direction="row" alignItems="center" justifyContent="flex-start">
<StyledSwitch
checked={dataGridActive}
onChange={onClick}
size={isCompact ? "small" : "default"}
label="Use data grid view"
colors={colors}
/>
</Stack>
);
};

const StyledSwitch = styled(Switch)<{ colors: Colors }>`
& > span:nth-child(2) {
color: ${({ colors }) => colors.interactive.primaryResting};
}
`;

export default DataGridSwitch;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./DataGridSwitch.tsx";
Loading

0 comments on commit c9f5f9a

Please sign in to comment.