Skip to content

Commit

Permalink
feat(@leav/ui): be able to play with side panel provided by explorer
Browse files Browse the repository at this point in the history
  • Loading branch information
P0ppoff committed Nov 13, 2024
1 parent 901cfc6 commit eedd8d9
Show file tree
Hide file tree
Showing 30 changed files with 866 additions and 455 deletions.
2 changes: 1 addition & 1 deletion apps/data-studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"antd": "5.15.3",
"apollo-cache-inmemory": "1.6.6",
"apollo-upload-client": "14.1.3",
"aristid-ds": "10.1.0-c112384",
"aristid-ds": "10.1.0-b8e3d81",
"dayjs": "1.11.10",
"graphql": "15.0.0",
"graphql-tag": "2.12.6",
Expand Down
16 changes: 10 additions & 6 deletions apps/data-studio/src/components/Router/Router.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
// This file is released under LGPL V3
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
import {APPS_ENDPOINT, APP_ENDPOINT, themeVars} from '@leav/ui';
import {APPS_ENDPOINT, APP_ENDPOINT, Explorer, themeVars} from '@leav/ui';
import {Layout} from 'antd';
import Sidebar from 'components/Sidebar';
import TopBar from 'components/TopBar';
Expand Down Expand Up @@ -45,11 +45,15 @@ const Router: FunctionComponent = () => {
/>
</Header>
<Layout style={{overflow: 'hidden', position: 'relative'}}>
<Content style={{background: themeVars.defaultBg, overflow: 'hidden'}}>
<UserPanel userPanelVisible={userPanelVisible} hideUserPanel={hideUserPanel} />
<NotifsPanel setNbNotifs={_setNbNotifs} />
<Routes />
</Content>
<Explorer.EditSettingsContextProvider>
<Content style={{background: themeVars.defaultBg, overflow: 'hidden'}}>
<UserPanel userPanelVisible={userPanelVisible} hideUserPanel={hideUserPanel} />
<NotifsPanel setNbNotifs={_setNbNotifs} />
<Routes />
</Content>
{/* TODO: handle conflict with app side panel */}
<Explorer.SettingsSidePanel />
</Explorer.EditSettingsContextProvider>
</Layout>
</Layout>
</Layout>
Expand Down
2 changes: 1 addition & 1 deletion apps/login/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"@ant-design/icons": "5.2.6",
"@leav/ui": "workspace:libs/ui",
"antd": "5.15.3",
"aristid-ds": "10.1.0-c112384",
"aristid-ds": "10.1.0-b8e3d81",
"i18next": "22.5.0",
"i18next-browser-languagedetector": "7.0.2",
"i18next-http-backend": "2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/portal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@leav/ui": "workspace:libs/ui",
"@leav/utils": "workspace:libs/utils",
"antd": "5.15.3",
"aristid-ds": "10.1.0-c112384",
"aristid-ds": "10.1.0-b8e3d81",
"cross-fetch": "3.1.5",
"graphql-ws": "5.12.0",
"i18next": "22.5.0",
Expand Down
2 changes: 1 addition & 1 deletion libs/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@ant-design/icons": ">=5.2",
"@apollo/client": ">=3.8.1",
"antd": "5.15.3",
"aristid-ds": "10.1.0-c112384",
"aristid-ds": "10.1.0-b8e3d81",
"dayjs": "^1.11.10",
"i18next": "22.5",
"react": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion libs/ui/src/components/Explorer/DataView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
PropertyValueTreeValueFragment,
PropertyValueValueFragment
} from '_ui/_gqlTypes';
import {IItemAction, IItemData, ItemWhoAmI} from './types';
import {IItemAction, IItemData, ItemWhoAmI} from './_types';

const USELESS = '';

Expand Down
14 changes: 10 additions & 4 deletions libs/ui/src/components/Explorer/Explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// This file is released under LGPL V3
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
import {FunctionComponent} from 'react';
import {KitTypography} from 'aristid-ds';
import {KitSpace, KitTypography} from 'aristid-ds';
import styled from 'styled-components';
import {IItemAction} from './types';
import {IItemAction} from './_types';
import {DataView} from './DataView';
import {useExplorerData} from './useExplorerData';
import {useOpenSettings} from './edit-settings/useOpenSettings';
import {useExplorerData} from './_queries/useExplorerData';
import {useDeactivateAction} from './useDeactivateAction';
import {useEditAction} from './useEditAction';
import {useCreateMainAction} from './useCreateMainAction';
Expand Down Expand Up @@ -57,6 +58,8 @@ export const Explorer: FunctionComponent<IExplorerProps> = ({
refetch
});

