fix(app): sync showSystem between stacks and apps tables [EE-6216] (#10532)

pull/10509/head^2
Ali 1 year ago committed by GitHub
parent 7d868d1dc9
commit 1140804fe9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -20,6 +20,7 @@ angular.module('portainer.kubernetes').component('kubernetesApplicationsDatatabl
onChangeNamespaceDropdown: '<', onChangeNamespaceDropdown: '<',
isAppsLoading: '<', isAppsLoading: '<',
isSystemResources: '<', isSystemResources: '<',
isVisible: '<',
setSystemResources: '<', setSystemResources: '<',
hideStacksFunctionality: '<', hideStacksFunctionality: '<',
}, },

@ -4,7 +4,7 @@ import KubernetesApplicationHelper from 'Kubernetes/helpers/application';
import KubernetesNamespaceHelper from 'Kubernetes/helpers/namespaceHelper'; import KubernetesNamespaceHelper from 'Kubernetes/helpers/namespaceHelper';
import { KubernetesConfigurationKinds } from 'Kubernetes/models/configuration/models'; import { KubernetesConfigurationKinds } from 'Kubernetes/models/configuration/models';
angular.module('portainer.docker').controller('KubernetesApplicationsDatatableController', [ angular.module('portainer.kubernetes').controller('KubernetesApplicationsDatatableController', [
'$scope', '$scope',
'$controller', '$controller',
'DatatableService', 'DatatableService',
@ -175,8 +175,15 @@ angular.module('portainer.docker').controller('KubernetesApplicationsDatatableCo
} }
}; };
this.$onChanges = function () { this.$onChanges = function (changes) {
if (typeof this.isSystemResources !== 'undefined') { // when the table is visible, sync the show system setting with the stack show system setting
if (changes.isVisible && changes.isVisible.currentValue) {
const storedStacksSettings = DatatableService.getDataTableSettings('kubernetes.applications.stacks');
if (storedStacksSettings && storedStacksSettings.state) {
this.settings.showSystem = storedStacksSettings.state.showSystemResources;
DatatableService.setDataTableSettings(this.settingsKey, this.settings);
}
} else if (typeof this.isSystemResources !== 'undefined') {
this.settings.showSystem = this.isSystemResources; this.settings.showSystem = this.isSystemResources;
DatatableService.setDataTableSettings(this.settingsKey, this.settings); DatatableService.setDataTableSettings(this.settingsKey, this.settings);
} }
@ -223,6 +230,12 @@ angular.module('portainer.docker').controller('KubernetesApplicationsDatatableCo
this.settings = storedSettings; this.settings = storedSettings;
this.settings.open = false; this.settings.open = false;
// make show system in sync with the stack show system settings
const storedStacksSettings = DatatableService.getDataTableSettings('kubernetes.applications.stacks');
if (storedStacksSettings && storedStacksSettings.state) {
this.settings.showSystem = storedStacksSettings.state.showSystemResources;
}
this.setSystemResources && this.setSystemResources(this.settings.showSystem); this.setSystemResources && this.setSystemResources(this.settings.showSystem);
} }
this.settingsLoaded = true; this.settingsLoaded = true;

@ -160,6 +160,8 @@ export const ngModule = angular
'namespaces', 'namespaces',
'onNamespaceChange', 'onNamespaceChange',
'isLoading', 'isLoading',
'showSystem',
'setSystemResources',
]) ])
); );

@ -24,6 +24,7 @@
on-change-namespace-dropdown="(ctrl.onChangeNamespaceDropdown)" on-change-namespace-dropdown="(ctrl.onChangeNamespaceDropdown)"
is-apps-loading="ctrl.state.isAppsLoading" is-apps-loading="ctrl.state.isAppsLoading"
is-system-resources="ctrl.state.isSystemResources" is-system-resources="ctrl.state.isSystemResources"
is-visible="ctrl.state.activeTab === 0"
set-system-resources="(ctrl.setSystemResources)" set-system-resources="(ctrl.setSystemResources)"
hide-stacks-functionality="ctrl.deploymentOptions.hideStacksFunctionality" hide-stacks-functionality="ctrl.deploymentOptions.hideStacksFunctionality"
> >
@ -40,6 +41,8 @@
namespace="ctrl.state.namespaceName" namespace="ctrl.state.namespaceName"
is-loading="ctrl.state.isAppsLoading" is-loading="ctrl.state.isAppsLoading"
on-namespace-change="(ctrl.onChangeNamespaceDropdown)" on-namespace-change="(ctrl.onChangeNamespaceDropdown)"
show-system="ctrl.state.isSystemResources"
set-system-resources="(ctrl.setSystemResources)"
> >
</kubernetes-applications-stacks-datatable> </kubernetes-applications-stacks-datatable>
</uib-tab> </uib-tab>

@ -95,7 +95,7 @@ export function createPersistedStore<T extends BasicTableSettings>(
...create(set), ...create(set),
}) as T, }) as T,
{ {
name: `datatable_settings_${keyBuilder(storageKey)}`, name: keyBuilder(`datatable_settings_${storageKey}`),
} }
) )
); );

