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

[BUGFIX] fix NavDrawer to force href update of menu items #32

Merged
merged 7 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 0 additions & 3 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@
"scripts": {
"app": "yarn workspace mlp-ui",
"lib": "yarn workspace @gojek/mlp-ui",

"format": "yarn prettier --write",
"prettier": "prettier \"**/*.{js,jsx,ts,tsx,json,css,scss,md}\"",
"lint": "yarn workspaces run lint",

"wait-for-lib": "wait-on packages/lib/dist/index.js packages/lib/dist/index.es.js",
"start:app": "sleep 1; run-s wait-for-lib \"app start\"",
"start:lib": "yarn lib start",
"start": "run-p start:lib start:app",

"version:app": "yarn lib version",
"version:lib": "yarn app version",
"set-version-from-git:package": "run-p \"version:* --new-version {1} --no-git-tag-version\" --",
Expand Down
18 changes: 9 additions & 9 deletions ui/packages/app/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
{
"name": "mlp-ui",
"version": "1.4.6",
"version": "1.4.9",
"private": true,
"license": "Apache-2.0",
"dependencies": {
"@elastic/datemath": "5.0.3",
"@elastic/eui": "31.10.0",
"@gojek/mlp-ui": "1.4.6",
"@reach/router": "1.3.3",
"@elastic/datemath": "^5.0.3",
"@elastic/eui": "32.3.0",
"@gojek/mlp-ui": "1.4.9",
"@reach/router": "1.3.4",
"@sentry/browser": "5.15.5",
"moment": "2.25.3",
"moment": "^2.29.1",
"object-assign-deep": "0.4.0",
"query-string": "5.1.1",
"react": "16.13.1",
"react-dom": "16.13.1",
"query-string": "^7.0.1",
"react": "16.14.0",
"react-dom": "16.14.0",
"react-scripts": "3.4.1"
},
"scripts": {
Expand Down
37 changes: 19 additions & 18 deletions ui/packages/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gojek/mlp-ui",
"version": "1.4.6",
"version": "1.4.9",
"license": "Apache-2.0",
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down Expand Up @@ -31,26 +31,26 @@
},
"dependencies": {
"classnames": "^2.2.6",
"lodash": "^4.17.20",
"prop-types": "15.7.2",
"lodash": "^4.17.21",
"prop-types": "^15.7.2",
"proper-url-join": "2.1.1",
"query-string": "^6.13.1",
"query-string": "^7.0.1",
"react-collapsed": "^3.0.1",
"react-ellipsis-text": "^1.2.1",
"react-fast-compare": "^3.2.0",
"react-google-login": "5.1.19",
"react-google-login": "5.2.2",
"react-scroll": "^1.8.1",
"react-sticky": "^6.0.3",
"resize-observer-polyfill": "^1.5.1",
"yup": "^0.29.1"
"yup": "^0.29.3"
},
"peerDependencies": {
"@elastic/eui": "31.10.0",
"@reach/router": "1.3.3",
"@elastic/eui": "^32.3.0",
"@reach/router": "1.3.4",
"@sentry/browser": "5.15.5",
"moment": "^2.27.0",
"react": "16.13.1",
"react-dom": "16.13.1"
"moment": "^2.29.1",
"react": "16.14.0",
"react-dom": "16.14.0"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
Expand All @@ -60,15 +60,16 @@
"@babel/plugin-proposal-export-default-from": "^7.8.3",
"@babel/preset-env": "^7.9.6",
"@babel/preset-react": "^7.9.4",
"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^20.0.0",
"@rollup/plugin-eslint": "^8.0.1",
"@rollup/plugin-node-resolve": "^13.0.4",
"node-importer": "1.0.2",
"node-sass": "^4.14.1",
"rollup": "^1.32.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^8.3.0",
"rollup-plugin-eslint": "^7.0.0",
"node-sass": "^4.11.0",
"rollup": "^2.56.2",
"rollup-plugin-ignore-import": "^1.3.2",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-peer-deps-external": "^2.2.3",
"rollup-plugin-sass": "^1.2.2"
"rollup-plugin-sass": "^1.2.4",
"rollup-pluginutils": "^2.8.2"
}
}
7 changes: 4 additions & 3 deletions ui/packages/lib/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import babel from "rollup-plugin-babel";
import resolve from "rollup-plugin-node-resolve";
import babel from "@rollup/plugin-babel";
import resolve from "@rollup/plugin-node-resolve";
import eslint from "@rollup/plugin-eslint";
import sass from "rollup-plugin-sass";
import peerDepsExternal from "rollup-plugin-peer-deps-external";
import ignoreImport from "rollup-plugin-ignore-import";
import nodeSass from "node-sass";
import { eslint } from "rollup-plugin-eslint";

import pkg from "./package.json";

Expand Down Expand Up @@ -42,6 +42,7 @@ export default {
}),
resolve(),
babel({
babelHelpers: "bundled",
exclude: "node_modules/**"
})
]
Expand Down
17 changes: 6 additions & 11 deletions ui/packages/lib/src/components/accordion_form/AccordionForm.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import React, { useRef } from "react";
import { EuiFlexGroup, EuiFlexItem, EuiSpacer } from "@elastic/eui";
import { StepActions } from "../multi_steps_form/StepActions";
import { Sticky, StickyContainer } from "react-sticky";
import { StepActions } from "../multi_steps_form";
import FormValidationContext from "../form/validation/context";
import { MultiSectionFormValidationContextProvider } from "../form/validation/multi_section_provider";
import {
AccordionFormScrollController,
AccordionFormSection,
AccordionFormSideNav
} from ".";

