removed need of refresher (#394)

This commit is contained in:
Erik Jan de Wit 2021-02-24 08:58:50 +01:00 committed by GitHub
parent e370859690
commit ca92447444
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 15 deletions

View file

@ -85,7 +85,6 @@ export type DataListProps<T> = {
isPaginated?: boolean; isPaginated?: boolean;
ariaLabelKey: string; ariaLabelKey: string;
searchPlaceholderKey: string; searchPlaceholderKey: string;
setRefresher?: (refresher: () => void) => void;
columns: Field<T>[]; columns: Field<T>[];
actions?: Action<T>[]; actions?: Action<T>[];
actionResolver?: IActionsResolver; actionResolver?: IActionsResolver;
@ -121,7 +120,6 @@ export function KeycloakDataTable<T>({
searchPlaceholderKey, searchPlaceholderKey,
isPaginated = false, isPaginated = false,
onSelect, onSelect,
setRefresher,
canSelectAll = false, canSelectAll = false,
loader, loader,
columns, columns,
@ -144,10 +142,6 @@ export function KeycloakDataTable<T>({
const refresh = () => setKey(new Date().getTime()); const refresh = () => setKey(new Date().getTime());
const handleError = useErrorHandler(); const handleError = useErrorHandler();
useEffect(() => {
setRefresher && setRefresher(refresh);
}, []);
useEffect(() => { useEffect(() => {
return asyncStateFetch( return asyncStateFetch(
async () => { async () => {

View file

@ -1,4 +1,4 @@
import React, { useState } from "react"; import React, { useEffect, useState } from "react";
import { useHistory, useParams, useRouteMatch } from "react-router-dom"; import { useHistory, useParams, useRouteMatch } from "react-router-dom";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { import {
@ -36,7 +36,8 @@ export const AssociatedRolesTab = ({
const history = useHistory(); const history = useHistory();
const { addAlert } = useAlerts(); const { addAlert } = useAlerts();
const { url } = useRouteMatch(); const { url } = useRouteMatch();
const tableRefresher = React.useRef<() => void>(); const [key, setKey] = useState(0);
const refresh = () => setKey(new Date().getTime());
const [selectedRows, setSelectedRows] = useState<RoleRepresentation[]>([]); const [selectedRows, setSelectedRows] = useState<RoleRepresentation[]>([]);
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
@ -48,8 +49,8 @@ export const AssociatedRolesTab = ({
return Promise.resolve(additionalRoles); return Promise.resolve(additionalRoles);
}; };
React.useEffect(() => { useEffect(() => {
tableRefresher.current && tableRefresher.current(); refresh();
}, [additionalRoles]); }, [additionalRoles]);
const RoleName = (role: RoleRepresentation) => <>{role.name}</>; const RoleName = (role: RoleRepresentation) => <>{role.name}</>;
@ -99,10 +100,6 @@ export const AssociatedRolesTab = ({
}, },
}); });
const setRefresher = (refresher: () => void) => {
tableRefresher.current = refresher;
};
const goToCreate = () => history.push(`${url}/add-role`); const goToCreate = () => history.push(`${url}/add-role`);
return ( return (
<> <>
@ -116,6 +113,7 @@ export const AssociatedRolesTab = ({
toggleDialog={() => setOpen(!open)} toggleDialog={() => setOpen(!open)}
/> />
<KeycloakDataTable <KeycloakDataTable
key={key}
loader={loader} loader={loader}
ariaLabelKey="roles:roleList" ariaLabelKey="roles:roleList"
searchPlaceholderKey="roles:searchFor" searchPlaceholderKey="roles:searchFor"
@ -124,7 +122,6 @@ export const AssociatedRolesTab = ({
setSelectedRows([...rows]); setSelectedRows([...rows]);
}} }}
isPaginated isPaginated
setRefresher={setRefresher}
toolbarItem={ toolbarItem={
<> <>
<Checkbox <Checkbox