|
87 | 87 | cloneNodeAndRefresh,
|
88 | 88 | deleteNodeAndRefresh,
|
89 | 89 | deleteNodesAndRefresh,
|
90 |
| - show: showChildren(nodeIndex, node), |
| 90 | + show: visibility[nodeIndex].show, |
91 | 91 | }"
|
92 | 92 | ></slot>
|
93 | 93 | <ActionButton
|
|
99 | 99 | :size="size"
|
100 | 100 | round
|
101 | 101 | :disabled="selectedNodes.some(([n]) => n)"
|
102 |
| - @click="updateNodeAndRefresh(node)" |
| 102 | + @click="() => updateNodeAndRefresh(node)" |
103 | 103 | >
|
104 | 104 | <IconFa name="pencil" />
|
105 | 105 | </ActionButton>
|
|
119 | 119 | :size="size"
|
120 | 120 | :disabled="selectedNodes.some(([n]) => n)"
|
121 | 121 | toggle="dropdown"
|
122 |
| - @click="setModel()" |
| 122 | + @click="() => setModel()" |
123 | 123 | >
|
124 | 124 | <IconFa name="ellipsis-vertical" />
|
125 | 125 | </ActionLink>
|
|
131 | 131 | :theme="invertedTheme"
|
132 | 132 | :size="size"
|
133 | 133 | :aria-label="t('table_duplicate')"
|
134 |
| - @click="cloneNodeAndRefresh(node, setModel)" |
| 134 | + @click="() => cloneNodeAndRefresh(node, setModel)" |
135 | 135 | >
|
136 | 136 | <IconFa name="clone" />
|
137 | 137 | <span>
|
|
145 | 145 | :size="size"
|
146 | 146 | :aria-label="t('table_delete')"
|
147 | 147 | @click="
|
148 |
| - deleteNodeAndRefresh(node, setModel, dropdownRef) |
| 148 | + () => |
| 149 | + deleteNodeAndRefresh( |
| 150 | + node, |
| 151 | + setModel, |
| 152 | + dropdownRef |
| 153 | + ) |
149 | 154 | "
|
150 | 155 | >
|
151 | 156 | <IconFa name="trash-can" />
|
|
160 | 165 | cloneNodeAndRefresh,
|
161 | 166 | deleteNodeAndRefresh,
|
162 | 167 | deleteNodesAndRefresh,
|
163 |
| - show: showChildren(nodeIndex, node), |
| 168 | + show: visibility[nodeIndex].show, |
164 | 169 | }"
|
165 | 170 | ></slot>
|
166 | 171 | </ul>
|
|
173 | 178 | <tr class="no--hover --width-100">
|
174 | 179 | <td :colspan="propertiesMeta.length + 2">
|
175 | 180 | <div
|
176 |
| - v-show="showChildren(nodeIndex, node)" |
| 181 | + v-show="visibility[nodeIndex].show" |
177 | 182 | class="box --button --bdr-solid --bgColor-none"
|
178 | 183 | >
|
179 | 184 | <slot
|
|
183 | 188 | cloneNodeAndRefresh,
|
184 | 189 | deleteNodeAndRefresh,
|
185 | 190 | deleteNodesAndRefresh,
|
186 |
| - show: showChildren(nodeIndex, node), |
| 191 | + show: visibility[nodeIndex].show, |
187 | 192 | }"
|
188 | 193 | ></slot>
|
189 | 194 | </div>
|
|
195 | 200 | <ActionLink
|
196 | 201 | :theme="theme || themeValues"
|
197 | 202 | :size="size"
|
198 |
| - :active="showChildren(nodeIndex, node)" |
| 203 | + :active="visibility[nodeIndex].show" |
199 | 204 | :tooltip="
|
200 | 205 | t(
|
201 |
| - showChildren(nodeIndex, node) |
| 206 | + visibility[nodeIndex].show |
202 | 207 | ? 'table_hide_name'
|
203 | 208 | : 'table_see_name',
|
204 | 209 | {
|
|
210 | 215 | )
|
211 | 216 | "
|
212 | 217 | tooltip-position="right"
|
213 |
| - :disabled="!childrenCount(node) || showNodeChildren?.(node)" |
| 218 | + :disabled=" |
| 219 | + !visibility[nodeIndex].childrenCount || |
| 220 | + visibility[nodeIndex].showNodeChildren |
| 221 | + " |
214 | 222 | class="--p-5"
|
215 |
| - @click="toggleChildren(nodeIndex)" |
| 223 | + @click="() => toggleChildren(nodeIndex)" |
216 | 224 | >
|
217 |
| - <span v-if="childrenCount(node) >= 1"> |
218 |
| - {{ childrenCount(node) }} |
| 225 | + <span v-if="visibility[nodeIndex].childrenCount >= 1"> |
| 226 | + {{ visibility[nodeIndex].childrenCount }} |
219 | 227 | </span>
|
220 | 228 | <IconFa name="chevron-down" indicator />
|
221 | 229 | </ActionLink>
|
222 | 230 | <ActionButtonLink
|
223 | 231 | v-if="createNodeChildren"
|
224 | 232 | :theme="theme || themeValues"
|
225 | 233 | :size="size"
|
226 |
| - :disabled="!!disableCreateNodeChildren?.(node)" |
| 234 | + :disabled="visibility[nodeIndex].disableCreateNodeChildren" |
227 | 235 | :tooltip="
|
228 | 236 | t('table_create_new_name', {
|
229 | 237 | name:
|
|
236 | 244 | class="--p-5:md-inv"
|
237 | 245 | link-button
|
238 | 246 | round
|
239 |
| - @click="createNodeChildren(node)" |
| 247 | + @click="() => createNodeChildren?.(node)" |
240 | 248 | >
|
241 | 249 | <IconFa name="plus" />
|
242 | 250 | </ActionButtonLink>
|
|
254 | 262 | </template>
|
255 | 263 |
|
256 | 264 | <script setup lang="ts" generic="T extends Record<string, any>">
|
| 265 | + import { computed } from "vue"; |
| 266 | +
|
257 | 267 | import { useI18n } from "@open-xamu-co/ui-common-helpers";
|
258 | 268 |
|
259 | 269 | import IconFa from "../icon/Fa.vue";
|
|
270 | 280 |
|
271 | 281 | export interface iTableBodyProps<Ti extends Record<string, any>> extends iTableChildProps<Ti> {}
|
272 | 282 |
|
| 283 | + interface INodeVisibility { |
| 284 | + disableCreateNodeChildren?: boolean; |
| 285 | + showNodeChildren?: boolean; |
| 286 | + childrenCount: number; |
| 287 | + show: boolean; |
| 288 | + } |
| 289 | +
|
273 | 290 | /**
|
274 | 291 | * Table body
|
275 | 292 | *
|
|
283 | 300 | const { t } = useHelpers(useI18n);
|
284 | 301 | const { themeValues, dangerThemeValues } = useTheme(props);
|
285 | 302 |
|
286 |
| - /** Can the node be shown? */ |
287 |
| - function showChildren(nodeIndex: number, node: T) { |
288 |
| - const shouldShow = props.selectedNodes[nodeIndex][1] && !!props.childrenCount(node); |
| 303 | + /** |
| 304 | + * Cached node visibility |
| 305 | + */ |
| 306 | + const visibility = computed(() => { |
| 307 | + return props.nodes.reduce( |
| 308 | + (acc, node, nodeIndex) => { |
| 309 | + const disableCreateNodeChildren = props.disableCreateNodeChildren?.(node); |
| 310 | + const showNodeChildren = props.showNodeChildren?.(node); |
| 311 | + const childrenCount = props.childrenCount(node); |
| 312 | + const shouldShow = props.selectedNodes[nodeIndex][1] && !!childrenCount; |
289 | 313 |
|
290 |
| - return props.showNodeChildren?.(node) ?? shouldShow; |
291 |
| - } |
| 314 | + acc[nodeIndex] = { |
| 315 | + disableCreateNodeChildren, |
| 316 | + showNodeChildren, |
| 317 | + childrenCount, |
| 318 | + show: showNodeChildren ?? shouldShow, |
| 319 | + }; |
| 320 | +
|
| 321 | + return acc; |
| 322 | + }, |
| 323 | + {} as Record<number, INodeVisibility> |
| 324 | + ); |
| 325 | + }); |
292 | 326 | </script>
|
0 commit comments