Skip to content

Commit

Permalink
feat: add defaultValue prop to filter components for improved initial…
Browse files Browse the repository at this point in the history
…ization

- Introduced a defaultValue prop in FilterInput.vue, FilterSelect.vue, and ListLayout.vue to allow for pre-setting values.
- Updated the initialization logic in FilterInput and FilterSelect to utilize the defaultValue prop on component mount.
- Enhanced ListActionFilter interface to include defaultValue for better type safety and consistency across filter components.
- Improved user experience by ensuring filters can start with predefined values, streamlining the filtering process.
  • Loading branch information
tikazyq committed Dec 23, 2024
1 parent 654c520 commit 1187831
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/components/ui/filter/FilterInput.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<script setup lang="ts">
import { ref } from 'vue';
import { onBeforeMount, ref } from 'vue';
import { debounce } from '@/utils';
defineProps<{
const props = defineProps<{
id?: string;
prefixIcon?: Icon;
label?: string;
placeholder?: string;
defaultValue?: any;
}>();
const emit = defineEmits<{
Expand All @@ -16,6 +17,9 @@ const emit = defineEmits<{
}>();
const internalModelValue = ref();
onBeforeMount(() => {
internalModelValue.value = props.defaultValue;
});
const onChange = debounce((value: any) => {
emit('change', value);
Expand Down
7 changes: 6 additions & 1 deletion src/components/ui/filter/FilterSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const props = withDefaults(
options?: SelectOption[];
optionsRemote?: FilterSelectOptionsRemote;
noAllOption?: boolean;
defaultValue?: any;
}>(),
{
clearable: true,
Expand Down Expand Up @@ -62,7 +63,11 @@ const getOptions = async () => {
onBeforeMount(getOptions);
const initializeModelValue = () => {
const { options, noAllOption } = props;
const { options, noAllOption, defaultValue } = props;
if (typeof defaultValue !== 'undefined') {
internalModelValue.value = defaultValue;
return;
}
if (noAllOption) {
internalModelValue.value = options ? options[0]?.value : undefined;
}
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/layout/content/list/ListLayout.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export declare global {
}

interface ListActionFilter extends ListAction {
defaultValue?: any;
placeholder?: string;
options?: SelectOption[];
optionsRemote?: FilterSelectOptionsRemote;
Expand Down
2 changes: 2 additions & 0 deletions src/layouts/content/list/ListLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ defineOptions({ name: 'ClListLayout' });
:label="item.label"
:placeholder="(item as ListActionFilter).placeholder"
:prefix-icon="(item as ListActionFilter).prefixIcon"
:default-value="(item as ListActionFilter).defaultValue"
@change="
(value: any) => (item as ListActionFilter).onChange?.(value)
"
Expand All @@ -165,6 +166,7 @@ defineOptions({ name: 'ClListLayout' });
:options-remote="(item as ListActionFilter).optionsRemote"
:clearable="(item as ListActionFilter).clearable"
:no-all-option="(item as ListActionFilter).noAllOption"
:default-value="(item as ListActionFilter).defaultValue"
@change="
(value: any) => (item as ListActionFilter).onChange?.(value)
"
Expand Down
4 changes: 2 additions & 2 deletions src/views/dependency/list/useDependencyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const useDependencyList = () => {
action: ACTION_FILTER_SELECT,
id: 'filter-select-lang',
className: 'select-lang',
defaultValue: state.lang,
onChange: value => {
onListFilterChangeByKey(store, ns, 'type', FILTER_OP_EQUAL, {
update: false,
Expand Down Expand Up @@ -710,8 +711,7 @@ const useDependencyList = () => {
};

onBeforeUnmount(() => {
store.commit(`${ns}/setLang`, 'python');
store.commit(`${ns}/setRepoTabName`, 'installed');
store.commit(`${ns}/setSearchQuery`, '');
});

// options
Expand Down

0 comments on commit 1187831

Please sign in to comment.