Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ export const DirectoryList = ({
relativePrefixToRoot,
}: {
streamDocument: StreamDocument;
directoryChildren: any[];
directoryChildren: {
id: string;
name: string;
slug: string;
meta?: {
entityType?: {
id: "dm_country" | "dm_region" | "dm_city";
};
};
dm_addressCountryDisplayName?: string;
dm_addressRegionDisplayName?: string;
}[];
relativePrefixToRoot: string;
}) => {
const sortedDirectoryChildren = sortAlphabetically(directoryChildren, "name");
Expand All @@ -44,10 +55,10 @@ export const DirectoryList = ({
let label;
switch (child?.meta?.entityType?.id) {
case "dm_country":
label = child.c_addressCountryDisplayName ?? child.name;
label = child.dm_addressCountryDisplayName ?? child.name;
break;
case "dm_region":
label = child.c_addressRegionDisplayName ?? child.name;
label = child.dm_addressRegionDisplayName ?? child.name;
break;
case "dm_city":
label = child.name;
Expand Down
6 changes: 3 additions & 3 deletions packages/visual-editor/src/utils/directory/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export const isDirectoryGrid = (children: string | any[]): boolean => {
// sortAlphabetically takes in an array of objects and sorts them alphabetically.
// They are sorted by the value of the field declared by sortBy.
// ex. if sortBy is name, the directoryChildren will be ordered by name alphabetically.
export const sortAlphabetically = (
directoryChildren: any[],
export const sortAlphabetically = <T extends Record<string, any>>(
directoryChildren: T[],
sortBy: string
) => {
): T[] => {
const sortFn = (p1: any, p2: any) => {
const val1 = p1[sortBy] ?? "";
const val2 = p2[sortBy] ?? "";
Expand Down