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

upcoming: [DI-20360] - Updated preferences logic to remove flickering issue #10853

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1cda196
upcoming: [DI-20360] - Modified user preference logic
nikhagra-akamai Aug 26, 2024
f54ca49
upcoming: [DI-20360] - Modified user preference logic
nikhagra-akamai Aug 27, 2024
1096463
upcoming: [DI-20360] - Removed useEffect from widget component
nikhagra-akamai Aug 29, 2024
6e9f899
upcoming: [DI-20360] - Updated request.tsx file
nikhagra-akamai Aug 29, 2024
a7ce52f
upcoming: [DI-20360] - remove sensitive information
nikhagra-akamai Aug 29, 2024
12fcb4b
upcoming: [DI-20360] - Update preference logic to avoid extra re-rend…
nikhagra-akamai Sep 2, 2024
c82dcc3
Merge branch 'develop' of github.com:linode/manager into feature/user…
nikhagra-akamai Sep 2, 2024
7d14f46
upcoming: [DI-20360] - Updated preference logic in custom select
nikhagra-akamai Sep 2, 2024
a32940d
upcoming: [DI-20360] - Metrics api hardcoded url removed
nikhagra-akamai Sep 2, 2024
0545491
upcoming: [DI-20360] - Updated jsdocs & removed un-used variable
nikhagra-akamai Sep 3, 2024
33938a5
upcoming: [DI-20360] - Test cases updated
nikhagra-akamai Sep 3, 2024
c279885
upcoming: [DI-20360] - added changeset
nikhagra-akamai Sep 3, 2024
21496fb
upcoming: [DI-20360] - Removed unused variable
nikhagra-akamai Sep 3, 2024
32a571a
upcoming: [DI-20360] - merge conflicts resolved
nikhagra-akamai Sep 4, 2024
4ebcaf1
upcoming: [DI-20360] - Optimized user preferences to avoid passing up…
nikhagra-akamai Sep 9, 2024
4f9adad
upcoming: [DI-20360] - Eslint errors resolve
nikhagra-akamai Sep 9, 2024
78887f7
upcoming: [DI-20360] - Merge conflicts resolved
nikhagra-akamai Sep 10, 2024
638c9dd
Merge branch 'develop' of github.com:linode/manager into feature/user…
nikhagra-akamai Sep 10, 2024
a29a798
upcoming: [DI-20360] - Changes based on review comments
nikhagra-akamai Sep 11, 2024
0341fa9
upcoming: [DI-20360] - Passing default values to components instead o…
nikhagra-akamai Sep 11, 2024
3682243
upcoming: [DI-20360] - Upddated widget components to avoid infinite loop
nikhagra-akamai Sep 11, 2024
e5d8257
upcoming: [DI-20360] - Updated review comment suggestions & test cases
nikhagra-akamai Sep 16, 2024
a2744c0
upcoming: [DI-20360] - Updated review comments
nikhagra-akamai Sep 16, 2024
2a662ae
upcoming: [DI-20360] - Test cases updated
nikhagra-akamai Sep 18, 2024
1e7e897
upcoming: [DI-20360] - Modified user preference logic
nikhagra-akamai Aug 26, 2024
c4e4845
upcoming: [DI-20360] - Modified user preference logic
nikhagra-akamai Aug 27, 2024
c03e981
upcoming: [DI-20360] - Updated request.tsx file
nikhagra-akamai Aug 29, 2024
ddc1dca
upcoming: [DI-20360] - remove sensitive information
nikhagra-akamai Aug 29, 2024
32c723c
upcoming: [DI-20360] - Update preference logic to avoid extra re-rend…
nikhagra-akamai Sep 2, 2024
2261c75
upcoming: [DI-20360] - Updated preference logic in custom select
nikhagra-akamai Sep 2, 2024
a24d22a
upcoming: [DI-20360] - Optimized user preferences to avoid passing up…
nikhagra-akamai Sep 9, 2024
ef4f647
upcoming: [DI-20360] - Changes based on review comments
nikhagra-akamai Sep 11, 2024
22374c6
upcoming: [DI-20360] - Upddated widget components to avoid infinite loop
nikhagra-akamai Sep 11, 2024
a7a1b0f
upcoming: [DI-20360] - Updated review comment suggestions & test cases
nikhagra-akamai Sep 16, 2024
427cd4e
upcoming: [DI-20360] - Updated useAclpPreference hook to use ref for …
venkat199501 Sep 19, 2024
c187805
upcoming: [DI-20360] - Updated compare props logic
nikhagra-akamai Sep 23, 2024
b411b94
upcoming: [DI-20360] - Test cases updated
nikhagra-akamai Sep 24, 2024
6efbcae
upcoming: [DI-20360] - Merge conflicts resolved
nikhagra-akamai Sep 24, 2024
9468109
upcoming: [DI-20360] - Updated ESLint issues
nikhagra-akamai Sep 24, 2024
3bd5d3b
upcoming: [DI-20360] - Updated review comments
nikhagra-akamai Sep 24, 2024
56af561
upcoming: [DI-20360] - Test cases updated
nikhagra-akamai Sep 24, 2024
383dd1a
upcoming: [DI-20360] - Updated logic to prevent widget preference to …
nikhagra-akamai Sep 24, 2024
28b5ff9
upcoming: [DI-20360] - Separated components into different files
nikhagra-akamai Sep 24, 2024
1f164c3
upcoming: [DI-20360] - updated funcntions with useMemo
nikhagra-akamai Sep 24, 2024
a8ee8c9
upcoming: [DI-20360] - updated eslint issues
nikhagra-akamai Sep 24, 2024
da521cd
upcoming: [DI-20360] - Updated widget preferences logic
nikhagra-akamai Sep 25, 2024
432f48d
upcoming: [DI-20360] - Updated deep equal logic
nikhagra-akamai Sep 25, 2024
b51e591
Updated aggregate function type
nikhagra-akamai Sep 26, 2024
7a1e419
upcoming: [DI-20360] - Updated global filter test cases
nikhagra-akamai Sep 26, 2024
88c8c90
upcoming: [DI-20360] - Updated eslint issue
nikhagra-akamai Sep 26, 2024
e25a627
upcoming: [DI-20360] - Removed unnecessary compare functions
nikhagra-akamai Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/api-v4": Upcoming Features
---

