Skip to content

Commit

Permalink
(chore) lint
Browse files Browse the repository at this point in the history
  • Loading branch information
icrc-jofrancisco committed Dec 18, 2023
1 parent db458fb commit 63768af
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -1,36 +1,25 @@
import React, { useCallback, useEffect, useState } from "react";
import {
ModalBody,
ModalFooter,
ModalHeader,
Button,
InlineLoading,
} from "@carbon/react";
import { useTranslation } from "react-i18next";
import { getCurrentOfflineMode, showToast } from "@openmrs/esm-framework";
import React, { useCallback, useEffect, useState } from 'react';
import { ModalBody, ModalFooter, ModalHeader, Button, InlineLoading } from '@carbon/react';
import { useTranslation } from 'react-i18next';
import { getCurrentOfflineMode, showToast } from '@openmrs/esm-framework';

export interface OfflineActionsProgressModalProps {
items?: Array<any>;
closeModal: (active: boolean) => void;
}

const OfflineReadyModal: React.FC<OfflineActionsProgressModalProps> = ({
closeModal,
items,
}) => {
const OfflineReadyModal: React.FC<OfflineActionsProgressModalProps> = ({ closeModal, items }) => {
const { t } = useTranslation();
const [isRunning, setIsRunning] = useState(true);
const [abortController, setAbortController] = useState(
() => new AbortController()
);
const [abortController, setAbortController] = useState(() => new AbortController());

async function dispatchOfflineEvent() {
//TODO CHANGE MODE
let mode = getCurrentOfflineMode().active;
window.dispatchEvent(
new CustomEvent(`openmrs:offline-${mode ? "enabled" : "disabled"}`, {
new CustomEvent(`openmrs:offline-${mode ? 'enabled' : 'disabled'}`, {
detail: getCurrentOfflineMode(),
})
}),
);

setIsRunning(false);
Expand All @@ -46,45 +35,39 @@ const OfflineReadyModal: React.FC<OfflineActionsProgressModalProps> = ({

showToast({
critical: true,
kind: "warning",
description: t(
"unavailableOfflineFeatures",
"Some features may not be available offline."
),
title: t("offlinePreparationCanceled", "Offline preparation canceled"),
kind: 'warning',
description: t('unavailableOfflineFeatures', 'Some features may not be available offline.'),
title: t('offlinePreparationCanceled', 'Offline preparation canceled'),
});
closeModal(false);
} else {
showToast({
critical: true,
kind: "success",
description: t("offlineModeIsReady", "Offline mode is ready"),
title: t("offline", "Offline"),
kind: 'success',
description: t('offlineModeIsReady', 'Offline mode is ready'),
title: t('offline', 'Offline'),
});
closeModal(true);
}
}, [abortController, closeModal, isRunning, t]);

return (
<>
<ModalHeader
title={t("preparingOfflineMode", "Preparing for offline mode")}
closeModal={handleClose}
/>
<ModalHeader title={t('preparingOfflineMode', 'Preparing for offline mode')} closeModal={handleClose} />
<ModalBody>
{isRunning && (
<InlineLoading
// className={styles.loader}
description={t("loading", "Loading") + "..."}
description={t('loading', 'Loading') + '...'}
/>
)}
</ModalBody>
<ModalFooter>
<Button kind="danger" onClick={handleClose} disabled={!isRunning}>
{t("cancel", "Cancel")}
{t('cancel', 'Cancel')}
</Button>
<Button kind="primary" onClick={handleClose} disabled={isRunning}>
{t("confirm", "Confirm")}
{t('confirm', 'Confirm')}
</Button>
</ModalFooter>
</>
Expand Down
12 changes: 3 additions & 9 deletions packages/apps/esm-offline-tools-app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import offlineToolsComponent from './root.component';
import offlineToolsLinkComponent from './offline-tools-app-menu-link.component';
import offlineToolsNavItemsComponent from './nav/offline-tools-nav-menu.component';
import offlineToolsConfirmationModalComponent from './components/confirmation-modal.component';
import offlineToolsOfflineReadyModalComponent from "./components/offline-ready-modal.component";
import offlineToolsOfflineReadyModalComponent from './components/offline-ready-modal.component';
import offlineToolsPatientsCardComponent from './offline-patients/patients-overview-card.component';
import offlineToolsActionsCardComponent from './offline-actions/offline-actions-overview-card.component';
import offlineToolsActionsComponent from './offline-actions/offline-actions.component';
Expand Down Expand Up @@ -37,15 +37,9 @@ export const offlineToolsNavItems = getSyncLifecycle(offlineToolsNavItemsCompone

export const offlineToolsConfirmationModal = getSyncLifecycle(offlineToolsConfirmationModalComponent, options);

export const offlineToolsOfflineReadyModal = getSyncLifecycle(
offlineToolsOfflineReadyModalComponent,
options
);
export const offlineToolsOfflineReadyModal = getSyncLifecycle(offlineToolsOfflineReadyModalComponent, options);

export const offlineToolsPatientsCard = getSyncLifecycle(
offlineToolsPatientsCardComponent,
options
);
export const offlineToolsPatientsCard = getSyncLifecycle(offlineToolsPatientsCardComponent, options);

export const offlineToolsActionsCard = getSyncLifecycle(offlineToolsActionsCardComponent, options);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React, { useState, useCallback } from "react";
import { useTranslation } from "react-i18next";
import { Toggle, Button, DefinitionTooltip } from "@carbon/react";
import { Network_3 } from "@carbon/react/icons";
import React, { useState, useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { Toggle, Button, DefinitionTooltip } from '@carbon/react';
import { Network_3 } from '@carbon/react/icons';
import {
getCurrentOfflineMode,
setCurrentOfflineMode,
showModal,
useConnectivity,
} from "@openmrs/esm-framework/src/internal";
import styles from "./offline-actions-mode-button.scss";
} from '@openmrs/esm-framework/src/internal';
import styles from './offline-actions-mode-button.scss';

function doNotCloseMenu(ev: React.SyntheticEvent) {
ev.stopPropagation();
Expand All @@ -17,16 +17,14 @@ function doNotCloseMenu(ev: React.SyntheticEvent) {
const OfflineActionsModeButton: React.FC = () => {
const { t } = useTranslation();
const isOnline = useConnectivity();
const [lastRun, setLastRun] = useState<string>(
() => getCurrentOfflineMode().lastRun
);
const [lastRun, setLastRun] = useState<string>(() => getCurrentOfflineMode().lastRun);
const [active, setActive] = useState(() => getCurrentOfflineMode().active);

const toggle = useCallback(() => {
const dispose = showModal("offline-tools-offline-ready-modal", {
const dispose = showModal('offline-tools-offline-ready-modal', {
closeModal: (result) => {
setActive(result);
setCurrentOfflineMode(result ? "on" : "off");
setCurrentOfflineMode(result ? 'on' : 'off');
dispose();
},
});
Expand All @@ -42,30 +40,21 @@ const OfflineActionsModeButton: React.FC = () => {
<div>
<Network_3 size={20} />
<span onClick={doNotCloseMenu} role="none">
{t("offlineReady", "Offline Ready")}
{t('offlineReady', 'Offline Ready')}
</span>
</div>
<DefinitionTooltip
openOnHover
align="top"
definition={`${t("lastRun", "Last Run")}: ${
active ? lastRun : t("never", "Never")
}`}
definition={`${t('lastRun', 'Last Run')}: ${active ? lastRun : t('never', 'Never')}`}
>
{active && (
<Button kind="ghost" onClick={handleRefresh}>
{t("refresh", "Refresh")}
{t('refresh', 'Refresh')}
</Button>
)}
</DefinitionTooltip>
{!active && (
<Toggle
className={styles.toggle}
id="offlineModeSwitch"
toggled={active}
onToggle={toggle}
/>
)}
{!active && <Toggle className={styles.toggle} id="offlineModeSwitch" toggled={active} onToggle={toggle} />}
</div>
)
);
Expand Down
2 changes: 1 addition & 1 deletion packages/apps/esm-offline-tools-app/translations/am.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"homeOverviewCardPatientsNewlyRegistered": "Newly registered",
"homeOverviewCardView": "View",
"lastRun": "Last Run",
"loading": "Loading",
"never": "Never",
"offline": "Offline",
"offlineActions": "Offline actions",
Expand Down Expand Up @@ -62,7 +63,6 @@
"offlineReady": "Offline Ready",
"offlineToolsAppMenuLink": "Offline tools",
"preparingOfflineMode": "Preparing for offline mode",
"progressBarLabel": "{progress}% Complete",
"refresh": "Refresh",
"unavailableOfflineFeatures": "Some features may not be available offline."
}
2 changes: 1 addition & 1 deletion packages/apps/esm-offline-tools-app/translations/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"homeOverviewCardPatientsNewlyRegistered": "مُسجل حديثًا",
"homeOverviewCardView": "عرض",
"lastRun": "Last Run",
"loading": "Loading",
"never": "Never",
"offline": "Offline",
"offlineActions": "الأنشطة بدون اتصال",
Expand Down Expand Up @@ -66,7 +67,6 @@
"offlineReady": "جاهز للعمل بدون اتصال",
"offlineToolsAppMenuLink": "أدوات العمل بدون اتصال",
"preparingOfflineMode": "Preparing for offline mode",
"progressBarLabel": "{progress}% Complete",
"refresh": "Refresh",
"unavailableOfflineFeatures": "Some features may not be available offline."
}
2 changes: 1 addition & 1 deletion packages/apps/esm-offline-tools-app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"homeOverviewCardPatientsNewlyRegistered": "Newly registered",
"homeOverviewCardView": "View",
"lastRun": "Last Run",
"loading": "Loading",
"never": "Never",
"offline": "Offline",
"offlineActions": "Offline Actions",
Expand Down Expand Up @@ -62,7 +63,6 @@
"offlineReady": "Offline Ready",
"offlineToolsAppMenuLink": "Offline tools",
"preparingOfflineMode": "Preparing for offline mode",
"progressBarLabel": "{{progress}}% Complete",
"refresh": "Refresh",
"unavailableOfflineFeatures": "Some features may not be available offline."
}
2 changes: 1 addition & 1 deletion packages/apps/esm-offline-tools-app/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"homeOverviewCardPatientsNewlyRegistered": "Recién registrados",
"homeOverviewCardView": "Ver",
"lastRun": "Última carrera",
"loading": "Loading",
"never": "Nunca",
"offline": "Offline",
"offlineActions": "Acciones offline",
Expand Down Expand Up @@ -63,7 +64,6 @@
"offlineReady": "Listo offline",
"offlineToolsAppMenuLink": "Herramientas offline",
"preparingOfflineMode": "Preparando modo sin conexión",
"progressBarLabel": "{{progress}}% Completo",
"refresh": "Actualizar",
"unavailableOfflineFeatures": "Some features may not be available offline."
}
2 changes: 1 addition & 1 deletion packages/apps/esm-offline-tools-app/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"homeOverviewCardPatientsNewlyRegistered": "Nouvellement enregistré",
"homeOverviewCardView": "Voir",
"lastRun": "Dernière course",
"loading": "Loading",
"never": "Jamais",
"offline": "Offline",
"offlineActions": "Actions hors ligne",
Expand Down Expand Up @@ -63,7 +64,6 @@
"offlineReady": "Prêt pour être hors ligne",
"offlineToolsAppMenuLink": "Outils hors ligne",
"preparingOfflineMode": "Préparation du mode hors ligne",
"progressBarLabel": "{{progress}}% Complet",
"refresh": "rafraîchir",
"unavailableOfflineFeatures": "Some features may not be available offline."
}
2 changes: 1 addition & 1 deletion packages/apps/esm-offline-tools-app/translations/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"homeOverviewCardPatientsNewlyRegistered": "רשומים חדשים",
"homeOverviewCardView": "צפה",
"lastRun": "Last Run",
"loading": "Loading",
"never": "Never",
"offline": "Offline",
"offlineActions": "פעולות לא מקוונות",
Expand Down Expand Up @@ -64,7 +65,6 @@
"offlineReady": "מצב לא מקוון מוכן",
"offlineToolsAppMenuLink": "כלי לא מקוונים",
"preparingOfflineMode": "Preparing for offline mode",
"progressBarLabel": "{progress}% Complete",
"refresh": "Refresh",
"unavailableOfflineFeatures": "Some features may not be available offline."
}
2 changes: 1 addition & 1 deletion packages/apps/esm-offline-tools-app/translations/km.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"homeOverviewCardPatientsNewlyRegistered": "Newly registered",
"homeOverviewCardView": "View",
"lastRun": "Last Run",
"loading": "Loading",
"never": "Never",
"offline": "Offline",
"offlineActions": "សកម្មភាពក្រៅបណ្តាញ",
Expand Down Expand Up @@ -61,7 +62,6 @@
"offlineReady": "Offline Ready",
"offlineToolsAppMenuLink": "Offline tools",
"preparingOfflineMode": "Preparing for offline mode",
"progressBarLabel": "{progress}% Complete",
"refresh": "Refresh",
"unavailableOfflineFeatures": "Some features may not be available offline."
}
14 changes: 7 additions & 7 deletions packages/framework/esm-offline/src/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async function isPrivateBrowsing() {
return (await isFirefoxPrivateBrowsing()) || (await isEdgePrivateBrowsing()) || (await isSafariPrivateBrowsing());
}

export type OfflineMode = "on" | "off" | "unavailable";
export type OfflineMode = 'on' | 'off' | 'unavailable';
export type OfflineHandler = () => void | Promise<void>;

export interface OfflineModeResult {
Expand All @@ -41,15 +41,15 @@ export interface OfflineModeResult {
lastRun: string;
}

const offlineModeStorageKey = "openmrs:offline-mode";
let offlineMode: OfflineMode = "unavailable";
let lastRun: string = "";
const offlineModeStorageKey = 'openmrs:offline-mode';
let offlineMode: OfflineMode = 'unavailable';
let lastRun: string = '';

export function getCurrentOfflineMode(): OfflineModeResult {
return {
current: offlineMode,
notAvailable: offlineMode === "unavailable",
active: offlineMode === "on",
notAvailable: offlineMode === 'unavailable',
active: offlineMode === 'on',
lastRun: lastRun,
};
}
Expand All @@ -62,7 +62,7 @@ export function setCurrentOfflineMode(mode: OfflineMode) {
}

export function registerOfflineHandler(setupOffline: OfflineHandler) {
window.addEventListener("openmrs:offline-enabled", setupOffline);
window.addEventListener('openmrs:offline-enabled', setupOffline);
const offlineMode = getCurrentOfflineMode();
if (offlineMode.active) {
setupOffline();
Expand Down
15 changes: 5 additions & 10 deletions packages/framework/esm-offline/src/public.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
export {
type OfflineMode,
type OfflineModeResult,
getCurrentOfflineMode,
registerOfflineHandler,
} from "./mode";
export * from "./offline-patient-data";
export * from "./service-worker-messaging";
export * from "./service-worker-http-headers";
export * from "./uuid";
export { type OfflineMode, type OfflineModeResult, getCurrentOfflineMode, registerOfflineHandler } from './mode';
export * from './offline-patient-data';
export * from './service-worker-messaging';
export * from './service-worker-http-headers';
export * from './uuid';
export {
type QueueItemDescriptor,
type SyncItem,
Expand Down

0 comments on commit 63768af

Please sign in to comment.