Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Nov 23, 2023
2 parents 26ce92f + c64e075 commit 72465a5
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import formatDateString from "../DateFormatter";
import ConfirmModal from "../Modals/ConfirmModal";
import ProgressSpinner from "../ProgressSpinner";
import { CurveValuesPlot } from "./CurveValuesPlot";
import EditInterval from "./EditInterval";
import EditNumber from "./EditNumber";
import EditSelectedLogCurveInfo from "./EditSelectedLogCurveInfo";
import { LogCurveInfoRow } from "./LogCurveInfoListView";
import { ContentTable, ContentTableColumn, ContentTableRow, ContentType, ExportableContentTableColumn, Order } from "./table";

Expand Down Expand Up @@ -142,20 +142,19 @@ export const CurveValuesView = (): React.ReactElement => {
);

const updateColumns = (curveSpecifications: CurveSpecification[]) => {
const isNewMnemonic = (mnemonic: string) => {
return columns.map((column) => column.property).indexOf(mnemonic) < 0;
};
const newColumns = curveSpecifications
.filter((curveSpecification) => isNewMnemonic(curveSpecification.mnemonic))
.map((curveSpecification) => {
return {
columnOf: curveSpecification,
property: curveSpecification.mnemonic,
label: `${curveSpecification.mnemonic} (${curveSpecification.unit})`,
type: getColumnType(curveSpecification)
};
});
setColumns([...columns, ...newColumns]);
const newColumns = curveSpecifications.map((curveSpecification) => {
return {
columnOf: curveSpecification,
property: curveSpecification.mnemonic,
label: `${curveSpecification.mnemonic} (${curveSpecification.unit})`,
type: getColumnType(curveSpecification)
};
});
const prevMnemonics = columns.map((column) => column.property);
const newMnemonics = newColumns.map((column) => column.property);
if (prevMnemonics.length !== newMnemonics.length || prevMnemonics.some((value, index) => value !== newMnemonics[index])) {
setColumns(newColumns);
}
};

