Skip to content

Commit

Permalink
css work
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmooney committed Aug 9, 2024
1 parent 15bd3b1 commit 8c0ea13
Show file tree
Hide file tree
Showing 5 changed files with 193 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import {
import { Button, ReactWidget } from '@jupyterlab/ui-components';
import { Panel } from '@lumino/widgets';
import React, { useEffect, useState } from 'react';
import { getSourceLayerNames } from '../../tools';
import { IControlPanelModel } from '../../types';
import { RightPanelWidget } from '../rightpanel';
import { getSourceLayerNames } from '../../../tools';
import { IControlPanelModel } from '../../../types';
import { RightPanelWidget } from '../../rightpanel';
import FilterRow from './FilterRow';

/**
* The filters panel widget.
Expand Down Expand Up @@ -128,13 +129,16 @@ const FilterComponent = (props: IFilterComponentProps) => {
const layer = model?.getLayer(selectedLayer);

return (
<ul style={{ listStyleType: 'none' }}>
{layer?.filters?.map(filter => (
<li>
{filter.feature} {filter.operator} {filter.value}
</li>
))}
</ul>
<div className="jp-gis-filter-">
<span className="jp-gis-text-label">Applied Filters</span>
<ul style={{ listStyleType: 'none' }}>
{layer?.filters?.map(filter => (
<li>
{filter.feature} {filter.operator} {filter.value}
</li>
))}
</ul>
</div>
);
};

Expand All @@ -144,7 +148,7 @@ const FilterComponent = (props: IFilterComponentProps) => {
if (!filterContainer) {
return;
}
filterContainer.style.display = 'block';
filterContainer.style.display = 'flex';

setFilterRows([
...filterRows,
Expand Down Expand Up @@ -176,127 +180,50 @@ const FilterComponent = (props: IFilterComponentProps) => {
};

return (
<div style={{ display: 'flex', flexDirection: 'column', padding: 7 }}>
<div className="jp-gis-filter-main">
{selectedLayer && (
<>
<div style={{ display: 'flex', flexDirection: 'column' }}>
{displayFilters()}
<div style={{ display: 'flex', justifyContent: 'space-around' }}>
<Button
className="jp-Dialog-button jp-mod-accept jp-mod-styled"
onClick={addFilterRow}
>
Add
</Button>
<Button
className="jp-Dialog-button jp-mod-reject jp-mod-styled"
onClick={clearFilters}
>
Clear
</Button>
</div>

<div id="filter-container" style={{ display: 'none' }}>
{filterRows.map((row, index) => (
<FilterRow
key={index}
index={index}
features={featureStuff}
rows={filterRows}
setRows={setFilterRows}
/>
))}
</div>
{displayFilters()}
<div className="jp-gis-filter-button-container">
<Button
className="jp-Dialog-button jp-mod-accept jp-mod-styled"
onClick={submitFilter}
onClick={addFilterRow}
>
Submit
Add
</Button>
<Button
className="jp-Dialog-button jp-mod-reject jp-mod-styled"
onClick={clearFilters}
>
Clear
</Button>
</div>

<div
id="filter-container"
style={{ display: 'none' }}
className="jp-gis-filter-select-container"
>
{filterRows.map((row, index) => (
<FilterRow
key={index}
index={index}
features={featureStuff}
filterRows={filterRows}
setFilterRows={setFilterRows}
/>
))}
</div>
<Button
className="jp-Dialog-button jp-mod-accept jp-mod-styled"
onClick={submitFilter}
>
Submit
</Button>
</>
)}
</div>
);
};

const FilterRow = ({
index,
features,
rows,
setRows
}: {
index: number;
features: Record<string, Set<string>>;
rows: any;
setRows: any;
}) => {
const operators = ['==', '!=', '>', '<'];

const [selectedFeature, setSelectedFeature] = useState(
Object.keys(features)[0]
);

useEffect(() => {
const valueSelect = document.getElementById(
`filter-value${index}`
) as HTMLSelectElement;
if (!valueSelect) {
return;
}
const currentValue = valueSelect.options[valueSelect.selectedIndex].value;
handleValueChange({
target: { value: currentValue }
});
}, [selectedFeature]);

const handleKeyChange = event => {
const newFilters = [...rows];
newFilters[index].key = event.target.value;
setSelectedFeature(event.target.value);
setRows(newFilters);
};

const handleOperatorChange = event => {
const newFilters = [...rows];
newFilters[index].operator = event.target.value;
setRows(newFilters);
};

const handleValueChange = event => {
const newFilters = [...rows];
newFilters[index].value = event.target.value;
setRows(newFilters);
};

return (
<div>
<select onChange={handleKeyChange}>
{/* Populate options based on the keys of the filters object */}
{Object.keys(features).map((key, keyIndex) => (
<option key={keyIndex} value={key}>
{key}
</option>
))}
</select>
<select onChange={handleOperatorChange}>
{operators.map((operator, operatorIndex) => (
<option key={operatorIndex} value={operator}>
{operator}
</option>
))}
</select>
<select id={`filter-value${index}`} onChange={handleValueChange}>
{/* Populate options based on the values of the selected key */}
{features[selectedFeature] &&
[...features[selectedFeature]].map((value, valueIndex) => (
<option key={valueIndex} value={value}>
{value}
</option>
))}
</select>
</div>
);
};

