mirror of
https://github.com/godotengine/godot-team-reports.git
synced 2025-12-31 13:48:17 +03:00
Store user configured filters in localStorage
This commit is contained in:
@@ -10,19 +10,25 @@ export default class PullRequestList extends LitElement {
|
|||||||
:host {
|
:host {
|
||||||
--pulls-background-color: #e5edf8;
|
--pulls-background-color: #e5edf8;
|
||||||
--pulls-toolbar-color: #9bbaed;
|
--pulls-toolbar-color: #9bbaed;
|
||||||
|
--pulls-toolbar-accent-color: #5a6f90;
|
||||||
|
|
||||||
--sort-color: #5c7bb6;
|
--sort-color: #5c7bb6;
|
||||||
--sort-color-hover: #2862cd;
|
--sort-color-hover: #2862cd;
|
||||||
--sort-color-active: #2054b5;
|
--sort-color-active: #2054b5;
|
||||||
|
|
||||||
|
--reset-color: #4e4f53;
|
||||||
}
|
}
|
||||||
@media (prefers-color-scheme: dark) {
|
@media (prefers-color-scheme: dark) {
|
||||||
:host {
|
:host {
|
||||||
--pulls-background-color: #191d23;
|
--pulls-background-color: #191d23;
|
||||||
--pulls-toolbar-color: #222c3d;
|
--pulls-toolbar-color: #222c3d;
|
||||||
|
--pulls-toolbar-accent-color: #566783;
|
||||||
|
|
||||||
--sort-color: #4970ad;
|
--sort-color: #4970ad;
|
||||||
--sort-color-hover: #5b87de;
|
--sort-color-hover: #5b87de;
|
||||||
--sort-color-active: #6b9aea;
|
--sort-color-active: #6b9aea;
|
||||||
|
|
||||||
|
--reset-color: #7f8185;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,13 +65,12 @@ export default class PullRequestList extends LitElement {
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
font-size: 15px;
|
|
||||||
padding: 10px 14px;
|
padding: 10px 14px;
|
||||||
margin-bottom: 6px;
|
margin-bottom: 6px;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host .pulls-count {
|
:host .pulls-count {
|
||||||
|
font-size: 15px;
|
||||||
}
|
}
|
||||||
:host .pulls-count strong {
|
:host .pulls-count strong {
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
@@ -117,18 +122,37 @@ export default class PullRequestList extends LitElement {
|
|||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:host .pulls-reset {
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
border-top: 1px solid var(--pulls-toolbar-accent-color);
|
||||||
|
margin-top: 8px;
|
||||||
|
padding-top: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:host .pulls-reset-action {
|
||||||
|
color: var(--reset-color);
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
@media only screen and (max-width: 900px) {
|
@media only screen and (max-width: 900px) {
|
||||||
:host .team-pulls {
|
:host .team-pulls {
|
||||||
padding: 8px;
|
padding: 8px;
|
||||||
max-width: 95%;
|
max-width: 95%;
|
||||||
margin: 0px auto;
|
margin: 0px auto;
|
||||||
}
|
}
|
||||||
:host .pulls-count {
|
|
||||||
margin-bottom: 12px;
|
|
||||||
}
|
|
||||||
:host .team-pulls-toolbar {
|
:host .team-pulls-toolbar {
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
}
|
}
|
||||||
|
:host .pulls-count {
|
||||||
|
font-size: 17px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
text-align: center;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
:host .pulls-count strong {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
:host .pulls-filters {
|
:host .pulls-filters {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
@@ -157,35 +181,77 @@ export default class PullRequestList extends LitElement {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this._sortBy = "age";
|
// Look in global.js for the actual defaults.
|
||||||
this._sortDirection = "desc";
|
this._sortBy = "age";
|
||||||
this._showDraft = false;
|
this._sortDirection = "desc";
|
||||||
|
this._showDraft = false;
|
||||||
this._filterMilestone = "4.0";
|
this._filterMilestone = "4.0";
|
||||||
this._filterMergeable = "";
|
this._filterMergeable = "";
|
||||||
|
|
||||||
|
this.restoreUserPreferences();
|
||||||
|
}
|
||||||
|
|
||||||
|
restoreUserPreferences() {
|
||||||
|
const userPreferences = greports.util.getLocalPreferences();
|
||||||
|
|
||||||
|
this._sortBy = userPreferences["sortBy"];
|
||||||
|
this._sortDirection = userPreferences["sortDirection"];
|
||||||
|
this._showDraft = userPreferences["showDraft"];
|
||||||
|
this._filterMilestone = userPreferences["filterMilestone"];
|
||||||
|
this._filterMergeable = userPreferences["filterMergeable"];
|
||||||
|
}
|
||||||
|
|
||||||
|
saveUserPreferences() {
|
||||||
|
const currentPreferences = {
|
||||||
|
"sortBy": this._sortBy,
|
||||||
|
"sortDirection": this._sortDirection,
|
||||||
|
"showDraft": this._showDraft,
|
||||||
|
"filterMilestone": this._filterMilestone,
|
||||||
|
"filterMergeable": this._filterMergeable,
|
||||||
|
};
|
||||||
|
|
||||||
|
greports.util.setLocalPreferences(currentPreferences);
|
||||||
|
}
|
||||||
|
|
||||||
|
onResetPreferencesClicked() {
|
||||||
|
greports.util.resetLocalPreferences();
|
||||||
|
|
||||||
|
this.restoreUserPreferences();
|
||||||
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
onSortClicked(sortField, event) {
|
onSortClicked(sortField, event) {
|
||||||
this._sortBy = sortField;
|
this._sortBy = sortField;
|
||||||
|
|
||||||
|
this.saveUserPreferences();
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
onSortDirectionClicked(sortDirection, event) {
|
onSortDirectionClicked(sortDirection, event) {
|
||||||
this._sortDirection = sortDirection;
|
this._sortDirection = sortDirection;
|
||||||
|
|
||||||
|
this.saveUserPreferences();
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
onDraftsChecked(event) {
|
onDraftsChecked(event) {
|
||||||
this._showDraft = event.target.checked;
|
this._showDraft = event.target.checked;
|
||||||
|
|
||||||
|
this.saveUserPreferences();
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
onMilestoneChanged(event) {
|
onMilestoneChanged(event) {
|
||||||
this._filterMilestone = event.target.value;
|
this._filterMilestone = event.target.value;
|
||||||
|
|
||||||
|
this.saveUserPreferences();
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
onMergeableChanged(event) {
|
onMergeableChanged(event) {
|
||||||
this._filterMergeable = event.target.value;
|
this._filterMergeable = event.target.value;
|
||||||
|
|
||||||
|
this.saveUserPreferences();
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,8 +298,11 @@ export default class PullRequestList extends LitElement {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!milestones.includes(this._filterMilestone)) {
|
// Values can be dynamically removed from the selector,
|
||||||
this._filterMilestone = "";
|
// but we don't really want to break the filters.
|
||||||
|
let milestone = "";
|
||||||
|
if (milestones.includes(this._filterMilestone)) {
|
||||||
|
milestone = this._filterMilestone;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mergeables = [
|
let mergeables = [
|
||||||
@@ -244,7 +313,7 @@ export default class PullRequestList extends LitElement {
|
|||||||
if (!this._showDraft && item.is_draft) {
|
if (!this._showDraft && item.is_draft) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this._filterMilestone !== "" && item.milestone && item.milestone.title !== this._filterMilestone) {
|
if (milestone !== "" && item.milestone && item.milestone.title !== milestone) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this._filterMergeable !== "" && this.getMergeableFilterValue(item.mergeable_state, item.mergeable_reason) !== this._filterMergeable) {
|
if (this._filterMergeable !== "" && this.getMergeableFilterValue(item.mergeable_state, item.mergeable_reason) !== this._filterMergeable) {
|
||||||
@@ -275,6 +344,7 @@ export default class PullRequestList extends LitElement {
|
|||||||
<input
|
<input
|
||||||
id="show-drafts"
|
id="show-drafts"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
|
.checked="${this._showDraft}"
|
||||||
@click="${this.onDraftsChecked}"
|
@click="${this.onDraftsChecked}"
|
||||||
/>
|
/>
|
||||||
</span>
|
</span>
|
||||||
@@ -287,7 +357,7 @@ export default class PullRequestList extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<option
|
<option
|
||||||
value="${item}"
|
value="${item}"
|
||||||
.selected="${this._filterMilestone === item}"
|
.selected="${milestone === item}"
|
||||||
>
|
>
|
||||||
${item}
|
${item}
|
||||||
</option>
|
</option>
|
||||||
@@ -295,7 +365,7 @@ export default class PullRequestList extends LitElement {
|
|||||||
})}
|
})}
|
||||||
</select>
|
</select>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span class="pulls-filter">
|
<span class="pulls-filter">
|
||||||
<span>mergeable: </span>
|
<span>mergeable: </span>
|
||||||
<select @change="${this.onMergeableChanged}">
|
<select @change="${this.onMergeableChanged}">
|
||||||
@@ -354,6 +424,15 @@ export default class PullRequestList extends LitElement {
|
|||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
<span class="pulls-reset">
|
||||||
|
<span
|
||||||
|
class="pulls-reset-action"
|
||||||
|
@click="${this.onResetPreferencesClicked}"
|
||||||
|
>
|
||||||
|
reset filters
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
const READING_SPEED = 200;
|
const LOCAL_PREFERENCE_PREFIX = "_godot_up"
|
||||||
|
const LOCAL_PREFERENCE_DEFAULTS = {
|
||||||
|
"sortBy" : "age",
|
||||||
|
"sortDirection" : "desc",
|
||||||
|
"showDraft" : false,
|
||||||
|
"filterMilestone" : "4.0",
|
||||||
|
"filterMergeable" : "",
|
||||||
|
};
|
||||||
|
|
||||||
// API Interaction
|
// API Interaction
|
||||||
const ReportsAPI = {
|
const ReportsAPI = {
|
||||||
@@ -83,6 +90,33 @@ const ReportsUtils = {
|
|||||||
url.hash = hash;
|
url.hash = hash;
|
||||||
window.history.pushState({}, "", url);
|
window.history.pushState({}, "", url);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getLocalPreferences() {
|
||||||
|
// Always fallback on defaults.
|
||||||
|
const localPreferences = { ...LOCAL_PREFERENCE_DEFAULTS };
|
||||||
|
|
||||||
|
for (let key in localPreferences) {
|
||||||
|
const storedValue = localStorage.getItem(`${LOCAL_PREFERENCE_PREFIX}_${key}`);
|
||||||
|
if (storedValue != null) {
|
||||||
|
localPreferences[key] = JSON.parse(storedValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return localPreferences;
|
||||||
|
},
|
||||||
|
|
||||||
|
setLocalPreferences(currentPreferences) {
|
||||||
|
for (let key in currentPreferences) {
|
||||||
|
// Only store known properties.
|
||||||
|
if (key in LOCAL_PREFERENCE_DEFAULTS) {
|
||||||
|
localStorage.setItem(`${LOCAL_PREFERENCE_PREFIX}_${key}`, JSON.stringify(currentPreferences[key]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
resetLocalPreferences() {
|
||||||
|
this.setLocalPreferences(LOCAL_PREFERENCE_DEFAULTS);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const ReportsSingleton = {
|
const ReportsSingleton = {
|
||||||
|
|||||||
Reference in New Issue
Block a user