@material-ui/icons#LayersClear TypeScript Examples
The following examples show how to use
@material-ui/icons#LayersClear.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestDetailsModal.tsx From frontend with Apache License 2.0 | 4 votes |
TestDetailsModal: React.FunctionComponent<{
testRun: TestRun;
touched: boolean;
handleClose: () => void;
}> = ({ testRun, touched, handleClose }) => {
const classes = useStyles();
const navigate = useNavigate();
const { enqueueSnackbar } = useSnackbar();
const testRunDispatch = useTestRunDispatch();
const stageWidth = (window.innerWidth / 2) * 0.8;
const stageHeigth = window.innerHeight * 0.6;
const stageScaleBy = 1.2;
const [stageScale, setStageScale] = React.useState(1);
const [stagePos, setStagePos] = React.useState(defaultStagePos);
const [stageInitPos, setStageInitPos] = React.useState(defaultStagePos);
const [stageOffset, setStageOffset] = React.useState(defaultStagePos);
const [processing, setProcessing] = React.useState(false);
const [isDrawMode, setIsDrawMode] = useState(false);
const [valueOfIgnoreOrCompare, setValueOfIgnoreOrCompare] = useState(
"Ignore Areas"
);
const [isDiffShown, setIsDiffShown] = useState(false);
const [selectedRectId, setSelectedRectId] = React.useState<string>();
const [ignoreAreas, setIgnoreAreas] = React.useState<IgnoreArea[]>([]);
const [applyIgnoreDialogOpen, setApplyIgnoreDialogOpen] = React.useState(
false
);
const toggleApplyIgnoreDialogOpen = () => {
setApplyIgnoreDialogOpen(!applyIgnoreDialogOpen);
};
const [image, imageStatus] = useImage(
staticService.getImage(testRun.imageName)
);
const [baselineImage, baselineImageStatus] = useImage(
staticService.getImage(testRun.baselineName)
);
const [diffImage, diffImageStatus] = useImage(
staticService.getImage(testRun.diffName)
);
const applyIgnoreAreaText =
"Apply selected ignore area to all images in this build.";
React.useEffect(() => {
fitStageToScreen();
// eslint-disable-next-line
}, [image]);
React.useEffect(() => {
setIsDiffShown(!!testRun.diffName);
}, [testRun.diffName]);
React.useEffect(() => {
setIgnoreAreas(JSON.parse(testRun.ignoreAreas));
}, [testRun]);
const isImageSizeDiffer = React.useMemo(
() =>
testRun.baselineName &&
testRun.imageName &&
(image?.height !== baselineImage?.height ||
image?.width !== baselineImage?.width),
[image, baselineImage, testRun.baselineName, testRun.imageName]
);
const handleIgnoreAreaChange = (ignoreAreas: IgnoreArea[]) => {
setIgnoreAreas(ignoreAreas);
testRunDispatch({
type: "touched",
payload: testRun.ignoreAreas !== JSON.stringify(ignoreAreas),
});
};
const removeSelection = (event: KonvaEventObject<MouseEvent>) => {
// deselect when clicked not on Rect
const isRectClicked = event.target.className === "Rect";
if (!isRectClicked) {
setSelectedRectId(undefined);
}
};
const deleteIgnoreArea = (id: string) => {
handleIgnoreAreaChange(ignoreAreas.filter((area) => area.id !== id));
setSelectedRectId(undefined);
};
const saveTestRun = (ignoreAreas: IgnoreArea[], successMessage: string) => {
testRunService
.updateIgnoreAreas({
ids: [testRun.id],
ignoreAreas,
})
.then(() => {
enqueueSnackbar(successMessage, {
variant: "success",
});
})
.catch((err) =>
enqueueSnackbar(err, {
variant: "error",
})
);
};
const saveIgnoreAreasOrCompareArea = () => {
if (valueOfIgnoreOrCompare.includes("Ignore")) {
saveTestRun(ignoreAreas, "Ignore areas are updated.");
} else {
const invertedIgnoreAreas = invertIgnoreArea(
image!.width,
image!.height,
head(ignoreAreas)
);
handleIgnoreAreaChange(invertedIgnoreAreas);
saveTestRun(
invertedIgnoreAreas,
"Selected area has been inverted to ignore areas and saved."
);
}
testRunDispatch({ type: "touched", payload: false });
};
const onIgnoreOrCompareSelectChange = (value: string) => {
if (value.includes("Compare")) {
setValueOfIgnoreOrCompare("Compare Area");
} else {
setValueOfIgnoreOrCompare("Ignore Areas");
}
};
const setOriginalSize = () => {
setStageScale(1);
resetPositioin();
};
const fitStageToScreen = () => {
const scale = image
? Math.min(
stageWidth < image.width ? stageWidth / image.width : 1,
stageHeigth < image.height ? stageHeigth / image.height : 1
)
: 1;
setStageScale(scale);
resetPositioin();
};
const resetPositioin = () => {
setStagePos(defaultStagePos);
setStageOffset(defaultStagePos);
};
const applyIgnoreArea = () => {
let newIgnoreArea = ignoreAreas.find((area) => selectedRectId! === area.id);
if (newIgnoreArea) {
setProcessing(true);
testRunService
.getList(testRun.buildId)
.then((testRuns: TestRun[]) => {
let allIds = testRuns.map((item) => item.id);
let data: UpdateIgnoreAreaDto = {
ids: allIds,
ignoreAreas: [newIgnoreArea!],
};
testRunService.addIgnoreAreas(data).then(() => {
setProcessing(false);
setSelectedRectId(undefined);
enqueueSnackbar(
"Ignore areas are updated in all images in this build.",
{
variant: "success",
}
);
});
})
.catch((error) => {
enqueueSnackbar("There was an error : " + error, {
variant: "error",
});
setProcessing(false);
});
} else {
enqueueSnackbar(
"There was an error determining which ignore area to apply.",
{ variant: "error" }
);
}
};
useHotkeys(
"d",
() => !!testRun.diffName && setIsDiffShown((isDiffShown) => !isDiffShown),
[testRun.diffName]
);
useHotkeys("ESC", handleClose, [handleClose]);
return (
<React.Fragment>
<AppBar position="sticky">
<Toolbar>
<Grid container justifyContent="space-between">
<Grid item>
<Typography variant="h6">{testRun.name}</Typography>
</Grid>
{testRun.diffName && (
<Grid item>
<Tooltip title={"Hotkey: D"}>
<Switch
checked={isDiffShown}
onChange={() => setIsDiffShown(!isDiffShown)}
name="Toggle diff"
/>
</Tooltip>
</Grid>
)}
{(testRun.status === TestStatus.unresolved ||
testRun.status === TestStatus.new) && (
<Grid item>
<ApproveRejectButtons testRun={testRun} />
</Grid>
)}
<Grid item>
<IconButton color="inherit" onClick={handleClose}>
<Close />
</IconButton>
</Grid>
</Grid>
</Toolbar>
</AppBar>
{processing && <LinearProgress />}
<Box m={1}>
<Grid container alignItems="center">
<Grid item xs={12}>
<Grid container alignItems="center">
<Grid item>
<TestRunDetails testRun={testRun} />
</Grid>
{isImageSizeDiffer && (
<Grid item>
<Tooltip
title={
"Image height/width differ from baseline! Cannot calculate diff!"
}
>
<IconButton>
<WarningRounded color="secondary" />
</IconButton>
</Tooltip>
</Grid>
)}
</Grid>
</Grid>
<Grid item>
<Grid container alignItems="center" spacing={2}>
<Grid item>
<Select
id="area-select"
labelId="areaSelect"
value={valueOfIgnoreOrCompare}
onChange={(event) =>
onIgnoreOrCompareSelectChange(event.target.value as string)
}
>
{["Ignore Areas", "Compare Area"].map((eachItem) => (
<MenuItem key={eachItem} value={eachItem}>
{eachItem}
</MenuItem>
))}
</Select>
</Grid>
<Grid item>
<ToggleButton
value={"drawMode"}
selected={isDrawMode}
onClick={() => {
setIsDrawMode(!isDrawMode);
}}
>
<Add />
</ToggleButton>
</Grid>
<Grid item>
<IconButton
disabled={!selectedRectId || ignoreAreas.length === 0}
onClick={() =>
selectedRectId && deleteIgnoreArea(selectedRectId)
}
>
<Delete />
</IconButton>
</Grid>
<Tooltip title="Clears all ignore areas." aria-label="reject">
<Grid item>
<IconButton
disabled={ignoreAreas.length === 0}
onClick={() => {
handleIgnoreAreaChange([]);
}}
>
<LayersClear />
</IconButton>
</Grid>
</Tooltip>
<Tooltip
title={applyIgnoreAreaText}
aria-label="apply ignore area"
>
<Grid item>
<IconButton
disabled={!selectedRectId || ignoreAreas.length === 0}
onClick={() => toggleApplyIgnoreDialogOpen()}
>
<Collections />
</IconButton>
</Grid>
</Tooltip>
<Grid item>
<IconButton
disabled={!touched}
onClick={() => saveIgnoreAreasOrCompareArea()}
>
<Save />
</IconButton>
</Grid>
</Grid>
</Grid>
<Grid item>
<Button
color="primary"
disabled={!testRun.testVariationId}
onClick={() => {
navigate(
`${routes.VARIATION_DETAILS_PAGE}/${testRun.testVariationId}`
);
}}
>
Baseline history
</Button>
</Grid>
<Grid item>
<CommentsPopper
text={testRun.comment}
onSave={(comment) =>
testRunService
.update(testRun.id, { comment })
.then(() =>
enqueueSnackbar("Comment updated", {
variant: "success",
})
)
.catch((err) =>
enqueueSnackbar(err, {
variant: "error",
})
)
}
/>
</Grid>
</Grid>
</Box>
<Box
overflow="hidden"
minHeight="65%"
className={classes.drawAreaContainer}
>
<Grid container style={{ height: "100%" }}>
<Grid item xs={6} className={classes.drawAreaItem}>
<DrawArea
type="Baseline"
imageName={testRun.baselineName}
branchName={testRun.baselineBranchName}
imageState={[baselineImage, baselineImageStatus]}
ignoreAreas={[]}
tempIgnoreAreas={[]}
setIgnoreAreas={handleIgnoreAreaChange}
selectedRectId={selectedRectId}
setSelectedRectId={setSelectedRectId}
onStageClick={removeSelection}
stageScaleState={[stageScale, setStageScale]}
stagePosState={[stagePos, setStagePos]}
stageInitPosState={[stageInitPos, setStageInitPos]}
stageOffsetState={[stageOffset, setStageOffset]}
drawModeState={[false, setIsDrawMode]}
/>
</Grid>
<Grid item xs={6} className={classes.drawAreaItem}>
{isDiffShown ? (
<DrawArea
type="Diff"
imageName={testRun.diffName}
branchName={testRun.branchName}
imageState={[diffImage, diffImageStatus]}
ignoreAreas={ignoreAreas}
tempIgnoreAreas={JSON.parse(testRun.tempIgnoreAreas)}
setIgnoreAreas={handleIgnoreAreaChange}
selectedRectId={selectedRectId}
setSelectedRectId={setSelectedRectId}
onStageClick={removeSelection}
stageScaleState={[stageScale, setStageScale]}
stagePosState={[stagePos, setStagePos]}
stageInitPosState={[stageInitPos, setStageInitPos]}
stageOffsetState={[stageOffset, setStageOffset]}
drawModeState={[isDrawMode, setIsDrawMode]}
/>
) : (
<DrawArea
type="Image"
imageName={testRun.imageName}
branchName={testRun.branchName}
imageState={[image, imageStatus]}
ignoreAreas={ignoreAreas}
tempIgnoreAreas={JSON.parse(testRun.tempIgnoreAreas)}
setIgnoreAreas={handleIgnoreAreaChange}
selectedRectId={selectedRectId}
setSelectedRectId={setSelectedRectId}
onStageClick={removeSelection}
stageScaleState={[stageScale, setStageScale]}
stagePosState={[stagePos, setStagePos]}
stageInitPosState={[stageInitPos, setStageInitPos]}
stageOffsetState={[stageOffset, setStageOffset]}
drawModeState={[isDrawMode, setIsDrawMode]}
/>
)}
</Grid>
</Grid>
</Box>
<ScaleActionsSpeedDial
onZoomInClick={() => setStageScale(stageScale * stageScaleBy)}
onZoomOutClick={() => setStageScale(stageScale / stageScaleBy)}
onOriginalSizeClick={setOriginalSize}
onFitIntoScreenClick={fitStageToScreen}
/>
<BaseModal
open={applyIgnoreDialogOpen}
title={applyIgnoreAreaText}
submitButtonText={"Yes"}
onCancel={toggleApplyIgnoreDialogOpen}
content={
<Typography>
{`All images in the current build will be re-compared with new ignore area taken into account. Are you sure?`}
</Typography>
}
onSubmit={() => {
toggleApplyIgnoreDialogOpen();
applyIgnoreArea();
}}
/>
</React.Fragment>
);
}
Example #2
Source File: BulkOperation.tsx From frontend with Apache License 2.0 | 4 votes |
BulkOperation: React.FunctionComponent = () => {
const props = useGridSlotComponentProps();
const { enqueueSnackbar } = useSnackbar();
const [approveDialogOpen, setApproveDialogOpen] = React.useState(false);
const [rejectDialogOpen, setRejectDialogOpen] = React.useState(false);
const [deleteDialogOpen, setDeleteDialogOpen] = React.useState(false);
const [downloadDialogOpen, setDownloadDialogOpen] = React.useState(false);
const [clearIgnoreDialogOpen, setClearIgnoreDialogOpen] = React.useState(false);
const [isProcessing, setIsProcessing] = React.useState(false);
const ids: GridRowId[] = React.useMemo(
() => Object.values(props.state.selection),
[props.state.selection]
);
const isMerge: boolean = React.useMemo(
() =>
!!head(
props.rows.filter((value: GridRowData) =>
ids.includes(value.id.toString())
)
)?.merge,
// eslint-disable-next-line
[ids]
);
const idsEligibleForApproveOrReject: string[] = React.useMemo(
() =>
props.rows
.filter(
(value: GridRowData) =>
ids.includes(value.id.toString()) &&
[TestStatus.new, TestStatus.unresolved].includes(
value.status.toString()
)
)
.map((value: GridRowData) => value.id.toString()),
// eslint-disable-next-line
[ids]
);
const selectedRows: GridSelectionModel = props.state.selection;
const count = Object.keys(selectedRows).length;
const toggleApproveDialogOpen = () => {
setApproveDialogOpen(!approveDialogOpen);
};
const toggleRejectDialogOpen = () => {
setRejectDialogOpen(!rejectDialogOpen);
};
const toggleDeleteDialogOpen = () => {
setDeleteDialogOpen(!deleteDialogOpen);
};
const toggleDownloadDialogOpen = () => {
setDownloadDialogOpen(!downloadDialogOpen);
};
const toggleClearIgnoreDialogOpen = () => {
setClearIgnoreDialogOpen(!clearIgnoreDialogOpen);
};
const getTitle = () => {
if (clearIgnoreDialogOpen) {
return "Clear Ignore Area For Selected Items";
}
return submitButtonText() + " Test Runs";
};
const submitButtonText = (): string => {
if (approveDialogOpen) {
return "Approve";
}
if (rejectDialogOpen) {
return "Reject";
}
if (deleteDialogOpen) {
return "Delete";
}
if (downloadDialogOpen) {
return "Download";
}
if (clearIgnoreDialogOpen) {
return "Clear";
}
return "";
};
const closeModal = () => {
if (deleteDialogOpen) {
return toggleDeleteDialogOpen();
}
if (downloadDialogOpen) {
return toggleDownloadDialogOpen();
}
if (approveDialogOpen) {
return toggleApproveDialogOpen();
}
if (rejectDialogOpen) {
return toggleRejectDialogOpen();
}
if (clearIgnoreDialogOpen) {
return toggleClearIgnoreDialogOpen();
}
};
const getBulkAction = () => {
if (deleteDialogOpen) {
return testRunService.removeBulk(ids);
}
if (downloadDialogOpen) {
let urlsToDownload: { download: string, filename: string }[] = [];
ids.forEach((id) => {
testRunService.getDetails(id.toString())
.then(
(e) => {
urlsToDownload.push({ "download": "static/imageUploads/" + e.imageName, "filename": e.name });
//Call getFile function only when all images names are pushed into the array.
if (urlsToDownload.length === ids.length) {
testRunService.getFiles(urlsToDownload);
}
});
});
}
if (rejectDialogOpen) {
return testRunService.rejectBulk(idsEligibleForApproveOrReject);
}
if (approveDialogOpen) {
return testRunService.approveBulk(idsEligibleForApproveOrReject, isMerge);
}
return testRunService.updateIgnoreAreas({
ids,
ignoreAreas: [],
});
};
const dismissDialog = () => {
if (deleteDialogOpen) {
return toggleDeleteDialogOpen();
}
if (downloadDialogOpen) {
return toggleDownloadDialogOpen();
}
if (approveDialogOpen) {
return toggleApproveDialogOpen();
}
if (clearIgnoreDialogOpen) {
return toggleClearIgnoreDialogOpen();
}
return toggleRejectDialogOpen();
};
return (
<>
<Tooltip
title="Approve unresolved in selected rows."
aria-label="approve"
>
<span>
<IconButton disabled={count === 0} onClick={toggleApproveDialogOpen}>
<ThumbUp />
</IconButton>
</span>
</Tooltip>
<Tooltip title="Reject unresolved in selected rows." aria-label="reject">
<span>
<IconButton disabled={count === 0} onClick={toggleRejectDialogOpen}>
<ThumbDown />
</IconButton>
</span>
</Tooltip>
<Tooltip title="Download images for selected rows." aria-label="download">
<span>
<IconButton disabled={count === 0} onClick={toggleDownloadDialogOpen}>
<CloudDownload />
</IconButton>
</span>
</Tooltip>
<Tooltip title="Delete selected rows." aria-label="delete">
<span>
<IconButton disabled={count === 0} onClick={toggleDeleteDialogOpen}>
<Delete />
</IconButton>
</span>
</Tooltip>
<Tooltip
title="Clear ignore areas for selected rows."
aria-label="clear ignore area"
>
<span>
<IconButton
disabled={count === 0}
onClick={toggleClearIgnoreDialogOpen}
>
<LayersClear />
</IconButton>
</span>
</Tooltip>
<BaseModal
open={
deleteDialogOpen ||
downloadDialogOpen ||
approveDialogOpen ||
rejectDialogOpen ||
clearIgnoreDialogOpen
}
title={getTitle()}
submitButtonText={submitButtonText()}
onCancel={dismissDialog}
content={
<Typography>
{`Are you sure you want to ${submitButtonText().toLowerCase()} ${count} items?`}
</Typography>
}
onSubmit={() => {
setIsProcessing(true);
getBulkAction()
.then(() => {
setIsProcessing(false);
enqueueSnackbar(`${count} test runs processed.`, {
variant: "success",
});
})
.catch((err) => {
setIsProcessing(false);
enqueueSnackbar(err, {
variant: "error",
});
});
closeModal();
}}
/>
{isProcessing && <LinearProgress />}
</>
);
}