Add export to FilterValue interface ([#10853](https://github.com/linode/manager/pull/10853))
5 changes: 2 additions & 3 deletions packages/api-v4/src/cloudpulse/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface Dashboard {
export interface TimeGranularity {
unit: string;
value: number;
label?: string;
}

export interface TimeDuration {
Expand Down Expand Up @@ -44,8 +45,7 @@ export interface Filters {
value: string;
}

// Define the type for filter values
type FilterValue =
export type FilterValue =
nikhagra-akamai marked this conversation as resolved.
Show resolved Hide resolved
| number
| string
| string[]
Expand All @@ -56,7 +56,6 @@ type FilterValue =
type WidgetFilterValue = { [key: string]: AclpWidget };

export interface AclpConfig {
// we maintain only the filters selected in the preferences for latest selected dashboard
[key: string]: FilterValue;
widgets?: WidgetFilterValue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Upcoming Features
---

add useAclpPreference hook in UserPreference.ts, update CloudPulseWidget.ts, CloudPulseDashboard & GlobalFilters to use useAclpPreference and pass preference values to child component ([#10853](https://github.com/linode/manager/pull/10853))
Original file line number Diff line number Diff line change
@@ -1,37 +1,20 @@
import { Grid, Paper } from '@mui/material';
import { Grid } from '@mui/material';
import React from 'react';

import CloudPulseIcon from 'src/assets/icons/entityIcons/monitor.svg';
import { CircleProgress } from 'src/components/CircleProgress';
import { ErrorState } from 'src/components/ErrorState/ErrorState';
import { Placeholder } from 'src/components/Placeholder/Placeholder';
import { useCloudPulseDashboardByIdQuery } from 'src/queries/cloudpulse/dashboards';
import { useResourcesQuery } from 'src/queries/cloudpulse/resources';
import {
useCloudPulseJWEtokenQuery,
useGetCloudPulseMetricDefinitionsByServiceType,
} from 'src/queries/cloudpulse/services';

import { getUserPreferenceObject } from '../Utils/UserPreference';
import { createObjectCopy } from '../Utils/utils';
import { CloudPulseWidget } from '../Widget/CloudPulseWidget';
import {
allIntervalOptions,
getInSeconds,
getIntervalIndex,
} from '../Widget/components/CloudPulseIntervalSelect';
import { useAclpPreference } from '../Utils/UserPreference';
import { RenderWidgets } from '../Widget/CloudPulseWidgetRenderer';

import type {
CloudPulseMetricsAdditionalFilters,
CloudPulseWidgetProperties,
} from '../Widget/CloudPulseWidget';
import type {
AvailableMetrics,
Dashboard,
JWETokenPayLoad,
TimeDuration,
Widgets,
} from '@linode/api-v4';
import type { CloudPulseMetricsAdditionalFilters } from '../Widget/CloudPulseWidget';
import type { JWETokenPayLoad, TimeDuration } from '@linode/api-v4';

export interface DashboardProperties {
/**
Expand All @@ -52,7 +35,7 @@ export interface DashboardProperties {
/**
* optional timestamp to pass as react query param to forcefully re-fetch data
*/
manualRefreshTimeStamp?: number | undefined;
manualRefreshTimeStamp?: number;

/**
* Selected region for the dashboard
Expand Down Expand Up @@ -80,53 +63,14 @@ export const CloudPulseDashboard = (props: DashboardProperties) => {
savePref,
} = props;

const { preferences } = useAclpPreference();

const getJweTokenPayload = (): JWETokenPayLoad => {
return {
resource_ids: resourceList?.map((resource) => Number(resource.id)) ?? [],
};
};

const getCloudPulseGraphProperties = (
widget: Widgets
): CloudPulseWidgetProperties => {
const graphProp: CloudPulseWidgetProperties = {
additionalFilters,
ariaLabel: widget.label,
authToken: '',
availableMetrics: undefined,
duration,
errorLabel: 'Error While Loading Data',
resourceIds: resources,
resources: [],
serviceType: dashboard?.service_type ?? '',
timeStamp: manualRefreshTimeStamp,
unit: widget.unit ?? '%',
widget: { ...widget },
};
if (savePref) {
setPreferredWidgetPlan(graphProp.widget);
}
return graphProp;
};

const setPreferredWidgetPlan = (widgetObj: Widgets) => {
const widgetPreferences = getUserPreferenceObject().widgets;
const pref = widgetPreferences?.[widgetObj.label];
if (pref) {
Object.assign(widgetObj, {
aggregate_function: pref.aggregateFunction,
size: pref.size,
time_granularity: { ...pref.timeGranularity },
});
}
};

const getTimeGranularity = (scrapeInterval: string) => {
const scrapeIntervalValue = getInSeconds(scrapeInterval);
const index = getIntervalIndex(scrapeIntervalValue);
return index < 0 ? allIntervalOptions[0] : allIntervalOptions[index];
};

const {
data: dashboard,
isLoading: isDashboardLoading,
Expand Down Expand Up @@ -182,76 +126,18 @@ export const CloudPulseDashboard = (props: DashboardProperties) => {
return <ErrorState errorText={'Error loading metric definitions'} />;
}

const RenderWidgets = () => {
if (!dashboard || !dashboard.widgets?.length) {
return renderPlaceHolder(
'No visualizations are available at this moment. Create Dashboards to list here.'
);
}

if (
!dashboard.service_type ||
!Boolean(resources.length > 0) ||
!jweToken?.token ||
!Boolean(resourceList?.length)
) {
return renderPlaceHolder(
'Select Dashboard, Region and Resource to visualize metrics'
);
}

// maintain a copy
const newDashboard: Dashboard = createObjectCopy(dashboard)!;
return (
<Grid columnSpacing={2} container item rowSpacing={2} xs={12}>
{{ ...newDashboard }.widgets.map((widget, index) => {
// check if widget metric definition is available or not
if (widget) {
// find the metric defintion of the widget label
const availMetrics = metricDefinitions?.data.find(
(availMetrics: AvailableMetrics) =>
widget.label === availMetrics.label
);
const cloudPulseWidgetProperties = getCloudPulseGraphProperties({
...widget,
});

// metric definition is available but time_granularity is not present
if (
availMetrics &&
!cloudPulseWidgetProperties.widget.time_granularity
) {
cloudPulseWidgetProperties.widget.time_granularity = getTimeGranularity(
availMetrics.scrape_interval
);
}
return (
<CloudPulseWidget
key={widget.label}
{...cloudPulseWidgetProperties}
authToken={jweToken?.token}
availableMetrics={availMetrics}
resources={resourceList!}
savePref={savePref}
/>
);
} else {
return <React.Fragment key={index}></React.Fragment>;
}
})}
</Grid>
);
};

const renderPlaceHolder = (title: string) => {
return (
<Grid item xs>
<Paper>
<Placeholder icon={CloudPulseIcon} isEntity title={title} />
</Paper>
</Grid>
);
};

return <RenderWidgets />;
return (
<RenderWidgets
additionalFilters={additionalFilters}
dashboard={dashboard}
duration={duration}
jweToken={jweToken}
manualRefreshTimeStamp={manualRefreshTimeStamp}
metricDefinitions={metricDefinitions}
preferences={preferences}
resourceList={resourceList}
resources={resources}
savePref={savePref}
/>
);
};
Loading
Loading