Skip to content

Commit

Permalink
chore(code): make sonar happy
Browse files Browse the repository at this point in the history
  • Loading branch information
nurikk committed Nov 25, 2021
1 parent ebca22a commit 275939f
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/components/device-page/scene.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { ChangeEvent, useState } from "react";
import { CompositeFeature, Device, DeviceState, EndpointDescription, GenericExposedFeature, Group, Scene, WithFreiendlyName, WithScenes } from "../../types";
import { CompositeFeature, Device, DeviceState, GenericExposedFeature, Group, Scene, WithFreiendlyName, WithScenes } from "../../types";
import actions from "../../actions/actions";
import { SceneApi, SceneId } from "../../actions/SceneApi";
import { connect } from "unistore/react";
Expand Down
2 changes: 1 addition & 1 deletion src/components/device-page/settings.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component, ReactNode } from "react";
import { BridgeInfo, Device, KVP } from "../../types";
import { Device, KVP } from "../../types";
import { DeviceApi } from "../../actions/DeviceApi";
import Form from '@rjsf/bootstrap-4';
import { JSONSchema7 } from "json-schema"
Expand Down
10 changes: 5 additions & 5 deletions src/components/grid/ReactTableCom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ export const Table: React.FC<Props> = ({ columns, data, id }) => {
<th className="text-nowrap" {...column.getHeaderProps(column.getSortByToggleProps())}>
<span className={cx({ 'btn-link mr-1': column.canSort })}>{column.render('Header')}</span>
<span>
{column.isSorted
? column.isSortedDesc
? <i className={`fa fa-sort-amount-down-alt`} />
: <i className={`fa fa-sort-amount-down`} />
: <i className={`fa fa-sort-amount-down invisible`} />}
<i className={cx('fa', {
'fa-sort-amount-down invisible': !column.isSorted,
'fa-sort-amount-down-alt': column.isSorted && !column.isSortedDesc,
'fa-sort-amount-down': column.isSorted && column.isSortedDesc,
})} />
</span>
</th>
))}
Expand Down
41 changes: 27 additions & 14 deletions src/components/modal/GlobalModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,57 @@ const MODAL_COMPONENTS: any = {

};

type GlobalModalContext = {
type Store = {
modalType: string;
modalProps: Record<string, any>;
}

type GlobalModalContextType = {
showModal: (modalType: string, modalProps?: any) => void;
hideModal: () => void;
store: any;
store: Store;
};

const initalState: GlobalModalContext = {
showModal: () => { },
hideModal: () => { },
store: {},

const initalState: GlobalModalContextType = {
showModal: () => {
// empty function
},
hideModal: () => {
// empty function
},
store: {} as Store,
};

const GlobalModalContext = createContext(initalState);
export const useGlobalModalContext = () => useContext(GlobalModalContext);

export const GlobalModal: React.FC<{}> = ({ children }) => {
const [store, setStore] = useState<Record<string, unknown>>();
const { modalType, modalProps } = store || {};
const [store, setStore] = useState<Store>({} as Store);
const { modalType, modalProps } = store;

const showModal = (modalType: string, modalProps: any = {}) => {
const showModal = (t: string, p: any = {}) => {
setStore({
...store,
modalType,
modalProps,
modalType: t,
modalProps: p,
});
};

const hideModal = () => {
setStore({
...store,
modalType: null,
modalType: "",
modalProps: {},
});
};

const renderComponent = () => {
const ModalComponent = MODAL_COMPONENTS[modalType as any];
if (!modalType || !ModalComponent) {
if (!modalType) {
return null;
}
const ModalComponent = MODAL_COMPONENTS[modalType];
if (!ModalComponent) {
return null;
}
return <ModalComponent id="global-modal" {...modalProps} />;
Expand Down

0 comments on commit 275939f

Please sign in to comment.