-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
193 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
packages/base/src/panelview/components/filter-panel/FilterRow.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |