mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
fix tool disabling for docs and others (#5722)
# Description of Changes <!-- Please provide a summary of the changes, including: - What was changed - Why the change was made - Any challenges encountered Closes #(issue_number) --> --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### Translations (if applicable) - [ ] I ran [`scripts/counter_translation.py`](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/docs/counter_translation.md) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details.
This commit is contained in:
+101
-10
@@ -1,6 +1,6 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button, Stack, Paper, Text, Loader, Group, MultiSelect } from '@mantine/core';
|
||||
import { Button, Stack, Paper, Text, Loader, Group, MultiSelect, Switch } from '@mantine/core';
|
||||
import { alert } from '@app/components/toast';
|
||||
import RestartConfirmationModal from '@app/components/shared/config/RestartConfirmationModal';
|
||||
import { useRestartServer } from '@app/components/shared/config/useRestartServer';
|
||||
@@ -9,6 +9,11 @@ import PendingBadge from '@app/components/shared/config/PendingBadge';
|
||||
import { useLoginRequired } from '@app/hooks/useLoginRequired';
|
||||
import LoginRequiredBanner from '@app/components/shared/config/LoginRequiredBanner';
|
||||
|
||||
interface UISettingsData {
|
||||
defaultHideUnavailableTools?: boolean;
|
||||
defaultHideUnavailableConversions?: boolean;
|
||||
}
|
||||
|
||||
interface EndpointsSettingsData {
|
||||
toRemove?: string[];
|
||||
groupsToRemove?: string[];
|
||||
@@ -31,11 +36,24 @@ export default function AdminEndpointsSection() {
|
||||
sectionName: 'endpoints',
|
||||
});
|
||||
|
||||
const {
|
||||
settings: uiSettings,
|
||||
setSettings: setUiSettings,
|
||||
loading: uiLoading,
|
||||
saving: uiSaving,
|
||||
fetchSettings: fetchUiSettings,
|
||||
saveSettings: saveUiSettings,
|
||||
isFieldPending: isUiFieldPending,
|
||||
} = useAdminSettings<UISettingsData>({
|
||||
sectionName: 'ui',
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (loginEnabled) {
|
||||
fetchSettings();
|
||||
fetchUiSettings();
|
||||
}
|
||||
}, [loginEnabled, fetchSettings]);
|
||||
}, [loginEnabled, fetchSettings, fetchUiSettings]);
|
||||
|
||||
const handleSave = async () => {
|
||||
if (!validateLoginEnabled()) {
|
||||
@@ -54,8 +72,29 @@ export default function AdminEndpointsSection() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleUiSave = async () => {
|
||||
if (!validateLoginEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await saveUiSettings();
|
||||
alert({
|
||||
alertType: 'success',
|
||||
title: t('admin.success', 'Success'),
|
||||
body: t('admin.settings.saveSuccess', 'Settings saved successfully. Restart required for changes to take effect.'),
|
||||
});
|
||||
} catch (_error) {
|
||||
alert({
|
||||
alertType: 'error',
|
||||
title: t('admin.error', 'Error'),
|
||||
body: t('admin.settings.saveError', 'Failed to save settings'),
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// Override loading state when login is disabled
|
||||
const actualLoading = loginEnabled ? loading : false;
|
||||
const actualLoading = loginEnabled ? (loading || uiLoading) : false;
|
||||
|
||||
if (actualLoading) {
|
||||
return (
|
||||
@@ -77,11 +116,16 @@ export default function AdminEndpointsSection() {
|
||||
'auto-redact',
|
||||
'auto-rename',
|
||||
'auto-split-pdf',
|
||||
'automate',
|
||||
'booklet-imposition',
|
||||
'cert-sign',
|
||||
'compare',
|
||||
'compress-pdf',
|
||||
'crop',
|
||||
'dev-airgapped-docs',
|
||||
'dev-api-docs',
|
||||
'dev-folder-scanning-docs',
|
||||
'dev-sso-guide-docs',
|
||||
'edit-table-of-contents',
|
||||
'eml-to-pdf',
|
||||
'extract-image-scans',
|
||||
@@ -109,6 +153,7 @@ export default function AdminEndpointsSection() {
|
||||
'pdf-to-text',
|
||||
'pdf-to-word',
|
||||
'pdf-to-xml',
|
||||
'pipeline',
|
||||
'rearrange-pages',
|
||||
'remove-annotations',
|
||||
'remove-blanks',
|
||||
@@ -143,6 +188,9 @@ export default function AdminEndpointsSection() {
|
||||
'Security',
|
||||
'Other',
|
||||
'Advance',
|
||||
'Automation',
|
||||
'DeveloperTools',
|
||||
'DeveloperDocs',
|
||||
// Tool Groups
|
||||
'CLI',
|
||||
'Python',
|
||||
@@ -224,18 +272,61 @@ export default function AdminEndpointsSection() {
|
||||
disabled={!loginEnabled}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Paper bg="var(--mantine-color-blue-light)" p="sm" radius="sm">
|
||||
<Text size="xs" c="dimmed">
|
||||
{t('admin.settings.endpoints.note', 'Note: Disabling endpoints restricts API access but does not remove UI components. Restart required for changes to take effect.')}
|
||||
</Text>
|
||||
</Paper>
|
||||
</Stack>
|
||||
</Paper>
|
||||
|
||||
<Group justify="flex-end">
|
||||
<Button onClick={handleSave} loading={saving} size="sm" disabled={!loginEnabled}>
|
||||
{t('admin.settings.save', 'Save Changes')}
|
||||
{t('admin.settings.save', 'Save Endpoint Settings')}
|
||||
</Button>
|
||||
</Group>
|
||||
|
||||
<Paper withBorder p="md" radius="md">
|
||||
<Stack gap="md">
|
||||
<div>
|
||||
<Text fw={600} size="sm" mb="xs">{t('admin.settings.endpoints.userDefaults', 'User Preference Defaults')}</Text>
|
||||
<Text size="xs" c="dimmed">
|
||||
{t('admin.settings.endpoints.userDefaultsDescription', 'Set default values for user preferences. Users can override these in their personal settings.')}
|
||||
</Text>
|
||||
</div>
|
||||
|
||||
<Switch
|
||||
label={
|
||||
<Group gap="xs">
|
||||
<span>{t('admin.settings.endpoints.defaultHideUnavailableTools.label', 'Hide unavailable tools by default')}</span>
|
||||
<PendingBadge show={isUiFieldPending('defaultHideUnavailableTools')} />
|
||||
</Group>
|
||||
}
|
||||
description={t('admin.settings.endpoints.defaultHideUnavailableTools.description', 'Remove disabled tools instead of showing them greyed out')}
|
||||
checked={uiSettings.defaultHideUnavailableTools || false}
|
||||
onChange={(e) => {
|
||||
if (!loginEnabled) return;
|
||||
setUiSettings({ ...uiSettings, defaultHideUnavailableTools: e.currentTarget.checked });
|
||||
}}
|
||||
disabled={!loginEnabled}
|
||||
/>
|
||||
|
||||
<Switch
|
||||
label={
|
||||
<Group gap="xs">
|
||||
<span>{t('admin.settings.endpoints.defaultHideUnavailableConversions.label', 'Hide unavailable conversions by default')}</span>
|
||||
<PendingBadge show={isUiFieldPending('defaultHideUnavailableConversions')} />
|
||||
</Group>
|
||||
}
|
||||
description={t('admin.settings.endpoints.defaultHideUnavailableConversions.description', 'Remove disabled conversion options instead of showing them greyed out')}
|
||||
checked={uiSettings.defaultHideUnavailableConversions || false}
|
||||
onChange={(e) => {
|
||||
if (!loginEnabled) return;
|
||||
setUiSettings({ ...uiSettings, defaultHideUnavailableConversions: e.currentTarget.checked });
|
||||
}}
|
||||
disabled={!loginEnabled}
|
||||
/>
|
||||
</Stack>
|
||||
</Paper>
|
||||
|
||||
<Group justify="flex-end">
|
||||
<Button onClick={handleUiSave} loading={uiSaving} size="sm" disabled={!loginEnabled}>
|
||||
{t('admin.settings.save', 'Save User Defaults')}
|
||||
</Button>
|
||||
</Group>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user