Skip to content

Commit

Permalink
#133 simplify process to get custom preference entry values
Browse files Browse the repository at this point in the history
  • Loading branch information
JAGFx committed Aug 29, 2022
1 parent 4016ad2 commit 71b2e3a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .run/Unit tests.run.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Unit tests" type="JavaScriptTestRunnerJest">
<config-file value="$PROJECT_DIR$/jest.config.json" />
<config-file value="$PROJECT_DIR$/tools/.jestrc.js" />
<node-interpreter value="project" />
<node-options value="" />
<jest-package value="$PROJECT_DIR$/node_modules/jest" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<UserPreferenceListItemSelect
configuration-id="general_refresh_rate"
/>
<UserPreferenceListItemSelect
configuration-id="general_skin_on_load"
:values="[{ label: 'One', value: 'Two' }]"
/>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ import { loadPreferenceEntryValues } from '@/jagfx/core/configuration/preference
import UserPreferenceListItem from '@/jagfx/application/components/menu/UserPreferenceTab/UserPreferenceListItem.vue';
defineProps({
const props = defineProps({
configurationId: {
type: String,
required: true
},
values: {
type: Array,
required: false,
default: () => []
}
});
const loadValues = (preferenceEntry) =>
loadPreferenceEntryValues(preferenceEntry);
const loadValues = (preferenceEntry) => {
return props.values.length > 0
? props.values
: loadPreferenceEntryValues(preferenceEntry);
};
</script>

<style lang="scss" scoped></style>
28 changes: 1 addition & 27 deletions src/jagfx/core/configuration/preference-entry/loader.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
export const loadPreferenceEntryValues = (preferenceEntry) => {
if (
Array.isArray(preferenceEntry) ||
preferenceEntry === null ||
typeof preferenceEntry !== 'object' ||
!Array.isArray(preferenceEntry.values) ||
!Object.hasOwnProperty.call(preferenceEntry, 'values') ||
preferenceEntry.values === null
) {
return null;
}

if (
Array.isArray(preferenceEntry.values) &&
preferenceEntry.values.length > 0
) {
return preferenceEntry.values;
}

if (
Array.isArray(preferenceEntry.values) &&
preferenceEntry.values.length === 0
) {
// TODO Return loaded value
return [];
}

return null;
return preferenceEntry?.values ?? null;
};

// TODO Add test for it + tast to check all entry on map.json file

0 comments on commit 71b2e3a

Please sign in to comment.