fix(apps): persist table settings [r8s-120]

fix/r8s-120/app-table-settings-persistence
testA113 2024-10-08 18:01:22 +13:00
parent b14438fd99
commit ec65b1ff7f
8 changed files with 12 additions and 86 deletions

View File

@ -15,8 +15,6 @@ export const applicationsModule = angular
'namespaces', 'namespaces',
'onNamespaceChange', 'onNamespaceChange',
'onRefresh', 'onRefresh',
'showSystem',
'onShowSystemChange',
'onRemove', 'onRemove',
'hideStacks', 'hideStacks',
]) ])

View File

@ -215,8 +215,6 @@ export const ngModule = angular
'namespace', 'namespace',
'namespaces', 'namespaces',
'onNamespaceChange', 'onNamespaceChange',
'showSystem',
'setSystemResources',
]) ])
) )
.component( .component(

View File

@ -18,8 +18,6 @@
namespace="ctrl.state.namespaceName" namespace="ctrl.state.namespaceName"
on-namespace-change="(ctrl.onChangeNamespaceDropdown)" on-namespace-change="(ctrl.onChangeNamespaceDropdown)"
is-loading="ctrl.state.isAppsLoading" is-loading="ctrl.state.isAppsLoading"
show-system="ctrl.state.isSystemResources"
on-show-system-change="(ctrl.setSystemResources)"
on-remove="(ctrl.removeAction)" on-remove="(ctrl.removeAction)"
hide-stacks="ctrl.deploymentOptions.hideStacksFunctionality" hide-stacks="ctrl.deploymentOptions.hideStacksFunctionality"
> >
@ -50,8 +48,6 @@
namespace="ctrl.state.namespaceName" namespace="ctrl.state.namespaceName"
on-namespace-change="(ctrl.onChangeNamespaceDropdown)" on-namespace-change="(ctrl.onChangeNamespaceDropdown)"
is-loading="ctrl.state.isAppsLoading" is-loading="ctrl.state.isAppsLoading"
show-system="ctrl.state.isSystemResources"
on-show-system-change="(ctrl.setSystemResources)"
on-remove="(ctrl.removeAction)" on-remove="(ctrl.removeAction)"
hide-stacks="ctrl.deploymentOptions.hideStacksFunctionality" hide-stacks="ctrl.deploymentOptions.hideStacksFunctionality"
> >

View File

@ -42,7 +42,6 @@ class KubernetesApplicationsController {
this.removeStacksActionAsync = this.removeStacksActionAsync.bind(this); this.removeStacksActionAsync = this.removeStacksActionAsync.bind(this);
this.onPublishingModeClick = this.onPublishingModeClick.bind(this); this.onPublishingModeClick = this.onPublishingModeClick.bind(this);
this.onChangeNamespaceDropdown = this.onChangeNamespaceDropdown.bind(this); this.onChangeNamespaceDropdown = this.onChangeNamespaceDropdown.bind(this);
this.setSystemResources = this.setSystemResources.bind(this);
} }
selectTab(index) { selectTab(index) {
@ -133,12 +132,6 @@ class KubernetesApplicationsController {
}); });
} }
setSystemResources(flag) {
return this.$scope.$applyAsync(() => {
this.state.isSystemResources = flag;
});
}
async onInit() { async onInit() {
this.state = { this.state = {
activeTab: this.LocalStorage.getActiveTab('applications'), activeTab: this.LocalStorage.getActiveTab('applications'),
@ -150,7 +143,6 @@ class KubernetesApplicationsController {
ports: [], ports: [],
namespaces: [], namespaces: [],
namespaceName: '', namespaceName: '',
isSystemResources: undefined,
}; };
this.deploymentOptions = await getDeploymentOptions(); this.deploymentOptions = await getDeploymentOptions();

View File

@ -1,4 +1,3 @@
import { useEffect } from 'react';
import { BoxIcon } from 'lucide-react'; import { BoxIcon } from 'lucide-react';
import { useKubeStore } from '@/react/kubernetes/datatables/default-kube-datatable-store'; import { useKubeStore } from '@/react/kubernetes/datatables/default-kube-datatable-store';
@ -33,8 +32,6 @@ export function ApplicationsDatatable({
namespace = '', namespace = '',
namespaces, namespaces,
onNamespaceChange, onNamespaceChange,
showSystem,
onShowSystemChange,
hideStacks, hideStacks,
}: { }: {
onRefresh: () => void; onRefresh: () => void;
@ -42,8 +39,6 @@ export function ApplicationsDatatable({
namespace?: string; namespace?: string;
namespaces: Array<Namespace>; namespaces: Array<Namespace>;
onNamespaceChange(namespace: string): void; onNamespaceChange(namespace: string): void;
showSystem?: boolean;
onShowSystemChange(showSystem: boolean): void;
hideStacks: boolean; hideStacks: boolean;
}) { }) {
const envId = useEnvironmentId(); const envId = useEnvironmentId();
@ -58,20 +53,13 @@ export function ApplicationsDatatable({
undefined, undefined,
false false
); );
const { setShowSystemResources } = tableState;
useEffect(() => {
setShowSystemResources(showSystem || false);
}, [showSystem, setShowSystemResources]);
const applicationsQuery = useApplications(envId, { const applicationsQuery = useApplications(envId, {
refetchInterval: tableState.autoRefreshRate * 1000, refetchInterval: tableState.autoRefreshRate * 1000,
namespace, namespace,
withDependencies: true, withDependencies: true,
}); });
const applications = applicationsQuery.data ?? []; const applications = applicationsQuery.data ?? [];
const filteredApplications = showSystem const filteredApplications = tableState.showSystemResources
? applications ? applications
: applications.filter( : applications.filter(
(application) => (application) =>
@ -124,10 +112,7 @@ export function ApplicationsDatatable({
} }
renderTableSettings={() => ( renderTableSettings={() => (
<TableSettingsMenu> <TableSettingsMenu>
<DefaultDatatableSettings <DefaultDatatableSettings settings={tableState} />
settings={tableState}
onShowSystemChange={onShowSystemChange}
/>
</TableSettingsMenu> </TableSettingsMenu>
)} )}
description={ description={

View File

@ -1,5 +1,4 @@
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';
@ -7,16 +6,17 @@ import { createStore } from '@/react/kubernetes/datatables/default-kube-datatabl
import { useEnvironmentId } from '@/react/hooks/useEnvironmentId'; import { useEnvironmentId } from '@/react/hooks/useEnvironmentId';
import { isSystemNamespace } from '@/react/kubernetes/namespaces/queries/useIsSystemNamespace'; import { isSystemNamespace } from '@/react/kubernetes/namespaces/queries/useIsSystemNamespace';
import { useNamespacesQuery } from '@/react/kubernetes/namespaces/queries/useNamespacesQuery'; import { useNamespacesQuery } from '@/react/kubernetes/namespaces/queries/useNamespacesQuery';
import { DefaultDatatableSettings } from '@/react/kubernetes/datatables/DefaultDatatableSettings';
import { ExpandableDatatable } from '@@/datatables/ExpandableDatatable'; import { ExpandableDatatable } from '@@/datatables/ExpandableDatatable';
import { useTableState } from '@@/datatables/useTableState'; import { useTableState } from '@@/datatables/useTableState';
import { TableSettingsMenu } from '@@/datatables';
import { useApplications } from '../../application.queries'; import { useApplications } from '../../application.queries';
import { columns } from './columns'; import { columns } from './columns';
import { SubRows } from './SubRows'; import { SubRows } from './SubRows';
import { Namespace, Stack } from './types'; import { Namespace, Stack } from './types';
import { StacksSettingsMenu } from './StacksSettingsMenu';
import { NamespaceFilter } from './NamespaceFilter'; import { NamespaceFilter } from './NamespaceFilter';
import { TableActions } from './TableActions'; import { TableActions } from './TableActions';
import { getStacksFromApplications } from './getStacksFromApplications'; import { getStacksFromApplications } from './getStacksFromApplications';
@ -30,8 +30,6 @@ interface Props {
namespace?: string; namespace?: string;
namespaces: Array<Namespace>; namespaces: Array<Namespace>;
onNamespaceChange(namespace: string): void; onNamespaceChange(namespace: string): void;
showSystem?: boolean;
setSystemResources(showSystem: boolean): void;
} }
export function ApplicationsStacksDatatable({ export function ApplicationsStacksDatatable({
@ -39,17 +37,9 @@ export function ApplicationsStacksDatatable({
namespace = '', namespace = '',
namespaces, namespaces,
onNamespaceChange, onNamespaceChange,
showSystem,
setSystemResources,
}: Props) { }: Props) {
const tableState = useTableState(settingsStore, storageKey); const tableState = useTableState(settingsStore, storageKey);
const { setShowSystemResources } = tableState;
useEffect(() => {
setShowSystemResources(showSystem || false);
}, [showSystem, setShowSystemResources]);
const envId = useEnvironmentId(); const envId = useEnvironmentId();
const applicationsQuery = useApplications(envId, { const applicationsQuery = useApplications(envId, {
refetchInterval: tableState.autoRefreshRate * 1000, refetchInterval: tableState.autoRefreshRate * 1000,
@ -58,7 +48,7 @@ export function ApplicationsStacksDatatable({
}); });
const namespaceListQuery = useNamespacesQuery(envId); const namespaceListQuery = useNamespacesQuery(envId);
const applications = applicationsQuery.data ?? []; const applications = applicationsQuery.data ?? [];
const filteredApplications = showSystem const filteredApplications = tableState.showSystemResources
? applications ? applications
: applications.filter( : applications.filter(
(item) => (item) =>
@ -90,12 +80,14 @@ export function ApplicationsStacksDatatable({
namespaces={namespaces} namespaces={namespaces}
value={namespace} value={namespace}
onChange={onNamespaceChange} onChange={onNamespaceChange}
showSystem={showSystem} showSystem={tableState.showSystemResources}
/> />
</div> </div>
<div className="space-y-2"> <div className="space-y-2">
<SystemResourceDescription showSystemResources={showSystem} /> <SystemResourceDescription
showSystemResources={tableState.showSystemResources}
/>
</div> </div>
</div> </div>
} }
@ -103,10 +95,9 @@ export function ApplicationsStacksDatatable({
<TableActions selectedItems={selectedItems} onRemove={onRemove} /> <TableActions selectedItems={selectedItems} onRemove={onRemove} />
)} )}
renderTableSettings={() => ( renderTableSettings={() => (
<StacksSettingsMenu <TableSettingsMenu>
setSystemResources={setSystemResources} <DefaultDatatableSettings settings={tableState} />
settings={tableState} </TableSettingsMenu>
/>
)} )}
getRowId={(row) => `${row.Name}-${row.ResourcePool}`} getRowId={(row) => `${row.Name}-${row.ResourcePool}`}
data-cy="applications-stacks-datatable" data-cy="applications-stacks-datatable"

View File

@ -1,31 +0,0 @@
import { SystemResourcesSettings } from '@/react/kubernetes/datatables/SystemResourcesSettings';
import { TableSettingsMenu } from '@@/datatables';
import { TableSettingsMenuAutoRefresh } from '@@/datatables/TableSettingsMenuAutoRefresh';
import { type TableSettings } from './types';
export function StacksSettingsMenu({
settings,
setSystemResources,
}: {
settings: TableSettings;
setSystemResources(showSystem: boolean): void;
}) {
return (
<TableSettingsMenu>
<SystemResourcesSettings
value={settings.showSystemResources}
onChange={(value) => {
setSystemResources(value);
settings.setShowSystemResources(value);
}}
/>
<TableSettingsMenuAutoRefresh
onChange={settings.setAutoRefreshRate}
value={settings.autoRefreshRate}
/>
</TableSettingsMenu>
);
}

View File

@ -16,10 +16,8 @@ export interface TableSettings
export function DefaultDatatableSettings({ export function DefaultDatatableSettings({
settings, settings,
onShowSystemChange,
}: { }: {
settings: TableSettings; settings: TableSettings;
onShowSystemChange?(showSystem: boolean): void;
}) { }) {
return ( return (
<> <>
@ -27,7 +25,6 @@ export function DefaultDatatableSettings({
value={settings.showSystemResources} value={settings.showSystemResources}
onChange={(value) => { onChange={(value) => {
settings.setShowSystemResources(value); settings.setShowSystemResources(value);
onShowSystemChange?.(value);
}} }}
/> />