kibana/examples/files_example/public/components/app.tsx
Lene Gadewoll a2e929b485
[9.0] Upgrade EUI to v101.0.1 (#215698) (#216378)
# Backport

This will backport the following commits from `main` to `9.0`:
- [Upgrade EUI to v101.0.1
(#215698)](https://github.com/elastic/kibana/pull/215698)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Lene
Gadewoll","email":"lene.gadewoll@elastic.co"},"sourceCommit":{"committedDate":"2025-03-28T18:29:23Z","message":"Upgrade
EUI to v101.0.1 (#215698)\n\n`100.0.0`  `101.0.1`\n\n[Questions? Please
see our Kibana
upgrade\nFAQ.](https://github.com/elastic/eui/blob/main/wiki/eui-team-processes/upgrading-kibana.md#faq-for-kibana-teams)\n\n##
Package updates\n\n###
`@elastic/eui`\n[`v101.0.1`](https://github.com/elastic/eui/releases/v101.0.1)\n\n-
Updated `EuiProvider` and `EuiThemeProvider` with a
new\n`highContrastMode`
([#8444](https://github.com/elastic/eui/pull/8444))\n- This prop allows
toggling a higher contrast visual style that\nprimarily affects borders
and shadows\n- On `EuiProvider`, if the `highContrastMode` prop is not
passed, this\nsetting will inherit from the user's OS/system settings\n-
If the user is using a forced colors mode (e.g. Windows' high
contrast\nthemes), this system setting will take precedence over
any\n`highContrastMode` or `colorMode` props passed\n- Added
`highContrastModeStyles` and `preventForcedColors` styling
utils\n([#8444](https://github.com/elastic/eui/pull/8444))\n- Updated
`EuiRangeTooltip` to be easier to see in dark
mode\n([#8444](https://github.com/elastic/eui/pull/8444))\n- Updated
some deprecated color token usages that have direct\nsubstitutes
([#8444](https://github.com/elastic/eui/pull/8444))\n - `text` ->
`textParagraph`\n - `title` -> `textHeading`\n - `subduedText` ->
`textSubdued`\n - `disabledText` -> `textDisabled`\n - `accentText` ->
`textAccent`\n - `dangerText` -> `textDanger`\n - `warningText` ->
`textWarning`\n- `useEuiShadow()` now accepts a second `options`
argument\n([#8234](https://github.com/elastic/eui/pull/8234))\n-
`useEuiShadowFlat()` now accepts an `options` object instead of only
a\ncolor ([#8234](https://github.com/elastic/eui/pull/8234))\n- Updated
`EuiPopover` and `EuiToolTip` to be easier to see in dark\nmode.
([#8174](https://github.com/elastic/eui/pull/8174))\n\n**Bug
fixes**\n\n- Fixed a visual bug where a transparent border would create
visible\nempty space (`LIGHT` mode only) for the
components:\n([#8427](https://github.com/elastic/eui/pull/8427))\n -
`EuiPanel`\n - `EuiPopover`\n - `EuiToolTip`\n - `EuiToast`\n -
`EuiTour`\n \n --- \n \n###
`@elastic/eui-theme-common`\n[`v0.1.0`](https://github.com/elastic/eui/releases/v0.1.0)\n\n-
Removed type
`EuiShadowCustomColor`\n([#8444](https://github.com/elastic/eui/pull/8444))\n-
Added types: ([#8444](https://github.com/elastic/eui/pull/8444))\n -
`EuiShadowOptions`\n - `EuiThemeHighContrastModeProp`\n -
`EuiThemeHighContrastMode`\n- Updated shadow utils to accepts a second
`options` argument and return\nborders in high contrast
mode:\n([#8444](https://github.com/elastic/eui/pull/8444))\n -
`euiShadow`\n - `euiShadowXSmall`\n - `euiShadowSmall`\n -
`euiShadowMedium`\n - `euiShadowLarge`\n - `euiSlightShadowHover`\n -
`euiShadowFlat`\n \n ---\n \n###
`@elastic/eui-theme-borealis`\n[`v0.1.0`](https://github.com/elastic/eui/releases/v0.1.0)\n\n-
Added new component level
tokens:\n([#8444](https://github.com/elastic/eui/pull/8444))\n -
`buttonGroupBackgroundDisabledSelected`\n - `overlayMaskBackground`\n -
`overlayMaskBackgroundHighContrast`\n -
`skeletonBackgroundSkeletonMiddleHighContrast`\n \n\n## Additional
changes\n\nThe latest `@elastic/eui` package introduces high contrast
mode support.\nThis PR sets all usages of `EuiProvider` to
use\n`highContrastMode={false}` to introduce it in disabled state
(this\nreflects the current functionality in Kibana). This is because
the UI\nfor the high contrast mode functionality (and style adjustments)
need to\nfirst be implemented on Kibana side (by shared-ux).\n\n##
QA\n\nAdding high contrast mode in disabled state should result in no
visual\nchanges in Kibana. Please ensure your product view remain
unchanged.\n\n---------\n\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"2cd777d96909a73bab547cc3e3f509fc7ef916af","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","EUI","v9.0.0","backport:prev-minor","ci:cloud-deploy","ci:project-deploy-elasticsearch","ci:project-deploy-observability","ci:project-deploy-security","Team:obs-ux-infra_services","Team:obs-ux-management","v9.1.0"],"title":"Upgrade
EUI to
v101.0.1","number":215698,"url":"https://github.com/elastic/kibana/pull/215698","mergeCommit":{"message":"Upgrade
EUI to v101.0.1 (#215698)\n\n`100.0.0`  `101.0.1`\n\n[Questions? Please
see our Kibana
upgrade\nFAQ.](https://github.com/elastic/eui/blob/main/wiki/eui-team-processes/upgrading-kibana.md#faq-for-kibana-teams)\n\n##
Package updates\n\n###
`@elastic/eui`\n[`v101.0.1`](https://github.com/elastic/eui/releases/v101.0.1)\n\n-
Updated `EuiProvider` and `EuiThemeProvider` with a
new\n`highContrastMode`
([#8444](https://github.com/elastic/eui/pull/8444))\n- This prop allows
toggling a higher contrast visual style that\nprimarily affects borders
and shadows\n- On `EuiProvider`, if the `highContrastMode` prop is not
passed, this\nsetting will inherit from the user's OS/system settings\n-
If the user is using a forced colors mode (e.g. Windows' high
contrast\nthemes), this system setting will take precedence over
any\n`highContrastMode` or `colorMode` props passed\n- Added
`highContrastModeStyles` and `preventForcedColors` styling
utils\n([#8444](https://github.com/elastic/eui/pull/8444))\n- Updated
`EuiRangeTooltip` to be easier to see in dark
mode\n([#8444](https://github.com/elastic/eui/pull/8444))\n- Updated
some deprecated color token usages that have direct\nsubstitutes
([#8444](https://github.com/elastic/eui/pull/8444))\n - `text` ->
`textParagraph`\n - `title` -> `textHeading`\n - `subduedText` ->
`textSubdued`\n - `disabledText` -> `textDisabled`\n - `accentText` ->
`textAccent`\n - `dangerText` -> `textDanger`\n - `warningText` ->
`textWarning`\n- `useEuiShadow()` now accepts a second `options`
argument\n([#8234](https://github.com/elastic/eui/pull/8234))\n-
`useEuiShadowFlat()` now accepts an `options` object instead of only
a\ncolor ([#8234](https://github.com/elastic/eui/pull/8234))\n- Updated
`EuiPopover` and `EuiToolTip` to be easier to see in dark\nmode.
([#8174](https://github.com/elastic/eui/pull/8174))\n\n**Bug
fixes**\n\n- Fixed a visual bug where a transparent border would create
visible\nempty space (`LIGHT` mode only) for the
components:\n([#8427](https://github.com/elastic/eui/pull/8427))\n -
`EuiPanel`\n - `EuiPopover`\n - `EuiToolTip`\n - `EuiToast`\n -
`EuiTour`\n \n --- \n \n###
`@elastic/eui-theme-common`\n[`v0.1.0`](https://github.com/elastic/eui/releases/v0.1.0)\n\n-
Removed type
`EuiShadowCustomColor`\n([#8444](https://github.com/elastic/eui/pull/8444))\n-
Added types: ([#8444](https://github.com/elastic/eui/pull/8444))\n -
`EuiShadowOptions`\n - `EuiThemeHighContrastModeProp`\n -
`EuiThemeHighContrastMode`\n- Updated shadow utils to accepts a second
`options` argument and return\nborders in high contrast
mode:\n([#8444](https://github.com/elastic/eui/pull/8444))\n -
`euiShadow`\n - `euiShadowXSmall`\n - `euiShadowSmall`\n -
`euiShadowMedium`\n - `euiShadowLarge`\n - `euiSlightShadowHover`\n -
`euiShadowFlat`\n \n ---\n \n###
`@elastic/eui-theme-borealis`\n[`v0.1.0`](https://github.com/elastic/eui/releases/v0.1.0)\n\n-
Added new component level
tokens:\n([#8444](https://github.com/elastic/eui/pull/8444))\n -
`buttonGroupBackgroundDisabledSelected`\n - `overlayMaskBackground`\n -
`overlayMaskBackgroundHighContrast`\n -
`skeletonBackgroundSkeletonMiddleHighContrast`\n \n\n## Additional
changes\n\nThe latest `@elastic/eui` package introduces high contrast
mode support.\nThis PR sets all usages of `EuiProvider` to
use\n`highContrastMode={false}` to introduce it in disabled state
(this\nreflects the current functionality in Kibana). This is because
the UI\nfor the high contrast mode functionality (and style adjustments)
need to\nfirst be implemented on Kibana side (by shared-ux).\n\n##
QA\n\nAdding high contrast mode in disabled state should result in no
visual\nchanges in Kibana. Please ensure your product view remain
unchanged.\n\n---------\n\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"2cd777d96909a73bab547cc3e3f509fc7ef916af"}},"sourceBranch":"main","suggestedTargetBranches":["9.0"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/215698","number":215698,"mergeCommit":{"message":"Upgrade
EUI to v101.0.1 (#215698)\n\n`100.0.0`  `101.0.1`\n\n[Questions? Please
see our Kibana
upgrade\nFAQ.](https://github.com/elastic/eui/blob/main/wiki/eui-team-processes/upgrading-kibana.md#faq-for-kibana-teams)\n\n##
Package updates\n\n###
`@elastic/eui`\n[`v101.0.1`](https://github.com/elastic/eui/releases/v101.0.1)\n\n-
Updated `EuiProvider` and `EuiThemeProvider` with a
new\n`highContrastMode`
([#8444](https://github.com/elastic/eui/pull/8444))\n- This prop allows
toggling a higher contrast visual style that\nprimarily affects borders
and shadows\n- On `EuiProvider`, if the `highContrastMode` prop is not
passed, this\nsetting will inherit from the user's OS/system settings\n-
If the user is using a forced colors mode (e.g. Windows' high
contrast\nthemes), this system setting will take precedence over
any\n`highContrastMode` or `colorMode` props passed\n- Added
`highContrastModeStyles` and `preventForcedColors` styling
utils\n([#8444](https://github.com/elastic/eui/pull/8444))\n- Updated
`EuiRangeTooltip` to be easier to see in dark
mode\n([#8444](https://github.com/elastic/eui/pull/8444))\n- Updated
some deprecated color token usages that have direct\nsubstitutes
([#8444](https://github.com/elastic/eui/pull/8444))\n - `text` ->
`textParagraph`\n - `title` -> `textHeading`\n - `subduedText` ->
`textSubdued`\n - `disabledText` -> `textDisabled`\n - `accentText` ->
`textAccent`\n - `dangerText` -> `textDanger`\n - `warningText` ->
`textWarning`\n- `useEuiShadow()` now accepts a second `options`
argument\n([#8234](https://github.com/elastic/eui/pull/8234))\n-
`useEuiShadowFlat()` now accepts an `options` object instead of only
a\ncolor ([#8234](https://github.com/elastic/eui/pull/8234))\n- Updated
`EuiPopover` and `EuiToolTip` to be easier to see in dark\nmode.
([#8174](https://github.com/elastic/eui/pull/8174))\n\n**Bug
fixes**\n\n- Fixed a visual bug where a transparent border would create
visible\nempty space (`LIGHT` mode only) for the
components:\n([#8427](https://github.com/elastic/eui/pull/8427))\n -
`EuiPanel`\n - `EuiPopover`\n - `EuiToolTip`\n - `EuiToast`\n -
`EuiTour`\n \n --- \n \n###
`@elastic/eui-theme-common`\n[`v0.1.0`](https://github.com/elastic/eui/releases/v0.1.0)\n\n-
Removed type
`EuiShadowCustomColor`\n([#8444](https://github.com/elastic/eui/pull/8444))\n-
Added types: ([#8444](https://github.com/elastic/eui/pull/8444))\n -
`EuiShadowOptions`\n - `EuiThemeHighContrastModeProp`\n -
`EuiThemeHighContrastMode`\n- Updated shadow utils to accepts a second
`options` argument and return\nborders in high contrast
mode:\n([#8444](https://github.com/elastic/eui/pull/8444))\n -
`euiShadow`\n - `euiShadowXSmall`\n - `euiShadowSmall`\n -
`euiShadowMedium`\n - `euiShadowLarge`\n - `euiSlightShadowHover`\n -
`euiShadowFlat`\n \n ---\n \n###
`@elastic/eui-theme-borealis`\n[`v0.1.0`](https://github.com/elastic/eui/releases/v0.1.0)\n\n-
Added new component level
tokens:\n([#8444](https://github.com/elastic/eui/pull/8444))\n -
`buttonGroupBackgroundDisabledSelected`\n - `overlayMaskBackground`\n -
`overlayMaskBackgroundHighContrast`\n -
`skeletonBackgroundSkeletonMiddleHighContrast`\n \n\n## Additional
changes\n\nThe latest `@elastic/eui` package introduces high contrast
mode support.\nThis PR sets all usages of `EuiProvider` to
use\n`highContrastMode={false}` to introduce it in disabled state
(this\nreflects the current functionality in Kibana). This is because
the UI\nfor the high contrast mode functionality (and style adjustments)
need to\nfirst be implemented on Kibana side (by shared-ux).\n\n##
QA\n\nAdding high contrast mode in disabled state should result in no
visual\nchanges in Kibana. Please ensure your product view remain
unchanged.\n\n---------\n\nCo-authored-by: Elastic Machine
<elasticmachine@users.noreply.github.com>","sha":"2cd777d96909a73bab547cc3e3f509fc7ef916af"}}]}]
BACKPORT-->

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2025-03-31 14:30:00 +02:00

192 lines
5.7 KiB
TypeScript

/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/
import React, { useState } from 'react';
import { useQuery } from '@tanstack/react-query';
import type { FileJSON } from '@kbn/files-plugin/common';
import type { FilesClientResponses } from '@kbn/files-plugin/public';
import {
EuiProvider,
EuiPageTemplate,
EuiInMemoryTable,
EuiInMemoryTableProps,
EuiButton,
EuiIcon,
EuiButtonIcon,
EuiLink,
} from '@elastic/eui';
import { CoreStart } from '@kbn/core/public';
import { MyFilePicker } from './file_picker';
import type { MyImageMetadata } from '../../common';
import type { FileClients } from '../types';
import { DetailsFlyout } from './details_flyout';
import { ConfirmButtonIcon } from './confirm_button';
import { Modal } from './modal';
interface FilesExampleAppDeps {
files: FileClients;
notifications: CoreStart['notifications'];
}
type ListResponse = FilesClientResponses<MyImageMetadata>['list'];
export const FilesExampleApp = ({ files, notifications }: FilesExampleAppDeps) => {
const { data, isLoading, error, refetch } = useQuery<ListResponse>(
['files'],
() => files.example.list(),
{ refetchOnWindowFocus: false }
);
const [showUploadModal, setShowUploadModal] = useState(false);
const [showFilePickerModal, setShowFilePickerModal] = useState(false);
const [isDeletingFile, setIsDeletingFile] = useState(false);
const [selectedItem, setSelectedItem] = useState<undefined | FileJSON<MyImageMetadata>>();
const renderToolsRight = () => {
return [
<EuiButton
onClick={() => setShowFilePickerModal(true)}
isDisabled={isLoading || isDeletingFile}
iconType="eye"
>
Select a file
</EuiButton>,
<EuiButton
onClick={() => setShowUploadModal(true)}
isDisabled={isLoading || isDeletingFile}
iconType="exportAction"
>
Upload image
</EuiButton>,
];
};
const items = [...(data?.files ?? [])].reverse();
const columns: EuiInMemoryTableProps<FileJSON<MyImageMetadata>>['columns'] = [
{
field: 'name',
name: 'Name',
render: (name, item) => (
<EuiLink disabled={isDeletingFile} onClick={() => setSelectedItem(item)}>
{name}
</EuiLink>
),
},
{
field: 'status',
name: 'Status',
render: (status: FileJSON['status']) =>
status === 'READY' ? (
<EuiIcon color="success" type="checkInCircleFilled" aria-label={status} />
) : status === 'AWAITING_UPLOAD' ? (
<EuiIcon type="clock" aria-label={status} />
) : (
<EuiIcon color="danger" type="warning" arial-label={status} />
),
},
{
name: 'Actions',
actions: [
{
name: 'View',
description: 'View file',
isPrimary: true,
render: (item) => (
<EuiButtonIcon
disabled={isDeletingFile}
aria-label="View file details"
iconType="eye"
onClick={() => setSelectedItem(item)}
/>
),
},
{
name: 'Delete',
description: 'Delete this file',
render: (item) => (
<ConfirmButtonIcon
disabled={isDeletingFile}
label="Delete this file"
confirmationText="Are you sure you want to delete this file?"
onConfirm={async () => {
try {
setIsDeletingFile(true);
await files.example.delete({ id: item.id });
await refetch();
} finally {
setIsDeletingFile(false);
}
}}
/>
),
},
],
},
];
return (
<EuiProvider highContrastMode={false}>
<EuiPageTemplate restrictWidth>
<EuiPageTemplate.Header pageTitle="Files example" />
<EuiPageTemplate.Section>
<EuiInMemoryTable
columns={columns}
items={items}
itemId="id"
loading={isLoading || isDeletingFile}
error={error ? JSON.stringify(error) : undefined}
sorting
search={{
toolsRight: renderToolsRight(),
}}
pagination
/>
</EuiPageTemplate.Section>
</EuiPageTemplate>
{selectedItem && (
<DetailsFlyout
files={files}
file={selectedItem}
onDismiss={() => setSelectedItem(undefined)}
/>
)}
{showUploadModal && (
<Modal
client={files.unscoped}
onDismiss={() => setShowUploadModal(false)}
onUploaded={() => {
notifications.toasts.addSuccess('Uploaded file!');
refetch();
setShowUploadModal(false);
}}
/>
)}
{showFilePickerModal && (
<MyFilePicker
onClose={() => setShowFilePickerModal(false)}
onUpload={() => {
notifications.toasts.addSuccess({
title: 'Uploaded files',
});
refetch();
}}
onDone={(ids) => {
notifications.toasts.addSuccess({
title: 'Selected files!',
text: 'IDS:' + JSON.stringify(ids, null, 2),
});
setShowFilePickerModal(false);
}}
/>
)}
</EuiProvider>
);
};