Skip to content

Commit

Permalink
Merge pull request #2507 from DenverCoder544/featuredata_add_id_column
Browse files Browse the repository at this point in the history
Featuredata add id column
  • Loading branch information
ZakarFin authored Nov 13, 2023
2 parents dc25bcb + 81fa2d8 commit 32ac063
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
24 changes: 16 additions & 8 deletions bundles/framework/featuredata/plugin/FeatureDataPluginHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { FEATUREDATA_BUNDLE_ID } from '../view/FeatureDataContainer';
import { filterFeaturesByPropertyFilter } from '../../../mapping/mapmodule/oskariStyle/filter';
import { cleanFilter } from 'oskari-ui/components/FeatureFilter';

export const FEATUREDATA_DEFAULT_HIDDEN_FIELDS = ['__fid', '__centerX', '__centerY', 'geometry'];
export const ID_FIELD = '__fid';
export const ID_FIELD_LABEL = 'ID';

export const SELECTION_SERVICE_CLASSNAME = 'Oskari.mapframework.service.VectorFeatureSelectionService';
const EXPORT_FEATUREDATA_ROUTE = 'ExportTableFile';
Expand Down Expand Up @@ -69,7 +70,7 @@ class FeatureDataPluginUIHandler extends StateHandler {
}
const features = layerId ? this.getFeaturesByLayerId(layerId) : null;
const selectedFeatureIds = layerId ? this.getSelectedFeatureIdsByLayerId(layerId) : null;
const visibleColumnsSettings = features && features.length ? this.createVisibleColumnsSettings(layerId, features) : null;
const visibleColumnsSettings = features && features.length ? this.createVisibleColumnsSettings(layerId) : null;
this.updateState({
activeLayerId: layerId,
activeLayerFeatures: features,
Expand Down Expand Up @@ -109,7 +110,7 @@ class FeatureDataPluginUIHandler extends StateHandler {
if (newActiveLayerId && this.getState().flyoutOpen) {
activeLayerFeatures = this.getFeaturesByLayerId(newActiveLayerId);
selectedFeatureIds = activeLayerFeatures && activeLayerFeatures.length ? this.getSelectedFeatureIdsByLayerId(newActiveLayerId) : null;
visibleColumnsSettings = this.createVisibleColumnsSettings(newActiveLayerId, activeLayerFeatures);
visibleColumnsSettings = this.createVisibleColumnsSettings(newActiveLayerId);
};

return {
Expand Down Expand Up @@ -197,7 +198,7 @@ class FeatureDataPluginUIHandler extends StateHandler {
newState.activeLayerFeatures = newActiveLayerFeatures;
newState.sorting = newActiveLayerFeatures && newActiveLayerFeatures.length ? this.determineSortingColumn(activeLayerId, newActiveLayerFeatures) : null;
newState.selectedFeatureIds = newActiveLayerFeatures && newActiveLayerFeatures.length ? this.getSelectedFeatureIdsByLayerId(activeLayerId) : null;
newState.visibleColumnsSettings = this.createVisibleColumnsSettings(activeLayerId, newActiveLayerFeatures);
newState.visibleColumnsSettings = this.createVisibleColumnsSettings(activeLayerId);
newState.selectByPropertiesFilter = {};
newState.selectByPropertiesFeatureTypes = this.createSelectByPropertiesFeatureTypes(newState.visibleColumnsSettings);
}
Expand Down Expand Up @@ -236,7 +237,7 @@ class FeatureDataPluginUIHandler extends StateHandler {
}
}

createVisibleColumnsSettings (newActiveLayerId, features) {
createVisibleColumnsSettings (newActiveLayerId) {
const { activeLayerId, visibleColumnsSettings } = this.getState();
const activeLayerChanged = activeLayerId && newActiveLayerId && activeLayerId !== newActiveLayerId;

Expand All @@ -246,10 +247,17 @@ class FeatureDataPluginUIHandler extends StateHandler {

const activeLayer = this.mapModule.getSandbox().findMapLayerFromSelectedMapLayers(newActiveLayerId) || null;
const activeLayerProperties = activeLayer?.getProperties() || null;
const allColumns = activeLayerProperties?.map((property) => property.name);
let allColumns = activeLayerProperties?.map((property) => property.name);
const activeLayerPropertyLabels = activeLayer?.getPropertyLabels() || null;
const activeLayerPropertyTypes = activeLayer?.getPropertyTypes() || null;
const newVisibleColumns = activeLayerChanged ? [].concat(allColumns) : visibleColumnsSettings?.visibleColumns ? visibleColumnsSettings.visibleColumns : [].concat(allColumns);
if (!allColumns.includes(ID_FIELD)) {
allColumns = [ID_FIELD].concat(allColumns);
}

if (activeLayerPropertyLabels && !activeLayerPropertyLabels[ID_FIELD]) {
activeLayerPropertyLabels[ID_FIELD] = ID_FIELD_LABEL;
}

return {
allColumns,
Expand Down Expand Up @@ -343,7 +351,7 @@ class FeatureDataPluginUIHandler extends StateHandler {
// so we're creating this in that case
let { visibleColumnsSettings } = this.getState();
if (!visibleColumnsSettings) {
visibleColumnsSettings = this.createVisibleColumnsSettings(activeLayerId, features);
visibleColumnsSettings = this.createVisibleColumnsSettings(activeLayerId);
}

// get the first property that isn't in the default hidden fields and use that as default.
Expand All @@ -354,7 +362,7 @@ class FeatureDataPluginUIHandler extends StateHandler {

columnShouldBeVisible (key, visibleColumnsSettings) {
const { visibleColumns } = visibleColumnsSettings;
return !FEATUREDATA_DEFAULT_HIDDEN_FIELDS.includes(key) && visibleColumns?.includes(key);
return visibleColumns?.includes(key);
}

sendExportDataForm (data) {
Expand Down
3 changes: 1 addition & 2 deletions bundles/framework/featuredata/view/FeatureDataContainer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Table } from 'oskari-ui/components/Table';
import styled from 'styled-components';
import { getHeaderTheme } from 'oskari-ui/theme/ThemeHelper';
import { ShowSelectedItemsFirst } from './ShowSelectedItemsFirst';
import { FEATUREDATA_DEFAULT_HIDDEN_FIELDS } from '../plugin/FeatureDataPluginHandler';
import { TabTitle } from './TabStatusIndicator';
import { FilterVisibleColumns } from './FilterVisibleColumns';
import { ExportButton } from './ExportData';
Expand Down Expand Up @@ -100,7 +99,7 @@ const createFeaturedataGrid = (features, selectedFeatureIds, showSelectedFirst,
const createColumnSettings = (selectedFeatureIds, showSelectedFirst, sorting, visibleColumnsSettings) => {
const { allColumns, visibleColumns, activeLayerPropertyLabels } = visibleColumnsSettings;
return allColumns
.filter(key => !FEATUREDATA_DEFAULT_HIDDEN_FIELDS.includes(key) && visibleColumns.includes(key))
.filter(key => visibleColumns.includes(key))
.map(key => {
return {
align: 'left',
Expand Down
2 changes: 0 additions & 2 deletions bundles/framework/featuredata/view/FilterVisibleColumns.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useState } from 'react';
import styled from 'styled-components';
import { Select, Message } from 'oskari-ui';
import PropTypes from 'prop-types';
import { FEATUREDATA_DEFAULT_HIDDEN_FIELDS } from '../plugin/FeatureDataPluginHandler';
import { FEATUREDATA_BUNDLE_ID } from './FeatureDataContainer';

const FilterVisibleColumnsContainer = styled('div')`
Expand Down Expand Up @@ -40,7 +39,6 @@ const createOptions = (allColumns, activeLayerPropertyLabels) => {
}

return allColumns
.filter(key => !FEATUREDATA_DEFAULT_HIDDEN_FIELDS.includes(key))
.map(key => {
return {
label: activeLayerPropertyLabels && activeLayerPropertyLabels[key] ? activeLayerPropertyLabels[key] : key,
Expand Down

0 comments on commit 32ac063

Please sign in to comment.