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

Refactor HelpComponent #418

merged 26 commits into from
Jul 6, 2023

Conversation

aringocode
Copy link
Collaborator

@aringocode aringocode commented May 11, 2023

@aringocode aringocode self-assigned this May 11, 2023
@aringocode aringocode requested a review from Pe5h4 May 11, 2023 09:22
} else {
pathWithExtension = `${path}.json`
if (this.HelpCache[path] != undefined) {
if (this.HelpCache[path] != "") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aringoaway I was thinking, do we really need this condition? Seems redundant to me, because we are setting an empty string as a value to the cache, if the content has not been retrieved

this.HelpCache[path] = "";

So I suggest a refactoring

if (this.HelpCache[path] != undefined) {
	this.App.Store.dispatch({
		type: HELP_CONTENT,
		content: this.HelpCache[path]
	});
	return;
}

@aringocode
Copy link
Collaborator Author

helpFrame.mp4

@aringocode aringocode requested a review from Pe5h4 May 31, 2023 06:34
Copy link
Collaborator

@Pe5h4 Pe5h4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aringoaway Can I see also video with network in console? I want to see, if the iframe url is triggered only when ? button is pressed

@@ -8,31 +8,11 @@ export default class HelpService extends Service {
}

async setData(path) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aringoaway It does not have to be async since there is no async action

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aringoaway btw. setData is not a good name for it, since all you do is setting the path

@Pe5h4
Copy link
Collaborator

Pe5h4 commented May 31, 2023

Otherwise it looks good!

@aringocode
Copy link
Collaborator Author

aringocode commented May 31, 2023

@Aringoaway Can I see also video with network in console? I want to see, if the iframe url is triggered only when ? button is pressed
@Pe5h4 Yes, triggered only when ? is passed

callFrame.mp4

@aringocode aringocode requested a review from Pe5h4 May 31, 2023 15:18
@@ -445,14 +445,14 @@ class Application extends Component {

addHelpButton(path) {
useEffect(() => {
this.HelpService.setData(path);
this.HelpService.setPath(path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aringoaway Do we actually need the HelpService then? we can store the path directly to the store I assume

		this.Store.dispatch({
			type: HELP_CONTENT,
			path: path
		});

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. That's a great idea.

@aringocode aringocode requested a review from Pe5h4 May 31, 2023 15:56
Copy link
Collaborator

@Pe5h4 Pe5h4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aringoaway And this https://github.com/TeskaLabs/asab-webui/pull/418/files#diff-31d3784ef11656fbccbce9b6b554c572b43dfad75c897ef7fa510ba7a443735fR98 should be refactored to this.ReduxService.addReducer("header", headerReducer);

@@ -447,14 +445,17 @@ class Application extends Component {

addHelpButton(path) {
useEffect(() => {
this.HelpService.setData(path);
this.Store.dispatch({
type: HELP_CONTENT,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aringoaway type should be SET_HELP_CONTENT_PATH or something similar as we spoke of about on standup

this.HelpService.setData(path);
this.Store.dispatch({
type: HELP_CONTENT,
path: path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aringoaway should be somethng like helpContentPath: path

@@ -10,8 +10,9 @@ export default function HelpButton() {

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

const content = useSelector(state => state?.helpButton.content);
if ((content == undefined) || (content == "")) return null;
const path = useSelector(state => state?.helpButton.path);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aringoaway should be const path = useSelector(state => state?.header.helpContentPath); as we spoke of on standup

@@ -1,14 +1,14 @@
import { HELP_CONTENT } from '../../actions';

const initialState = {
content: ""
path: ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Aringoaway helpContentPath

@aringocode aringocode changed the title Add HelpCache Refactor HelpComponent Jun 26, 2023
@aringocode aringocode requested a review from Pe5h4 June 26, 2023 08:54
Copy link
Collaborator

@Pe5h4 Pe5h4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aringocode Minor thing, otherwise good!

@@ -447,14 +445,17 @@ class Application extends Component {

addHelpButton(path) {
useEffect(() => {
this.HelpService.setData(path);
this.Store.dispatch({
type: HELP_CONTENT,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aringocode Set type to SET_HELP_PATH

@aringocode aringocode requested a review from Pe5h4 June 27, 2023 08:03
@@ -1,4 +1,4 @@
import { HELP_CONTENT, SET_BREADCRUMB_NAME } from '../../actions';
import { SET_HELP_PATH, SET_BREADCRUMB_NAME } from '../../actions';

const initialState = {
content: "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aringocode Shouldnt here be some default content as we spoke of after the standup? Meaning https://docs.teskalabs.com/logman.io/ or https://docs.teskalabs.com/logman.io/user/ or so...

Btw. can you please rename content to path? Since its not content any longer, but path/url

@aringocode aringocode requested a review from Pe5h4 July 4, 2023 07:15
@aringocode
Copy link
Collaborator Author

@Pe5h4 Can you review pls?

lmio-webui-HelpButton.mp4
seacat-admin-webui-HelpButton.mp4

const title = useSelector(state => state.config?.title);

useEffect(() => {
if (location.pathname.includes("auth") || (title == "SeaCat Admin")) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aringocode I dont think this is correct. We want to make it more variable in case of what URL we are going to insert. So what we want to pass is the whole url, meaning https://docs.teskalabs.com/logman.io/user/whatever since the help component may be used also for some external documentation. I suggest to remove all logman.io / auth/Seacat Admin specifications. If nothing will be passed, then we dont display the HelpButton

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will also get rid of this useEffect and other unnecessary code about switching the paths

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pe5h4 ok, I refactored it

helpButton.mp4


#### Example code

```javascript
export function Container(props) {
props.app.addHelpButton("Path/to/help-content");
props.app.addHelpButton("Path/part/to/documentation");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aringocode this should be

props.app.addHelpButton("https://docs.teskalabs.com/path/to/documentation");

@aringocode aringocode requested a review from Pe5h4 July 4, 2023 11:39
Copy link
Collaborator

@Pe5h4 Pe5h4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aringocode Alright, looks good, only minor change request

</Button>
</CardHeader>
<CardBody>
<iframe className="help-iframe" src={`https://docs.teskalabs.com/logman.io/user/${path}`} title=""/>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aringocode Here you want to have just

<iframe className="help-iframe" src={path} />

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pe5h4 Ohhh...., I understand) can you review again pls?))

@aringocode aringocode requested a review from Pe5h4 July 4, 2023 13:15
this.HelpService.setData(path);
this.Store.dispatch({
type: SET_HELP_PATH,
path: path
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aringocode Alright, sorry for requesting changes all over again :D Here the path should be renamed to helpPath or helpContentPath or something similar. path is just too general

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

helpPath: path

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pe5h4 ok, i renamed it

@aringocode aringocode requested a review from Pe5h4 July 4, 2023 13:53
Copy link
Collaborator

@Pe5h4 Pe5h4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aringocode Alright, good

@aringocode aringocode marked this pull request as ready for review July 6, 2023 07:45
@aringocode aringocode merged commit 0a1b9ce into master Jul 6, 2023
@aringocode aringocode deleted the bugfix/add-help-cache branch July 6, 2023 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants