Skip to content

Commit

Permalink
Merge branch 'main' into expandable-flyout-package-storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeOberti authored Jun 7, 2024
2 parents 8b8b3ac + 75d6815 commit 7727bb8
Show file tree
Hide file tree
Showing 103 changed files with 1,258 additions and 427 deletions.
36 changes: 0 additions & 36 deletions .buildkite/pipelines/on_merge_unsupported_ftrs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,39 +80,3 @@ steps:
limit: 3
- exit_status: '*'
limit: 1

- command: .buildkite/scripts/steps/functional/defend_workflows.sh
label: 'Defend Workflows Cypress Tests'
agents:
image: family/kibana-ubuntu-2004
imageProject: elastic-images-prod
provider: gcp
enableNestedVirtualization: true
localSsdInterface: nvme
localSsds: 1
machineType: n2-standard-4
depends_on: build
timeout_in_minutes: 60
parallelism: 20
retry:
automatic:
- exit_status: '-1'
limit: 1

- command: .buildkite/scripts/steps/functional/defend_workflows_serverless.sh
label: 'Defend Workflows Cypress Tests on Serverless'
agents:
image: family/kibana-ubuntu-2004
imageProject: elastic-images-prod
provider: gcp
enableNestedVirtualization: true
localSsdInterface: nvme
localSsds: 1
machineType: n2-standard-4
depends_on: build
timeout_in_minutes: 60
parallelism: 14
retry:
automatic:
- exit_status: '-1'
limit: 1
13 changes: 4 additions & 9 deletions .buildkite/scripts/steps/artifacts/docker_image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,10 @@ echo "--- Build Kibana"
node scripts/build \
--debug \
--release \
--serverless \
--docker-cross-compile \
--docker-images \
--docker-namespace="kibana-ci" \
--docker-tag="$KIBANA_IMAGE_TAG" \
--skip-docker-ubuntu \
--skip-docker-chainguard \
--skip-docker-ubi \
--skip-docker-fips \
--skip-docker-cloud
--docker-tag="$KIBANA_IMAGE_TAG"

echo "--- Tag images"
docker rmi "$KIBANA_IMAGE"
Expand Down Expand Up @@ -99,8 +94,8 @@ ts-node "$(git rev-parse --show-toplevel)/.buildkite/scripts/steps/artifacts/val
"$CDN_ASSETS_FOLDER"

echo "--- Upload archives"
buildkite-agent artifact upload "kibana-$BASE_VERSION-linux-x86_64.tar.gz"
buildkite-agent artifact upload "kibana-$BASE_VERSION-linux-aarch64.tar.gz"
buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-linux-x86_64.tar.gz"
buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-linux-aarch64.tar.gz"
buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-docker-image.tar.gz"
buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-docker-image-aarch64.tar.gz"
buildkite-agent artifact upload "kibana-serverless-$BASE_VERSION-docker-build-context.tar.gz"
Expand Down
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ examples/unified_field_list_examples @elastic/kibana-data-discovery
src/plugins/unified_histogram @elastic/kibana-data-discovery
src/plugins/unified_search @elastic/kibana-visualizations
packages/kbn-unsaved-changes-badge @elastic/kibana-data-discovery
packages/kbn-unsaved-changes-prompt @elastic/kibana-management
x-pack/plugins/upgrade_assistant @elastic/kibana-management
x-pack/plugins/observability_solution/uptime @elastic/obs-ux-infra_services-team
x-pack/plugins/drilldowns/url_drilldown @elastic/appex-sharedux
Expand Down
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@
"unifiedHistogram": "src/plugins/unified_histogram",
"unifiedDataTable": "packages/kbn-unified-data-table",
"unsavedChangesBadge": "packages/kbn-unsaved-changes-badge",
"unsavedChangesPrompt": "packages/kbn-unsaved-changes-prompt",
"managedContentBadge": "packages/kbn-managed-content-badge"
},
"translations": []
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -889,6 +889,7 @@
"@kbn/unified-histogram-plugin": "link:src/plugins/unified_histogram",
"@kbn/unified-search-plugin": "link:src/plugins/unified_search",
"@kbn/unsaved-changes-badge": "link:packages/kbn-unsaved-changes-badge",
"@kbn/unsaved-changes-prompt": "link:packages/kbn-unsaved-changes-prompt",
"@kbn/upgrade-assistant-plugin": "link:x-pack/plugins/upgrade_assistant",
"@kbn/uptime-plugin": "link:x-pack/plugins/observability_solution/uptime",
"@kbn/url-drilldown-plugin": "link:x-pack/plugins/drilldowns/url_drilldown",
Expand Down
7 changes: 5 additions & 2 deletions packages/kbn-storybook/src/lib/decorators.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import { CoreTheme } from '@kbn/core-theme-browser';
import { I18nStart } from '@kbn/core-i18n-browser';
import type { AnalyticsServiceStart } from '@kbn/core-analytics-browser';
import { KibanaRootContextProvider } from '@kbn/react-kibana-context-root';
import { i18n } from '@kbn/i18n';

const theme$ = new BehaviorSubject<CoreTheme>({ darkMode: false });

