Persist "show only mine" across page refresh (#661)

* turn off filter by default

* store in session storage

* update keys
This commit is contained in:
sua yoo 2023-02-28 18:37:20 -08:00 committed by GitHub
parent 29f31cd462
commit dc62d4b874
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 2 deletions

View File

@ -25,6 +25,8 @@ type RunningCrawlsMap = {
[configId: string]: string;
};
const FILTER_BY_CURRENT_USER_STORAGE_KEY =
"btrix.filterByCurrentUser.crawlConfigs";
const MIN_SEARCH_LENGTH = 2;
const sortableFieldLabels = {
created_desc: msg("Newest"),
@ -72,7 +74,7 @@ export class CrawlTemplatesList extends LiteElement {
};
@state()
private filterByCurrentUser = true;
private filterByCurrentUser = false;
@state()
private searchBy: string = "";
@ -87,6 +89,13 @@ export class CrawlTemplatesList extends LiteElement {
threshold: 0.2, // stricter; default is 0.6
});
constructor() {
super();
this.filterByCurrentUser =
window.sessionStorage.getItem(FILTER_BY_CURRENT_USER_STORAGE_KEY) ===
"true";
}
protected async willUpdate(changedProperties: Map<string, any>) {
if (
changedProperties.has("orgId") ||
@ -105,6 +114,12 @@ export class CrawlTemplatesList extends LiteElement {
});
}
}
if (changedProperties.has("filterByCurrentUser")) {
window.sessionStorage.setItem(
FILTER_BY_CURRENT_USER_STORAGE_KEY,
this.filterByCurrentUser.toString()
);
}
}
private async fetchCrawlConfigs() {

View File

@ -31,6 +31,7 @@ type CrawlSearchResult = {
type SortField = "started" | "finished" | "configName" | "fileSize";
type SortDirection = "asc" | "desc";
const FILTER_BY_CURRENT_USER_STORAGE_KEY = "btrix.filterByCurrentUser.crawls";
const POLL_INTERVAL_SECONDS = 10;
const MIN_SEARCH_LENGTH = 2;
const sortableFields: Record<
@ -113,7 +114,7 @@ export class CrawlsList extends LiteElement {
};
@state()
private filterByCurrentUser = true;
private filterByCurrentUser = false;
@state()
private filterByState: CrawlState[] = [];
@ -150,6 +151,13 @@ export class CrawlsList extends LiteElement {
crawlsResults
) as CrawlSearchResult[];
constructor() {
super();
this.filterByCurrentUser =
window.sessionStorage.getItem(FILTER_BY_CURRENT_USER_STORAGE_KEY) ===
"true";
}
protected willUpdate(changedProperties: Map<string, any>) {
if (
changedProperties.has("shouldFetch") ||
@ -166,6 +174,13 @@ export class CrawlsList extends LiteElement {
} else {
this.stopPollTimer();
}
if (changedProperties.has("filterByCurrentUser")) {
window.sessionStorage.setItem(
FILTER_BY_CURRENT_USER_STORAGE_KEY,
this.filterByCurrentUser.toString()
);
}
}
}