-
Notifications
You must be signed in to change notification settings - Fork 0
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
22 changed files
with
3,529 additions
and
2,186 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
"Geospatial", | ||
"gnis", | ||
"hostingchannels", | ||
"Immer", | ||
"lods", | ||
"lucide", | ||
"noopener", | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,84 +1,95 @@ | ||
import Collection from '@arcgis/core/core/Collection.js'; | ||
import { Button, Tag, TagGroup } from '@ugrc/utah-design-system'; | ||
import { useEffect, useState } from 'react'; | ||
import { type Selection } from 'react-aria-components'; | ||
import { tv } from 'tailwind-variants'; | ||
import { ProjectStatus } from './data/filters'; | ||
import { Button, Radio, RadioGroup, Tag, TagGroup } from '@ugrc/utah-design-system'; | ||
import { Dispatch, useContext } from 'react'; | ||
import { type Key } from 'react-stately'; | ||
import { type FilterAction, FilterContext } from './contexts'; | ||
import { FeatureType } from './data/filters'; | ||
import { areSetsEqual } from './utils'; | ||
const emptySet = new Set<Key>(); | ||
|
||
const defaultState = new Set(['Proposed', 'Current', 'Pending Completed', 'Completed']); | ||
const all = ''; | ||
const none = '1=0'; | ||
|
||
const tagStyles = tv({ | ||
variants: { | ||
status: { | ||
draft: 'data-[selected]:bg-zinc-500 data-[selected]:hover:border-zinc-700 data-[selected]:border-gray-200', | ||
proposed: 'data-[selected]:bg-zinc-800 data-[selected]:hover:border-zinc-900 data-[selected]:border-gray-200', | ||
current: 'data-[selected]:bg-sky-600 data-[selected]:hover:border-sky-800 data-[selected]:border-gray-200', | ||
'pending completed': | ||
'data-[selected]:bg-yellow-500 data-[selected]:hover:border-yellow-600 data-[selected]:border-gray-200', | ||
completed: 'data-[selected]:bg-green-700 data-[selected]:hover:border-green-900 data-[selected]:border-gray-200', | ||
cancelled: 'data-[selected]:bg-red-700 data-[selected]:hover:border-red-900 data-[selected]:border-gray-200', | ||
}, | ||
}, | ||
}); | ||
|
||
type Status = keyof typeof tagStyles.variants.status; | ||
|
||
const setDefinitionExpression = (layers: Collection<__esri.FeatureLayer>, keys: Selection) => | ||
layers | ||
.filter((x) => x.id.startsWith('feature')) | ||
.forEach((layer) => { | ||
if (keys === 'all') { | ||
layer.definitionExpression = all; | ||
|
||
return; | ||
} | ||
|
||
if (keys.size === 0) { | ||
layer.definitionExpression = none; | ||
|
||
return; | ||
} | ||
|
||
const statusField = layer.id === 'feature-centroids' ? 'status' : 'statusDescription'; | ||
|
||
layer.definitionExpression = `${statusField} in (${Array.from(keys) | ||
.map((status) => `'${status}'`) | ||
.join(',')})`; | ||
}); | ||
|
||
export const FeatureData = ({ | ||
layers, | ||
status, | ||
}: { | ||
layers: __esri.Collection<__esri.FeatureLayer>; | ||
status: ProjectStatus[]; | ||
}) => { | ||
const [selected, setSelected] = useState<Selection>(defaultState); | ||
|
||
// synchronizes the definition expressions with the initial ui state | ||
useEffect(() => { | ||
setDefinitionExpression(layers, selected); | ||
}, [layers, selected]); | ||
export const FeatureData = ({ featureTypes }: { featureTypes: FeatureType[] }) => { | ||
const { dispatch, defaultFeatureState, selectedFeatures } = useContext(FilterContext); | ||
|
||
return ( | ||
<> | ||
<TagGroup selectionMode="multiple" selectedKeys={selected} onSelectionChange={setSelected}> | ||
{status.map(({ code, value }) => ( | ||
<Tag id={value} key={code} textValue={value} className={tagStyles({ status: value.toLowerCase() as Status })}> | ||
{value} | ||
<TagGroup | ||
selectionMode="multiple" | ||
defaultSelectedKeys={defaultFeatureState} | ||
selectedKeys={selectedFeatures} | ||
onSelectionChange={(value) => | ||
dispatch({ | ||
type: 'set', | ||
payload: { | ||
features: value as Set<Key>, | ||
}, | ||
metadata: 'feature', | ||
}) | ||
} | ||
> | ||
{featureTypes.map(({ code, featureType }) => ( | ||
<Tag id={featureType} key={code} textValue={featureType}> | ||
{featureType} | ||
</Tag> | ||
))} | ||
</TagGroup> | ||
{!areSetsEqual(defaultState, selected === 'all' ? new Set([]) : selected) && ( | ||
<span> | ||
<Button variant="destructive" size="extraSmall" onPress={() => setSelected(defaultState)}> | ||
Reset | ||
</Button> | ||
</span> | ||
)} | ||
<span className="flex gap-2"> | ||
<Button | ||
variant="destructive" | ||
size="extraSmall" | ||
isDisabled={areSetsEqual( | ||
defaultFeatureState as Set<Key>, | ||
selectedFeatures === 'all' ? emptySet : selectedFeatures, | ||
)} | ||
onPress={() => | ||
dispatch({ | ||
type: 'set', | ||
payload: { | ||
features: defaultFeatureState as Set<Key>, | ||
}, | ||
metadata: 'feature', | ||
}) | ||
} | ||
> | ||
Reset | ||
</Button> | ||
<Button | ||
variant="destructive" | ||
size="extraSmall" | ||
isDisabled={selectedFeatures === 'all' || selectedFeatures.size === 0} | ||
onPress={() => | ||
dispatch({ | ||
type: 'set', | ||
payload: { | ||
features: emptySet, | ||
}, | ||
metadata: 'feature', | ||
}) | ||
} | ||
> | ||
Clear | ||
</Button> | ||
</span> | ||
<JoinWith defaultValue={'or'} dispatch={dispatch} /> | ||
</> | ||
); | ||
}; | ||
|
||
export const JoinWith = ({ defaultValue, dispatch }: { defaultValue: string; dispatch: Dispatch<FilterAction> }) => { | ||
return ( | ||
<RadioGroup | ||
defaultValue={defaultValue} | ||
label="Feature match style" | ||
onChange={(value) => { | ||
dispatch({ | ||
type: 'set', | ||
payload: { | ||
join: value as 'and' | 'or', | ||
}, | ||
metadata: 'feature-join', | ||
}); | ||
}} | ||
> | ||
<Radio value="or">any</Radio> | ||
<Radio value="and">all</Radio> | ||
</RadioGroup> | ||
); | ||
}; |
Oops, something went wrong.