const getTableData = React.useCallback(() => {
Expand Down Expand Up @@ -271,9 +270,9 @@ export const CurveValuesView = (): React.ReactElement => {
<>
<ContentContainer>
<CommonPanelContainer>
<EditInterval
<EditSelectedLogCurveInfo
disabled={autoRefresh}
key="editinterval"
key="editSelectedLogCurveInfo"
overrideStartIndex={autoRefresh ? getCurrentMinIndex() : null}
overrideEndIndex={autoRefresh ? getCurrentMaxIndex() : null}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ChangeEvent, ReactElement, useContext, useState } from "react";
import styled from "styled-components";
import OperationContext from "../../contexts/operationContext";
import { TooltipLayout } from "../ContextMenus/OptionsContextMenu";
import { StyledButton } from "./EditInterval";
import { StyledButton } from "./EditSelectedLogCurveInfo";

interface EditNumberProps {
label: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,87 @@
import { Button, Icon, Label, TextField, Typography } from "@equinor/eds-core-react";
import { Autocomplete, Button, Icon, Label, TextField, Typography } from "@equinor/eds-core-react";
import { isValid, parse } from "date-fns";
import { format } from "date-fns-tz";
import { Dispatch, SetStateAction, useContext, useEffect, useState } from "react";
import { CSSProperties, Dispatch, SetStateAction, useContext, useEffect, useState } from "react";
import styled from "styled-components";
import NavigationContext from "../../contexts/navigationContext";
import NavigationType from "../../contexts/navigationType";
import OperationContext from "../../contexts/operationContext";
import { ComponentType } from "../../models/componentType";
import LogCurveInfo from "../../models/logCurveInfo";
import LogObject from "../../models/logObject";
import { truncateAbortHandler } from "../../services/apiClient";
import ComponentService from "../../services/componentService";
import { Colors, colors, dark } from "../../styles/Colors";
import { WITSML_INDEX_TYPE_DATE_TIME } from "../Constants";
import { formatIndexValue } from "../Modals/SelectIndexToDisplayModal";

interface EditIntervalProps {
interface EditSelectedLogCurveInfoProps {
disabled?: boolean;
overrideStartIndex?: string;
overrideEndIndex?: string;
}

const EditInterval = (props: EditIntervalProps): React.ReactElement => {
const EditSelectedLogCurveInfo = (props: EditSelectedLogCurveInfoProps): React.ReactElement => {
const { disabled, overrideStartIndex, overrideEndIndex } = props;
const { dispatchNavigation, navigationState } = useContext(NavigationContext);
const { selectedObject, selectedLogCurveInfo } = navigationState;
const selectedLog = selectedObject as LogObject;

const [logCurveInfo, setLogCurveInfo] = useState<LogCurveInfo[]>([]);
const [selectedMnemonics, setSelectedMnemonics] = useState<string[]>([]);
const [startIndex, setStartIndex] = useState<string>(null);
const [endIndex, setEndIndex] = useState<string>(null);
const [isEdited, setIsEdited] = useState<boolean>(false);
const [isValidStart, setIsValidStart] = useState<boolean>(true);
const [isValidEnd, setIsValidEnd] = useState<boolean>(true);
const [isFetchingMnemonics, setIsFetchingMnemonics] = useState<boolean>(true);
const {
operationState: { colors }
} = useContext(OperationContext);

useEffect(() => {
const minIndex = selectedLogCurveInfo?.[0]?.minIndex;
const maxIndex = selectedLogCurveInfo?.[0]?.maxIndex;
const selectedMnemonics = selectedLogCurveInfo?.map((lci) => lci.mnemonic)?.filter((mnemonic) => mnemonic !== selectedLog.indexCurve);
setSelectedMnemonics(selectedMnemonics || []);
setStartIndex(getParsedValue(String(minIndex)));
setEndIndex(getParsedValue(String(maxIndex)));
}, []);

useEffect(() => {
setIsFetchingMnemonics(true);
if (selectedLog) {
const controller = new AbortController();

const getLogCurveInfo = async () => {
const logCurveInfo = await ComponentService.getComponents(
selectedLog.wellUid,
selectedLog.wellboreUid,
selectedLog.uid,
ComponentType.Mnemonic,
undefined,
controller.signal
);
setLogCurveInfo(logCurveInfo.slice(1)); // Skip the first one as it is the index curve
setIsFetchingMnemonics(false);
};

getLogCurveInfo().catch(truncateAbortHandler);

return () => {
controller.abort();
};
}
}, [selectedLog]);

useEffect(() => {
if (overrideStartIndex) setStartIndex(getParsedValue(overrideStartIndex));
if (overrideEndIndex) setEndIndex(getParsedValue(overrideEndIndex));
}, [overrideStartIndex, overrideEndIndex]);

const submitEditInterval = () => {
const submitLogCurveInfo = () => {
setIsEdited(false);
const logCurveInfoWithUpdatedIndex = selectedLogCurveInfo.map((logCurveInfo) => {
const filteredLogCurveInfo = logCurveInfo.filter((lci) => selectedMnemonics.includes(lci.mnemonic));
const logCurveInfoWithUpdatedIndex = filteredLogCurveInfo.map((logCurveInfo) => {
return {
...logCurveInfo,
minIndex: formatIndexValue(startIndex),
Expand Down Expand Up @@ -86,10 +121,15 @@ const EditInterval = (props: EditIntervalProps): React.ReactElement => {
}
};

const onMnemonicsChange = ({ selectedItems }: { selectedItems: string[] }) => {
setSelectedMnemonics(selectedItems);
setIsEdited(true);
};

const dateTimeFormat = "yyyy-MM-dd'T'HH:mm:ss";

return (
<EditIntervalLayout colors={colors}>
<Layout colors={colors}>
<Typography
style={{
color: `${colors.interactive.primaryResting}`
Expand Down Expand Up @@ -128,14 +168,34 @@ const EditInterval = (props: EditIntervalProps): React.ReactElement => {
}}
/>
</StartEndIndex>
<StyledButton variant={"ghost"} color={"primary"} onClick={submitEditInterval} disabled={!isValidStart || !isValidEnd}>
<StartEndIndex>
<StyledLabel label="Mnemonics" />
<Autocomplete
id={"mnemonics"}
disabled={disabled || isFetchingMnemonics}
label={""}
multiple={true}
// @ts-ignore. Variant is defined and exists in the documentation, but not in the type definition.
variant={selectedMnemonics.length === 0 ? "error" : null}
options={logCurveInfo.map((lci) => lci.mnemonic)}
selectedOptions={selectedMnemonics}
onFocus={(e) => e.preventDefault()}
onOptionsChange={onMnemonicsChange}
style={
{
"--eds-input-background": colors.ui.backgroundDefault
} as CSSProperties
}
/>
</StartEndIndex>
<StyledButton variant={"ghost"} color={"primary"} onClick={submitLogCurveInfo} disabled={disabled || !isValidStart || !isValidEnd || selectedMnemonics.length === 0}>
<Icon size={16} name={isEdited ? "arrowForward" : "sync"} />
</StyledButton>
</EditIntervalLayout>
</Layout>
);
};

const EditIntervalLayout = styled.div<{ colors: Colors }>`
const Layout = styled.div<{ colors: Colors }>`
display: flex;
gap: 0.25rem;
align-items: center;
Expand All @@ -149,7 +209,7 @@ const StartEndIndex = styled.div`
`;

const StyledLabel = styled(Label)`
width: 5rem;
white-space: nowrap;
align-items: center;
font-style: italic;
`;
Expand Down Expand Up @@ -189,4 +249,4 @@ export const StyledButton = styled(Button)`
align-items: center;
justify-content: center;
`;
export default EditInterval;
export default EditSelectedLogCurveInfo;

0 comments on commit 72465a5

Please sign in to comment.