ImagesTable: extract toolbar to separate component

This extracts the toolbar, that was getting bit too big to a separate component.
It also adjusts the title to correspond to the filter of the images.
If there is a Blueprint selected, it changes the title to '<BlueprintName> images'
This commit is contained in:
Ondrej Ezr 2024-03-07 12:57:42 +01:00 committed by Lucas Garfield
parent 61c25e8331
commit 947c20875c
3 changed files with 136 additions and 62 deletions

View file

@ -2,25 +2,22 @@ import React from 'react';
import { Button } from '@patternfly/react-core';
import { selectSelectedBlueprintId } from '../../store/BlueprintSlice';
import { useAppSelector } from '../../store/hooks';
import { useComposeBlueprintMutation } from '../../store/imageBuilderApi';
interface BuildImagesButtonProps {
selectedBlueprint?: string | undefined;
}
export const BuildImagesButton: React.FunctionComponent<
BuildImagesButtonProps
> = ({ selectedBlueprint }: BuildImagesButtonProps) => {
export const BuildImagesButton = () => {
const selectedBlueprintId = useAppSelector(selectSelectedBlueprintId);
const [buildBlueprint, { isLoading: imageBuildLoading }] =
useComposeBlueprintMutation();
const onBuildHandler = async () => {
selectedBlueprint && (await buildBlueprint({ id: selectedBlueprint }));
selectedBlueprintId && (await buildBlueprint({ id: selectedBlueprintId }));
};
return (
<Button
ouiaId="build-images-button"
onClick={onBuildHandler}
isDisabled={!selectedBlueprint}
isDisabled={!selectedBlueprintId}
isLoading={imageBuildLoading}
>
Build images