Skip to content

Commit 8381c5e

Browse files
allow selection of country for named locations
1 parent c5ac3f3 commit 8381c5e

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

src/pages/tenant/conditional/list-named-locations/index.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
TrashIcon,
1212
} from "@heroicons/react/24/outline";
1313
import { LocationOn } from "@mui/icons-material";
14+
import countryList from "/src/data/countryList.json";
1415

1516
const Page = () => {
1617
const pageTitle = "Named Locations";
@@ -62,8 +63,18 @@ const Page = () => {
6263
namedLocationId: "id",
6364
change: "!addLocation",
6465
},
65-
fields: [{ type: "textField", name: "input", label: "Country Code" }],
66-
confirmText: "Enter a two-letter country code, e.g., US.",
66+
fields: [
67+
{
68+
type: "autoComplete",
69+
name: "input",
70+
label: "Country",
71+
options: countryList.map(({ Code, Name }) => ({
72+
value: Code,
73+
label: `${Name} (${Code})`,
74+
})),
75+
},
76+
],
77+
confirmText: "Select a country to add to this named location.",
6778
condition: (row) => row["@odata.type"] == "#microsoft.graph.countryNamedLocation",
6879
},
6980
{
@@ -75,8 +86,18 @@ const Page = () => {
7586
namedLocationId: "id",
7687
change: "!removeLocation",
7788
},
78-
fields: [{ type: "textField", name: "input", label: "Country Code" }],
79-
confirmText: "Enter a two-letter country code, e.g., US.",
89+
fields: [
90+
{
91+
type: "autoComplete",
92+
name: "input",
93+
label: "Country",
94+
options: countryList.map(({ Code, Name }) => ({
95+
value: Code,
96+
label: `${Name} (${Code})`,
97+
})),
98+
},
99+
],
100+
confirmText: "Select a country to remove from this named location.",
80101
condition: (row) => row["@odata.type"] == "#microsoft.graph.countryNamedLocation",
81102
},
82103
{

src/utils/get-cipp-formatting.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ import { getCippTranslation } from "./get-cipp-translation";
3232
import DOMPurify from "dompurify";
3333
import { getSignInErrorCodeTranslation } from "./get-cipp-signin-errorcode-translation";
3434
import { CollapsibleChipList } from "../components/CippComponents/CollapsibleChipList";
35+
import countryList from "../data/countryList.json";
36+
37+
// Helper function to convert country codes to country names
38+
const getCountryNameFromCode = (countryCode) => {
39+
const country = countryList.find((c) => c.Code === countryCode);
40+
return country ? country.Name : countryCode;
41+
};
3542

3643
export const getCippFormatting = (data, cellName, type, canReceive, flatten = true) => {
3744
const isText = type === "text";
@@ -416,6 +423,19 @@ export const getCippFormatting = (data, cellName, type, canReceive, flatten = tr
416423
return isText ? data : <CippCopyToClipBoard text={data} type="chip" />;
417424
}
418425

426+
if (cellName === "countriesAndRegions") {
427+
if (Array.isArray(data)) {
428+
const countryNames = data
429+
.filter((item) => item !== null && item !== undefined)
430+
.map((countryCode) => getCountryNameFromCode(countryCode));
431+
432+
return isText ? countryNames.join(", ") : renderChipList(countryNames);
433+
} else {
434+
const countryName = getCountryNameFromCode(data);
435+
return isText ? countryName : <CippCopyToClipBoard text={countryName} type="chip" />;
436+
}
437+
}
438+
419439
if (cellName === "excludedTenants") {
420440
// Handle null or undefined data
421441
if (data === null || data === undefined) {

0 commit comments

Comments
 (0)