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

[code-health] Separate state slices on explorer engine and improve code quality #2147

Merged
merged 19 commits into from
Sep 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions aim/web/ui/config-overrides.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const webpack = require('webpack');
const WebpackDynamicPublicPathPlugin = require('webpack-dynamic-public-path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');

Expand Down Expand Up @@ -44,6 +45,12 @@ module.exports = {
externalPublicPath: 'window.externalPublicPath',
}),
);

config.plugins.push(
new webpack.DefinePlugin({
__DEV__: !isEnvProduction,
}),
);
return config;
},
};
18 changes: 9 additions & 9 deletions aim/web/ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aim/web/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"typeface-roboto": "^1.1.13",
"web-vitals": "^1.0.1",
"yup": "^0.32.9",
"zustand": "^4.0.0-rc.4"
"zustand": "^4.1.1"
},
"scripts": {
"start": "react-app-rewired --max_old_space_size=4096 start",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function SliderWithInput({
/>
) : (
<Slider
value={selectedRangeValue}
value={[...selectedRangeValue]}
onChange={((e: any, value: any) => onRangeChange(value)) as any}
min={min}
max={max}
Expand Down
1 change: 1 addition & 0 deletions aim/web/ui/src/config/enums/routesEnum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum PathEnum {
Images_Explore = '/images',
Images_Explore_Id = '/images/:appId',
Figures_Explorer = '/figures',
New_Figures_Explorer = '/new-fig',
}

export { PathEnum };
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PipelineStatusEnum } from 'modules/core/engine';
import { PipelineStatusEnum } from 'modules/core/engine/types';

import emptyBookmarks from 'assets/illustrations/emptyBookmarks.svg';
import emptySearch from 'assets/illustrations/emptySearch.svg';
Expand Down
1 change: 1 addition & 0 deletions aim/web/ui/src/config/pageTitles/pageTitles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const pageTitles = {
BOOKMARKS: 'Bookmarks',
TAGS: 'Tags',
RUN_DETAIL: '',
FIGURES_EXPLORER_NEW: 'New Figures',
};

export default pageTitles;
8 changes: 4 additions & 4 deletions aim/web/ui/src/hooks/useDepthMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ function useDepthMap<T>({
(value: number, groupId: string): void => {
if (sync) {
const syncedDepthMap = generateMapBy(value);
state.methods.update(syncedDepthMap);
state.update(syncedDepthMap);
} else {
state.methods.update({ [groupId]: value });
state.update({ [groupId]: value });
}
},
[sync, generateMapBy, state.methods],
[sync, generateMapBy, state],
);

React.useEffect(() => {
// set/reset depth map
state.methods.update(initialMap);
state.update(initialMap);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, deps);

Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ function BoxFullViewPopover({
{item.run?.hash && (
<div className='BoxFullViewPopover__container__detail-section'>
<ErrorBoundary>
<AttachedTagsList
runHash={item.run.hash}
tags={item.run?.tags}
/>
<AttachedTagsList runHash={item.run.hash} />
</ErrorBoundary>
</div>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ function BoxVirtualizer(props: IBoxVirtualizerProps<AimFlatObjectBase<any>>) {
item.style.top >= gridWindow.top - item.style.height &&
item.style.top <= gridWindow.top + gridWindow.height,
);

const groupedByPosition = _.groupBy(filteredItems, (item) => {
const rowId = item.groups?.rows ? item.groups.rows[0] : '';
const columnId = item.groups?.columns ? item.groups.columns[0] : '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export interface IBoxWrapperProps<T> extends IBaseComponentProps {
groupId: string;
depthSelector: (groupKey: string) => (state: any) => number;
onDepthMapChange: (value: number, groupId: string) => void;
visualizationName: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
background-color: white;
width: calc(100% - 2px);
height: 1.75rem;
margin-bottom: toRem(1px);
& > .Slider {
width: 100%;
max-width: 46rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,22 @@ import './BoxWrapper.scss';
function BoxWrapper(props: IBoxWrapperProps<AimFlatObjectBase<any>>) {
const {
engine,
engine: {
useStore,
sequenceNameSelector,
boxConfig: { stateSelector: boxConfigStateSelector },
controls: {
captionProperties: { stateSelector: captionPropertiesStateSelector },
},
},
engine: { useStore },
items,
component: BoxContent,
groupId,
depthSelector,
onDepthMapChange,
} = props;
const vizEngine = engine.visualizations[props.visualizationName];

const [fullView, setFullView] = React.useState<boolean>(false);
const sequenceName: SequenceTypesEnum = useStore(sequenceNameSelector);
const boxConfig = useStore(boxConfigStateSelector);
const sequenceName: SequenceTypesEnum = engine.pipeline.getSequenceName();
const boxConfig = useStore(vizEngine.box.stateSelector);
const captionProperties: ICaptionProperties = useStore(
captionPropertiesStateSelector,
vizEngine.controls.captionProperties.stateSelector,
);
const foundGroups = engine.useStore(engine.foundGroupsSelector);
const foundGroups = engine.useStore(engine.pipeline.foundGroupsSelector);
const depth = engine.useStore(depthSelector(groupId));
const captionBoxRef: React.RefObject<HTMLDivElement | null> =
React.useRef<HTMLDivElement>(null);
Expand Down Expand Up @@ -111,6 +105,7 @@ function BoxWrapper(props: IBoxWrapperProps<AimFlatObjectBase<any>>) {
data={currentItem}
engine={engine}
style={currentItem.style}
visualizationName={props.visualizationName}
/>
)}
</div>
Expand All @@ -124,6 +119,7 @@ function BoxWrapper(props: IBoxWrapperProps<AimFlatObjectBase<any>>) {
captionBoxRef={captionBoxRef}
engine={engine}
item={currentItem}
visualizationName={props.visualizationName}
/>
)}
{fullView && (
Expand All @@ -135,7 +131,13 @@ function BoxWrapper(props: IBoxWrapperProps<AimFlatObjectBase<any>>) {
>
<div className='BoxWrapper__fullViewContent'>
<div className='BoxWrapper__fullViewContent__box'>
{BoxContent && <BoxContent data={currentItem} engine={engine} />}
{BoxContent && (
<BoxContent
data={currentItem}
engine={engine}
visualizationName={props.visualizationName}
/>
)}
</div>
</div>
{renderDepthSlider({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';

export interface ICaptionBoxProps {
engine: IBaseComponentProps['engine'];
import { IBaseComponentProps } from 'modules/BaseExplorer/types';

export interface ICaptionBoxProps extends IBaseComponentProps {
captionBoxRef: React.RefObject<HTMLDivElement>;
item: any;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ import './CaptionBox.scss';
function CaptionBox(props: ICaptionBoxProps) {
const {
captionBoxRef,
visualizationName,
engine: {
useStore,
additionalDataSelector,
controls: {
captionProperties: { stateSelector },
},
visualizations,
pipeline: { additionalDataSelector },
},
} = props;
const {
controls: {
captionProperties: { stateSelector },
},
} = visualizations[visualizationName];

const captionProperties = useStore(stateSelector);
const availableModifiers = useStore(additionalDataSelector);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import React from 'react';
import classNames from 'classnames';

import { IBaseComponentProps } from 'modules/BaseExplorer/types';

import ControlPopover from 'components/ControlPopover/ControlPopover';
import { Button, Icon, Text } from 'components/kit';
import { Icon, Button, Text } from 'components/kit';

import BoxPropertiesPopover from './Popover';

import { IBoxPropertiesProps, IBoxConfigState } from '.';

function BoxProperties(props: IBoxPropertiesProps) {
const {
engine,
engine: {
useStore,
boxConfig: { stateSelector: boxSelector },
controls: {
boxProperties: { settings },
},
},
visualizationName,
engine: { visualizations, useStore },
} = props;
const boxProperties: IBoxConfigState = useStore(boxSelector);
const vizEngine = visualizations[visualizationName];

const boxProperties: IBoxConfigState = useStore(vizEngine.box.stateSelector);
return (
<ControlPopover
title='Configure box size'
Expand Down Expand Up @@ -51,10 +45,10 @@ function BoxProperties(props: IBoxPropertiesProps) {
)}
component={
<BoxPropertiesPopover
update={engine.boxConfig.methods.update}
reset={engine.boxConfig.methods.reset}
update={vizEngine.box.methods.update}
reset={vizEngine.box.methods.reset}
boxProperties={boxProperties}
settings={settings}
settings={vizEngine.controls.boxProperties.settings}
/>
}
/>
Expand All @@ -63,4 +57,4 @@ function BoxProperties(props: IBoxPropertiesProps) {

BoxProperties.displayName = 'BoxProperties';

export default React.memo<IBaseComponentProps>(BoxProperties);
export default React.memo<IBoxPropertiesProps>(BoxProperties);
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import classNames from 'classnames';

import { IBaseComponentProps } from 'modules/BaseExplorer/types';

import ControlPopover from 'components/ControlPopover/ControlPopover';
import { Button, Icon, Text } from 'components/kit';
import ControlPopover from 'components/ControlPopover/ControlPopover';
import ErrorBoundary from 'components/ErrorBoundary/ErrorBoundary';

import CaptionPropertiesPopover from './CaptionPropertiesPopover';
Expand All @@ -14,14 +14,15 @@ import { ICaptionProperties, ICaptionPropertiesProps } from './';
function CaptionProperties(props: ICaptionPropertiesProps) {
const {
engine,
engine: {
useStore,
controls: {
captionProperties: { stateSelector },
},
},
visualizationName,
engine: { useStore, visualizations },
} = props;
const captionProperties: ICaptionProperties = useStore(stateSelector);
const vizEngine = visualizations[visualizationName];

const captionProperties: ICaptionProperties = useStore(
vizEngine.controls.captionProperties.stateSelector,
);

return (
<ErrorBoundary>
<ControlPopover
Expand Down Expand Up @@ -54,6 +55,7 @@ function CaptionProperties(props: ICaptionPropertiesProps) {
<CaptionPropertiesPopover
engine={engine}
captionProperties={captionProperties}
visualizationName={props.visualizationName}
/>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@ function CaptionPropertiesPopover(
): React.FunctionComponentElement<React.ReactNode> {
const {
captionProperties,
visualizationName,
engine: {
useStore,
additionalDataSelector,
controls: {
captionProperties: {
methods: { update: updateCaptionProperties },
},
},
pipeline: { additionalDataSelector },
visualizations,
},
} = props;
const updateCaptionProperties =
visualizations[visualizationName].controls.captionProperties.methods.update;

const availableModifiers = useStore(additionalDataSelector);
const [searchValue, setSearchValue] = React.useState<string>('');

Expand Down
Loading