const settingsButton = useOpenSettings();

return (
<>
{loading ? (
Expand All @@ -67,7 +70,10 @@ export const Explorer: FunctionComponent<IExplorerProps> = ({
<KitTypography.Title level="h1">
{library /* TODO: get correct name from backend */}
</KitTypography.Title>
{createButton}
<KitSpace size="xs">
{settingsButton}
{createButton}
</KitSpace>
</ExplorerHeaderDivStyled>
<DataView
dataGroupedFilteredSorted={data ?? []}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
// This file is released under LGPL V3
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
import {IItemData} from './types';
import {IItemData} from '../_types';
import {ExplorerQuery, useExplorerQuery} from '_ui/_gqlTypes';

const _mapping = (data: ExplorerQuery, libraryId: string): IItemData[] =>
Expand Down
File renamed without changes.
11 changes: 11 additions & 0 deletions libs/ui/src/components/Explorer/edit-settings/DisplayMode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
// This file is released under LGPL V3
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
import {useSharedTranslation} from '_ui/hooks/useSharedTranslation';
import {FunctionComponent} from 'react';

export const DisplayMode: FunctionComponent = () => {
const {t} = useSharedTranslation();

return <div>TODO</div>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
// This file is released under LGPL V3
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
import {createContext, ReactNode} from 'react';

interface IActiveSettings {
content: ReactNode;
title: string;
onClickLeftButton?: () => void;
}

export interface IEditSettingsContext {
setActiveSettings: (params: IActiveSettings) => void;
activeSettings: null | IActiveSettings;
onClose: () => void;
}

export const EditSettingsContext = createContext<IEditSettingsContext>({
setActiveSettings: () => {
throw new Error('Not implemented');
},
activeSettings: null,
onClose: () => {
throw new Error('Not implemented');
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
// This file is released under LGPL V3
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
import {FunctionComponent, useState} from 'react';
import {EditSettingsContext, IEditSettingsContext} from './EditSettingsContext';

export const EditSettingsContextProvider: FunctionComponent = ({children}) => {
const [activeSettings, setActiveSettings] = useState<IEditSettingsContext['activeSettings']>(null);
const onClose = () => setActiveSettings(null);

return (
<EditSettingsContext.Provider
value={{
activeSettings,
setActiveSettings,
onClose
}}
>
{children}
</EditSettingsContext.Provider>
);
};
75 changes: 75 additions & 0 deletions libs/ui/src/components/Explorer/edit-settings/SettingItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
// This file is released under LGPL V3
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
import {KitTypography} from 'aristid-ds';
import {FunctionComponent, ReactNode} from 'react';
import {FaChevronRight} from 'react-icons/fa';
import styled from 'styled-components';

const StyledValue = styled(KitTypography.Text)`
color: var(--general-utilities-disabled);
`;

const StyledConfigurationItem = styled.li`
list-style: none;
&:first-child {
margin-top: calc(var(--general-spacing-xs) * 1px);
}
> button {
color: var(--general-utilities-text-primary);
border: none;
background: transparent;
display: flex;
width: 100%;
height: 40px;
align-items: center;
padding: 0 calc(var(--general-spacing-xs) * 1px);
gap: calc(var(--general-spacing-xs) * 1px);
border-radius: calc(var(--general-spacing-xs) * 1px);
text-align: left;
cursor: pointer;
&:hover {
background: var(--general-utilities-main-light);
${StyledValue} {
color: var(--general-utilities-text-primary);
}
}
.title {
flex: 1 1 auto;
}
.value {
flex: 0 1 auto;
text-align: right;
}
> svg {
flex: 0 0 calc(var(--general-spacing-s) * 1px);
}
}
`;

export const SettingItem: FunctionComponent<{
icon: ReactNode;
title: string;
onClick: () => void;
value?: string;
}> = ({icon, title, value = '', onClick}) => (
<StyledConfigurationItem>
<button onClick={onClick}>
{icon}
<KitTypography.Text size="fontSize5" ellipsis className="title">
{title}
</KitTypography.Text>
<StyledValue size="fontSize5" ellipsis className="value">
{value}
</StyledValue>
<FaChevronRight />
</button>
</StyledConfigurationItem>
);
97 changes: 97 additions & 0 deletions libs/ui/src/components/Explorer/edit-settings/SettingsPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
// This file is released under LGPL V3
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
import styled from 'styled-components';
import {FunctionComponent, useState} from 'react';
import {KitTypography} from 'aristid-ds';
import {FaFilter, FaList, FaSortAlphaDown} from 'react-icons/fa';
import {useSharedTranslation} from '_ui/hooks/useSharedTranslation';
import {DisplayMode} from './DisplayMode';
import {SettingItem} from './SettingItem';
import {useEditSettings} from './useEditSettings';

export type SettingsPanelPages = 'view-configuration' | 'display-mode';

const ContentWrapperStyledDiv = styled.div`
display: flex;
flex-direction: column;
gap: calc(var(--general-spacing-s) * 1px);
`;

const ConfigurationStyledMenu = styled.menu`
padding: 0;
`;

export const SettingsPanel: FunctionComponent = () => {
const {t} = useSharedTranslation();

const {setActiveSettings, activeSettings} = useEditSettings();

const [currentPage, setCurrentPage] = useState<SettingsPanelPages>('view-configuration');

const _goToAdvancedSettingsPage = (page: SettingsPanelPages) => {
if (!activeSettings) {
throw Error('Should not be able to change side pane page if there is no side panel!');
}

const _changePanelPage = ({
pageName,
title,
onClickLeftButton
}: {
pageName: SettingsPanelPages;
title: string;
onClickLeftButton?: () => void;
}) => {
setCurrentPage(pageName);
setActiveSettings({
...activeSettings!,
title,
onClickLeftButton
});
};

_changePanelPage({
pageName: page,
title: t(`explorer.${page}`),
onClickLeftButton: () => {
const rootPanel = {pageName: 'view-configuration', title: t('explorer.settings')} as const;
_changePanelPage(rootPanel);
}
});
};

// TODO: look for MemoryRouter

return (
<ContentWrapperStyledDiv>
{currentPage === 'view-configuration' && (
<nav>
<KitTypography.Title level="h4">{t('explorer.view-configuration')}</KitTypography.Title>
<ConfigurationStyledMenu>
<SettingItem
icon={<FaList />}
title={t('explorer.display-mode')}
onClick={() => _goToAdvancedSettingsPage('display-mode')}
/>
<SettingItem
icon={<FaFilter />}
title={t('explorer.filters')}
onClick={() => {
/* TODO: not implemented yet */
}}
/>
<SettingItem
icon={<FaSortAlphaDown />}
title={t('explorer.sort')}
onClick={() => {
/* TODO: not implemented yet */
}}
/>
</ConfigurationStyledMenu>
</nav>
)}
{currentPage === 'display-mode' && <DisplayMode />}
</ContentWrapperStyledDiv>
);
};
41 changes: 41 additions & 0 deletions libs/ui/src/components/Explorer/edit-settings/SidePanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright LEAV Solutions 2017 until 2023/11/05, Copyright Aristid from 2023/11/06
// This file is released under LGPL V3
// License text available at https://www.gnu.org/licenses/lgpl-3.0.txt
import {ButtonHTMLAttributes, FunctionComponent} from 'react';
import {KitSidePanel} from 'aristid-ds';
import {useEditSettings} from './useEditSettings';
import {useSharedTranslation} from '_ui/hooks/useSharedTranslation';

export const SidePanel: FunctionComponent = () => {
const {t} = useSharedTranslation();

const {activeSettings, onClose} = useEditSettings();

if (!activeSettings) {
return null;
}

// TODO: handle transition opening/closing on floating prop true

const makeA11yBackButton: ButtonHTMLAttributes<HTMLButtonElement> = {
title: String(t('explorer.back')) /* TODO: avoid transform null to 'null' */
};

return (
<KitSidePanel
style={{zIndex: '10000'}}
initialOpen
floating
closable
idCardProps={{title: activeSettings.title}}
leftActionProps={
activeSettings.onClickLeftButton
? {onClick: activeSettings.onClickLeftButton, ...makeA11yBackButton}
: undefined
}
onClose={onClose}
>
{activeSettings.content}
</KitSidePanel>
);
};
Loading

0 comments on commit eedd8d9

Please sign in to comment.