Skip to content

Commit

Permalink
Merge branch 'main' into tooltip.for-the-last
Browse files Browse the repository at this point in the history
  • Loading branch information
szabosteve committed Feb 16, 2022
2 parents 6c20fe8 + 86f212f commit 907642b
Show file tree
Hide file tree
Showing 130 changed files with 947 additions and 764 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,5 @@ class ExitFullScreenButtonUi extends PureComponent<ExitFullScreenButtonProps> {
}
}

/** @deprecated Use `ExitFullScreenButton` from `src/plugins/shared_ux/public`. */
export const ExitFullScreenButton = ExitFullScreenButtonUi;
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ export interface Props {

/**
* A service-enabled component that provides Kibana-specific functionality to the `ExitFullScreenButton`
* component. Use of this component requires both the `EuiTheme` context as well as the Shared UX
* `ServicesProvider`.
* component.
*
* Use of this component requires both the `EuiTheme` context as well as either a configured Shared UX
* `ServicesProvider` or the `ServicesContext` provided by the Shared UX public plugin contract.
*
* See shared-ux/public/services for information.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,5 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
/* eslint-disable import/no-default-export */

import { ExitFullScreenButton } from './exit_full_screen_button';
export { ExitFullScreenButton } from './exit_full_screen_button';

/**
* Exporting the ExitFullScreenButton component as a default export so it can be
* loaded by React.lazy.
*/
export default ExitFullScreenButton;
6 changes: 5 additions & 1 deletion src/plugins/shared_ux/public/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { withSuspense } from './utility';
* The Lazily-loaded `ExitFullScreenButton` component. Consumers should use `React.Suspennse` or the
* `withSuspense` HOC to load this component.
*/
export const LazyExitFullScreenButton = React.lazy(() => import('./exit_full_screen_button'));
export const LazyExitFullScreenButton = React.lazy(() =>
import('./exit_full_screen_button').then(({ ExitFullScreenButton }) => ({
default: ExitFullScreenButton,
}))
);

/**
* A `ExitFullScreenButton` component that is wrapped by the `withSuspense` HOC. This component can
Expand Down
5 changes: 4 additions & 1 deletion src/plugins/shared_ux/public/services/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ const ServicesContext = createContext<SharedUXServices>(servicesFactory());

/**
* The `React.Context` Provider component for the `SharedUXServices` context. Any
* plugin or environemnt that consumes SharedUX components needs to wrap their React
* plugin or environment that consumes SharedUX components needs to wrap their React
* tree with this provider.
*
* Within a plugin, you can use the `ServicesContext` provided by the SharedUX plugin start
* lifeycle method.
*/
export const ServicesProvider: FC<SharedUXServices> = ({ children, ...services }) => (
<ServicesContext.Provider value={services}>{children}</ServicesContext.Provider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function ServiceContents({

const detailsUrl = apmRouter.link('/services/{serviceName}', {
path: { serviceName },
query: { rangeFrom, rangeTo, environment, kuery },
query: { rangeFrom, rangeTo, environment, kuery, comparisonEnabled },
});

const focusUrl = apmRouter.link('/services/{serviceName}/service-map', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ describe('<AgentEnrollmentFlyout />', () => {
jest.clearAllMocks();
});

it('should show loading when agent policies are loading', async () => {
(useAgentEnrollmentFlyoutData as jest.Mock).mockReturnValue?.({
agentPolicies: [],
refreshAgentPolicies: jest.fn(),
isLoadingInitialAgentPolicies: true,
});

await act(async () => {
testBed = await setup({
onClose: jest.fn(),
});
testBed.component.update();
});

const { exists } = testBed;
expect(exists('agentEnrollmentFlyout')).toBe(true);
expect(exists('loadingSpinner')).toBe(true);
});

describe('managed instructions', () => {
it('uses the agent policy selection step', async () => {
const { exists } = testBed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
import { FLEET_SERVER_PACKAGE } from '../../constants';
import type { PackagePolicy } from '../../types';

import { Loading } from '..';

import { ManagedInstructions } from './managed_instructions';
import { StandaloneInstructions } from './standalone_instructions';
import { MissingFleetServerHostCallout } from './missing_fleet_server_host_callout';
Expand Down Expand Up @@ -64,7 +66,12 @@ export const AgentEnrollmentFlyout: React.FunctionComponent<Props> = ({
const [policyId, setSelectedPolicyId] = useState(agentPolicy?.id);
const [isFleetServerPolicySelected, setIsFleetServerPolicySelected] = useState<boolean>(false);

const { agentPolicies, refreshAgentPolicies } = useAgentEnrollmentFlyoutData();
const {
agentPolicies,
isLoadingInitialAgentPolicies,
isLoadingAgentPolicies,
refreshAgentPolicies,
} = useAgentEnrollmentFlyoutData();

useEffect(() => {
async function checkPolicyIsFleetServer() {
Expand Down Expand Up @@ -141,7 +148,9 @@ export const AgentEnrollmentFlyout: React.FunctionComponent<Props> = ({
) : undefined
}
>
{mode === 'managed' ? (
{isLoadingInitialAgentPolicies ? (
<Loading />
) : mode === 'managed' ? (
<ManagedInstructions
settings={settings.data?.item}
setSelectedPolicyId={setSelectedPolicyId}
Expand All @@ -150,6 +159,7 @@ export const AgentEnrollmentFlyout: React.FunctionComponent<Props> = ({
viewDataStep={viewDataStep}
isFleetServerPolicySelected={isFleetServerPolicySelected}
refreshAgentPolicies={refreshAgentPolicies}
isLoadingAgentPolicies={isLoadingAgentPolicies}
/>
) : (
<StandaloneInstructions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const ManagedInstructions = React.memo<InstructionProps>(
isFleetServerPolicySelected,
settings,
refreshAgentPolicies,
isLoadingAgentPolicies,
}) => {
const fleetStatus = useFleetStatus();

Expand Down Expand Up @@ -161,7 +162,10 @@ export const ManagedInstructions = React.memo<InstructionProps>(
return null;
}

if (fleetStatus.isReady && (isLoadingAgents || fleetServers.length > 0)) {
if (
fleetStatus.isReady &&
(isLoadingAgents || isLoadingAgentPolicies || fleetServers.length > 0)
) {
return (
<>
<EuiText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export interface BaseProps {
export interface InstructionProps extends BaseProps {
agentPolicies: AgentPolicy[];
refreshAgentPolicies: () => void;
isLoadingAgentPolicies?: boolean;
}
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/public/components/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { EuiLoadingSpinnerSize } from '@elastic/eui/src/components/loading/
export const Loading: React.FunctionComponent<{ size?: EuiLoadingSpinnerSize }> = ({ size }) => (
<EuiFlexGroup justifyContent="spaceAround">
<EuiFlexItem grow={false}>
<EuiLoadingSpinner size={size || 'xl'} />
<EuiLoadingSpinner size={size || 'xl'} data-test-subj="loadingSpinner" />
</EuiFlexItem>
</EuiFlexGroup>
);
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('useAgentEnrollmentFlyoutData', () => {
(useGetAgentPolicies as jest.Mock).mockReturnValue({ data: undefined, isLoading: true });
const { result } = testRenderer.renderHook(() => useAgentEnrollmentFlyoutData());
expect(result.current.agentPolicies).toEqual([]);
expect(result.current.isLoadingAgentPolicies).toBe(true);
});

it('should return empty agentPolicies when http not loading and no data', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import { useGetAgentPolicies } from './use_request';
interface AgentEnrollmentFlyoutData {
agentPolicies: AgentPolicy[];
refreshAgentPolicies: () => void;
isLoadingInitialAgentPolicies: boolean;
isLoadingAgentPolicies: boolean;
}

export function useAgentEnrollmentFlyoutData(): AgentEnrollmentFlyoutData {
const {
data: agentPoliciesData,
isInitialRequest,
isLoading: isLoadingAgentPolicies,
resendRequest: refreshAgentPolicies,
} = useGetAgentPolicies({
Expand All @@ -34,5 +37,10 @@ export function useAgentEnrollmentFlyoutData(): AgentEnrollmentFlyoutData {
return [];
}, [isLoadingAgentPolicies, agentPoliciesData?.items]);

return { agentPolicies, refreshAgentPolicies };
return {
agentPolicies,
refreshAgentPolicies,
isLoadingInitialAgentPolicies: isInitialRequest && isLoadingAgentPolicies,
isLoadingAgentPolicies,
};
}
8 changes: 5 additions & 3 deletions x-pack/plugins/lens/common/expressions/datatable/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ function isValidNumber(value: unknown): boolean {
}

export function isNumericFieldForDatatable(currentData: Datatable | undefined, accessor: string) {
const isNumeric =
currentData?.columns.find((col) => col.id === accessor || getOriginalId(col.id) === accessor)
?.meta.type === 'number';
const column = currentData?.columns.find(
(col) => col.id === accessor || getOriginalId(col.id) === accessor
);
// min and max aggs are reporting as number but are actually dates - work around this by checking for the date formatter until this is fixed at the source
const isNumeric = column?.meta.type === 'number' && column?.meta.params?.id !== 'date';

return (
isNumeric &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,9 @@ export const getDatatableVisualization = ({

const hasNoSummaryRow = column.summaryRow == null || column.summaryRow === 'none';

const canColor =
datasource!.getOperationForColumnId(column.columnId)?.dataType === 'number';

return {
type: 'expression',
chain: [
Expand All @@ -383,7 +386,7 @@ export const getDatatableVisualization = ({
!datasource!.getOperationForColumnId(column.columnId)?.isBucketed,
],
alignment: typeof column.alignment === 'undefined' ? [] : [column.alignment],
colorMode: [column.colorMode ?? 'none'],
colorMode: [canColor && column.colorMode ? column.colorMode : 'none'],
palette: [paletteService.get(CUSTOM_PALETTE).toExpression(paletteParams)],
summaryRow: hasNoSummaryRow ? [] : [column.summaryRow!],
summaryLabel: hasNoSummaryRow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,35 @@ describe('heatmap suggestions', () => {
table: {
layerId: 'first',
isMultiRow: true,
columns: [],
columns: [
{
columnId: 'date-column-01',
operation: {
isBucketed: true,
dataType: 'date',
scale: 'interval',
label: 'Date',
},
},
{
columnId: 'another-bucket-column',
operation: {
isBucketed: true,
dataType: 'string',
scale: 'ratio',
label: 'Bucket',
},
},
{
columnId: 'metric-column',
operation: {
isBucketed: false,
dataType: 'number',
scale: 'ratio',
label: 'Metric',
},
},
],
changeType: 'initial',
},
state: {
Expand All @@ -208,7 +236,35 @@ describe('heatmap suggestions', () => {
table: {
layerId: 'first',
isMultiRow: true,
columns: [],
columns: [
{
columnId: 'date-column-01',
operation: {
isBucketed: true,
dataType: 'date',
scale: 'interval',
label: 'Date',
},
},
{
columnId: 'another-bucket-column',
operation: {
isBucketed: true,
dataType: 'string',
scale: 'ratio',
label: 'Bucket',
},
},
{
columnId: 'metric-column',
operation: {
isBucketed: false,
dataType: 'number',
scale: 'ratio',
label: 'Metric',
},
},
],
changeType: 'reduced',
},
state: {
Expand All @@ -223,6 +279,9 @@ describe('heatmap suggestions', () => {
layerId: 'first',
layerType: layerTypes.DATA,
shape: 'heatmap',
valueAccessor: 'metric-column',
xAccessor: 'date-column-01',
yAccessor: 'another-bucket-column',
gridConfig: {
type: HEATMAP_GRID_FUNCTION,
isCellLabelVisible: false,
Expand All @@ -240,7 +299,7 @@ describe('heatmap suggestions', () => {
title: 'Heat map',
hide: true,
previewIcon: 'empty',
score: 0,
score: 0.3,
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export const getSuggestions: Visualization<HeatmapVisualizationState>['getSugges
(state?.shape === CHART_SHAPES.HEATMAP &&
(state.xAccessor || state.yAccessor || state.valueAccessor) &&
table.changeType !== 'extended') ||
table.columns.some((col) => col.operation.isStaticValue)
table.columns.some((col) => col.operation.isStaticValue) ||
// do not use suggestions with non-numeric metrics
table.columns.some((col) => !col.operation.isBucketed && col.operation.dataType !== 'number')
) {
return [];
}
Expand All @@ -44,6 +46,10 @@ export const getSuggestions: Visualization<HeatmapVisualizationState>['getSugges

const [groups, metrics] = partition(table.columns, (col) => col.operation.isBucketed);

if (groups.length === 0 && metrics.length === 0) {
return [];
}

if (groups.length >= 3) {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ const expectedIndexPatterns = {
};

const bytesColumn: GenericIndexPatternColumn = {
label: 'Max of bytes',
label: 'Sum of bytes',
dataType: 'number',
isBucketed: false,

// Private
operationType: 'max',
operationType: 'sum',
sourceField: 'bytes',
params: { format: { id: 'bytes' } },
};
Expand Down Expand Up @@ -529,7 +529,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
columns: {
...state.layers.first.columns,
col1: expect.objectContaining({
operationType: 'max',
operationType: 'sum',
sourceField: 'memory',
params: { format: { id: 'bytes' } },
// Other parts of this don't matter for this test
Expand Down Expand Up @@ -728,7 +728,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
act(() => {
wrapper
.find('input[data-test-subj="indexPattern-label-edit"]')
.simulate('change', { target: { value: 'Maximum of bytes' } });
.simulate('change', { target: { value: 'Sum of bytes' } });
});

expect(setState.mock.calls[0]).toEqual([expect.any(Function)]);
Expand All @@ -740,7 +740,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
columns: {
...state.layers.first.columns,
col1: expect.objectContaining({
label: 'Maximum of bytes',
label: 'Sum of bytes',
customLabel: false,
// Other parts of this don't matter for this test
}),
Expand Down
Loading

0 comments on commit 907642b

Please sign in to comment.