From 70807c6f8a0c9849ae2deb384b14ab90fe894e55 Mon Sep 17 00:00:00 2001 From: JAGFx Date: Thu, 28 Jul 2022 19:57:50 +0200 Subject: [PATCH] :recycle: #133 refactor some stuff around user preferences --- .../ConfigurationListItemSwitch.vue | 19 --------- .../ConfigurationTab/ConfigurationTab.vue | 13 ------ src/application/components/menu/Menu.vue | 12 +++--- .../UserPreferenceList.vue} | 10 +++-- .../UserPreferenceListItem.vue} | 6 +-- .../UserPreferenceListItemSelect.vue} | 6 +-- .../UserPreferenceListItemSwitch.vue | 19 +++++++++ .../UserPreferenceSearchBar.vue} | 0 .../UserPreferencesTab/UserPreferenceTab.vue | 13 ++++++ .../uses/useConfigurationLibrary.js | 32 --------------- .../uses/usePreferencesEntryLibrary.js | 32 +++++++++++++++ .../configurationLibrary.util.js | 38 ------------------ .../PreferenceEntry.js} | 2 +- .../map.json} | 0 .../user-preferences/preference-entry.util.js | 40 +++++++++++++++++++ .../preference-entry.util.spec.js} | 2 +- 16 files changed, 124 insertions(+), 120 deletions(-) delete mode 100644 src/application/components/menu/ConfigurationTab/ConfigurationListItemSwitch.vue delete mode 100644 src/application/components/menu/ConfigurationTab/ConfigurationTab.vue rename src/application/components/menu/{ConfigurationTab/ConfigurationList.vue => UserPreferencesTab/UserPreferenceList.vue} (51%) rename src/application/components/menu/{ConfigurationTab/ConfigurationListItem.vue => UserPreferencesTab/UserPreferenceListItem.vue} (75%) rename src/application/components/menu/{ConfigurationTab/ConfigurationListItemSelect.vue => UserPreferencesTab/UserPreferenceListItemSelect.vue} (68%) create mode 100644 src/application/components/menu/UserPreferencesTab/UserPreferenceListItemSwitch.vue rename src/application/components/menu/{ConfigurationTab/ConfigurationSearchBar.vue => UserPreferencesTab/UserPreferenceSearchBar.vue} (100%) create mode 100644 src/application/components/menu/UserPreferencesTab/UserPreferenceTab.vue delete mode 100644 src/application/uses/useConfigurationLibrary.js create mode 100644 src/application/uses/usePreferencesEntryLibrary.js delete mode 100644 src/domain/configuration/configurationLibrary.util.js rename src/domain/{configuration/configurationLibrary.model.js => user-preferences/PreferenceEntry.js} (85%) rename src/domain/{configuration/configuration.library.json => user-preferences/map.json} (100%) create mode 100644 src/domain/user-preferences/preference-entry.util.js rename src/domain/{configuration/configurationLibrary.util.spec.js => user-preferences/preference-entry.util.spec.js} (88%) diff --git a/src/application/components/menu/ConfigurationTab/ConfigurationListItemSwitch.vue b/src/application/components/menu/ConfigurationTab/ConfigurationListItemSwitch.vue deleted file mode 100644 index 6878f81..0000000 --- a/src/application/components/menu/ConfigurationTab/ConfigurationListItemSwitch.vue +++ /dev/null @@ -1,19 +0,0 @@ - - - - - diff --git a/src/application/components/menu/ConfigurationTab/ConfigurationTab.vue b/src/application/components/menu/ConfigurationTab/ConfigurationTab.vue deleted file mode 100644 index 26c9182..0000000 --- a/src/application/components/menu/ConfigurationTab/ConfigurationTab.vue +++ /dev/null @@ -1,13 +0,0 @@ - - - - - diff --git a/src/application/components/menu/Menu.vue b/src/application/components/menu/Menu.vue index 747c8c6..28bd542 100644 --- a/src/application/components/menu/Menu.vue +++ b/src/application/components/menu/Menu.vue @@ -24,9 +24,9 @@ diff --git a/src/application/components/menu/ConfigurationTab/ConfigurationListItem.vue b/src/application/components/menu/UserPreferencesTab/UserPreferenceListItem.vue similarity index 75% rename from src/application/components/menu/ConfigurationTab/ConfigurationListItem.vue rename to src/application/components/menu/UserPreferencesTab/UserPreferenceListItem.vue index 3de4ad5..dbc95db 100644 --- a/src/application/components/menu/ConfigurationTab/ConfigurationListItem.vue +++ b/src/application/components/menu/UserPreferencesTab/UserPreferenceListItem.vue @@ -18,8 +18,8 @@ diff --git a/src/application/components/menu/ConfigurationTab/ConfigurationListItemSelect.vue b/src/application/components/menu/UserPreferencesTab/UserPreferenceListItemSelect.vue similarity index 68% rename from src/application/components/menu/ConfigurationTab/ConfigurationListItemSelect.vue rename to src/application/components/menu/UserPreferencesTab/UserPreferenceListItemSelect.vue index c9f105f..38bcb2b 100644 --- a/src/application/components/menu/ConfigurationTab/ConfigurationListItemSelect.vue +++ b/src/application/components/menu/UserPreferencesTab/UserPreferenceListItemSelect.vue @@ -1,5 +1,5 @@ + + diff --git a/src/application/components/menu/ConfigurationTab/ConfigurationSearchBar.vue b/src/application/components/menu/UserPreferencesTab/UserPreferenceSearchBar.vue similarity index 100% rename from src/application/components/menu/ConfigurationTab/ConfigurationSearchBar.vue rename to src/application/components/menu/UserPreferencesTab/UserPreferenceSearchBar.vue diff --git a/src/application/components/menu/UserPreferencesTab/UserPreferenceTab.vue b/src/application/components/menu/UserPreferencesTab/UserPreferenceTab.vue new file mode 100644 index 0000000..bb09b69 --- /dev/null +++ b/src/application/components/menu/UserPreferencesTab/UserPreferenceTab.vue @@ -0,0 +1,13 @@ + + + + + diff --git a/src/application/uses/useConfigurationLibrary.js b/src/application/uses/useConfigurationLibrary.js deleted file mode 100644 index deee434..0000000 --- a/src/application/uses/useConfigurationLibrary.js +++ /dev/null @@ -1,32 +0,0 @@ -import { - applyFiltersToConfigurationsSettingsList, - convertJsonObjectToConfigurationItem -} from '@/domain/configuration/configurationLibrary.util.js'; -import { computed, reactive, readonly } from 'vue'; -import configurationMap from '@/domain/configuration/configuration.library.json'; - -const state = reactive({ - search: '' -}); - -const getters = { - search: computed(() => state.search), - configurationMatchWithSearch: computed(() => - applyFiltersToConfigurationsSettingsList( - { - label: state.search - }, - configurationMap.map((configurationItem) => - convertJsonObjectToConfigurationItem(configurationItem) - ) - ) - ) -}; - -const actions = {}; - -export const useConfigurationLibrary = () => ({ - state: readonly(state), - ...getters, - ...actions -}); diff --git a/src/application/uses/usePreferencesEntryLibrary.js b/src/application/uses/usePreferencesEntryLibrary.js new file mode 100644 index 0000000..289012a --- /dev/null +++ b/src/application/uses/usePreferencesEntryLibrary.js @@ -0,0 +1,32 @@ +import { + applyFiltersToPreferenceEntriesList, + convertJsonObjectToPreferenceEntry +} from '@/domain/user-preferences/preference-entry.util.js'; +import { computed, reactive, readonly } from 'vue'; +import map from '@/domain/user-preferences/map.json'; + +const state = reactive({ + search: '' +}); + +const getters = { + search: computed(() => state.search), + configurationMatchWithSearch: computed(() => + applyFiltersToPreferenceEntriesList( + { + label: state.search + }, + map.map((configurationItem) => + convertJsonObjectToPreferenceEntry(configurationItem) + ) + ) + ) +}; + +const actions = {}; + +export const usePreferencesEntryLibrary = () => ({ + state: readonly(state), + ...getters, + ...actions +}); diff --git a/src/domain/configuration/configurationLibrary.util.js b/src/domain/configuration/configurationLibrary.util.js deleted file mode 100644 index 9b14408..0000000 --- a/src/domain/configuration/configurationLibrary.util.js +++ /dev/null @@ -1,38 +0,0 @@ -import configurationMap from '@/domain/configuration/configuration.library.json'; -import { ConfigurationLibrary } from '@/domain/configuration/configurationLibrary.model.js'; - -export const retrieveConfigurationSettings = (configurationId) => { - const matches = configurationMap.filter( - (configuration) => configuration.id === configurationId - ); - - if (matches.length !== 1) - throw new Error(`Unable to find ${configurationId} on configuration map`); - - return matches.at(0); -}; - -export const applyFiltersToConfigurationsSettingsList = (filters, list) => { - return list.filter((configurationSetting) => { - const filterMatches = [true]; - - if (Object.hasOwn(filters, 'label') && filters.label.length !== 0) { - filterMatches.push( - configurationSetting.label - .toLowerCase() - .includes(filters.label.toLowerCase()) - ); - } - - if (Object.hasOwn(filters, 'target') && filters.target.length !== 0) { - filterMatches.push( - configurationSetting.target.includes(filters.target.toLowerCase()) - ); - } - - return filterMatches.every((match) => match); - }); -}; - -export const convertJsonObjectToConfigurationItem = (json) => - Object.assign(new ConfigurationLibrary(), json); diff --git a/src/domain/configuration/configurationLibrary.model.js b/src/domain/user-preferences/PreferenceEntry.js similarity index 85% rename from src/domain/configuration/configurationLibrary.model.js rename to src/domain/user-preferences/PreferenceEntry.js index 4559e36..4ff88fd 100644 --- a/src/domain/configuration/configurationLibrary.model.js +++ b/src/domain/user-preferences/PreferenceEntry.js @@ -1,4 +1,4 @@ -export class ConfigurationLibrary { +export class PreferenceEntry { constructor(id = '', target = '', label = '', description = '', values = []) { this.id = id; this.target = target; diff --git a/src/domain/configuration/configuration.library.json b/src/domain/user-preferences/map.json similarity index 100% rename from src/domain/configuration/configuration.library.json rename to src/domain/user-preferences/map.json diff --git a/src/domain/user-preferences/preference-entry.util.js b/src/domain/user-preferences/preference-entry.util.js new file mode 100644 index 0000000..e6238bb --- /dev/null +++ b/src/domain/user-preferences/preference-entry.util.js @@ -0,0 +1,40 @@ +import map from '@/domain/user-preferences/map.json'; +import { PreferenceEntry } from '@/domain/user-preferences/PreferenceEntry.js'; + +export const findPreferenceEntryById = (preferenceEntryId) => { + const matches = map.filter( + (preferenceEntry) => preferenceEntry.id === preferenceEntryId + ); + + if (matches.length !== 1) + throw new Error( + `Unable to find ${preferenceEntryId} on preference entries list` + ); + + return matches.at(0); +}; + +export const applyFiltersToPreferenceEntriesList = (filters, list) => { + return list.filter((preferenceEntry) => { + const filterMatches = [true]; + + if (Object.hasOwn(filters, 'label') && filters.label.length !== 0) { + filterMatches.push( + preferenceEntry.label + .toLowerCase() + .includes(filters.label.toLowerCase()) + ); + } + + if (Object.hasOwn(filters, 'target') && filters.target.length !== 0) { + filterMatches.push( + preferenceEntry.target.includes(filters.target.toLowerCase()) + ); + } + + return filterMatches.every((match) => match); + }); +}; + +export const convertJsonObjectToPreferenceEntry = (json) => + Object.assign(new PreferenceEntry(), json); diff --git a/src/domain/configuration/configurationLibrary.util.spec.js b/src/domain/user-preferences/preference-entry.util.spec.js similarity index 88% rename from src/domain/configuration/configurationLibrary.util.spec.js rename to src/domain/user-preferences/preference-entry.util.spec.js index 696c6bd..f6aebb5 100644 --- a/src/domain/configuration/configurationLibrary.util.spec.js +++ b/src/domain/user-preferences/preference-entry.util.spec.js @@ -17,7 +17,7 @@ jest.mock('@/domain/configuration/configuration.library.json', () => [ existingConfiguration ]); -import { retrieveConfigurationSettings } from '@/domain/configuration/configurationLibrary.util.js'; +import { retrieveConfigurationSettings } from '@/domain/user-preferences/configurationLibrary.util.js'; beforeEach(() => { jest.resetModules();