export default FilterComponent;
92 changes: 92 additions & 0 deletions packages/base/src/panelview/components/filter-panel/FilterRow.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import React, { useEffect, useState } from 'react';

const FilterRow = ({
index,
features,
filterRows,
setFilterRows
}: {
index: number;
features: Record<string, Set<string>>;
filterRows: any;
setFilterRows: any;
}) => {
const operators = ['==', '!=', '>', '<'];

const [selectedFeature, setSelectedFeature] = useState(
Object.keys(features)[0]
);

useEffect(() => {
const valueSelect = document.getElementById(
`filter-value${index}`
) as HTMLSelectElement;
if (!valueSelect) {
return;
}
const currentValue = valueSelect.options[valueSelect.selectedIndex].value;
handleValueChange({
target: { value: currentValue }
});
}, [selectedFeature]);

const handleKeyChange = event => {
const newFilters = [...filterRows];
newFilters[index].key = event.target.value;
setSelectedFeature(event.target.value);
setFilterRows(newFilters);
};

const handleOperatorChange = event => {
const newFilters = [...filterRows];
newFilters[index].operator = event.target.value;
setFilterRows(newFilters);
};

const handleValueChange = event => {
const newFilters = [...filterRows];
newFilters[index].value = event.target.value;
setFilterRows(newFilters);
};

return (
<div className="jp-gis-filter-row">
<select
className="jp-mod-styled jp-SchemaForm"
onChange={handleKeyChange}
>
{/* Populate options based on the keys of the filters object */}
{Object.keys(features).map((key, keyIndex) => (
<option key={keyIndex} value={key}>
{key}
</option>
))}
</select>
<select
className="jp-mod-styled jp-SchemaForm"
onChange={handleOperatorChange}
>
{operators.map((operator, operatorIndex) => (
<option key={operatorIndex} value={operator}>
{operator}
</option>
))}
</select>
<select
className="jp-mod-styled jp-SchemaForm"
id={`filter-value${index}`}
onChange={handleValueChange}
>
{/* Populate options based on the values of the selected key */}
{features[selectedFeature] &&
[...features[selectedFeature]].map((value, valueIndex) => (
<option key={valueIndex} value={value}>
{value}
</option>
))}
</select>
</div>
);
};

export default FilterRow;
2 changes: 1 addition & 1 deletion packages/base/src/panelview/rightpanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
import { SidePanel } from '@jupyterlab/ui-components';

import { IControlPanelModel } from '../types';
import { FilterPanel } from './components/Filter';
import { FilterPanel } from './components/filter-panel/Filter';
import { ControlPanelHeader } from './header';
import { ObjectProperties } from './objectproperties';

Expand Down
9 changes: 9 additions & 0 deletions packages/base/style/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@import url('./layerBrowser.css');
@import url('./leftPanel.css');
@import url('./terrainDialog.css');
@import url('./filterPanel.css');
@import url('maplibre-gl/dist/maplibre-gl.css');

.jGIS-Toolbar-GroupName {
Expand Down Expand Up @@ -43,3 +44,11 @@
.jGIS-property-panel .jp-SchemaForm .array-item-list:has(.field-array) {
flex-direction: column;
}

.jp-gis-text-label {
margin: 0;
padding: 0;
font-weight: bold;
display: block;
position: relative;
}
43 changes: 43 additions & 0 deletions packages/base/style/filterPanel.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
.jp-gis-filter-main {
display: flex;
flex-direction: column;
padding: 10px;
gap: 1rem;
}

.jp-gis-filter-list {
display: flex;
flex-direction: column;
}

.jp-gis-filter-button-container {
display: flex;
justify-content: flex-end;
}

.jp-gis-filter-main > .jp-Dialog-button {
width: fit-content;
align-self: flex-end;
}

.jp-gis-filter-select-container {
display: flex;
flex-direction: column;
gap: 0.5rem;
}

.jp-gis-filter-row {
display: flex;
justify-content: space-around;
width: 100%;
gap: 0.25rem;
}

.jp-gis-filter-row > select {
text-transform: capitalize;
}

.jp-gis-filter-row > option {
text-transform: capitalize;
font-size: var(--jp-ui-font-size1);
}

0 comments on commit 8c0ea13

Please sign in to comment.