Skip to content

Commit

Permalink
support filter url param
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhauck committed Jan 4, 2024
1 parent 9d1db0d commit cc2189f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 23 deletions.
18 changes: 18 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
*/
import { HTMLStencilElement, JSXBase } from "@stencil/core/internal";
import { DistanceUnit, EDrawMode, ELayoutMode, IBasemapConfig, IExportInfos, IInventoryItem, ILayerAndTableIds, IMapChange, IMapInfo, ISearchConfiguration, ISelectionSet, ISketchGraphicsChange, ISolutionSpatialReferenceInfo, ISpatialRefRepresentation, IValueChange, theme } from "./utils/interfaces";
import { LayerExpression } from "@esri/instant-apps-components";
import { UserSession } from "@esri/solution-common";
export { DistanceUnit, EDrawMode, ELayoutMode, IBasemapConfig, IExportInfos, IInventoryItem, ILayerAndTableIds, IMapChange, IMapInfo, ISearchConfiguration, ISelectionSet, ISketchGraphicsChange, ISolutionSpatialReferenceInfo, ISpatialRefRepresentation, IValueChange, theme } from "./utils/interfaces";
export { LayerExpression } from "@esri/instant-apps-components";
export { UserSession } from "@esri/solution-common";
export namespace Components {
interface ArcgisLogin {
Expand Down Expand Up @@ -93,6 +95,10 @@ export namespace Components {
* string: default center point values for the map ; delimited x;y pair
*/
"defaultCenter": string;
/**
* string: default layer expression to apply to the current layer
*/
"defaultFilter": string;
/**
* string: Global ID of the feature to select
*/
Expand Down Expand Up @@ -358,6 +364,10 @@ export namespace Components {
"value": any;
}
interface LayerTable {
/**
* LayerExpression[]: default layer expression(s) to apply to the current layer
*/
"defaultFilter": LayerExpression[];
/**
* string: Global ID of the feature to select
*/
Expand Down Expand Up @@ -1886,6 +1896,10 @@ declare namespace LocalJSX {
* string: default center point values for the map ; delimited x;y pair
*/
"defaultCenter"?: string;
/**
* string: default layer expression to apply to the current layer
*/
"defaultFilter"?: string;
/**
* string: Global ID of the feature to select
*/
Expand Down Expand Up @@ -2150,6 +2164,10 @@ declare namespace LocalJSX {
"value"?: any;
}
interface LayerTable {
/**
* LayerExpression[]: default layer expression(s) to apply to the current layer
*/
"defaultFilter"?: LayerExpression[];
/**
* string: Global ID of the feature to select
*/
Expand Down
20 changes: 20 additions & 0 deletions src/components/crowdsource-manager/crowdsource-manager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Component, Element, Host, h, Listen, Prop, State, VNode, Watch } from "
import CrowdsourceManager_T9n from "../../assets/t9n/crowdsource-manager/resources.json";
import { getLocaleComponentStrings } from "../../utils/locale";
import { ELayoutMode, IBasemapConfig, ILayerAndTableIds, IMapChange, IMapInfo, ISearchConfiguration, theme } from "../../utils/interfaces";
import { LayerExpression } from "@esri/instant-apps-components";

@Component({
tag: "crowdsource-manager",
Expand All @@ -44,6 +45,11 @@ export class CrowdsourceManager {
*/
@Prop() defaultCenter = "";

/**
* string: default layer expression to apply to the current layer
*/
@Prop() defaultFilter = "";

/**
* string: Global ID of the feature to select
*/
Expand Down Expand Up @@ -247,6 +253,11 @@ export class CrowdsourceManager {
*/
protected _defaultCenter: number[];

/**
* string: Definition expression to be used by current layer
*/
protected _defaultFilter: LayerExpression[];

/**
* string[]: List of global ids that should be selected by default
*/
Expand Down Expand Up @@ -298,6 +309,14 @@ export class CrowdsourceManager {
this.defaultCenter.split(";").map(v => parseFloat(v));
}

/**
* Watch for filter url param to be set
*/
@Watch("defaultFilter")
defaultFilterWatchHandler(): void {
this._defaultFilter = JSON.parse(this.defaultFilter);
}

/**
* Watch for globalid url param to be set
*/
Expand Down Expand Up @@ -814,6 +833,7 @@ export class CrowdsourceManager {
}
<div class={`width-full height-full position-relative`}>
<layer-table
defaultFilter={hasMapAndLayer ? this._defaultFilter : undefined}
defaultGlobalId={hasMapAndLayer ? this._defaultGlobalId : undefined}
defaultLayerId={hasMapAndLayer ? this.defaultLayer : ""}
defaultOid={hasMapAndLayer && !this.defaultGlobalId ? this._defaultOid : undefined}
Expand Down
1 change: 1 addition & 0 deletions src/components/crowdsource-manager/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
| ------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------ | ---------------------- | ----------- |
| `basemapConfig` | -- | IBasemapConfig: List of any basemaps to filter out from the basemap widget | `IBasemapConfig` | `undefined` |
| `defaultCenter` | `default-center` | string: default center point values for the map ; delimited x;y pair | `string` | `""` |
| `defaultFilter` | `default-filter` | string: default layer expression to apply to the current layer | `string` | `""` |
| `defaultGlobalId` | `default-global-id` | string: Global ID of the feature to select | `string` | `""` |
| `defaultLayer` | `default-layer` | string: when provided this layer ID will be used when the app loads | `string` | `""` |
| `defaultLevel` | `default-level` | string: default zoom level | `string` | `""` |
Expand Down
43 changes: 38 additions & 5 deletions src/components/layer-table/layer-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import { getLocaleComponentStrings } from "../../utils/locale";
import { getLayerOrTable, goToSelection } from "../../utils/mapViewUtils";
import { queryAllIds, queryFeatureIds, queryFeaturesByGlobalID } from "../../utils/queryUtils";
import * as downloadUtils from "../../utils/downloadUtils";
import { IColumnsInfo, IExportInfos, ILayerExpression, ILayerInfo, IMapClick, IMapInfo, IToolInfo, IToolSizeInfo } from "../../utils/interfaces";
import { IColumnsInfo, IExportInfos, ILayerInfo, IMapClick, IMapInfo, IToolInfo, IToolSizeInfo } from "../../utils/interfaces";
import "@esri/instant-apps-components/dist/components/instant-apps-social-share";
import { LayerExpression } from "@esri/instant-apps-components";

@Component({
tag: "layer-table",
Expand All @@ -44,15 +45,20 @@ export class LayerTable {
//--------------------------------------------------------------------------

/**
* string: when provided this layer ID will be used when the app loads
* LayerExpression[]: default layer expression(s) to apply to the current layer
*/
@Prop() defaultLayerId: string;
@Prop() defaultFilter: LayerExpression[];

/**
* string: Global ID of the feature to select
*/
@Prop() defaultGlobalId: string[];

/**
* string: when provided this layer ID will be used when the app loads
*/
@Prop() defaultLayerId: string;

/**
* number: when provided this will be used to select a feature in the table by default
*/
Expand Down Expand Up @@ -231,6 +237,11 @@ export class LayerTable {
*/
protected _editEnabled: boolean;

/**
* boolean: When true the default filter provided via url param has been honored and should now be ignored
*/
protected _defaultFilterHonored = false;

/**
* boolean: When true the default global id provided via url param has been honored and should now be ignored
*/
Expand Down Expand Up @@ -262,9 +273,9 @@ export class LayerTable {
protected _filterList: HTMLInstantAppsFilterListElement;

/**
* ILayerExpression[]: All layer expressions from the current filter config for the currently selected layer
* LayerExpression[]: All layer expressions from the current filter config for the currently selected layer
*/
protected _layerExpressions: ILayerExpression[];
protected _layerExpressions: LayerExpression[];

/**
* IHandle: The map click handle
Expand Down Expand Up @@ -1268,6 +1279,20 @@ export class LayerTable {
urlObj.searchParams.set("oid", this._selectedIndexes.join(","));
}

if (this._filterActive) {
const filter = JSON.parse(this._filterList.urlParams.get("filter"));
const layerExpressions = this._filterList.layerExpressions.map(layerExp => {
layerExp.expressions = layerExp.expressions.map(exp => {
if (exp.id.toString() === filter.expressionId.toString()) {
exp.active = true;
}
return exp;
})
return layerExp;
});
urlObj.searchParams.set("filter", JSON.stringify(layerExpressions));
}

this._shareNode.shareUrl = urlObj.href;
}

Expand Down Expand Up @@ -1545,6 +1570,12 @@ export class LayerTable {
}
this._defaultGlobalIdHonored = true;
}

if (!this._defaultFilterHonored && this.defaultFilter && this._filterList) {
this._layerExpressions = this.defaultFilter;
this._filterActive = true;
this._defaultFilterHonored = true;
}
});

this._showOnlySelected = false;
Expand Down Expand Up @@ -1709,13 +1740,15 @@ export class LayerTable {
*/
protected _handleFilterListReset(): void {
this._filterActive = false;
this._updateShareUrl();
}

/**
* Check if the layers definitionExpression has been modified
*/
protected _handleFilterUpdate(): void {
this._filterActive = this._definitionExpression !== this._layer.definitionExpression;
this._updateShareUrl();
}

/**
Expand Down
37 changes: 19 additions & 18 deletions src/components/layer-table/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------ | ---------- | ----------- |
| `defaultGlobalId` | -- | string: Global ID of the feature to select | `string[]` | `undefined` |
| `defaultLayerId` | `default-layer-id` | string: when provided this layer ID will be used when the app loads | `string` | `undefined` |
| `defaultOid` | -- | number: when provided this will be used to select a feature in the table by default | `number[]` | `undefined` |
| `enableAutoRefresh` | `enable-auto-refresh` | boolean: when true the layer table will auto refresh the data | `boolean` | `undefined` |
| `enableCSV` | `enable-c-s-v` | boolean: when true the export to csv button will be available | `boolean` | `undefined` |
| `enableColumnReorder` | `enable-column-reorder` | boolean: when true the layer table will support drag/drop of columns to adjust order | `boolean` | `true` |
| `enableInlineEdit` | `enable-inline-edit` | boolean: when true edits can be applied directly within the table | `boolean` | `undefined` |
| `enableShare` | `enable-share` | boolean: when true the share widget will be available | `boolean` | `undefined` |
| `isMobile` | `is-mobile` | When true the component will render an optimized view for mobile devices | `boolean` | `undefined` |
| `mapInfo` | -- | IMapInfo: key configuration details about the current map | `IMapInfo` | `undefined` |
| `mapView` | -- | esri/views/View: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html | `MapView` | `undefined` |
| `onlyShowUpdatableLayers` | `only-show-updatable-layers` | boolean: When true only editable layers that support the update capability will be available | `boolean` | `undefined` |
| `shareIncludeEmbed` | `share-include-embed` | boolean: When true the share options will include embed option | `boolean` | `undefined` |
| `shareIncludeSocial` | `share-include-social` | boolean: When true the share options will include social media sharing | `boolean` | `undefined` |
| `showNewestFirst` | `show-newest-first` | boolean: when true the table will be sorted by objectid in descending order by default | `boolean` | `undefined` |
| `zoomAndScrollToSelected` | `zoom-and-scroll-to-selected` | boolean: When true the selected feature will zoomed to in the map and the row will be scrolled to within the table | `boolean` | `undefined` |
| Property | Attribute | Description | Type | Default |
| ------------------------- | ----------------------------- | ------------------------------------------------------------------------------------------------------------------ | ------------------- | ----------- |
| `defaultFilter` | -- | LayerExpression[]: default layer expression(s) to apply to the current layer | `LayerExpression[]` | `undefined` |
| `defaultGlobalId` | -- | string: Global ID of the feature to select | `string[]` | `undefined` |
| `defaultLayerId` | `default-layer-id` | string: when provided this layer ID will be used when the app loads | `string` | `undefined` |
| `defaultOid` | -- | number: when provided this will be used to select a feature in the table by default | `number[]` | `undefined` |
| `enableAutoRefresh` | `enable-auto-refresh` | boolean: when true the layer table will auto refresh the data | `boolean` | `undefined` |
| `enableCSV` | `enable-c-s-v` | boolean: when true the export to csv button will be available | `boolean` | `undefined` |
| `enableColumnReorder` | `enable-column-reorder` | boolean: when true the layer table will support drag/drop of columns to adjust order | `boolean` | `true` |
| `enableInlineEdit` | `enable-inline-edit` | boolean: when true edits can be applied directly within the table | `boolean` | `undefined` |
| `enableShare` | `enable-share` | boolean: when true the share widget will be available | `boolean` | `undefined` |
| `isMobile` | `is-mobile` | When true the component will render an optimized view for mobile devices | `boolean` | `undefined` |
| `mapInfo` | -- | IMapInfo: key configuration details about the current map | `IMapInfo` | `undefined` |
| `mapView` | -- | esri/views/View: https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html | `MapView` | `undefined` |
| `onlyShowUpdatableLayers` | `only-show-updatable-layers` | boolean: When true only editable layers that support the update capability will be available | `boolean` | `undefined` |
| `shareIncludeEmbed` | `share-include-embed` | boolean: When true the share options will include embed option | `boolean` | `undefined` |
| `shareIncludeSocial` | `share-include-social` | boolean: When true the share options will include social media sharing | `boolean` | `undefined` |
| `showNewestFirst` | `show-newest-first` | boolean: when true the table will be sorted by objectid in descending order by default | `boolean` | `undefined` |
| `zoomAndScrollToSelected` | `zoom-and-scroll-to-selected` | boolean: When true the selected feature will zoomed to in the map and the row will be scrolled to within the table | `boolean` | `undefined` |


## Events
Expand Down

0 comments on commit cc2189f

Please sign in to comment.