Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: module tree expansion state when closing the module of the selected decl #3022

Merged
merged 3 commits into from
Oct 7, 2024
Merged
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
24 changes: 12 additions & 12 deletions frontend/console/src/features/modules/ModulesTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ const ModuleSection = ({
)
}

function getInitialExpandedModules(moduleName?: string, declName?: string): string[] {
if (moduleName && declName) {
addModuleToLocalStorageIfMissing(moduleName)
}
return listExpandedModulesFromLocalStorage()
}

const declTypesSearchParamKey = 'dt'

export const ModulesTree = ({ modules }: { modules: ModuleTreeItem[] }) => {
Expand All @@ -144,9 +137,13 @@ export const ModulesTree = ({ modules }: { modules: ModuleTreeItem[] }) => {
const declTypesFromUrl = declTypeMultiselectOpts.filter((o) => declTypeKeysFromUrl.includes(o.key))
const [selectedDeclTypes, setSelectedDeclTypes] = useState(declTypesFromUrl.length === 0 ? declTypeMultiselectOpts : declTypesFromUrl)

const [expandedModules, setExpandedModules] = useState(getInitialExpandedModules(moduleName, declName))
const initialExpanded = listExpandedModulesFromLocalStorage()
const [expandedModules, setExpandedModules] = useState(initialExpanded)
useEffect(() => {
setExpandedModules(getInitialExpandedModules(moduleName, declName))
if (moduleName && declName) {
addModuleToLocalStorageIfMissing(moduleName)
}
setExpandedModules(listExpandedModulesFromLocalStorage())
}, [moduleName, declName])

function msOnChange(opts: MultiselectOpt[]) {
Expand All @@ -160,14 +157,17 @@ export const ModulesTree = ({ modules }: { modules: ModuleTreeItem[] }) => {
setSelectedDeclTypes(opts)
}

function toggle(moduleName: string) {
toggleModuleExpansionInLocalStorage(moduleName)
function toggle(toggledModule: string) {
toggleModuleExpansionInLocalStorage(toggledModule)
setExpandedModules(listExpandedModulesFromLocalStorage())
}

function collapseAll() {
collapseAllModulesInLocalStorage()
setExpandedModules([])
if (moduleName && declName) {
addModuleToLocalStorageIfMissing(moduleName)
}
setExpandedModules(listExpandedModulesFromLocalStorage())
}

modules.sort((m1, m2) => Number(m1.isBuiltin) - Number(m2.isBuiltin))
Expand Down
Loading