@ -1,11 +1,11 @@
import { List } from 'lucide-react'; import { List } from 'lucide-react';
import { useEffect } from 'react';
import { useAuthorizations } from '@/react/hooks/useUser'; import { useAuthorizations } from '@/react/hooks/useUser';
import { SystemResourceDescription } from '@/react/kubernetes/datatables/SystemResourceDescription'; import { SystemResourceDescription } from '@/react/kubernetes/datatables/SystemResourceDescription';
import { systemResourcesSettings } from '@/react/kubernetes/datatables/SystemResourcesSettings'; import { createStore } from '@/react/kubernetes/datatables/default-kube-datatable-store';
import { ExpandableDatatable } from '@@/datatables/ExpandableDatatable'; import { ExpandableDatatable } from '@@/datatables/ExpandableDatatable';
import { createPersistedStore, refreshableSettings } from '@@/datatables/types';
import { useRepeater } from '@@/datatables/useRepeater'; import { useRepeater } from '@@/datatables/useRepeater';
import { useTableState } from '@@/datatables/useTableState'; import { useTableState } from '@@/datatables/useTableState';
import { InsightsBox } from '@@/InsightsBox'; import { InsightsBox } from '@@/InsightsBox';
@ -14,21 +14,14 @@ import { KubernetesStack } from '../../types';
import { columns } from './columns'; import { columns } from './columns';
import { SubRows } from './SubRows'; import { SubRows } from './SubRows';
import { Namespace, TableSettings } from './types'; import { Namespace } from './types';
import { StacksSettingsMenu } from './StacksSettingsMenu'; import { StacksSettingsMenu } from './StacksSettingsMenu';
import { NamespaceFilter } from './NamespaceFilter'; import { NamespaceFilter } from './NamespaceFilter';
import { TableActions } from './TableActions'; import { TableActions } from './TableActions';
const storageKey = 'kubernetes.applications.stacks'; const storageKey = 'kubernetes.applications.stacks';
const settingsStore = createPersistedStore<TableSettings>( const settingsStore = createStore(storageKey);
storageKey,
'name',
(set) => ({
...systemResourcesSettings(set),
...refreshableSettings(set),
})
);
interface Props { interface Props {
dataset: Array<KubernetesStack>; dataset: Array<KubernetesStack>;
@ -38,6 +31,8 @@ interface Props {
namespaces: Array<Namespace>; namespaces: Array<Namespace>;
onNamespaceChange(namespace: string): void; onNamespaceChange(namespace: string): void;
isLoading?: boolean; isLoading?: boolean;
showSystem?: boolean;
setSystemResources(showSystem: boolean): void;
} }
export function ApplicationsStacksDatatable({ export function ApplicationsStacksDatatable({
@ -48,9 +43,16 @@ export function ApplicationsStacksDatatable({
namespaces, namespaces,
onNamespaceChange, onNamespaceChange,
isLoading, isLoading,
showSystem,
setSystemResources,
}: Props) { }: Props) {
const tableState = useTableState(settingsStore, storageKey); const tableState = useTableState(settingsStore, storageKey);
useEffect(() => {
tableState.setShowSystemResources(showSystem || false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [showSystem]);
const authorized = useAuthorizations('K8sApplicationsW'); const authorized = useAuthorizations('K8sApplicationsW');
useRepeater(tableState.autoRefreshRate, onRefresh); useRepeater(tableState.autoRefreshRate, onRefresh);
@ -98,7 +100,12 @@ export function ApplicationsStacksDatatable({
renderTableActions={(selectedItems) => ( renderTableActions={(selectedItems) => (
<TableActions selectedItems={selectedItems} onRemove={onRemove} /> <TableActions selectedItems={selectedItems} onRemove={onRemove} />
)} )}
renderTableSettings={() => <StacksSettingsMenu settings={tableState} />} renderTableSettings={() => (
<StacksSettingsMenu
setSystemResources={setSystemResources}
settings={tableState}
/>
)}
getRowId={(row) => `${row.Name}-${row.ResourcePool}`} getRowId={(row) => `${row.Name}-${row.ResourcePool}`}
/> />
); );

@ -5,12 +5,21 @@ import { TableSettingsMenuAutoRefresh } from '@@/datatables/TableSettingsMenuAut
import { type TableSettings } from './types'; import { type TableSettings } from './types';
export function StacksSettingsMenu({ settings }: { settings: TableSettings }) { export function StacksSettingsMenu({
settings,
setSystemResources,
}: {
settings: TableSettings;
setSystemResources(showSystem: boolean): void;
}) {
return ( return (
<TableSettingsMenu> <TableSettingsMenu>
<SystemResourcesSettings <SystemResourcesSettings
value={settings.showSystemResources} value={settings.showSystemResources}
onChange={(value) => settings.setShowSystemResources(value)} onChange={(value) => {
setSystemResources(value);
settings.setShowSystemResources(value);
}}
/> />
<TableSettingsMenuAutoRefresh <TableSettingsMenuAutoRefresh

Loading…
Cancel
Save