Skip to content

Commit

Permalink
feat: 🎸 [TableToolbarAction] Check disable condition on data[]
Browse files Browse the repository at this point in the history
✅ Closes: 231
  • Loading branch information
luciob committed Feb 9, 2022
1 parent 61f3dff commit fd5d649
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions src/components/Table/components/ToolbarAction/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { CSSProperties, FC, useCallback, useMemo } from "react";
import { Icons } from "../../../../types/Icon";
import { ITableToolbarAction } from "../../../../types/Table";
import { getComposedDataCy } from "../../../../utils";
import { logWarn } from "../../../../utils/logger";
// import { logWarn } from "../../../../utils/logger";
import Button from "../../../Button";
import IconButton from "../../../IconButton";

Expand All @@ -20,17 +20,10 @@ const TableToolbarAction: FC<ITableToolbarAction> = ({
}) => {
const dataCy = useMemo(() => getComposedDataCy(externalDataCy, subpart, label), [externalDataCy, subpart, label]);

const disabled = useMemo(() => {
if (typeof externalDisabled === "function") {
logWarn(
"Table",
"Invalid type for disabled property: action won't be disabled as type function is valid only for position='row'"
);
return false;
}

return externalDisabled;
}, [externalDisabled]);
const disabled = useMemo(
() => (typeof externalDisabled === "function" ? externalDisabled(data as any[]) : externalDisabled),
[data, externalDisabled]
);

const onClick = useCallback(() => callback(data), [callback, data]);

Expand Down

0 comments on commit fd5d649

Please sign in to comment.