| 1 |
import React, { useEffect, useMemo } from 'react' |
| 2 |
import { fetchQueryParam } from '../../utils/urls' |
| 3 |
import { Toolbar } from '../common/Toolbar' |
| 4 |
import { CommunityCloud } from './CommunityCloud/CommunityCloud' |
| 5 |
import { SnippetsTable } from './SnippetsTable' |
| 6 |
|
| 7 |
const repositionTableOptionsSettings = () => { |
| 8 |
const screenOptionsForm = document.getElementById('adv-settings') |
| 9 |
const tableOptions = screenOptionsForm?.querySelector<HTMLFieldSetElement>('fieldset.table-options-prefs') |
| 10 |
// Locate the first column-visibility fieldset that is NOT the table-options one. |
| 11 |
// This relies on WordPress core rendering #adv-settings with .metabox-prefs fieldsets. |
| 12 |
// Verified against WP 6.5+ (core/Screen_Options). If WP changes this structure the |
| 13 |
// reordering will silently no-op, which is acceptable — it is a cosmetic improvement only. |
| 14 |
const columns = Array.from( |
| 15 |
screenOptionsForm?.querySelectorAll<HTMLFieldSetElement>('fieldset.metabox-prefs') ?? [] |
| 16 |
).find(fieldset => !fieldset.classList.contains('table-options-prefs')) |
| 17 |
|
| 18 |
if (screenOptionsForm && tableOptions && columns) { |
| 19 |
screenOptionsForm.insertBefore(tableOptions, columns) |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
export const ManageMenu = () => { |
| 24 |
const subpage = useMemo(() => fetchQueryParam('subpage'), []) |
| 25 |
|
| 26 |
useEffect(() => { |
| 27 |
if ('cloud-community' !== subpage) { |
| 28 |
repositionTableOptionsSettings() |
| 29 |
} |
| 30 |
}, [subpage]) |
| 31 |
|
| 32 |
return ( |
| 33 |
<> |
| 34 |
<Toolbar /> |
| 35 |
|
| 36 |
{'cloud-community' === subpage |
| 37 |
? <CommunityCloud /> |
| 38 |
: <SnippetsTable />} |
| 39 |
</> |
| 40 |
) |
| 41 |
} |
| 42 |
|