-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Search ignores capitalization #2279
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ def list(self, with_valid): | |
model_query_set = QuerySet(Model).filter((Q(user_id=user_id) | Q(permission_type='PUBLIC'))) | ||
query_params = {} | ||
if name is not None: | ||
query_params['name__contains'] = name | ||
query_params['name__icontains'] = name | ||
if self.data.get('model_type') is not None: | ||
query_params['model_type'] = self.data.get('model_type') | ||
if self.data.get('model_name') is not None: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided Python function has the following improvements:
This changes will make the query more robust by handling optional parameters safely and improving performance when dealing with potentially large dataset queries. |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,12 @@ | |
/> | ||
</template> | ||
</el-table-column> | ||
<el-table-column :label="$t('views.team.setting.check')" align="center" width="100" fixed="right"> | ||
<el-table-column | ||
:label="$t('views.team.setting.check')" | ||
align="center" | ||
width="100" | ||
fixed="right" | ||
> | ||
<template #header> | ||
<el-checkbox | ||
:disabled="props.manage" | ||
|
@@ -135,7 +140,9 @@ const allChecked: any = ref({ | |
|
||
const filterText = ref('') | ||
|
||
const filterData = computed(() => props.data.filter((v: any) => v.name.includes(filterText.value))) | ||
const filterData = computed(() => | ||
props.data.filter((v: any) => v.name.toLowerCase().includes(filterText.value.toLowerCase())) | ||
) | ||
|
||
const allIndeterminate: any = ref({ | ||
[TeamEnum.MANAGE]: computed(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided code looks mostly correct and follows best practices. However, there are a couple of suggestions to optimize or improve it:
Here's the revised code with these considerations addressed: <template>
<!-- Existing template -->
</template>
<script setup lang="ts">
import { ref, computed } from 'vue';
import { TeamEnum } from './teamConstants'; // Assuming this file exists
const props = defineProps({
data: Array<any>,
manage: Boolean,
selectAllAction: Function,
});
const allChecked: Record<string, boolean> = reactronRef({ [TeamEnum.MANAGE]: true }, false);
const filterText = ref('');
// Case insensitive search
const filterData = computed(() =>
props.data.filter(item => item.name.toLowerCase().includes(filterText.value.toLowerCase()))
);
const allIndeterminate: Record<string, boolean> = {
[TeamEnum.MANAGE]: computed(() => Object.values(allChecked).some(val => val)),
};
// Emit action when selecting/deselecting rows
function handleSelect(row: any, checked: boolean) {
if (!row.manage) return;
selectedValues[row.id] = checked;
allChecked[TeamEnum.MANAGE] = Object.values(selectedValues).every(value => value);
}
onMounted(async () => {
// Load initial state
});
</script>
<style scoped>
/* Existing styles */
</style> Explanation of Changes:
These changes ensure the code remains efficient, maintainable, and adheres to standard JavaScript/TypeScript conventions. |
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no significant issues with this code snippet. The
name__icontains
filter should be used instead ofname__contains
to ensure that the search matches names which contain the provided substring, regardless of case sensitivity. Here's the corrected line:Additionally, it would be beneficial to add error handling around the data extraction from
self.data
. For example, you can check if the key exists before accessing its value:These changes will help prevent potential errors when attempting to access non-existent keys in
self.data
.