Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

convert Topology filters localStorage to userSettings #7326

Merged
merged 1 commit into from Dec 1, 2020

Conversation

sahil143
Copy link
Contributor

@sahil143 sahil143 commented Nov 25, 2020

Fixes: https://issues.redhat.com/browse/ODC-5038

Removed filter and appliedFilters from redux/local storage and added in userSettings.

Screen shots / Gifs for design review: No UI changes

Unit test coverage report:

Test setup:

Browser conformance:

  • Chrome
  • Safari
  • Edge
  • Firefox

@@ -48,7 +43,7 @@ interface StateProps {

interface DispatchProps {
onSelectTab?: (name: string) => void;
onFiltersChange: (filters: DisplayFilters) => void;
// onFiltersChange: (filters: DisplayFilters) => void;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can remove comment


const TOPOLOGY_DISPLAY_FILTERS_CONFIG_MAP_KEY = `devcosole.topology.filters`;

const getTopologyFilters = (appliedFilters) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we have type for appliedFilters

TOPOLOGY_DISPLAY_FILTERS_CONFIG_MAP_KEY,
getDefaultAppliedFilters(),
);
const [filtersLoaded, setFiltersLoaded] = React.useState<boolean>(false);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this useState , can't we rely on appliedFiltersLoaded?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is needed because filters depend on the data which is coming from user settings(appliedFilters). so once the user settings is loaded we need to update the filters as well and notify the component that all of the data is loaded.

@invincibleJai
Copy link
Member

/cc @jerolimov


const useAppliedDisplayFilters = (): DisplayFilters => {
return useSelector((state: RootState) => getAppliedTopologyFilters(state));
const useAppliedDisplayFilters = (): { [filiterKey: string]: boolean } => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo

Suggested change
const useAppliedDisplayFilters = (): { [filiterKey: string]: boolean } => {
const useAppliedDisplayFilters = (): { [filterKey: string]: boolean } => {

import { getAppliedFilters } from '../redux/action';
import { DisplayFilters } from '../topology-types';

const TOPOLOGY_DISPLAY_FILTERS_CONFIG_MAP_KEY = `devcosole.topology.filters`;
Copy link
Member

@jerolimov jerolimov Nov 27, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const TOPOLOGY_DISPLAY_FILTERS_CONFIG_MAP_KEY = `devcosole.topology.filters`;
const TOPOLOGY_DISPLAY_FILTERS_USERSETTINGS_KEY = `devconsole.topology.filters`;

Typo in the key. And wdyt about using usersettings key instead of configmap key?

@jerolimov
Copy link
Member

jerolimov commented Nov 27, 2020

@sahil143 When having a Deployment and DeploymentConfig in my topology and filter for only Deployments and reload the page, the filter was automatically overridden / dropped.

When adding a console.warn to useUserSetting hook before calling updateConfigMap I notice that the filter is first stored correctly and was then removed when I reloaded the page:

When selecting Deployment it saves:

update devcosole.topology.filters
{
apps~v1~Deployment: true <===
expand-app-groups: true
expand-groups: true
helmGrouping: true
knativeServices: true
operatorGrouping: true
show-groups: true
show-labels: true
show-pod-count: true
}

After reload the page it sends two updates:

update devcosole.topology.filters
{
expand-app-groups: true
expand-groups: true
show-groups: true
show-labels: true
show-pod-count: true
}
update devcosole.topology.filters 
{
expand-app-groups: true
expand-groups: true
helmGrouping: true
knativeServices: true
operatorGrouping: true
show-groups: true
show-labels: true
show-pod-count: true
}

Any ideas? Did you need more info? We can make a call if you cant reproduce this.

boolean,
SetTopologyFilters,
] => {
const [appliedFilters, setAppliedFilters, appliedFiltersLoaded] = useUserSettings(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@invincibleJai Should this not use the fallback wrapper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing this, used the wrapper useUserSettingsCompatibility.

] => {
const [appliedFilters, setAppliedFilters, appliedFiltersLoaded] = useUserSettings(
TOPOLOGY_DISPLAY_FILTERS_CONFIG_MAP_KEY,
getDefaultAppliedFilters(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sahil143 I thought our goal here was to get rid of the reducer and obfuscate local storage... why are we using this as the defaults?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed.

[setAppliedFilters],
);

return [filters, appliedFilters, appliedFilters && filtersLoaded, setTopologyFilters];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If appliedFilters are what we have stored in user settings... and filters are just appliedFilters with added defaults... why are we providing both back? Wouldn't we want just filters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because appliedFilters is also being used in component.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... we probably should look to refactor that -- let's go with this for now since it's the status quo with the implementation. But it seems like an odd situation.

@@ -34,36 +31,29 @@ import QuickSearchButton from './quick-search/QuickSearchButton';
import { getNamespaceDashboardKialiLink } from '../utils/topology-utils';

import './TopologyFilterBar.scss';
import { FilterContext } from './FilterProvider';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: sort

import { useDeepCompareMemoize } from '@console/shared/src';
import { FilterContext } from './FilterProvider';
import { useContext } from 'react';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Sort

@sahil143
Copy link
Contributor Author

@sahil143 When having a Deployment and DeploymentConfig in my topology and filter for only Deployments and reload the page, the filter was automatically overridden / dropped.

I was able to reproduce this on master as well. I think we can log a bug to handle this.

@sahil143
Copy link
Contributor Author

@andrewballantyne @jerolimov Addressed all comments. Please review again.

@invincibleJai
Copy link
Member

@sahil143 When having a Deployment and DeploymentConfig in my topology and filter for only Deployments and reload the page, the filter was automatically overridden / dropped.

I was able to reproduce this on master as well. I think we can log a bug to handle this.

Verified the changes all works as expected apart from what mentioned above (this is observed in master as well so can be taken as separate issue)

@jerolimov
Copy link
Member

jerolimov commented Nov 30, 2020

@sahil143 @invincibleJai Yeah works "similar" to master, it was saved successfully and then override when loading the page.

As discussed in slack this is by design because the list of available resource types changes per project.

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 30, 2020
import * as React from 'react';
import { useUserSettingsCompatibility } from '@console/shared';
import { DEFAULT_TOPOLOGY_FILTERS } from './const';
import { getAppliedFilters } from '../redux/action';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getAppliedFilters was only used in this Provider. Can we remove it from redux/action.ts since it looks like that we still use redux here?!

[setAppliedFilters],
);

return [filters, appliedFilters, appliedFilters && filtersLoaded, setTopologyFilters];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm... we probably should look to refactor that -- let's go with this for now since it's the status quo with the implementation. But it seems like an odd situation.

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 30, 2020
add typings

remove comments

address review comments

refactor
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Nov 30, 2020
@jerolimov
Copy link
Member

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 30, 2020
@invincibleJai
Copy link
Member

/test e2e-gcp-console

@andrewballantyne
Copy link
Contributor

/retest

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

3 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@christianvogt
Copy link
Contributor

/approve

@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andrewballantyne, christianvogt, jerolimov, sahil143

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

2 similar comments
@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@jerolimov
Copy link
Member

/retest

@openshift-merge-robot openshift-merge-robot merged commit f65ce5e into openshift:master Dec 1, 2020
@spadgett spadgett added this to the v4.7 milestone Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants