Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#9473 fix longituindal profile issues - marker and dropup style issue #9485

Merged
merged 5 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion web/client/epics/longitudinalProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ export const LPonAddMarkerEpic = (action$) =>
opacity: 1,
size: 32,
anchor: "bottom",
offset: [0, -16],
rotate: 0,
msBringToFront: true,
msHeightReference: 'none',
Expand Down
16 changes: 12 additions & 4 deletions web/client/plugins/longitudinalProfile/Menu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree.
*/
import React, { useState, useCallback } from 'react';
import React, { useState, useEffect, useCallback } from 'react';
import PropTypes from 'prop-types';
import {DropdownButton, Glyphicon, MenuItem, NavDropdown} from 'react-bootstrap';
import {connect} from "react-redux";
Expand All @@ -23,6 +23,8 @@ import {
isParametersOpenSelector
} from "../../selectors/longitudinalProfile";
import { isCesium } from '../../selectors/maptype';
import { getOffsetTop, getOffsetBottom } from '../../utils/DOMUtil';


const TNavDropdown = tooltip(NavDropdown);
const TDropdownButton = tooltip(DropdownButton);
Expand All @@ -45,13 +47,19 @@ const UserMenu = ({
onToggleSourceMode
}) => {
let DropDown = nav ? TNavDropdown : TDropdownButton;

const [dropUp, setDropUp ] = useState(false);
const onToggleTool = useCallback((toolName) => () => {
onActivateTool();
onToggleSourceMode(toolName);
}, []);
useEffect(() => {
const ButtonElement = document.getElementById("longitudinal-tool");
const offsetTop = getOffsetTop(ButtonElement);
const offsetBottom = getOffsetBottom(ButtonElement);
const dropUpVal = offsetTop > 2000 && offsetBottom < 130;
setDropUp(dropUpVal);
}, []);
const [open, setMenuOpen ] = useState(false);

const body = (<>
{showDrawOption ? <MenuItem active={dataSourceMode === 'draw'} key="draw" onClick={onToggleTool('draw')}>
<Glyphicon glyph="pencil"/><Message msgId="longitudinalProfile.draw"/>
Expand All @@ -68,7 +76,7 @@ const UserMenu = ({
</MenuItem>
</>);
const DropDownMenu = (<DropDown
dropup
dropup={dropUp}
open={open}
onToggle={(val) => setMenuOpen(val)}
id="longitudinal-tool"
Expand Down
2 changes: 1 addition & 1 deletion web/client/themes/default/icons.less
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@
.glyphicon-zoom-out:before { content: "\f263"; }
.glyphicon-zoom-to:before { content: "\f264"; }

/*
/*
classes with icon code
they can be used as mixin to get the content code
structure .glyphicon-{iconName}-content
Expand Down
23 changes: 23 additions & 0 deletions web/client/utils/DOMUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,26 @@ export const scrollIntoViewId = (viewId) => {
}
};


/**
* @param {node} elem the node element you want to inspect top offset
* @returns {number} the total offset from the top
*/
export function getOffsetTop( elem ) {
var offsetTop = 0;
do {
if ( !isNaN( elem?.offsetTop ) ) {
offsetTop += elem.offsetTop;
}
// eslint-disable-next-line no-param-reassign, no-cond-assign
} while ( elem = elem?.offsetParent );
return offsetTop;
}
/**
* @param {node} elem the node element you want to inspect bottom offset
* @returns {number} the total offset from the bottom
*/
export const getOffsetBottom = ( element, containerClass = "container") =>{
const container = document.getElementById(containerClass);
return container.clientHeight - getOffsetTop(element);
};
22 changes: 21 additions & 1 deletion web/client/utils/__tests__/DOMUtil-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import expect from 'expect';

import { scrollIntoViewId } from '../DOMUtil';
import { getOffsetBottom, getOffsetTop, scrollIntoViewId } from '../DOMUtil';

describe('Test the DOMUtils', () => {

Expand All @@ -23,5 +23,25 @@ describe('Test the DOMUtils', () => {
scrollIntoViewId('container');
expect(spy.calls.length).toEqual(1);
});
it('test getOffsetTop', function() {
document.body.innerHTML = `
<div id="container">
<div id="content"}>
offtherailz marked this conversation as resolved.
Show resolved Hide resolved
test
</div>
</div>`;
const offset = getOffsetTop(document.querySelector("#content"));
expect(offset).toEqual(8);
});
it('test getOffsetBottom', function() {
document.body.innerHTML = `
<div id="container">
<div id="content"}>
offtherailz marked this conversation as resolved.
Show resolved Hide resolved
test
</div>
</div>`;
const offset = getOffsetBottom(document.querySelector("#content"));
expect(offset).toEqual(10);
});

});