Skip to content

Commit

Permalink
[ML] Fix the Dashboard saving indicator with Anomaly Swim Lane embedd…
Browse files Browse the repository at this point in the history
…able (#137989)
  • Loading branch information
darnautov authored Aug 4, 2022
1 parent 027b3a6 commit bd2361d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ export class AnomalySwimlaneEmbeddable extends Embeddable<
);
}

public reportsEmbeddableLoad() {
return true;
}

public onLoading() {
this.renderComplete.dispatchInProgress();
this.updateOutput({ loading: true, error: undefined });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,19 @@ import { i18n } from '@kbn/i18n';
import { SWIMLANE_TYPE, SwimlaneType } from '../../application/explorer/explorer_constants';
import { AnomalySwimlaneEmbeddableInput } from '..';

interface ExplicitInput {
panelTitle: string;
swimlaneType: SwimlaneType;
viewBy?: string;
}

export interface AnomalySwimlaneInitializerProps {
defaultTitle: string;
influencers: string[];
initialInput?: Partial<
Pick<AnomalySwimlaneEmbeddableInput, 'jobIds' | 'swimlaneType' | 'viewBy' | 'perPage'>
>;
onCreate: (swimlaneProps: {
panelTitle: string;
swimlaneType: SwimlaneType;
viewBy?: string;
}) => void;
onCreate: (swimlaneProps: ExplicitInput) => void;
onCancel: () => void;
}

Expand All @@ -47,7 +49,7 @@ export const AnomalySwimlaneInitializer: FC<AnomalySwimlaneInitializerProps> = (
initialInput,
}) => {
const [panelTitle, setPanelTitle] = useState(defaultTitle);
const [swimlaneType, setSwimlaneType] = useState(
const [swimlaneType, setSwimlaneType] = useState<SwimlaneType>(
initialInput?.swimlaneType ?? SWIMLANE_TYPE.OVERALL
);
const [viewBySwimlaneFieldName, setViewBySwimlaneFieldName] = useState(initialInput?.viewBy);
Expand Down Expand Up @@ -81,6 +83,12 @@ export const AnomalySwimlaneInitializer: FC<AnomalySwimlaneInitializerProps> = (
(swimlaneType === SWIMLANE_TYPE.OVERALL ||
(swimlaneType === SWIMLANE_TYPE.VIEW_BY && !!viewBySwimlaneFieldName));

const resultInput = {
panelTitle,
swimlaneType,
...(viewBySwimlaneFieldName ? { viewBy: viewBySwimlaneFieldName } : {}),
};

return (
<EuiModal initialFocus="[name=panelTitle]" onClose={onCancel}>
<EuiModalHeader>
Expand Down Expand Up @@ -162,15 +170,7 @@ export const AnomalySwimlaneInitializer: FC<AnomalySwimlaneInitializerProps> = (
/>
</EuiButtonEmpty>

<EuiButton
isDisabled={!isFormValid}
onClick={onCreate.bind(null, {
panelTitle,
swimlaneType,
viewBy: viewBySwimlaneFieldName,
})}
fill
>
<EuiButton isDisabled={!isFormValid} onClick={onCreate.bind(null, resultInput)} fill>
<FormattedMessage
id="xpack.ml.swimlaneEmbeddable.setupModal.confirmButtonLabel"
defaultMessage="Confirm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ export async function resolveAnomalySwimlaneUserInput(
defaultTitle={title}
influencers={influencers}
initialInput={input}
onCreate={({ panelTitle, viewBy, swimlaneType }) => {
onCreate={(explicitInput) => {
modalSession.close();
resolve({
jobIds,
title: panelTitle,
swimlaneType,
viewBy,
title: explicitInput.panelTitle,
...explicitInput,
});
}}
onCancel={() => {
Expand Down

0 comments on commit bd2361d

Please sign in to comment.