Add dash on table when selecting only some rows

Change-type: patch
Signed-off-by: Lorenzo Alberto Maria Ambrosi <lorenzothunder.ambrosi@gmail.com>
This commit is contained in:
Lorenzo Alberto Maria Ambrosi 2020-09-29 15:27:23 +02:00
parent a7637ad8d4
commit 640a7409ee
2 changed files with 52 additions and 20 deletions

View File

@ -79,7 +79,7 @@ const DrivesTable = styled((props: GenericTableProps<Drive>) => (
[data-display='table-body'] {
> [data-display='table-row'] > [data-display='table-cell'] {
&:nth-child(2) {
width: 38%;
width: 32%;
}
&:nth-child(3) {
@ -345,6 +345,16 @@ export class DriveSelector extends React.Component<
}
}
private deselectingAll(rows: DrivelistDrive[]) {
return (
rows.length > 0 &&
rows.length === this.state.selectedList.length &&
this.state.selectedList.every(
(d) => rows.findIndex((r) => d.device === r.device) > -1,
)
);
}
componentDidMount() {
this.unsubscribe = store.subscribe(() => {
const drives = getDrives();
@ -423,6 +433,7 @@ export class DriveSelector extends React.Component<
t.setRowSelection(selectedList);
}
}}
checkedRowsNumber={selectedList.length}
multipleSelection={this.props.multipleSelection}
columns={this.tableColumns}
data={displayedDrives}
@ -432,8 +443,11 @@ export class DriveSelector extends React.Component<
}
rowKey="displayName"
onCheck={(rows: Drive[]) => {
const newSelection = rows.filter(isDrivelistDrive);
let newSelection = rows.filter(isDrivelistDrive);
if (this.props.multipleSelection) {
if (this.deselectingAll(newSelection)) {
newSelection = [];
}
this.setState({
selectedList: newSelection,
});
@ -450,25 +464,21 @@ export class DriveSelector extends React.Component<
) {
return;
}
if (this.props.multipleSelection) {
const newList = [...selectedList];
const selectedIndex = selectedList.findIndex(
(drive) => drive.device === row.device,
const index = selectedList.findIndex(
(d) => d.device === row.device,
);
if (selectedIndex === -1) {
const newList = this.props.multipleSelection
? [...selectedList]
: [];
if (index === -1) {
newList.push(row);
} else {
// Deselect if selected
newList.splice(selectedIndex, 1);
newList.splice(index, 1);
}
this.setState({
selectedList: newList,
});
return;
}
this.setState({
selectedList: [row],
});
}}
/>
{numberOfHiddenSystemDrives > 0 && (

View File

@ -151,6 +151,11 @@ export const Modal = styled(({ style, children, ...props }) => {
padding: 0;
height: 100%;
> div:first-child {
height: 81%;
padding: 24px 30px 0;
}
> h3 {
margin: 0;
padding: 24px 30px 0;
@ -225,6 +230,8 @@ export const Alert = styled((props) => (
export interface GenericTableProps<T> extends BaseTableProps<T> {
refFn: (t: BaseTable<T>) => void;
data: T[];
checkedRowsNumber?: number;
multipleSelection: boolean;
showWarnings?: boolean;
}
@ -254,6 +261,22 @@ function StyledTable<T>() {
input[type='checkbox'] + div {
display: ${(props) => (props.multipleSelection ? 'flex' : 'none')};
${(props) =>
props.multipleSelection &&
props.checkedRowsNumber !== 0 &&
props.checkedRowsNumber !== props.data.length
? `
font-weight: 600;
color: ${colors.primary.foreground};
background: ${colors.primary.background};
::after {
content: '';
}
`
: ''}
}
}
}
@ -276,8 +299,7 @@ function StyledTable<T>() {
&[data-highlight='true'] {
&.system {
background-color: ${(props) =>
props.showWarnings ? '#fff5e6' : '#e8f5fc'};
background-color: ${(props) => (props.showWarnings ? '#fff5e6' : '#e8f5fc')};
}
> [data-display='table-cell']:first-child {