Skip to content

Commit

Permalink
fix(map-and-label): when modifying features on the map, tabs should s…
Browse files Browse the repository at this point in the history
…tay ordered by label not recently changed (#3626)
  • Loading branch information
jessicamcinchak authored Sep 5, 2024
1 parent 95d94bd commit 4db9b3a
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SiteAddress } from "@planx/components/FindProperty/model";
import { ErrorSummaryContainer } from "@planx/components/shared/Preview/ErrorSummaryContainer";
import { SchemaFields } from "@planx/components/shared/Schema/SchemaFields";
import { Feature, FeatureCollection, GeoJsonObject } from "geojson";
import sortBy from "lodash/sortBy";
import { useStore } from "pages/FlowEditor/lib/store";
import React, { useEffect, useState } from "react";
import { FONT_WEIGHT_SEMI_BOLD } from "theme";
Expand Down Expand Up @@ -60,6 +61,9 @@ const VerticalFeatureTabs: React.FC<{ features: Feature[] }> = ({
const { schema, activeIndex, formik, editFeature, isFeatureInvalid } =
useMapAndLabelContext();

// Features is inherently sorted by recently added/modified, order tabs by stable labels
const sortedFeatures = sortBy(features, ["properties.label"]);

return (
<Box
sx={{
Expand Down Expand Up @@ -88,7 +92,7 @@ const VerticalFeatureTabs: React.FC<{ features: Feature[] }> = ({
borderColor: (theme) => theme.palette.border.main,
}}
>
{features.map((feature, i) => (
{sortedFeatures.map((feature, i) => (
<StyledTab
key={`tab-${i}`}
value={i.toString()}
Expand All @@ -104,7 +108,7 @@ const VerticalFeatureTabs: React.FC<{ features: Feature[] }> = ({
/>
))}
</Tabs>
{features.map((feature, i) => (
{sortedFeatures.map((feature, i) => (
<TabPanel
key={`tabpanel-${i}`}
value={i.toString()}
Expand Down

0 comments on commit 4db9b3a

Please sign in to comment.