import "./AccordionForm.scss";
import { MultiSectionFormValidationContextProvider } from "../form";
import {AccordionFormSideNav} from "./AccordionFormSideNav";
import {AccordionFormScrollController} from "./AccordionFormScrollController";
import {AccordionFormSection} from "./AccordionFormSection";
import { useDimension } from "../../hooks";
import { isEmpty } from "../../utils/object";

export const isSectionInvalid = errors => !isEmpty(errors);
import "./AccordionForm.scss";

export const AccordionForm = ({
name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useContext, useEffect, useState } from "react";
import { FormValidationContext } from "../form/validation";
import { slugify } from "@gojek/mlp-ui";
import { scroller } from "react-scroll";
import { animatedScrollConfig } from "./scroll";
import { isSectionInvalid } from "./AccordionForm";
import { isSectionInvalid } from "./functions";
import {slugify} from "../../utils";

export const AccordionFormScrollController = ({ sections }) => {
const [isFormSubmissionInProgress, setFormSubmissionInProgress] = useState(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React from "react";
import { Element } from "react-scroll";
import { EuiAccordion } from "@elastic/eui";
import { slugify } from "@gojek/mlp-ui";
import { slugify } from "../../utils";
import { FormValidationContext } from "../form/validation";
import { isSectionInvalid } from "./AccordionForm";
import { isSectionInvalid } from "./functions";

export const AccordionFormSection = ({ section, errors, renderTitle }) => (
<Element name={slugify(section.title)}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from "react";
import { slugify } from "@gojek/mlp-ui";
import { EuiIcon, EuiSideNav } from "@elastic/eui";
import { Link } from "react-scroll";
import { animatedScrollConfig } from "./scroll";
import {slugify} from "../../utils";

export const AccordionFormSideNav = ({ name, sections }) => {
const sideNav = [
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/lib/src/components/accordion_form/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {isEmpty} from "../../utils/object";

export const isSectionInvalid = errors => !isEmpty(errors);
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Fragment } from "react";
import { useToggle } from "@gojek/mlp-ui";
import { EuiOverlayMask, EuiConfirmModal, EuiProgress } from "@elastic/eui";
import { useToggle } from "../../hooks";

export const ConfirmationModal = ({
title,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import React, { Fragment, useRef } from "react";
import { EuiButton, EuiFlexItem, EuiLink, EuiSpacer } from "@elastic/eui";
import classNames from "classnames";
import { useToggle } from "@gojek/mlp-ui";
import { useToggle, useDimension } from "../../hooks";

import "./ExpandableDescriptionList.scss";
import { useDimension } from "../../hooks";

export const ExpandableContainer = ({
maxHeight = 300,
Expand Down
6 changes: 3 additions & 3 deletions ui/packages/lib/src/components/form/context.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useState, useMemo } from "react";
import { set } from "@gojek/mlp-ui/src/utils";
import { StackableFunction } from "./functions/stackable_function";
import { useOnChangeHandler } from "./hooks/useOnChangeHandler";
import { set } from "../../utils";
import { StackableFunction } from "./functions";
import { useOnChangeHandler } from "./hooks";

export const FormContext = React.createContext({});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from "react";
import { EuiButtonEmpty, EuiContextMenu, EuiPopover } from "@elastic/eui";
import { flattenPanelTree } from "@gojek/mlp-ui";
import { flattenPanelTree } from "../../../utils";

export const DockerRegistryPopover = ({ value, registryOptions, onChange }) => {
const [isOpen, setOpen] = useState(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
EuiFormRow,
EuiInMemoryTable
} from "@elastic/eui";
import { get } from "@gojek/mlp-ui/src/utils";
import { get } from "../../../utils";

import "./InMemoryTableForm.scss";

Expand Down
2 changes: 1 addition & 1 deletion ui/packages/lib/src/components/form/validation/errors.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { get, normalizePath, set } from "@gojek/mlp-ui/src/utils";
import { get, normalizePath, set } from "../../../utils";

export const extractErrors = validationError => {
let errors = {};
Expand Down
5 changes: 3 additions & 2 deletions ui/packages/lib/src/components/header/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { HeaderUserMenu } from "./HeaderUserMenu";
import { slugify } from "../../utils";
import { NavDrawer } from "../nav_drawer";
import "./Header.scss";
import {Link} from "@reach/router";
terryyylim marked this conversation as resolved.
Show resolved Hide resolved

export const Header = ({
homeUrl = "/",
Expand All @@ -35,11 +36,11 @@ export const Header = ({
</EuiHeaderSectionItem>

<EuiHeaderSectionItem border="right">
<a href={homepage ? homepage : "/"}>
<Link to={homepage ? homepage : "/"}>
<EuiText className="header-title">
<h4>Machine Learning Platform</h4>
</EuiText>
</a>
</Link>
</EuiHeaderSectionItem>
<ProjectsDropdown
projects={projects}
Expand Down
13 changes: 10 additions & 3 deletions ui/packages/lib/src/components/nav_drawer/NavDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ export const NavDrawer = ({ homeUrl = "/", docLinks }) => {
? a.config.sections.map(s => ({
id: slugify(`${a.name}.${s.name}`),
label: s.name,
callback: () =>
navigate(urlJoin(a.href, "projects", projectId, s.href)),
callback: () => {
const dest = urlJoin(a.href, "projects", projectId, s.href)

isAppActive
? navigate(dest)
: window.location.href = dest
},
className: "euiTreeView__node---small---subsection"
}))
: undefined;
Expand All @@ -53,7 +58,9 @@ export const NavDrawer = ({ homeUrl = "/", docLinks }) => {

callback: () =>
!children || !projectId
? navigate(projectId ? `${a.href}/projects/${projectId}` : a.href)
? window.location.href = !!projectId
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm curious about this line. At first, I thought it should be a condition expression for the ternary operator, but it seems you are assigning value to window.location.href by using one =. Is it another JS magic that I don't know? Please enlighten me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Which part is magical here? :) yeah, I'm assigning a value (conditional) to window.location.href and with that you can sort of programatically trigger a click on a link with assigned href value.
Trick is that navigate comes from @reach/router and it navigates inside a single page app (SPA) (without triggering a full refresh of the page), so I need to emulate a click on a link to completely refresh the page (so another SPA can be downloaded)

? urlJoin(a.href, "projects", projectId)
: a.href
: {},
children: children
};
Expand Down
Loading