Skip to content

Commit abe1736

Browse files
committed
frontend: Settings: resourceMap: configSlice: Add feature to keep resource maps expanded by default
1 parent 17c7f01 commit abe1736

File tree

19 files changed

+103
-9
lines changed

19 files changed

+103
-9
lines changed

frontend/src/components/App/Settings/Settings.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ export default function Settings() {
4444
const storedTimezone = settingsObj.timezone;
4545
const storedRowsPerPageOptions = settingsObj.tableRowsPerPageOptions;
4646
const storedSortSidebar = settingsObj.sidebarSortAlphabetically;
47+
const expandLargeGraph = settingsObj.expandLargeGraph;
4748
const storedUseEvict = settingsObj.useEvict;
4849
const [selectedTimezone, setSelectedTimezone] = useState<string>(
4950
storedTimezone || Intl.DateTimeFormat().resolvedOptions().timeZone
5051
);
5152
const [sortSidebar, setSortSidebar] = useState<boolean>(storedSortSidebar);
53+
const [expandGraph, setExpandGraph] = useState<boolean>(expandLargeGraph);
5254
const [useEvict, setUseEvict] = useState<boolean>(storedUseEvict);
5355
const dispatch = useDispatch();
5456
const themeName = useTypedSelector(state => state.theme.name);
@@ -78,10 +80,19 @@ export default function Settings() {
7880
);
7981
}, [useEvict]);
8082

83+
useEffect(() => {
84+
dispatch(
85+
setAppSettings({
86+
expandLargeGraph: expandGraph,
87+
})
88+
);
89+
}, [expandGraph]);
90+
8191
const sidebarLabelID = 'sort-sidebar-label';
8292
const evictLabelID = 'use-evict-label';
8393
const tableRowsLabelID = 'rows-per-page-label';
8494
const timezoneLabelID = 'timezone-label';
95+
const expandGraphID = 'expand-graph-label';
8596

8697
return (
8798
<SectionBox
@@ -161,6 +172,20 @@ export default function Settings() {
161172
),
162173
nameID: evictLabelID,
163174
},
175+
{
176+
name: t('translation|Keep Large Graph Groups Expanded'),
177+
value: (
178+
<Switch
179+
color="primary"
180+
checked={expandGraph}
181+
onChange={e => setExpandGraph(e.target.checked)}
182+
inputProps={{
183+
'aria-labelledby': expandGraphID,
184+
}}
185+
/>
186+
),
187+
nameID: expandGraphID,
188+
},
164189
]}
165190
/>
166191
<Box

frontend/src/components/App/Settings/__snapshots__/Settings.General.stories.storyshot

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,13 @@
382382
</span>
383383
</dd>
384384
<dt
385-
class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-3 MuiGrid-grid-md-2 css-1hrqr1q-MuiGrid-root"
385+
class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-3 MuiGrid-grid-md-2 css-9i4s51-MuiGrid-root"
386386
id="use-evict-label"
387387
>
388388
Use evict for pod deletion
389389
</dt>
390390
<dd
391-
class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-9 MuiGrid-grid-md-10 css-ui3itl-MuiGrid-root"
391+
class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-9 MuiGrid-grid-md-10 css-1dbzfsd-MuiGrid-root"
392392
>
393393
<span
394394
class="MuiSwitch-root MuiSwitch-sizeMedium css-julti5-MuiSwitch-root"
@@ -414,6 +414,38 @@
414414
/>
415415
</span>
416416
</dd>
417+
<dt
418+
class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-3 MuiGrid-grid-md-2 css-1hrqr1q-MuiGrid-root"
419+
id="expand-graph-label"
420+
>
421+
Keep Large Graph Groups Expanded
422+
</dt>
423+
<dd
424+
class="MuiGrid-root MuiGrid-item MuiGrid-grid-xs-12 MuiGrid-grid-sm-9 MuiGrid-grid-md-10 css-ui3itl-MuiGrid-root"
425+
>
426+
<span
427+
class="MuiSwitch-root MuiSwitch-sizeMedium css-julti5-MuiSwitch-root"
428+
>
429+
<span
430+
class="MuiButtonBase-root MuiSwitch-switchBase MuiSwitch-colorPrimary PrivateSwitchBase-root MuiSwitch-switchBase MuiSwitch-colorPrimary css-1emuodk-MuiButtonBase-root-MuiSwitch-switchBase"
431+
>
432+
<input
433+
aria-labelledby="expand-graph-label"
434+
class="PrivateSwitchBase-input MuiSwitch-input css-1m9pwf3"
435+
type="checkbox"
436+
/>
437+
<span
438+
class="MuiSwitch-thumb css-jsexje-MuiSwitch-thumb"
439+
/>
440+
<span
441+
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
442+
/>
443+
</span>
444+
<span
445+
class="MuiSwitch-track css-1yjjitx-MuiSwitch-track"
446+
/>
447+
</span>
448+
</dd>
417449
</dl>
418450
<div
419451
class="MuiBox-root css-1k57ox4"

