Skip to content

Commit

Permalink
avniproject/avni-security#15, #1037 | Multiple changes
Browse files Browse the repository at this point in the history
Replace material-ui-rc-color-picker because it uses google fonts
Use icons in place of icon strings. Specify the icons to be used by MaterialTable
  • Loading branch information
vinayvenu committed Sep 12, 2023
1 parent d155a1c commit 1ca782a
Show file tree
Hide file tree
Showing 28 changed files with 207 additions and 162 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"jszip": "^3.2.2",
"lodash": "^4.17.19",
"material-table": "1.43.0",
"material-ui-rc-color-picker": "^1.0.4",
"moment": "^2.22.2",
"openchs-idi": "git+https://github.com/avniproject/openchs-idi#b6c57e051b91ed4bc2634f4f087dba51cc3a01c8",
"openchs-models": "1.30.61",
Expand All @@ -49,6 +48,7 @@
"react-beautiful-dnd": "^11.0.5",
"react-bootstrap": "^0.32.1",
"react-bootstrap-typeahead": "^3.1.5",
"react-colorful": "^5.6.1",
"react-copy-to-clipboard": "^5.0.1",
"react-dom": "^16.8.3",
"react-draft-wysiwyg": "^1.14.5",
Expand Down
6 changes: 0 additions & 6 deletions src/adminApp/Constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,3 @@ export const subjectTypeInitialState = {
shouldSyncByLocation: true,
lastNameOptional: false
};

export const colorPickerCSS = {
boxShadow: "5px 10px 8px 10px #888888",
border: "1px solid",
backgroundColor: "#fff"
};
6 changes: 4 additions & 2 deletions src/adminApp/CustomFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import Button from "@material-ui/core/Button";
import commonApi from "../common/service";
import { Privilege } from "openchs-models";
import UserInfo from "../common/model/UserInfo";
import Edit from "@material-ui/icons/Edit";
import Delete from "@material-ui/icons/DeleteOutline";

