Skip to content

Commit

Permalink
feat: allow to turn off filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
mildred committed Nov 20, 2024
1 parent a2b80a3 commit 548f39b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 23 deletions.
8 changes: 8 additions & 0 deletions schemas/core/SystemSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
"readOnly": true,
"section": "Default"
},
{
"fieldname": "allowFilterBypass",
"label": "Allow to bypass filters",
"fieldtype": "Check",
"default": false,
"description": "When linking documents, if no match is found and filtering is in effect, allow to disable filters.",
"section": "Default"
},
{
"fieldname": "locale",
"label": "Locale",
Expand Down
65 changes: 43 additions & 22 deletions src/components/Controls/Link.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default {
name: 'Link',
extends: AutoComplete,
data() {
return { results: [] };
return { results: [], filtersDisabled: false };
},
watch: {
value: {
Expand Down Expand Up @@ -45,7 +45,7 @@ export default {
getTargetSchemaName() {
return this.df.target;
},
async getOptions() {
async getOptions(filters) {
const schemaName = this.getTargetSchemaName();
if (!schemaName) {
return [];
Expand All @@ -56,7 +56,6 @@ export default {
}
const schema = fyo.schemaMap[schemaName];
const filters = await this.getFilters();
const fields = [
...new Set(['name', schema.titleField, this.df.groupBy]),
Expand All @@ -78,7 +77,8 @@ export default {
.filter(Boolean));
},
async getSuggestions(keyword = '') {
let options = await this.getOptions();
let filters = this.filtersDisabled ? null : await this.getFilters();
let options = await this.getOptions(filters || {});
if (keyword) {
options = options
Expand All @@ -88,21 +88,34 @@ export default {
.map(({ item }) => item);
}
if (this.doc && this.df.create) {
options = options.concat(this.getCreateNewOption());
if (options.length === 0 && !this.df.emptyMessage) {
if (filters && !!fyo.singles.SystemSettings?.allowFilterBypass) {
options = [
{
component: markRaw({
template:
'<span class="text-gray-600 dark:text-gray-400">{{ t`No results found, disable filters` }}</span>',
}),
action: () => this.disableFiltering(),
actionOnly: true,
},
];
} else if (!this.doc || !this.df.create) {
options = [
{
component: markRaw({
template:
'<span class="text-gray-600 dark:text-gray-400">{{ t`No results found` }}</span>',
}),
action: () => {},
actionOnly: true,
},
];
}
}
if (options.length === 0 && !this.df.emptyMessage) {
return [
{
component: markRaw({
template:
'<span class="text-gray-600 dark:text-gray-400">{{ t`No results found` }}</span>',
}),
action: () => {},
actionOnly: true,
},
];
if (this.doc && this.df.create) {
options = options.concat(this.getCreateNewOption());
}
return options;
Expand All @@ -129,6 +142,14 @@ export default {
}),
};
},
disableFiltering(keyword) {
this.filtersDisabled = true;
this.results = [];
setTimeout(() => {
this.toggleDropdown(true);
this.updateSuggestions(keyword);
}, 1);
},
async openNewDoc() {
const schemaName = this.df.target;
const name =
Expand All @@ -155,25 +176,25 @@ export default {
return createFilters;
}
const filters = await this.getFilters();
const filters = (await this.getFilters()) ?? {};
return getCreateFiltersFromListViewFilters(filters);
},
async getFilters() {
const { schemaName, fieldname } = this.df;
const getFilters = fyo.models[schemaName]?.filters?.[fieldname];
if (getFilters === undefined) {
return {};
return null;
}
if (this.doc) {
return (await getFilters(this.doc)) ?? {};
return await getFilters(this.doc);
}
try {
return (await getFilters()) ?? {};
return await getFilters();
} catch {
return {};
return null;
}
},
},
Expand Down
5 changes: 4 additions & 1 deletion translations/fr.csv
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ No,Non,
"No filters selected","Aucun filtre sélectionné",
"No linked entries found",,
"No results found","Aucun résultat trouvé",
"No results found, disable filters","Aucun résultat trouvé, désactiver les filtres",
"No rows added. Select a file or add rows.",,
"No transactions yet","Aucune transaction pour le moment",
"Non Active Serial Number ${0} cannot be used as Manufacture raw material",,
Expand Down Expand Up @@ -1055,4 +1056,6 @@ Yes,Oui,
"check values and click on","Vérifiez les valeurs et cliquez sur",
"in Batch ${0}",,
[email protected],,
"to apply changes","pour appliquer les changements",
"to apply changes","pour appliquer les changements",
"Allow to bypass filters","Autoriser la désactivation des filtres"
"When linking documents, if no match is found and filtering is in effect, allow to disable filters.","Lors de la sélection d'un document lié, autoriser à désactiver les filtres si aucun résultat n'est trouvé"

0 comments on commit 548f39b

Please sign in to comment.