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

feat: keep the geometry selected highlighted #91

Merged
merged 3 commits into from
Nov 30, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 15 additions & 3 deletions src/BrowseComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface IMuiVirtualizedTableProps {
isRetrievingMoreFeature: any;
handleRetrieveMoreFeature: any;
displayedRowCount: any;
selectedFeature: any;
}

class MuiVirtualizedTable extends React.PureComponent<IMuiVirtualizedTableProps> {
Expand All @@ -70,13 +71,21 @@ class MuiVirtualizedTable extends React.PureComponent<IMuiVirtualizedTableProps>

getRowStyle = ({ index }: { index: number }) => {
if (index >= 0) {
const { rowGetter, highlightFeature } = this.props;
const { rowGetter, highlightFeature, selectedFeature } = this.props;
const rowData = rowGetter({ index });
if (get(highlightFeature, 'id') === get(rowData, 'id')) {
if (
get(selectedFeature, 'id') !== get(highlightFeature, 'id') &&
get(highlightFeature, 'id') === get(rowData, 'id')
) {
return {
backgroundColor: '#eeeeee'
};
}
if (get(selectedFeature, 'id') === get(rowData, 'id')) {
return {
backgroundColor: '#757575'
};
}
}
return {};
};
Expand Down Expand Up @@ -253,6 +262,7 @@ export interface IBrowseComponentProps {
highlightFeature: any;
isRetrievingMoreFeature: () => boolean;
handleRetrieveMoreFeature: () => Promise<void>;
selectedFeature: any;
}

function BrowseComponent({
Expand All @@ -262,7 +272,8 @@ function BrowseComponent({
handleHoverFeature,
highlightFeature,
isRetrievingMoreFeature,
handleRetrieveMoreFeature
handleRetrieveMoreFeature,
selectedFeature
}: IBrowseComponentProps) {
/**
* Return an object with its id and all its properties
Expand Down Expand Up @@ -302,6 +313,7 @@ function BrowseComponent({
highlightFeature={highlightFeature}
isRetrievingMoreFeature={isRetrievingMoreFeature}
handleRetrieveMoreFeature={handleRetrieveMoreFeature}
selectedFeature={selectedFeature}
columns={[
// {
// width: 100,
Expand Down
2 changes: 2 additions & 0 deletions src/FormComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ export const FormComponent: FC<IProps> = ({
};

const Fields = ({ control, register }: Partial<UseFormReturn<IFormInput>>) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const { fields, append, remove } = useFieldArray({
control,
name: 'additionnalParameters'
Expand Down
15 changes: 12 additions & 3 deletions src/MapFeatureComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface IProps {
export interface IState {
bounds: L.LatLngBounds;
featureHover: any;
featureSelected: string;
}

export default class MapFeatureComponent extends React.Component<
Expand Down Expand Up @@ -54,7 +55,8 @@ export default class MapFeatureComponent extends React.Component<
const bounds = featureGeoJSONs.getBounds();
this.state = {
bounds,
featureHover: null
featureHover: null,
featureSelected: null
};
}

Expand Down Expand Up @@ -122,7 +124,13 @@ export default class MapFeatureComponent extends React.Component<

onClick = (e: LeafletMouseEvent) => {
const productId = e.propagatedFrom.feature.id;
e.layer.setStyle(MapFeatureComponent.HIGHLIGHT_EXTENT_STYLE);
e.layer.bringToFront();
this.props.handleClickFeature(productId);

this.setState({
featureSelected: productId
});
};

/**
Expand All @@ -131,10 +139,11 @@ export default class MapFeatureComponent extends React.Component<
*/
getStyle = (feature: any) => {
const { highlightFeature } = this.props;
const { featureHover } = this.state;
const { featureHover, featureSelected } = this.state;
if (
get(highlightFeature, 'id') === feature.id ||
featureHover === feature.id
featureHover === feature.id ||
featureSelected === feature.id
) {
return MapFeatureComponent.HIGHLIGHT_EXTENT_STYLE;
}
Expand Down
21 changes: 16 additions & 5 deletions src/ModalComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface IState {
highlightOnTableFeature: any;
zoomFeature: any;
features: any;
selectedFeature: any;
}

function Transition(props: any) {
Expand All @@ -62,7 +63,8 @@ export default class ModalComponent extends React.Component<IProps, IState> {
displayFeature: null,
highlightOnMapFeature: null,
highlightOnTableFeature: null,
zoomFeature: null
zoomFeature: null,
selectedFeature: null
};
}

Expand All @@ -81,11 +83,18 @@ export default class ModalComponent extends React.Component<IProps, IState> {
};

handleClickFeature = (productId: string) => {
const feature = this.getFeature(productId);
if (feature) {
if (!productId) {
this.setState({
displayFeature: feature
selectedFeature: null
});
} else {
const feature = this.getFeature(productId);
if (feature) {
this.setState({
displayFeature: feature,
selectedFeature: feature
});
}
}
};

Expand Down Expand Up @@ -141,7 +150,8 @@ export default class ModalComponent extends React.Component<IProps, IState> {
zoomFeature,
highlightOnMapFeature,
highlightOnTableFeature,
displayFeature
displayFeature,
selectedFeature
} = this.state;
return (
<Modal
Expand Down Expand Up @@ -210,6 +220,7 @@ export default class ModalComponent extends React.Component<IProps, IState> {
handleHoverFeature={this.handleHoverTableFeature}
isRetrievingMoreFeature={isRetrievingMoreFeature}
handleRetrieveMoreFeature={handleRetrieveMoreFeature}
selectedFeature={selectedFeature}
/>
</div>
</div>
Expand Down