Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor HelpComponent #418

Merged
merged 26 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@

- Fixed title display for buttons after a session has ended. Added disabling inputs, Pie chart clickable parts, disabling `tree-menu-item` and reloading the page after clicking the Forward or Backward buttons in the browser (INDIGO Sprint 230609, [!426](https://github.com/TeskaLabs/asab-webui/pull/426))

- Refactor HelpComponent, remove HelpService (INDIGO Sprint 230609, [!418](https://github.com/TeskaLabs/asab-webui/pull/418))

## v23.5

### Features
Expand Down
42 changes: 4 additions & 38 deletions doc/help-button.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,16 @@
# ASAB WebUI HelpButton component

Display information for your desired screen in modal.
Display documentation for your desired screen in modal. The documentation can be found [here](https://docs.teskalabs.com/logman.io/user/)

If you want to add this component, you need to call the `addHelpButton` method. This method takes only 1 parameter:
>- `path` (string) e.g.: `"Exports/Detail"` or `"Dashboards/SomeDashboardName"`, ...
>- `path` (string) e.g.: `"export"` or `"dashboards"`, ...

`Path/to/help-content` - is a path you set up in Library. **`Help` folder is excluded from this path.** Content file's extension can be omitted.
It will be sufficient to indicate the **correct** part of the documentation (parts of the documentation are in the sidebar), specify the path that comes after this part `https://docs.teskalabs.com/logman.io/user/`

#### Example code

```javascript
export function Container(props) {
props.app.addHelpButton("Path/to/help-content");
props.app.addHelpButton("https://docs.teskalabs.com/path/to/documentation");
}
```


### Add help-content to Library

1. Create `Help` folder in Library.
2. Inside, create a new subfolder (e.g. `Dashboards`, `Clients`, `Credentials`,..)
- Naming should match sidebar item's name (as in examples above)
3. Inside newly created subfolder, create a _json_ file named after the page where you want the HelpButton component to appear (e.g. `DashboardsName.json`).
4. This _json_ file carries the content which appears in modal (content supports markdown).

#### Specific example

```
- Library
- Help
- Dashboards
- DashboardsName.json
```

#### `DashboardsName.json` content example
```json
{
"content": "Help content"
}
```

#### Usage inside component
```javascript
export function DashboardsName(props) {
...
props.app.addHelpButton("Dashboards/DashboardsName");
...
}
```
2 changes: 1 addition & 1 deletion src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const ADD_ALERT = "asab/addAlert";
export const ACK_ALERT = "asab/ackAlert";
export const DEL_ALERT = "asab/delAlert";

export const HELP_CONTENT = "asab/setHelpContent";
export const SET_HELP_PATH = "asab/setHelpContent";
export const SET_BREADCRUMB_NAME = "asab/setBreadcrumbName";

export const SET_ADVANCED_MODE = "asab/setAdvancedMode";
Expand Down
17 changes: 9 additions & 8 deletions src/containers/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import HeaderService from '../services/HeaderService';
import SidebarService from './Sidebar/service';
import ThemeService from '../theme/ThemeService';
import BrandingService from '../services/BrandingService';
import HelpService from "../services/HelpService";
import TitleService from "../services/TitleService";

import AccessDeniedCard from '../modules/tenant/access/AccessDeniedCard';
import UnauthorizedAccessScreen from '../modules/auth/components/UnauthorizedAccessScreen';

import {ADD_ALERT, SET_ADVANCED_MODE, HELP_CONTENT, SET_BREADCRUMB_NAME} from '../actions';
import {ADD_ALERT, SET_ADVANCED_MODE, SET_HELP_PATH, SET_BREADCRUMB_NAME} from '../actions';


class Application extends Component {
Expand Down Expand Up @@ -92,8 +91,7 @@ class Application extends Component {
this.SidebarService = new SidebarService(this, "SidebarService");
this.ThemeService = new ThemeService(this, "ThemeService");
this.BrandingService = new BrandingService(this, "BrandingService");
this.HelpService = new HelpService(this, "HelpService");
this.TitleService = new TitleService(this, "TitleService")
this.TitleService = new TitleService(this, "TitleService");

this.ReduxService.addReducer("alerts", alertsReducer);
this.ReduxService.addReducer("advmode", advancedModeReducer);
Expand Down Expand Up @@ -447,14 +445,17 @@ class Application extends Component {

addHelpButton(path) {
useEffect(() => {
this.HelpService.setData(path);
this.Store.dispatch({
type: SET_HELP_PATH,
helpPath: path
});
return () => {
this.Store.dispatch({
type: HELP_CONTENT,
content: ""
type: SET_HELP_PATH,
helpPath: ""
})
}
}, [])
}, []);
}

// Method for overloading breadcrumb name
Expand Down
86 changes: 42 additions & 44 deletions src/containers/Header/HelpButton.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,48 @@
import React, { useState } from 'react';
import { useTranslation } from "react-i18next";
import { useSelector } from 'react-redux';
import React, {useState, useEffect} from 'react';
import {useTranslation} from "react-i18next";
import {useSelector} from 'react-redux';

import { Modal, NavLink, Card, CardHeader, CardBody, Button } from 'reactstrap';
import {Modal, NavLink, Card, CardHeader, CardBody, Button} from 'reactstrap';


export default function HelpButton() {
const { t } = useTranslation();

const [modal, setModal] = useState(false);

const content = useSelector(state => state?.header.content);
if ((content == undefined) || (content == "")) return null;

const toggle = () => setModal(!modal);

return (
<>
<NavLink
className="help-button"
onClick={toggle}
title={t("Show help info")}
href="#"
>
<i>?</i>
</NavLink>

<Modal isOpen={modal} toggle={toggle} className="center help-modal-card">
<Card>
<CardHeader className="border-bottom">
<div className="card-header-title">
<i className="cil-info pr-2" />
{t("HelpButton|Help")}
</div>
<Button outline color="primary" onClick={toggle}>
<i className="cil-x"/>
</Button>
</CardHeader>
<CardBody>
<div>{content}</div>
{/*TODO: uncomment and use when the documentation is ready to be displayed in the iframe*/}
{/*<iframe className="help-iframe" src="" title=""/>*/}
</CardBody>
</Card>
</Modal>
</>
);
const {t} = useTranslation();

const [modal, setModal] = useState(false);

const path = useSelector(state => state?.header.helpPath);
if ((path == undefined) || (path == "")) return null;

const toggle = () => setModal(!modal);

return (
<>
<NavLink
className="help-button"
onClick={toggle}
title={t("Show help info")}
href="#"
>
<i>?</i>
</NavLink>

<Modal isOpen={modal} toggle={toggle} className="center help-modal-card">
<Card>
<CardHeader className="border-bottom">
<div className="card-header-title">
<i className="cil-info pr-2" />
{t("HelpButton|Help")}
</div>
<Button outline color="primary" onClick={toggle}>
<i className="cil-x"/>
</Button>
</CardHeader>
<CardBody>
<iframe className="help-iframe" src={path} />
</CardBody>
</Card>
</Modal>
</>
);
}

14 changes: 7 additions & 7 deletions src/containers/Header/header.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ $toggle-text-color: var(--toggle-text-color);
min-height: 30vh;
}
}
//TODO: uncomment and use when the documentation is ready to be displayed in the iframe
//& .help-iframe {
// width: 100%;
// height: 80vh;
// overflow: hidden;
// border: 0;
//}

& .help-iframe {
width: 100%;
height: 80vh;
overflow: hidden;
border: 0;
}

}

2 changes: 1 addition & 1 deletion src/containers/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ export function Header(props) {
null
:
<Nav className="header-props-sm" navbar>
<HelpButton/>
<HelpButton />
<ThemeButton/>
{HeaderService.Items.map((item, idx) => (
<NavItem key={idx}>
Expand Down
8 changes: 4 additions & 4 deletions src/containers/Header/reducer.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { HELP_CONTENT, SET_BREADCRUMB_NAME } from '../../actions';
import { SET_HELP_PATH, SET_BREADCRUMB_NAME } from '../../actions';

const initialState = {
content: "",
helpPath: "",
breadcrumbName: undefined
}

export default (state = initialState, action) => {

switch (action.type) {
case HELP_CONTENT:
case SET_HELP_PATH:
return {
...state,
content: action.content
helpPath: action.helpPath
}

case SET_BREADCRUMB_NAME:
Expand Down
38 changes: 0 additions & 38 deletions src/services/HelpService.js

This file was deleted.