frontend/src/components/project/NewProjectPopup.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const makeStore = () => {
4545
tableRowsPerPageOptions: [15, 25, 50],
4646
timezone: 'UTC',
4747
useEvict: true,
48+
sidebarSortAlphabetically: false,
49+
expandLargeGraph: false,
4850
},
4951
},
5052
projects: {

frontend/src/components/project/ProjectCreateFromYaml.stories.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ const makeStore = () => {
4444
tableRowsPerPageOptions: [15, 25, 50],
4545
timezone: 'UTC',
4646
useEvict: true,
47+
sidebarSortAlphabetically: false,
48+
expandLargeGraph: false,
4749
},
4850
},
4951
projects: {

frontend/src/components/resourceMap/GraphView.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,9 @@ function GraphViewContent({
168168
// Expand all groups state
169169
const [expandAll, setExpandAll] = useState(false);
170170

171+
// Expand by Default
172+
const expandLargeGraph = useTypedSelector(state => state.config.settings.expandLargeGraph);
173+
171174
// Load source data
172175
const { nodes, edges, selectedSources, sourceData, isLoading, toggleSelection } = useSources();
173176

@@ -198,11 +201,18 @@ function GraphViewContent({
198201
namespaces: allNamespaces ?? [],
199202
k8sNodes: allNodes ?? [],
200203
});
201-
202-
const visibleGraph = collapseGraph(graph, { selectedNodeId, expandAll });
204+
const visibleGraph = collapseGraph(graph, { selectedNodeId, expandAll, expandLargeGraph });
203205

204206
return { visibleGraph, fullGraph: graph };
205-
}, [filteredGraph, groupBy, selectedNodeId, expandAll, allNamespaces]);
207+
}, [
208+
filteredGraph,
209+
groupBy,
210+
selectedNodeId,
211+
expandAll,
212+
allNamespaces,
213+
allNodes,
214+
expandLargeGraph,
215+
]);
206216

207217
const viewport = useGraphViewport();
208218

frontend/src/components/resourceMap/graph/graphGrouping.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,22 @@ export function findGroupContaining(
395395
* @param graph Single graph node
396396
* @param params.selectedNodeId Graph node that is selected
397397
* @param params.expandAll Display all the children within all groups
398+
* @param params.expandLargeGraph When true, Keeps Large groups expanded
398399
* @returns Collapsed graph
399400
*/
400401
export function collapseGraph(
401402
graph: GraphNode,
402-
{ selectedNodeId = 'root', expandAll }: { selectedNodeId?: string; expandAll: boolean }
403+
{
404+
selectedNodeId = 'root',
405+
expandAll,
406+
expandLargeGraph = false,
407+
}: { selectedNodeId?: string; expandAll: boolean; expandLargeGraph?: boolean }
403408
) {
404409
let root = { ...graph };
405410
let selectedGroup: GraphNode | undefined;
406411

412+
const primaryNodeIds = new Set(graph.nodes?.map(n => n.id) || []);
413+
407414
if (selectedNodeId) {
408415
selectedGroup = findGroupContaining(graph, selectedNodeId);
409416
}
@@ -418,8 +425,9 @@ export function collapseGraph(
418425
const isBig = (group.nodes?.length ?? 0) > 10 || (group.edges?.length ?? 0) > 0;
419426
const isSelectedGroup = selectedGroup?.id === group.id;
420427
const isRoot = group.id === 'root';
421-
422-
const collapsed = !expandAll && !isRoot && !isSelectedGroup && isBig;
428+
const isPrimaryGroup = primaryNodeIds.has(group.id);
429+
const shouldExpandPrimary = !expandLargeGraph || !isPrimaryGroup;
430+
const collapsed = !expandAll && !isRoot && !isSelectedGroup && isBig && shouldExpandPrimary;
423431

424432
return {
425433
...group,

frontend/src/i18n/locales/de/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
"Timezone to display for dates": "Zeitzone",
158158
"Sort sidebar items alphabetically": "",
159159
"Use evict for pod deletion": "",
160+
"Keep Large Graph Groups Expanded": "",
160161
"Theme": "Design",
161162
"Keyboard Shortcuts": "",
162163
"Configure keyboard shortcuts for quick access to various parts of the application.": "",

frontend/src/i18n/locales/en/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
"Timezone to display for dates": "Timezone to display for dates",
158158
"Sort sidebar items alphabetically": "Sort sidebar items alphabetically",
159159
"Use evict for pod deletion": "Use evict for pod deletion",
160+
"Keep Large Graph Groups Expanded": "Keep Large Graph Groups Expanded",
160161
"Theme": "Theme",
161162
"Keyboard Shortcuts": "Keyboard Shortcuts",
162163
"Configure keyboard shortcuts for quick access to various parts of the application.": "Configure keyboard shortcuts for quick access to various parts of the application.",

frontend/src/i18n/locales/es/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
"Timezone to display for dates": "Huso horario para mostrar en fechas",
158158
"Sort sidebar items alphabetically": "",
159159
"Use evict for pod deletion": "",
160+
"Keep Large Graph Groups Expanded": "",
160161
"Theme": "Tema",
161162
"Keyboard Shortcuts": "",
162163
"Configure keyboard shortcuts for quick access to various parts of the application.": "",

frontend/src/i18n/locales/fr/translation.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
"Timezone to display for dates": "Fuseau horaire à afficher pour les dates",
158158
"Sort sidebar items alphabetically": "Trier les éléments de la barre latérale par ordre alphabétique",
159159
"Use evict for pod deletion": "Utiliser l'éviction pour la suppression de pods",
160+
"Keep Large Graph Groups Expanded": "",
160161
"Theme": "Thème",
161162
"Keyboard Shortcuts": "",
162163
"Configure keyboard shortcuts for quick access to various parts of the application.": "",

0 commit comments

Comments
 (0)