Skip to content

Commit 4acaf0a

Browse files
committed
Merge branch 'feat/recommendation-manual-sync' of github.com:devtron-labs/dashboard into fix/rb-table
2 parents a369455 + 5910393 commit 4acaf0a

File tree

4 files changed

+92
-32
lines changed

4 files changed

+92
-32
lines changed

src/components/ResourceBrowser/ResourceList/ResourceFilterOptions.tsx

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
GVK_FILTER_API_VERSION_QUERY_PARAM_KEY,
2727
GVK_FILTER_KIND_QUERY_PARAM_KEY,
2828
GVKOptionValueType,
29+
Icon,
2930
Nodes,
3031
noop,
3132
OptionType,
@@ -56,6 +57,7 @@ const getResourceRecommendationsCSVData = importComponentFromFELibrary(
5657
null,
5758
'function',
5859
)
60+
const ResourceRecommenderActionMenu = importComponentFromFELibrary('ResourceRecommenderActionMenu', null, 'function')
5961

6062
const ResourceFilterOptions = ({
6163
selectedResource,
@@ -74,6 +76,7 @@ const ResourceFilterOptions = ({
7476
resourceRecommenderConfig,
7577
selectedAPIVersionGVKFilter,
7678
selectedKindGVKFilter,
79+
resourceLastScannedOnDetails,
7780
}: ResourceFilterOptionsProps) => {
7881
const { registerShortcut, unregisterShortcut } = useRegisterShortcut()
7982
const { clusterId } = useParams<K8sResourceListURLParams>()
@@ -311,13 +314,21 @@ const ResourceFilterOptions = ({
311314
/>
312315
</div>
313316

314-
{isResourceRecommender && getResourceRecommendationsCSVData && (
315-
<ExportToCsv
316-
fileName={FILE_NAMES.ResourceRecommendations}
317-
showOnlyIcon
318-
disabled={isResourceListLoading}
319-
apiPromise={getResourcesToExport}
320-
/>
317+
{isResourceRecommender && ResourceRecommenderActionMenu && getResourceRecommendationsCSVData && (
318+
<ResourceRecommenderActionMenu {...resourceLastScannedOnDetails}>
319+
<ExportToCsv
320+
fileName={FILE_NAMES.ResourceRecommendations}
321+
disabled={isResourceListLoading}
322+
apiPromise={getResourcesToExport}
323+
triggerElementClassname="bg__hover dc__transparent flexbox dc__gap-8 px-8 py-6 w-100"
324+
hideExportResultModal
325+
>
326+
<span className="mt-2 flex dc__no-shrink">
327+
<Icon name="ic-download" size={16} color="N800" />
328+
</span>
329+
<span className="cn-9 fs-13 fw-4 lh-1-5">Export CSV</span>
330+
</ExportToCsv>
331+
</ResourceRecommenderActionMenu>
321332
)}
322333
</div>
323334
</div>

src/components/ResourceBrowser/Types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
K8sResourceDetailType,
2828
OptionType,
2929
ResourceDetail,
30+
ResourceRecommenderActionMenuProps,
3031
SelectedResourceType,
3132
SelectPickerOptionType,
3233
ServerErrors,
@@ -114,6 +115,7 @@ export interface ResourceFilterOptionsProps
114115
reloadGVKOptions: () => void
115116
gvkOptionsError: ServerErrors
116117
}
118+
resourceLastScannedOnDetails?: Omit<ResourceRecommenderActionMenuProps, 'children'>
117119
selectedAPIVersionGVKFilter?: string
118120
selectedKindGVKFilter?: string
119121
resourceRecommenderConfig?: {

src/components/common/ExportToCsv/ExportToCsv.tsx

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ import {
2626
DetailsProgressing,
2727
GenericSectionErrorState,
2828
logExceptionToSentry,
29+
ToastManager,
30+
ToastVariantType,
31+
Tooltip,
2932
VisibleModal,
3033
} from '@devtron-labs/devtron-fe-common-lib'
3134

@@ -45,6 +48,9 @@ const ExportToCsv = <ConfigValueType extends string = string>({
4548
disabled = false,
4649
showOnlyIcon = false,
4750
configuration,
51+
hideExportResultModal = false,
52+
triggerElementClassname,
53+
children,
4854
}: ExportToCsvProps<ConfigValueType>) => {
4955
const [selectedConfig, setSelectedConfig] = useState<Record<ConfigValueType, boolean>>(
5056
getDefaultValueFromConfiguration(configuration),
@@ -99,6 +105,12 @@ const ExportToCsv = <ConfigValueType extends string = string>({
99105
} catch (err) {
100106
setErrorExportingData(true)
101107

108+
if (hideExportResultModal) {
109+
ToastManager.showToast({
110+
variant: ToastVariantType.error,
111+
description: `Failed to export ${fileNameKey || ''}. Please try again.`,
112+
})
113+
}
102114
// eslint-disable-next-line no-console
103115
console.error(
104116
`Data export failed at ${moment().format('HH:mm:ss')}. Reason - ${err.message || err.name}`,
@@ -219,34 +231,48 @@ const ExportToCsv = <ConfigValueType extends string = string>({
219231

220232
return (
221233
<div>
222-
<Button
223-
{...(showOnlyIcon
224-
? {
225-
icon: <ExportIcon />,
226-
ariaLabel: 'Export CSV',
227-
showAriaLabelInTippy: false,
228-
}
229-
: {
230-
text: 'Export CSV',
231-
startIcon: <ExportIcon />,
232-
})}
233-
onClick={handleExportToCsvClick}
234-
size={ComponentSizeType.medium}
235-
variant={ButtonVariantType.secondary}
236-
dataTestId="export-csv-button"
237-
disabled={disabled}
238-
showTooltip={disabled}
239-
tooltipProps={{
240-
content: 'Nothing to export',
241-
}}
242-
/>
234+
{children ? (
235+
<Tooltip alwaysShowTippyOnHover={disabled} content="Nothing to export">
236+
<button
237+
data-testid="export-csv-button"
238+
type="button"
239+
onClick={handleExportToCsvClick}
240+
disabled={disabled}
241+
className={triggerElementClassname}
242+
>
243+
{children}
244+
</button>
245+
</Tooltip>
246+
) : (
247+
<Button
248+
{...(showOnlyIcon
249+
? {
250+
icon: <ExportIcon />,
251+
ariaLabel: 'Export CSV',
252+
showAriaLabelInTippy: false,
253+
}
254+
: {
255+
text: 'Export CSV',
256+
startIcon: <ExportIcon />,
257+
})}
258+
onClick={handleExportToCsvClick}
259+
size={ComponentSizeType.medium}
260+
variant={ButtonVariantType.secondary}
261+
dataTestId="export-csv-button"
262+
disabled={disabled}
263+
showTooltip={disabled}
264+
tooltipProps={{
265+
content: 'Nothing to export',
266+
}}
267+
/>
268+
)}
243269
<CSVLink
244270
ref={csvRef}
245271
filename={`${fileName}_${moment().format(Moment12HourExportFormat)}.csv`}
246272
headers={CSV_HEADERS[fileName] || []}
247273
data={dataToExport || []}
248274
/>
249-
{(showExportingModal || isConfigurationAvailable) && (
275+
{!hideExportResultModal && (showExportingModal || isConfigurationAvailable) && (
250276
<VisibleModal className="export-to-csv-modal" data-testid="export-to-csv-modal">
251277
<div className="modal__body mt-40 p-0">
252278
<h2 className="cn-9 fw-6 fs-16 m-0 dc__border-bottom px-20 py-12">Export to CSV</h2>

src/components/common/ExportToCsv/types.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
import { FILE_NAMES } from './constants'
1818

19-
export interface ExportToCsvProps<ConfigValueType extends string = string> {
19+
export type ExportToCsvProps<ConfigValueType extends string = string> = {
2020
apiPromise: (selectedConfig: Record<ConfigValueType, boolean>) => Promise<unknown[]>
2121
fileName: FILE_NAMES
2222
className?: string
2323
disabled?: boolean
24-
showOnlyIcon?: boolean
2524
/**
2625
* Configuration for the export csv
2726
*/
@@ -33,7 +32,29 @@ export interface ExportToCsvProps<ConfigValueType extends string = string> {
3332
description?: string
3433
}[]
3534
}
36-
}
35+
/**
36+
* @default false
37+
* If true, the export result modal will not be shown after the export is completed.
38+
*/
39+
hideExportResultModal?: boolean
40+
} & (
41+
| {
42+
/**
43+
* If given would replace the Button component with the button tag and the children will be rendered inside it.
44+
*/
45+
triggerElementClassname: string
46+
/**
47+
* Content inside the button
48+
*/
49+
children: React.ReactNode
50+
showOnlyIcon?: never
51+
}
52+
| {
53+
children?: never
54+
triggerElementClassname?: never
55+
showOnlyIcon?: boolean
56+
}
57+
)
3758

3859
export interface ExportConfigurationProps<ConfigValueType extends string>
3960
extends Pick<ExportToCsvProps<ConfigValueType>, 'configuration'> {

0 commit comments

Comments
 (0)