-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(instance) move selection notification below table
- Loading branch information
Showing
9 changed files
with
121 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React, { FC } from "react"; | ||
import { Button } from "@canonical/react-components"; | ||
|
||
interface Props { | ||
totalCount: number; | ||
filteredNames: string[]; | ||
itemName: string; | ||
parentName: string; | ||
selectedNames: string[]; | ||
setSelectedNames: (val: string[]) => void; | ||
} | ||
|
||
const SelectedTableNotification: FC<Props> = ({ | ||
totalCount, | ||
filteredNames, | ||
itemName, | ||
parentName, | ||
selectedNames, | ||
setSelectedNames, | ||
}: Props) => { | ||
const isAllSelected = selectedNames.length === filteredNames.length; | ||
|
||
const selectAll = () => { | ||
setSelectedNames(filteredNames); | ||
}; | ||
|
||
const selectNone = () => { | ||
setSelectedNames([]); | ||
}; | ||
|
||
return ( | ||
<div> | ||
{isAllSelected ? ( | ||
<> | ||
{filteredNames.length === 1 ? ( | ||
<> | ||
<b>1</b> {itemName} is selected.{" "} | ||
</> | ||
) : ( | ||
<> | ||
All <b>{filteredNames.length}</b> {itemName}s selected.{" "} | ||
</> | ||
)} | ||
<Button | ||
appearance="link" | ||
className="u-no-margin--bottom u-no-padding--top" | ||
onClick={selectNone} | ||
> | ||
Clear selection | ||
</Button> | ||
</> | ||
) : ( | ||
<> | ||
<b>{selectedNames.length}</b> {itemName} | ||
{selectedNames.length > 1 && "s"} selected.{" "} | ||
<Button | ||
appearance="link" | ||
className="u-no-margin--bottom u-no-padding--top" | ||
onClick={selectAll} | ||
> | ||
Select all <b>{filteredNames.length}</b>{" "} | ||
{filteredNames.length === totalCount ? parentName : "filtered"}{" "} | ||
{itemName}s | ||
</Button> | ||
</> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default SelectedTableNotification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.