|
106 | 106 | } |
107 | 107 |
|
108 | 108 | $: if (!isWorkspaceLoading && selectedFilePath !== activeFilePath) { |
109 | | - console.log(`reactive nav! active: ${activeFilePath}, selected: ${selectedFilePath}`); |
110 | 109 | // the UI's selected file doesn't match our actively loaded file, try to navigate to selected |
111 | 110 | maybeNavigate(selectedFilePath); |
112 | 111 | } |
113 | 112 |
|
114 | | - async function maybeNavigate(nextPath: string | null) { |
115 | | - // don't navigate if the selected path is a text file and not a folder or binary |
116 | | - // treat `null` as a navigable path so we can intentionally unload the editor file rather than skipping |
117 | | - const isNavigableFileOrNull = (nextPath && isNavigableFile(workspaceTreeMap[nextPath]?.type)) || nextPath === null; |
118 | | - if (!isNavigableFileOrNull) { |
119 | | - // wait a tick then revert selected UI to the existing active path |
120 | | - await tick(); |
121 | | - selectedFilePath = activeFilePath; |
122 | | - return; |
123 | | - } |
124 | | -
|
125 | | - const didNavigate = await goToSequence(nextPath); |
126 | | - if (!didNavigate) { |
127 | | - // user decided not to navigate away due to unsaved changes, set selected UI back to active file |
128 | | - selectedFilePath = activeFilePath; |
129 | | - return; |
130 | | - } |
131 | | - // successfully navigated, update activeFilePath & get the file contents |
132 | | - activeFilePath = nextPath; |
133 | | - if (activeFilePath) { |
134 | | - const { filename } = separateFilenameFromPath(activeFilePath); |
135 | | - getSelectedFileContent(activeFilePath); |
136 | | - availableActionsForActiveFile = getAvailableActionsForNodes(allActionsForWorkspace, [ |
137 | | - workspaceTreeMap[activeFilePath], |
138 | | - ]); |
139 | | -
|
140 | | - if (filename) { |
141 | | - selectedFileName = filename; |
142 | | - selectedFileType = workspaceTreeMap[activeFilePath]?.type ?? null; |
143 | | - } else { |
144 | | - selectedFileName = undefined; |
145 | | - selectedFileType = null; |
146 | | - } |
147 | | - } else { |
148 | | - // navigated to a null/empty file, reset the editor contents |
149 | | - initialSelectedFileContent = ''; |
150 | | - updatedSelectedFileContent = initialSelectedFileContent; |
151 | | - selectedFileName = undefined; |
152 | | - selectedFileType = null; |
153 | | - } |
154 | | - } |
155 | | -
|
156 | 113 | $: if (initialWorkspace || $workspace) { |
157 | 114 | const ws: Workspace = $workspace ?? (initialWorkspace as Workspace); |
158 | 115 |
|
159 | 116 | hasEditWorkspacePermission = featurePermissions.workspace.canUpdate(user, ws); |
160 | 117 | hasEditWorkspaceCollaboratorsPermission = featurePermissions.workspaceCollaborators.canCreate(user, ws); |
161 | | - if (activeFilePath) { |
| 118 | + if (activeFilePath && workspaceTreeMap[activeFilePath]) { |
162 | 119 | hasEditFilePermission = featurePermissions.workspace.canUpdate(user, ws, workspaceTreeMap[activeFilePath]); |
| 120 | + availableActionsForActiveFile = getAvailableActionsForNodes(allActionsForWorkspace, [ |
| 121 | + workspaceTreeMap[activeFilePath], |
| 122 | + ]); |
163 | 123 | } else { |
164 | 124 | hasEditFilePermission = featurePermissions.workspace.canUpdate(user, ws); |
| 125 | + availableActionsForActiveFile = []; |
165 | 126 | } |
166 | 127 | } |
167 | 128 |
|
|
216 | 177 | } |
217 | 178 | } |
218 | 179 |
|
| 180 | + async function maybeNavigate(nextPath: string | null) { |
| 181 | + // don't navigate if the selected path is a text file and not a folder or binary |
| 182 | + // treat `null` as a navigable path so we can intentionally unload the editor file rather than skipping |
| 183 | + const isNavigableFileOrNull = (nextPath && isNavigableFile(workspaceTreeMap[nextPath]?.type)) || nextPath === null; |
| 184 | + if (!isNavigableFileOrNull) { |
| 185 | + // wait a tick then revert selected UI to the existing active path |
| 186 | + await tick(); |
| 187 | + selectedFilePath = activeFilePath; |
| 188 | + return; |
| 189 | + } |
| 190 | +
|
| 191 | + const didNavigate = await goToSequence(nextPath); |
| 192 | + if (!didNavigate) { |
| 193 | + // user decided not to navigate away due to unsaved changes, set selected UI back to active file |
| 194 | + selectedFilePath = activeFilePath; |
| 195 | + return; |
| 196 | + } |
| 197 | + // successfully navigated, update activeFilePath & get the file contents |
| 198 | + activeFilePath = nextPath; |
| 199 | + if (activeFilePath) { |
| 200 | + const { filename } = separateFilenameFromPath(activeFilePath); |
| 201 | + getSelectedFileContent(activeFilePath); |
| 202 | +
|
| 203 | + if (filename) { |
| 204 | + selectedFileName = filename; |
| 205 | + selectedFileType = workspaceTreeMap[activeFilePath]?.type ?? null; |
| 206 | + } else { |
| 207 | + selectedFileName = undefined; |
| 208 | + selectedFileType = null; |
| 209 | + } |
| 210 | + } else { |
| 211 | + // navigated to a null/empty file, reset the editor contents |
| 212 | + initialSelectedFileContent = ''; |
| 213 | + updatedSelectedFileContent = initialSelectedFileContent; |
| 214 | + selectedFileName = undefined; |
| 215 | + selectedFileType = null; |
| 216 | + } |
| 217 | + } |
| 218 | +
|
219 | 219 | function resetRefreshInterval() { |
220 | 220 | if (refreshInterval !== null) { |
221 | 221 | clearInterval(refreshInterval); |
|
0 commit comments