const i18n: I18nStart = {
const i18nStart: I18nStart = {
Context: ({ children }) => <I18nProvider>{children}</I18nProvider>,
};

Expand All @@ -36,14 +37,16 @@ const analytics: AnalyticsServiceStart = {
* `globals` provided by the Storybook theme switcher to set the `colorMode`.
*/
const KibanaContextDecorator: DecoratorFn = (storyFn, { globals }) => {
// TODO: Add a switcher to see components in other locales or pseudo locale
i18n.init({ locale: 'en', messages: {} });
const colorMode = globals.euiTheme === 'v8.dark' ? 'dark' : 'light';

useEffect(() => {
theme$.next({ darkMode: colorMode === 'dark' });
}, [colorMode]);

return (
<KibanaRootContextProvider {...{ theme: { theme$ }, analytics, i18n }}>
<KibanaRootContextProvider {...{ theme: { theme$ }, analytics, i18n: i18nStart }}>
{storyFn()}
</KibanaRootContextProvider>
);
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-storybook/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@kbn/repo-info",
"@kbn/dev-cli-runner",
"@kbn/core-theme-browser",
"@kbn/i18n",
"@kbn/i18n-react",
"@kbn/core-i18n-browser",
"@kbn/react-kibana-context-root",
Expand Down
29 changes: 29 additions & 0 deletions packages/kbn-text-based-editor/src/text_based_languages_editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,28 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
}
}, [language, onTextLangQuerySubmit, abortController, isQueryLoading, allowQueryCancellation]);

const onCommentLine = useCallback(() => {
const currentPosition = editor1.current?.getPosition();
const lineNumber = currentPosition?.lineNumber;
if (lineNumber) {
const lineContent = editorModel.current?.getLineContent(lineNumber) ?? '';
const hasComment = lineContent?.startsWith('//');
const commentedLine = hasComment ? lineContent?.replace('//', '') : `//${lineContent}`;
// executeEdits allows to keep edit in history
editor1.current?.executeEdits('comment', [
{
range: {
startLineNumber: lineNumber,
startColumn: 0,
endLineNumber: lineNumber,
endColumn: (lineContent?.length ?? 0) + 1,
},
text: commentedLine,
},
]);
}
}, []);

useEffect(() => {
if (!isLoading) setIsQueryLoading(false);
}, [isLoading]);
Expand Down Expand Up @@ -903,6 +925,13 @@ export const TextBasedLanguagesEditor = memo(function TextBasedLanguagesEditor({
onQuerySubmit
);

// on CMD/CTRL + / comment out the entire line
editor.addCommand(
// eslint-disable-next-line no-bitwise
monaco.KeyMod.CtrlCmd | monaco.KeyCode.Slash,
onCommentLine
);

setMeasuredEditorWidth(editor.getLayoutInfo().width);
setMeasuredContentWidth(editor.getContentWidth());

Expand Down
30 changes: 30 additions & 0 deletions packages/kbn-unsaved-changes-prompt/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# @kbn/unsaved-changes-prompt

The useUnsavedChangesPrompt function is a custom React hook that prompts users with
a confirmation dialog when they try to leave a page with unsaved changes. It blocks
navigation and shows a dialog using the provided openConfirm function. If the user
confirms, it navigates away; otherwise, it cancels the navigation, ensuring unsaved
changes are not lost.


```typescript
import { useUnsavedChangesPrompt } from '@kbn/unsaved-changes-prompt';

export const SampleForm = ({ servicesForUnsavedChangesPrompt }) => {
const { form } = useForm();
const isFormDirty = useFormIsModified({ form });

useUnsavedChangesPrompt({
hasUnsavedChanges: isFormDirty,
...servicesForUnsavedChangesPrompt,
});

return (
<>
<Form form={form}>
....
</Form>
</>
);
};
```
9 changes: 9 additions & 0 deletions packages/kbn-unsaved-changes-prompt/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { useUnsavedChangesPrompt } from './src/unsaved_changes_prompt';
13 changes: 13 additions & 0 deletions packages/kbn-unsaved-changes-prompt/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../..',
roots: ['<rootDir>/packages/kbn-unsaved-changes-prompt'],
};
5 changes: 5 additions & 0 deletions packages/kbn-unsaved-changes-prompt/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-common",
"id": "@kbn/unsaved-changes-prompt",
"owner": "@elastic/kibana-management"
}
6 changes: 6 additions & 0 deletions packages/kbn-unsaved-changes-prompt/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/unsaved-changes-prompt",
"private": true,
"version": "1.0.0",
"license": "SSPL-1.0 OR Elastic License 2.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

export { useUnsavedChangesPrompt } from './unsaved_changes_prompt';
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { createMemoryHistory } from 'history';
import { renderHook, act } from '@testing-library/react-hooks';

import { coreMock } from '@kbn/core/public/mocks';
import { CoreScopedHistory } from '@kbn/core/public';

import { useUnsavedChangesPrompt } from './unsaved_changes_prompt';

const basePath = '/mock';
const memoryHistory = createMemoryHistory({ initialEntries: [basePath] });
const history = new CoreScopedHistory(memoryHistory, basePath);
const coreStart = coreMock.createStart();
const navigateToUrl = jest.fn().mockImplementation(async (url) => {
history.push(url);
});

describe('useUnsavedChangesPrompt', () => {
it('should not block if not edited', () => {
renderHook(() =>
useUnsavedChangesPrompt({
hasUnsavedChanges: false,
http: coreStart.http,
openConfirm: coreStart.overlays.openConfirm,
history,
navigateToUrl,
})
);

act(() => history.push('/test'));

expect(history.location.pathname).toBe('/test');
expect(history.location.search).toBe('');
expect(coreStart.overlays.openConfirm).not.toBeCalled();
});

it('should block if edited', async () => {
coreStart.overlays.openConfirm.mockResolvedValue(true);

renderHook(() =>
useUnsavedChangesPrompt({
hasUnsavedChanges: true,
http: coreStart.http,
openConfirm: coreStart.overlays.openConfirm,
history,
navigateToUrl,
})
);

act(() => history.push('/test'));

// needed because we have an async useEffect
await act(() => new Promise((resolve) => resolve()));

expect(navigateToUrl).toBeCalledWith('/mock/test', expect.anything());
expect(coreStart.overlays.openConfirm).toBeCalled();
});
});
Loading

0 comments on commit 7727bb8

Please sign in to comment.