Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Private location] Add loading to delete location button #137846

Merged
merged 1 commit into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import { i18n } from '@kbn/i18n';
import { useKibana } from '@kbn/kibana-react-plugin/public';

export const DeleteLocation = ({
loading,
id,
locationMonitors,
onDelete,
}: {
id: string;
loading?: boolean;
onDelete: (id: string) => void;
locationMonitors: Array<{ id: string; count: number }>;
}) => {
Expand Down Expand Up @@ -54,6 +56,7 @@ export const DeleteLocation = ({
}
>
<EuiButtonIcon
isLoading={loading}
iconType="trash"
color="danger"
aria-label={DELETE_LABEL}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('useLocationMonitors', () => {
it('returns expected results', () => {
const { result } = renderHook(() => useLocationMonitors(), { wrapper: WrappedHelper });

expect(result.current).toStrictEqual({ locationMonitors: [] });
expect(result.current).toStrictEqual({ locationMonitors: [], loading: true });
expect(defaultCore.savedObjects.client.find).toHaveBeenCalledWith({
aggs: {
locations: {
Expand Down Expand Up @@ -42,11 +42,12 @@ describe('useLocationMonitors', () => {
wrapper: WrappedHelper,
});

expect(result.current).toStrictEqual({ locationMonitors: [] });
expect(result.current).toStrictEqual({ locationMonitors: [], loading: true });

await waitForNextUpdate();

expect(result.current).toStrictEqual({
loading: false,
locationMonitors: [
{
id: 'Test',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface AggsResponse {
export const useLocationMonitors = () => {
const { savedObjects } = useKibana().services;

const { data } = useFetcher(() => {
const { data, loading } = useFetcher(() => {
const aggs = {
locations: {
terms: {
Expand All @@ -47,8 +47,8 @@ export const useLocationMonitors = () => {
({ key, doc_count: count }) => ({ id: key, count })
);

return { locationMonitors: newValues };
return { locationMonitors: newValues, loading };
}
return { locationMonitors: [] };
}, [data]);
return { locationMonitors: [], loading };
}, [data, loading]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const PrivateLocationsTable = ({
onDelete: (id: string) => void;
privateLocations: PrivateLocation[];
}) => {
const { locationMonitors } = useLocationMonitors();
const { locationMonitors, loading } = useLocationMonitors();

const [pageIndex, setPageIndex] = useState(0);
const [pageSize, setPageSize] = useState(10);
Expand All @@ -48,7 +48,12 @@ export const PrivateLocationsTable = ({
name: ACTIONS_LABEL,
align: 'right' as const,
render: (id: string) => (
<DeleteLocation id={id} locationMonitors={locationMonitors} onDelete={onDelete} />
<DeleteLocation
id={id}
locationMonitors={locationMonitors}
onDelete={onDelete}
loading={loading}
/>
),
},
];
Expand Down