function hasEditPrivilege(userInfo) {
return UserInfo.hasPrivilege(userInfo, Privilege.PrivilegeType.EditOfflineDashboardAndReportCard);
Expand Down Expand Up @@ -91,7 +93,7 @@ const customFilters = ({
const styles = useStyles();

const editFilter = (filterType, title) => ({
icon: "edit",
icon: () => <Edit />,
tooltip: "Edit TaskAssignmentFilter",
onClick: (event, filter) => {
history.push({
Expand All @@ -111,7 +113,7 @@ const customFilters = ({
});

const deleteFilter = filterType => ({
icon: "delete_outline",
icon: () => <Delete />,
tooltip: "Delete filter",
onClick: (event, rowData) => {
const voidedMessage = `Do you want to delete ${rowData.titleKey} filter ?`;
Expand Down
6 changes: 4 additions & 2 deletions src/adminApp/EncounterType/EncounterTypeList.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import AvniMaterialTable from "adminApp/components/AvniMaterialTable";
import { connect } from "react-redux";
import UserInfo from "../../common/model/UserInfo";
import { Privilege } from "openchs-models";
import Edit from "@material-ui/icons/Edit";
import Delete from "@material-ui/icons/DeleteOutline";

function hasEditPrivilege(userInfo) {
return UserInfo.hasPrivilege(userInfo, Privilege.PrivilegeType.EditEncounterType);
Expand Down Expand Up @@ -128,14 +130,14 @@ const EncounterTypeList = ({ history, userInfo }) => {
};

const editEncounterType = rowData => ({
icon: "edit",
icon: () => <Edit />,
tooltip: "Edit encounter type",
onClick: event => history.push(`/appDesigner/encounterType/${rowData.id}`),
disabled: rowData.voided
});

const voidEncounterType = rowData => ({
icon: "delete_outline",
icon: () => <Delete />,
tooltip: "Delete encounter type",
onClick: (event, rowData) => {
const voidedMessage =
Expand Down
8 changes: 3 additions & 5 deletions src/adminApp/Program/EditProgramFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import _ from "lodash";
import FormLabel from "@material-ui/core/FormLabel";
import { AvniSelect } from "../../common/components/AvniSelect";
import MenuItem from "@material-ui/core/MenuItem";
import ColorPicker from "material-ui-rc-color-picker";
import { colorPickerCSS } from "../Constant";
import { AvniFormLabel } from "../../common/components/AvniFormLabel";
import { AvniSelectForm } from "../../common/components/AvniSelectForm";
import { findProgramEnrolmentForms, findProgramExitForms } from "../domain/formMapping";
Expand All @@ -19,6 +17,7 @@ import {
import RuleDesigner from "../../formDesigner/components/DeclarativeRule/RuleDesigner";
import { confirmBeforeRuleEdit } from "../../formDesigner/util";
import { JSEditor } from "../../common/components/JSEditor";
import { PopoverColorPicker } from "../../common/components/PopoverColorPicker";

const EditProgramFields = props => {
const {
Expand Down Expand Up @@ -69,12 +68,11 @@ const EditProgramFields = props => {

<br />
<AvniFormLabel label={"Colour Picker"} toolTipKey={"APP_DESIGNER_PROGRAM_COLOR"} />
<ColorPicker
<PopoverColorPicker
id="colour"
label="Colour"
style={colorPickerCSS}
color={program.colour}
onChange={color => dispatch({ type: "colour", payload: color.color })}
onChange={color => dispatch({ type: "colour", payload: color })}
/>

<br />
Expand Down
1 change: 0 additions & 1 deletion src/adminApp/Program/ProgramCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Title } from "react-admin";
import Button from "@material-ui/core/Button";
import { programInitialState } from "../Constant";
import { programReducer } from "../Reducers";
import "material-ui-rc-color-picker/assets/index.css";
import { DocumentationContainer } from "../../common/components/DocumentationContainer";
import ProgramService from "../service/ProgramService";
import EditProgramFields from "./EditProgramFields";
Expand Down
1 change: 0 additions & 1 deletion src/adminApp/Program/ProgramEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Grid from "@material-ui/core/Grid";
import DeleteIcon from "@material-ui/icons/Delete";
import { programInitialState } from "../Constant";
import { programReducer } from "../Reducers";
import "material-ui-rc-color-picker/assets/index.css";
import { findProgramEnrolmentForm, findProgramExitForm } from "../domain/formMapping";
import { SaveComponent } from "../../common/components/SaveComponent";
import { AvniSwitch } from "../../common/components/AvniSwitch";
Expand Down
6 changes: 4 additions & 2 deletions src/adminApp/Program/ProgramList.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import AvniMaterialTable from "adminApp/components/AvniMaterialTable";
import UserInfo from "../../common/model/UserInfo";
import { Privilege } from "openchs-models";
import { connect } from "react-redux";
import Edit from "@material-ui/icons/Edit";
import Delete from "@material-ui/icons/DeleteOutline";

function hasEditPrivilege(userInfo) {
return UserInfo.hasPrivilege(userInfo, Privilege.PrivilegeType.EditProgram);
Expand Down Expand Up @@ -123,14 +125,14 @@ const ProgramList = ({ history, userInfo }) => {
};

const editProgram = rowData => ({
icon: "edit",
icon: () => <Edit />,
tooltip: "Edit program",
onClick: event => history.push(`/appDesigner/program/${rowData.id}`),
disabled: rowData.voided
});

const voidProgram = rowData => ({
icon: "delete_outline",
icon: () => <Delete />,
tooltip: "Delete program",
onClick: (event, rowData) => {
const voidedMessage = "Do you really want to delete the program " + rowData.name + " ?";
Expand Down
6 changes: 4 additions & 2 deletions src/adminApp/SubjectType/SubjectTypesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import AvniMaterialTable from "adminApp/components/AvniMaterialTable";
import { connect } from "react-redux";
import UserInfo from "../../common/model/UserInfo";
import { Privilege } from "openchs-models";
import Edit from "@material-ui/icons/Edit";
import Delete from "@material-ui/icons/DeleteOutline";

function hasEditPrivilege(userInfo) {
return UserInfo.hasPrivilege(userInfo, Privilege.PrivilegeType.EditSubjectType);
Expand Down Expand Up @@ -83,14 +85,14 @@ const SubjectTypesList = ({ history, userInfo }) => {
};

const editSubjectType = rowData => ({
icon: "edit",
icon: () => <Edit />,
tooltip: "Edit subject type",
onClick: event => history.push(`/appDesigner/subjectType/${rowData.id}`),
disabled: rowData.voided
});

const voidSubjectType = rowData => ({
icon: "delete_outline",
icon: () => <Delete />,
tooltip: "Delete subject type",
onClick: (event, rowData) => {
const voidedMessage = "Do you really want to delete the subject type " + rowData.name + " ?";
Expand Down
7 changes: 5 additions & 2 deletions src/adminApp/Util/EntityListUtil.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import http from "../../common/utils/httpClient";
import Edit from "@material-ui/icons/Edit";
import React from "react";
import Delete from "@material-ui/icons/DeleteOutline";

class EntityListUtil {
static refreshTable = ref => ref.current && ref.current.onQueryChange();
Expand All @@ -9,7 +12,7 @@ class EntityListUtil {

static voidAction(rowData, tableRef, resourceName, entityDisplayName, entityFieldName) {
return {
icon: "delete_outline",
icon: () => <Delete />,
tooltip: `Delete ${entityDisplayName.toLowerCase()}}`,
onClick: (event, rowData) => {
const voidedMessage = `Do you really want to delete the ${entityDisplayName.toLowerCase()} ${
Expand All @@ -32,7 +35,7 @@ class EntityListUtil {

static editAction(rowData, history, entityName, entityDisplayName) {
return {
icon: "edit",
icon: () => <Edit />,
tooltip: `Edit ${entityDisplayName.toLowerCase()}`,
onClick: () => history.push(`/appDesigner/${entityName}/${rowData.id}`),
disabled: rowData.voided
Expand Down
5 changes: 3 additions & 2 deletions src/adminApp/components/AvniMaterialTable.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React, { forwardRef, Fragment, useEffect, useState } from "react";
import MaterialTable from "material-table";
import TablePagination from "@material-ui/core/TablePagination";
import { useLocation, useHistory } from "react-router-dom";
import { useHistory, useLocation } from "react-router-dom";
import MaterialTableIcons from "./MaterialTableIcons";

const AvniMaterialTable = forwardRef(
({ fetchData, options, components, route, ...props }, tableRef) => {
Expand All @@ -26,12 +27,12 @@ const AvniMaterialTable = forwardRef(
return (
<>
<MaterialTable
icons={MaterialTableIcons}
tableRef={tableRef}
data={typeof fetchData === "function" ? handleFetchData : fetchData}
components={{
Container: props => <Fragment>{props.children}</Fragment>,
Pagination: paginationProps => {
console.log("paginationprops", paginationProps);
const { ActionsComponent, onChangePage, ...tablePaginationProps } = paginationProps;
return (
<TablePagination
Expand Down
36 changes: 36 additions & 0 deletions src/adminApp/components/MaterialTableIcons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { forwardRef } from "react";
import AddBox from "@material-ui/icons/AddBox";
import Check from "@material-ui/icons/Check";
import Clear from "@material-ui/icons/Clear";
import DeleteOutline from "@material-ui/icons/DeleteOutline";
import ChevronRight from "@material-ui/icons/ChevronRight";
import Edit from "@material-ui/icons/Edit";
import SaveAlt from "@material-ui/icons/SaveAlt";
import FilterList from "@material-ui/icons/FilterList";
import FirstPage from "@material-ui/icons/FirstPage";
import LastPage from "@material-ui/icons/LastPage";
import ChevronLeft from "@material-ui/icons/ChevronLeft";
import Search from "@material-ui/icons/Search";
import ArrowDownward from "@material-ui/icons/ArrowDownward";
import Remove from "@material-ui/icons/Remove";
import ViewColumn from "@material-ui/icons/ViewColumn";

export default {
Add: forwardRef((props, ref) => <AddBox {...props} ref={ref} />),
Check: forwardRef((props, ref) => <Check {...props} ref={ref} />),
Clear: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
Delete: forwardRef((props, ref) => <DeleteOutline {...props} ref={ref} />),
DetailPanel: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
Edit: forwardRef((props, ref) => <Edit {...props} ref={ref} />),
Export: forwardRef((props, ref) => <SaveAlt {...props} ref={ref} />),
Filter: forwardRef((props, ref) => <FilterList {...props} ref={ref} />),
FirstPage: forwardRef((props, ref) => <FirstPage {...props} ref={ref} />),
LastPage: forwardRef((props, ref) => <LastPage {...props} ref={ref} />),
NextPage: forwardRef((props, ref) => <ChevronRight {...props} ref={ref} />),
PreviousPage: forwardRef((props, ref) => <ChevronLeft {...props} ref={ref} />),
ResetSearch: forwardRef((props, ref) => <Clear {...props} ref={ref} />),
Search: forwardRef((props, ref) => <Search {...props} ref={ref} />),
SortArrow: forwardRef((props, ref) => <ArrowDownward {...props} ref={ref} />),
ThirdStateCheck: forwardRef((props, ref) => <Remove {...props} ref={ref} />),
ViewColumn: forwardRef((props, ref) => <ViewColumn {...props} ref={ref} />)
};
84 changes: 84 additions & 0 deletions src/common/components/PopoverColorPicker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React, { useEffect, useCallback, useRef, useState } from "react";
import { HexColorPicker } from "react-colorful";
import { makeStyles } from "@material-ui/core";

// Source: https://codesandbox.io/s/opmco
const useClickOutside = (ref, handler) => {
useEffect(() => {
let startedInside = false;
let startedWhenMounted = false;

const listener = event => {
// Do nothing if `mousedown` or `touchstart` started inside ref element
if (startedInside || !startedWhenMounted) return;
// Do nothing if clicking ref's element or descendent elements
if (!ref.current || ref.current.contains(event.target)) return;

handler(event);
};

const validateEventStart = event => {
startedWhenMounted = ref.current;
startedInside = ref.current && ref.current.contains(event.target);
};

document.addEventListener("mousedown", validateEventStart);
document.addEventListener("touchstart", validateEventStart);
document.addEventListener("click", listener);

return () => {
document.removeEventListener("mousedown", validateEventStart);
document.removeEventListener("touchstart", validateEventStart);
document.removeEventListener("click", listener);
};
}, [ref, handler]);
};

const useStyles = makeStyles(theme => ({
picker: {
position: "relative"
},

swatch: {
width: "28px",
height: "28px",
borderRadius: "8px",
border: "3px solid #fff",
boxShadow: "0 0 0 1px rgba(0, 0, 0, 0.1), inset 0 0 0 1px rgba(0, 0, 0, 0.1)",
cursor: "pointer"
},

popOver: {
position: "absolute",
top: "calc(100% + 2px)",
left: "0",
borderRadius: "9px",
boxShadow: "0 6px 12px rgba(0, 0, 0, 0.15)",
zIndex: 100
}
}));

export const PopoverColorPicker = ({ color, onChange }) => {
const popover = useRef();
const [isOpen, toggle] = useState(false);
const classes = useStyles();

const close = useCallback(() => toggle(false), []);
useClickOutside(popover, close);

return (
<div className={classes.picker}>
<div
className={classes.swatch}
style={{ backgroundColor: color }}
onClick={() => toggle(true)}
/>

{isOpen && (
<div className={classes.popOver} ref={popover}>
<HexColorPicker color={color} onChange={onChange} />
</div>
)}
</div>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Observations from "dataEntryApp/components/Observations";
import CustomizedBackdrop from "../../components/CustomizedBackdrop";
import { DeleteButton } from "../../components/DeleteButton";
import { formatDate } from "../../../common/utils/General";
import { KeyboardArrowDown, KeyboardArrowUp } from "@material-ui/icons";

const useStyles = makeStyles(theme => ({
editLabel: {
Expand Down Expand Up @@ -222,8 +223,8 @@ const CompletedVisitsTable = ({
}}
detailPanel={[
{
icon: "keyboard_arrow_down",
openIcon: "keyboard_arrow_up",
icon: () => <KeyboardArrowDown />,
openIcon: () => <KeyboardArrowUp />,
render: row => {
return (
<Box margin={1} key={row.uuid}>
Expand Down
6 changes: 4 additions & 2 deletions src/formDesigner/common/ResourceListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Title } from "react-admin";
import http from "common/utils/httpClient";
import AvniMaterialTable from "adminApp/components/AvniMaterialTable";
import UserInfo from "../../common/model/UserInfo";
import Edit from "@material-ui/icons/Edit";
import Delete from "@material-ui/icons/DeleteOutline";

const ResourceListView = ({
history,
Expand All @@ -29,13 +31,13 @@ const ResourceListView = ({
}, []);

const editResource = rowData => ({
icon: "edit",
icon: () => <Edit />,
tooltip: `Edit ${title}`,
onClick: event => history.push(`/appDesigner/${resourceURLName}/${rowData.id}`)
});

const voidResource = rowData => ({
icon: "delete_outline",
icon: () => <Delete />,
tooltip: `Delete ${title}`,
onClick: (event, rowData) => {
const voidedMessage = `Do you really want to delete ${title} ${rowData.name} ?`;
Expand Down
Loading

0 comments on commit 1ca782a

Please sign in to comment.