-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12942 from nextcloud/feat/custom-settings-sections
feat(desktop): add OCA.Talk.Settings API to customize and manage settings
- Loading branch information
Showing
6 changed files
with
148 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
import { readonly, shallowReactive } from 'vue' | ||
|
||
import { emit } from '@nextcloud/event-bus' | ||
|
||
type TalkSettingsSection = { | ||
/** | ||
* Section internal ID | ||
*/ | ||
id: string | ||
/** | ||
* Section visible name | ||
*/ | ||
name: string | ||
/** | ||
* WebComponent's (custom element's) tag name to render as the section content | ||
*/ | ||
element: string | ||
} | ||
|
||
const customSettingsSections: TalkSettingsSection[] = shallowReactive([]) | ||
|
||
/** | ||
* Register a custom settings section | ||
* @param section - Settings section | ||
*/ | ||
function registerSection(section: TalkSettingsSection) { | ||
customSettingsSections.push(section) | ||
} | ||
|
||
/** | ||
* Unregister a custom settings section | ||
* @param id - Section ID | ||
*/ | ||
function unregisterSection(id: string) { | ||
const index = customSettingsSections.findIndex((section) => section.id === id) | ||
if (index !== -1) { | ||
customSettingsSections.splice(index, 1) | ||
} | ||
} | ||
|
||
/** | ||
* Open settings dialog | ||
*/ | ||
function open() { | ||
emit('show-settings', undefined) | ||
} | ||
|
||
export const SettingsAPI = { | ||
open, | ||
registerSection, | ||
unregisterSection, | ||
} | ||
|
||
/** | ||
* Composable to use custom settings in Talk | ||
*/ | ||
export function useCustomSettings() { | ||
return { | ||
customSettingsSections: readonly(customSettingsSections), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import { jest, describe, it, expect } from '@jest/globals' | ||
|
||
import { emit } from '@nextcloud/event-bus' | ||
|
||
import { SettingsAPI, useCustomSettings } from '../SettingsAPI.ts' | ||
|
||
jest.mock('@nextcloud/event-bus') | ||
|
||
describe('SettingsAPI', () => { | ||
it('should have open method to open settings', () => { | ||
expect(SettingsAPI.open).toBeDefined() | ||
SettingsAPI.open() | ||
// Currently, a global event is used to open the settings | ||
expect(emit).toHaveBeenCalledWith('show-settings', undefined) | ||
}) | ||
|
||
it('should have registerSection method to register settings sections', () => { | ||
const { customSettingsSections } = useCustomSettings() | ||
expect(customSettingsSections).toEqual([]) | ||
expect(SettingsAPI.registerSection).toBeDefined() | ||
SettingsAPI.registerSection({ | ||
id: 'test', | ||
name: 'Test', | ||
element: 'test-element', | ||
}) | ||
SettingsAPI.registerSection({ | ||
id: 'test2', | ||
name: 'Test 2', | ||
element: 'test-element-two', | ||
}) | ||
expect(customSettingsSections).toEqual([{ | ||
id: 'test', | ||
name: 'Test', | ||
element: 'test-element', | ||
}, { | ||
id: 'test2', | ||
name: 'Test 2', | ||
element: 'test-element-two', | ||
}]) | ||
}) | ||
|
||
it('should have unregisterSection method to unregister settings sections', () => { | ||
const { customSettingsSections } = useCustomSettings() | ||
expect(customSettingsSections).toEqual([{ | ||
id: 'test', | ||
name: 'Test', | ||
element: 'test-element', | ||
}, { | ||
id: 'test2', | ||
name: 'Test 2', | ||
element: 'test-element-two', | ||
}]) | ||
expect(SettingsAPI.unregisterSection).toBeDefined() | ||
SettingsAPI.unregisterSection('test') | ||
expect(customSettingsSections).toEqual([{ | ||
id: 'test2', | ||
name: 'Test 2', | ||
element: 'test-element-two', | ||
}]) | ||
}) | ||
}) |