From 139d75f98e3cfe17baf6671d10206de69b957579 Mon Sep 17 00:00:00 2001 From: Athitya Kumar Date: Sat, 22 Oct 2022 18:28:45 +0530 Subject: [PATCH 1/3] fix(9656): stores all states except workflows in local storage Signed-off-by: Athitya Kumar --- .../archived-workflow-list.tsx | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/ui/src/app/archived-workflows/components/archived-workflow-list/archived-workflow-list.tsx b/ui/src/app/archived-workflows/components/archived-workflow-list/archived-workflow-list.tsx index 8ebdeed005b6..5393a5115cf2 100644 --- a/ui/src/app/archived-workflows/components/archived-workflow-list/archived-workflow-list.tsx +++ b/ui/src/app/archived-workflows/components/archived-workflow-list/archived-workflow-list.tsx @@ -181,8 +181,54 @@ export class ArchivedWorkflowList extends BasePage, Sta return params; } + private filterStateObject(state: State, whitelistedStates: string[], blacklistedStates: string[]) { + const filteredState: State = {} as State; + + if (whitelistedStates.includes('pagination') || !blacklistedStates.includes('pagination')) { + filteredState.pagination = state.pagination; + } + + if (whitelistedStates.includes('namespace') || !blacklistedStates.includes('namespace')) { + filteredState.namespace = state.namespace; + } + + if (whitelistedStates.includes('name') || !blacklistedStates.includes('name')) { + filteredState.name = state.name; + } + + if (whitelistedStates.includes('namePrefix') || !blacklistedStates.includes('namePrefix')) { + filteredState.namePrefix = state.namePrefix; + } + + if (whitelistedStates.includes('selectedPhases') || !blacklistedStates.includes('selectedPhases')) { + filteredState.selectedPhases = state.selectedPhases; + } + + if (whitelistedStates.includes('selectedLabels') || !blacklistedStates.includes('selectedLabels')) { + filteredState.selectedLabels = state.selectedLabels; + } + + if (whitelistedStates.includes('minStartedAt') || !blacklistedStates.includes('minStartedAt')) { + filteredState.minStartedAt = state.minStartedAt; + } + + if (whitelistedStates.includes('maxStartedAt') || !blacklistedStates.includes('maxStartedAt')) { + filteredState.maxStartedAt = state.maxStartedAt; + } + + if (whitelistedStates.includes('error') || !blacklistedStates.includes('error')) { + filteredState.error = state.error; + } + + if (whitelistedStates.includes('deep') || !blacklistedStates.includes('deep')) { + filteredState.deep = state.deep; + } + + return filteredState; + } + private saveHistory() { - this.storage.setItem('options', this.state, {} as State); + this.storage.setItem('options', this.filterStateObject(this.state, [], ['workflows']), {} as State); const newNamespace = Utils.managedNamespace ? '' : this.state.namespace; this.url = uiUrl('archived-workflows' + (newNamespace ? '/' + newNamespace : '') + '?' + this.filterParams.toString()); Utils.currentNamespace = this.state.namespace; From b586b3e34ddf3835443606bd6a4656d0290d04b6 Mon Sep 17 00:00:00 2001 From: Athitya Kumar Date: Thu, 27 Oct 2022 14:03:49 +0530 Subject: [PATCH 2/3] fix(9656): loops through all keys to blacklist Signed-off-by: Athitya Kumar --- .../archived-workflow-list.tsx | 53 +++++-------------- 1 file changed, 12 insertions(+), 41 deletions(-) diff --git a/ui/src/app/archived-workflows/components/archived-workflow-list/archived-workflow-list.tsx b/ui/src/app/archived-workflows/components/archived-workflow-list/archived-workflow-list.tsx index 5393a5115cf2..b7f050d67848 100644 --- a/ui/src/app/archived-workflows/components/archived-workflow-list/archived-workflow-list.tsx +++ b/ui/src/app/archived-workflows/components/archived-workflow-list/archived-workflow-list.tsx @@ -181,54 +181,25 @@ export class ArchivedWorkflowList extends BasePage, Sta return params; } - private filterStateObject(state: State, whitelistedStates: string[], blacklistedStates: string[]) { - const filteredState: State = {} as State; + private filterOutStateObject(state: State, blacklistedStates: string[]) { + const filteredState: State = Object.assign({}, state); + let key: keyof typeof state; - if (whitelistedStates.includes('pagination') || !blacklistedStates.includes('pagination')) { - filteredState.pagination = state.pagination; - } - - if (whitelistedStates.includes('namespace') || !blacklistedStates.includes('namespace')) { - filteredState.namespace = state.namespace; - } - - if (whitelistedStates.includes('name') || !blacklistedStates.includes('name')) { - filteredState.name = state.name; - } - - if (whitelistedStates.includes('namePrefix') || !blacklistedStates.includes('namePrefix')) { - filteredState.namePrefix = state.namePrefix; - } - - if (whitelistedStates.includes('selectedPhases') || !blacklistedStates.includes('selectedPhases')) { - filteredState.selectedPhases = state.selectedPhases; - } - - if (whitelistedStates.includes('selectedLabels') || !blacklistedStates.includes('selectedLabels')) { - filteredState.selectedLabels = state.selectedLabels; - } - - if (whitelistedStates.includes('minStartedAt') || !blacklistedStates.includes('minStartedAt')) { - filteredState.minStartedAt = state.minStartedAt; - } - - if (whitelistedStates.includes('maxStartedAt') || !blacklistedStates.includes('maxStartedAt')) { - filteredState.maxStartedAt = state.maxStartedAt; - } - - if (whitelistedStates.includes('error') || !blacklistedStates.includes('error')) { - filteredState.error = state.error; - } - - if (whitelistedStates.includes('deep') || !blacklistedStates.includes('deep')) { - filteredState.deep = state.deep; + for (key in state) { + if (blacklistedStates.includes(key)) { + delete filteredState[key]; + } } return filteredState; } + private fetchBrowserStorageStateObject(state: State) { + return this.filterOutStateObject(state, ['workflows']); + } + private saveHistory() { - this.storage.setItem('options', this.filterStateObject(this.state, [], ['workflows']), {} as State); + this.storage.setItem('options', this.fetchBrowserStorageStateObject(this.state), {} as State); const newNamespace = Utils.managedNamespace ? '' : this.state.namespace; this.url = uiUrl('archived-workflows' + (newNamespace ? '/' + newNamespace : '') + '?' + this.filterParams.toString()); Utils.currentNamespace = this.state.namespace; From 525e381d8f2db973588e45ad62574c3aabcd7203 Mon Sep 17 00:00:00 2001 From: Athitya Kumar Date: Wed, 23 Nov 2022 00:29:41 +0530 Subject: [PATCH 3/3] fix(9656): creates new BrowserStorageOptions interface Signed-off-by: Athitya Kumar --- .../archived-workflow-list.tsx | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/ui/src/app/archived-workflows/components/archived-workflow-list/archived-workflow-list.tsx b/ui/src/app/archived-workflows/components/archived-workflow-list/archived-workflow-list.tsx index b7f050d67848..a718bae00c77 100644 --- a/ui/src/app/archived-workflows/components/archived-workflow-list/archived-workflow-list.tsx +++ b/ui/src/app/archived-workflows/components/archived-workflow-list/archived-workflow-list.tsx @@ -18,7 +18,7 @@ import {services} from '../../../shared/services'; import {Utils} from '../../../shared/utils'; import {ArchivedWorkflowFilters} from '../archived-workflow-filters/archived-workflow-filters'; -interface State { +interface BrowserStorageOptions { pagination: Pagination; namespace: string; name: string; @@ -27,11 +27,14 @@ interface State { selectedLabels: string[]; minStartedAt?: Date; maxStartedAt?: Date; - workflows?: Workflow[]; error?: Error; deep: boolean; } +interface State extends BrowserStorageOptions { + workflows?: Workflow[]; +} + const defaultPaginationLimit = 10; export class ArchivedWorkflowList extends BasePage, State> { @@ -181,25 +184,23 @@ export class ArchivedWorkflowList extends BasePage, Sta return params; } - private filterOutStateObject(state: State, blacklistedStates: string[]) { - const filteredState: State = Object.assign({}, state); - let key: keyof typeof state; - - for (key in state) { - if (blacklistedStates.includes(key)) { - delete filteredState[key]; - } - } - - return filteredState; - } - - private fetchBrowserStorageStateObject(state: State) { - return this.filterOutStateObject(state, ['workflows']); + private fetchBrowserStorageStateObject(state: State): BrowserStorageOptions { + const browserStorageOptions: BrowserStorageOptions = {} as BrowserStorageOptions; + browserStorageOptions.deep = state.deep; + browserStorageOptions.error = state.error; + browserStorageOptions.maxStartedAt = state.maxStartedAt; + browserStorageOptions.minStartedAt = state.minStartedAt; + browserStorageOptions.name = state.name; + browserStorageOptions.namePrefix = state.namePrefix; + browserStorageOptions.namespace = state.namespace; + browserStorageOptions.pagination = state.pagination; + browserStorageOptions.selectedLabels = state.selectedLabels; + browserStorageOptions.selectedPhases = state.selectedPhases; + return browserStorageOptions; } private saveHistory() { - this.storage.setItem('options', this.fetchBrowserStorageStateObject(this.state), {} as State); + this.storage.setItem('options', this.fetchBrowserStorageStateObject(this.state), {} as BrowserStorageOptions); const newNamespace = Utils.managedNamespace ? '' : this.state.namespace; this.url = uiUrl('archived-workflows' + (newNamespace ? '/' + newNamespace : '') + '?' + this.filterParams.toString()); Utils.currentNamespace = this.state.namespace;