Skip to content

Commit 7dd1fed

Browse files
authored
Merge pull request #32 from KelvinTegelaar/main
[pull] main from KelvinTegelaar:main
2 parents e0597eb + cefd906 commit 7dd1fed

File tree

14 files changed

+286
-235
lines changed

14 files changed

+286
-235
lines changed

src/components/CippComponents/CippBreadcrumbNav.jsx

Lines changed: 85 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,27 @@ export const CippBreadcrumbNav = () => {
6262
const titleCheckCountRef = useRef(0);
6363
const titleCheckIntervalRef = useRef(null);
6464

65+
// Helper function to filter out unnecessary query parameters
66+
const getCleanQueryParams = (query) => {
67+
const cleaned = { ...query };
68+
// Remove tenantFilter if it's "AllTenants" or not explicitly needed
69+
if (cleaned.tenantFilter === "AllTenants" || cleaned.tenantFilter === undefined) {
70+
delete cleaned.tenantFilter;
71+
}
72+
return cleaned;
73+
};
74+
75+
// Helper function to clean page titles
76+
const cleanPageTitle = (title) => {
77+
if (!title) return title;
78+
// Remove AllTenants and any surrounding separators
79+
return title
80+
.replace(/\s*-\s*AllTenants\s*/, "")
81+
.replace(/AllTenants\s*-\s*/, "")
82+
.replace(/AllTenants/, "")
83+
.trim();
84+
};
85+
6586
// Load tab options on mount
6687
useEffect(() => {
6788
loadTabOptions().then(setTabOptions);
@@ -109,6 +130,9 @@ export const CippBreadcrumbNav = () => {
109130
pageTitle = parts.slice(0, -1).join(" - ").trim();
110131
}
111132

133+
// Clean AllTenants from title
134+
pageTitle = cleanPageTitle(pageTitle);
135+
112136
// Skip if title is empty, generic, or error page
113137
if (
114138
!pageTitle ||
@@ -155,7 +179,10 @@ export const CippBreadcrumbNav = () => {
155179
if (samePath && !sameTitle) {
156180
// Same URL but title changed - update the entry
157181
const updated = [...prevHistory];
158-
updated[prevHistory.length - 1] = currentPage;
182+
updated[prevHistory.length - 1] = {
183+
...currentPage,
184+
query: getCleanQueryParams(currentPage.query),
185+
};
159186
if (titleCheckIntervalRef.current) {
160187
clearInterval(titleCheckIntervalRef.current);
161188
titleCheckIntervalRef.current = null;
@@ -173,7 +200,11 @@ export const CippBreadcrumbNav = () => {
173200

174201
// URL not in history (except possibly as last entry which we handled) - add as new entry
175202
if (existingIndex === -1) {
176-
const newHistory = [...prevHistory, currentPage];
203+
const cleanedCurrentPage = {
204+
...currentPage,
205+
query: getCleanQueryParams(currentPage.query),
206+
};
207+
const newHistory = [...prevHistory, cleanedCurrentPage];
177208

178209
// Keep only the last MAX_HISTORY_STORAGE pages
179210
const trimmedHistory =
@@ -192,7 +223,10 @@ export const CippBreadcrumbNav = () => {
192223
titleCheckIntervalRef.current = null;
193224
}
194225
const updated = prevHistory.slice(0, existingIndex + 1);
195-
updated[existingIndex] = currentPage;
226+
updated[existingIndex] = {
227+
...currentPage,
228+
query: getCleanQueryParams(currentPage.query),
229+
};
196230
return updated;
197231
});
198232
};
@@ -211,9 +245,10 @@ export const CippBreadcrumbNav = () => {
211245
const handleBreadcrumbClick = (index) => {
212246
const page = history[index];
213247
if (page) {
248+
const cleanedQuery = getCleanQueryParams(page.query);
214249
router.push({
215250
pathname: page.path,
216-
query: page.query,
251+
query: cleanedQuery,
217252
});
218253
}
219254
};
@@ -247,15 +282,18 @@ export const CippBreadcrumbNav = () => {
247282
return;
248283
}
249284

250-
const pageTitle = document.title.replace(" - CIPP", "").trim();
285+
let pageTitle = document.title.replace(" - CIPP", "").trim();
251286
const parts = pageTitle.split(" - ");
252287
const cleanTitle =
253288
parts.length > 1 && parts[parts.length - 1].includes(".")
254289
? parts.slice(0, -1).join(" - ").trim()
255290
: pageTitle;
256291

257-
if (cleanTitle && cleanTitle !== "CIPP" && !cleanTitle.toLowerCase().includes("loading")) {
258-
setCurrentPageTitle(cleanTitle);
292+
// Clean AllTenants from title
293+
const finalTitle = cleanPageTitle(cleanTitle);
294+
295+
if (finalTitle && finalTitle !== "CIPP" && !finalTitle.toLowerCase().includes("loading")) {
296+
setCurrentPageTitle(finalTitle);
259297
// Stop checking once we have a valid title
260298
if (hierarchicalTitleCheckRef.current) {
261299
clearInterval(hierarchicalTitleCheckRef.current);
@@ -316,11 +354,11 @@ export const CippBreadcrumbNav = () => {
316354

317355
// Check if this item matches the current path
318356
if (item.path && pathsMatch(item.path, currentPath)) {
319-
// If this is the current page, include current query params
357+
// If this is the current page, include current query params (cleaned)
320358
if (item.path === currentPath) {
321359
const lastItem = currentBreadcrumb[currentBreadcrumb.length - 1];
322360
if (lastItem) {
323-
lastItem.query = { ...router.query };
361+
lastItem.query = getCleanQueryParams(router.query);
324362
}
325363
}
326364
return currentBreadcrumb;
@@ -339,6 +377,32 @@ export const CippBreadcrumbNav = () => {
339377

340378
let result = findPathInMenu(nativeMenuItems);
341379

380+
// If we found a menu item, check if the current path matches any tab
381+
// If so, tabOptions wins and we use its label
382+
if (result.length > 0 && tabOptions.length > 0) {
383+
const normalizedCurrentPath = currentPath.replace(/\/$/, "");
384+
385+
// Check if current path matches any tab (exact match)
386+
const matchingTab = tabOptions.find((tab) => {
387+
const normalizedTabPath = tab.path.replace(/\/$/, "");
388+
return normalizedTabPath === normalizedCurrentPath;
389+
});
390+
391+
if (matchingTab) {
392+
// Tab matches the current path - use tab's label instead of config's
393+
result = result.map((item, idx) => {
394+
if (idx === result.length - 1) {
395+
return {
396+
...item,
397+
title: matchingTab.title,
398+
type: "tab",
399+
};
400+
}
401+
return item;
402+
});
403+
}
404+
}
405+
342406
// If not found in main menu, check if it's a tab page
343407
if (result.length === 0 && tabOptions.length > 0) {
344408
const normalizedCurrentPath = currentPath.replace(/\/$/, "");
@@ -395,12 +459,12 @@ export const CippBreadcrumbNav = () => {
395459
if (basePagePath.length > 0) {
396460
result = basePagePath;
397461

398-
// Add the tab as the final breadcrumb with current query params
462+
// Add the tab as the final breadcrumb with current query params (cleaned)
399463
result.push({
400464
title: matchingTab.title,
401465
path: matchingTab.path,
402466
type: "tab",
403-
query: { ...router.query }, // Include current query params for tab page
467+
query: getCleanQueryParams(router.query), // Include current query params for tab page
404468
});
405469
}
406470
}
@@ -411,7 +475,10 @@ export const CippBreadcrumbNav = () => {
411475
const lastItem = result[result.length - 1];
412476
if (lastItem.path && lastItem.path !== currentPath && currentPath.startsWith(lastItem.path)) {
413477
// Use the tracked page title if available, otherwise fall back to document.title
414-
const tabTitle = currentPageTitle || document.title.replace(" - CIPP", "").trim();
478+
let tabTitle = currentPageTitle || document.title.replace(" - CIPP", "").trim();
479+
480+
// Clean AllTenants from title
481+
tabTitle = cleanPageTitle(tabTitle);
415482

416483
// Add tab as an additional breadcrumb item
417484
if (
@@ -423,7 +490,7 @@ export const CippBreadcrumbNav = () => {
423490
title: tabTitle,
424491
path: currentPath,
425492
type: "tab",
426-
query: { ...router.query }, // Include current query params
493+
query: getCleanQueryParams(router.query), // Include current query params (cleaned)
427494
});
428495
}
429496
}
@@ -435,10 +502,11 @@ export const CippBreadcrumbNav = () => {
435502
// Handle click for hierarchical breadcrumbs
436503
const handleHierarchicalClick = (path, query) => {
437504
if (path) {
438-
if (query && Object.keys(query).length > 0) {
505+
const cleanedQuery = getCleanQueryParams(query);
506+
if (cleanedQuery && Object.keys(cleanedQuery).length > 0) {
439507
router.push({
440508
pathname: path,
441-
query: query,
509+
query: cleanedQuery,
442510
});
443511
} else {
444512
router.push(path);
@@ -478,7 +546,7 @@ export const CippBreadcrumbNav = () => {
478546
title,
479547
path,
480548
type: "fallback",
481-
query: index === pathSegments.length - 1 ? { ...router.query } : {},
549+
query: index === pathSegments.length - 1 ? getCleanQueryParams(router.query) : {},
482550
};
483551
});
484552

@@ -488,7 +556,7 @@ export const CippBreadcrumbNav = () => {
488556
currentPageTitle !== "CIPP" &&
489557
!currentPageTitle.toLowerCase().includes("loading")
490558
) {
491-
breadcrumbs[breadcrumbs.length - 1].title = currentPageTitle;
559+
breadcrumbs[breadcrumbs.length - 1].title = cleanPageTitle(currentPageTitle);
492560
}
493561
}
494562
}

src/components/CippComponents/CippTenantSelector.jsx

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export const CippTenantSelector = (props) => {
184184
// Cancel all in-flight queries before changing tenant
185185
queryClient.cancelQueries();
186186

187-
// Update router and settings
187+
// Update router only - let the URL watcher handle settings
188188
query.tenantFilter = currentTenant.value;
189189
router.replace(
190190
{
@@ -194,53 +194,52 @@ export const CippTenantSelector = (props) => {
194194
undefined,
195195
{ shallow: true }
196196
);
197-
198-
settings.handleUpdate({
199-
currentTenant: currentTenant.value,
200-
});
201197
}
202-
//if we have a tenantfilter, we add the tenantfilter to the title of the tab/page so its "Tenant - original title".
203198
}
204199
}, [currentTenant?.value]);
205200

206-
// This effect handles when the URL parameter changes externally
201+
// This effect handles when the URL parameter changes (from deep link or user selection)
202+
// This is the single source of truth for tenant changes
207203
useEffect(() => {
208-
if (!router.isReady || !tenantList.isSuccess || !settings.isInitialized) return;
204+
if (!router.isReady || !tenantList.isSuccess) return;
209205

210-
// Get the current tenant from URL or settings
211-
const urlTenant = router.query.tenantFilter || settings.currentTenant;
206+
const urlTenant = router.query.tenantFilter;
212207

213-
// Only update if there's a URL tenant and it's different from our current state
214-
if (urlTenant && (!currentTenant || urlTenant !== currentTenant.value)) {
208+
// Only process if we have a URL tenant
209+
if (urlTenant) {
215210
// Find the tenant in our list
216211
const matchingTenant = tenantList.data.find(
217212
({ defaultDomainName }) => defaultDomainName === urlTenant
218213
);
219214

220215
if (matchingTenant) {
221-
setSelectedTenant({
222-
value: urlTenant,
223-
label: `${matchingTenant.displayName} (${urlTenant})`,
224-
addedFields: {
225-
defaultDomainName: matchingTenant.defaultDomainName,
226-
displayName: matchingTenant.displayName,
227-
customerId: matchingTenant.customerId,
228-
initialDomainName: matchingTenant.initialDomainName,
229-
},
230-
});
216+
// Update local state if different
217+
if (!currentTenant || urlTenant !== currentTenant.value) {
218+
setSelectedTenant({
219+
value: urlTenant,
220+
label: `${matchingTenant.displayName} (${urlTenant})`,
221+
addedFields: {
222+
defaultDomainName: matchingTenant.defaultDomainName,
223+
displayName: matchingTenant.displayName,
224+
customerId: matchingTenant.customerId,
225+
initialDomainName: matchingTenant.initialDomainName,
226+
},
227+
});
228+
}
229+
230+
// Update settings if different (null filter in settings-context prevents saving null)
231+
if (settings.currentTenant !== urlTenant) {
232+
settings.handleUpdate({
233+
currentTenant: urlTenant,
234+
});
235+
}
231236
}
232237
}
233-
}, [
234-
router.isReady,
235-
router.query.tenantFilter,
236-
tenantList.isSuccess,
237-
settings.currentTenant,
238-
settings.isInitialized,
239-
]);
238+
}, [router.isReady, router.query.tenantFilter, tenantList.isSuccess]);
240239

241240
// This effect ensures the tenant filter parameter is included in the URL when missing
242241
useEffect(() => {
243-
if (!router.isReady || !settings.isInitialized || !settings.currentTenant) return;
242+
if (!router.isReady || !settings.currentTenant) return;
244243

245244
// If the tenant parameter is missing from the URL but we have it in settings
246245
if (!router.query.tenantFilter && settings.currentTenant) {
@@ -254,7 +253,7 @@ export const CippTenantSelector = (props) => {
254253
{ shallow: true }
255254
);
256255
}
257-
}, [router.isReady, router.query, settings.currentTenant, settings.isInitialized]);
256+
}, [router.isReady, router.query.tenantFilter, settings.currentTenant]);
258257

259258
useEffect(() => {
260259
if (tenant && currentTenant?.value && currentTenant?.value !== "AllTenants") {

src/components/CippStandards/CippStandardsSideBar.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ const CippStandardsSideBar = ({
556556
title="Add Standard"
557557
api={{
558558
confirmText: isDriftMode
559-
? "This template will automatically every hour to detect drift. Are you sure you want to apply this Drift Template?"
559+
? "This template will automatically every 12 hours to detect drift. Are you sure you want to apply this Drift Template?"
560560
: watchForm.runManually
561561
? "Are you sure you want to apply this standard? This template has been set to never run on a schedule. After saving the template you will have to run it manually."
562562
: "Are you sure you want to apply this standard? This will apply the template and run every 3 hours.",

src/layouts/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export const nativeMenuItems = [
195195
items: [
196196
{
197197
title: "Standards Management",
198-
path: "/tenant/standards/list-standards",
198+
path: "/tenant/standards/alignment",
199199
permissions: ["Tenant.Standards.*"],
200200
},
201201
{

src/pages/endpoint/MEM/devices/index.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,7 @@ const Page = () => {
178178
GUID: "id",
179179
Action: "resetPasscode",
180180
},
181-
condition: (row) =>
182-
row.operatingSystem === "iOS" ||
183-
row.operatingSystem === "macOS" ||
184-
row.operatingSystem === "Android",
181+
condition: (row) => row.operatingSystem === "Android",
185182
confirmText:
186183
"Are you sure you want to reset the passcode for [deviceName]? A new passcode will be generated and displayed.",
187184
},
@@ -194,10 +191,7 @@ const Page = () => {
194191
GUID: "id",
195192
Action: "removeDevicePasscode",
196193
},
197-
condition: (row) =>
198-
row.operatingSystem === "iOS" ||
199-
row.operatingSystem === "macOS" ||
200-
row.operatingSystem === "Android",
194+
condition: (row) => row.operatingSystem === "iOS",
201195
confirmText:
202196
"Are you sure you want to remove the passcode from [deviceName]? This will remove the device passcode requirement.",
203197
},

src/pages/tenant/administration/tenants/groups/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ const Page = () => {
148148
dynamicRules: formattedDynamicRules,
149149
});
150150
}
151-
}, [groupDetails.isSuccess, groupDetails.data]);
151+
}, [groupDetails.isSuccess, groupDetails.data, id]);
152152

153153
const customDataFormatter = (values) => {
154154
const formattedData = {

src/pages/tenant/manage/driftManagementActions.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ export const createDriftManagementActions = ({
4949
// Use Next.js router for internal navigation
5050
import("next/router")
5151
.then(({ default: router }) => {
52-
router.push(`/tenant/standards/template?id=${templateId}&type=${templateType}`);
52+
router.push(
53+
`/tenant/standards/templates/template?id=${templateId}&type=${templateType}`
54+
);
5355
})
5456
.catch(() => {
5557
// Fallback to window.location if router is not available
56-
window.location.href = `/tenant/standards/template?id=${templateId}&type=${templateType}`;
58+
window.location.href = `/tenant/standards/templates/template?id=${templateId}&type=${templateType}`;
5759
});
5860
},
5961
});

0 commit comments

Comments
 (0)