-
Notifications
You must be signed in to change notification settings - Fork 92
Feat add path setting #2433
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
Merged
Keith-CY
merged 8 commits into
nervosnetwork:develop
from
yanguoyu:feat-add-path-setting
Jul 4, 2022
Merged
Feat add path setting #2433
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
889f9a6
feat: Add setting for ckb-node and indexer data path.
yanguoyu 94718bb
fix: remove mistake pull
yanguoyu d4999de
fix: Add endline
yanguoyu 0c8c47c
fix: Fix ci test case failed.
yanguoyu 921d84e
fix: Add end line and use void not undefined with parameter
yanguoyu 6b5f26a
fix: Fix windows testcase
yanguoyu 3b6e9db
feat: Add open data path by electron API
yanguoyu 17df920
Fix: Avoid icon shrink
yanguoyu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 27 additions & 21 deletions
48
packages/neuron-ui/src/components/ClearCache/style.module.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import { useCallback, useState } from 'react' | ||
| import { useTranslation } from 'react-i18next' | ||
| import { | ||
| getCkbNodeDataPath, | ||
| getIndexerDataPath, | ||
| invokeShowOpenDialog, | ||
| startProcessMonitor, | ||
| stopProcessMonitor, | ||
| setCkbNodeDataPath, | ||
| setIndexerDataPath, | ||
| } from 'services/remote' | ||
| import { isSuccessResponse, useDialogWrapper, useDidMount } from 'utils' | ||
|
|
||
| export const useDataPath = ( | ||
| getPath: typeof getCkbNodeDataPath | typeof getIndexerDataPath, | ||
| setPath: typeof setCkbNodeDataPath | typeof setIndexerDataPath, | ||
| type: Parameters<typeof stopProcessMonitor>[0] | ||
| ) => { | ||
| const [t] = useTranslation() | ||
| const [prevPath, setPrevPath] = useState<string>() | ||
| const [currentPath, setCurrentPath] = useState<string | undefined>() | ||
| const { dialogRef, openDialog, closeDialog } = useDialogWrapper() | ||
| useDidMount(() => { | ||
| getPath(undefined).then(res => { | ||
| if (isSuccessResponse(res)) { | ||
| setPrevPath(res.result!) | ||
| } | ||
| }) | ||
| }) | ||
| const onSetting = useCallback(() => { | ||
| invokeShowOpenDialog({ | ||
| buttonLabel: t('settings.data.set', { lng: navigator.language }), | ||
| properties: ['openDirectory', 'createDirectory', 'promptToCreate', 'treatPackageAsDirectory'], | ||
| }).then(res => { | ||
| if (isSuccessResponse(res) && !res.result?.canceled && res.result?.filePaths?.length) { | ||
| setCurrentPath(res.result?.filePaths?.[0]) | ||
| stopProcessMonitor(type).then(stopRes => { | ||
| if (isSuccessResponse(stopRes)) { | ||
| openDialog() | ||
| } | ||
| }) | ||
| } | ||
| }) | ||
| }, [t, type]) | ||
| const onCancel = useCallback(() => { | ||
| startProcessMonitor(type).then(res => { | ||
| if (isSuccessResponse(res)) { | ||
| closeDialog() | ||
| } | ||
| }) | ||
| }, [closeDialog, type]) | ||
| const onConfirm = useCallback(() => { | ||
| setPath(currentPath!).then(res => { | ||
| if (isSuccessResponse(res)) { | ||
| setPrevPath(currentPath) | ||
| closeDialog() | ||
| } | ||
| }) | ||
| }, [currentPath, closeDialog, setPrevPath, setPath]) | ||
| return { | ||
| prevPath, | ||
| currentPath, | ||
| onSetting, | ||
| dialogRef, | ||
| onCancel, | ||
| onConfirm, | ||
| } | ||
| } | ||
|
|
||
| export default useDataPath | ||
66 changes: 66 additions & 0 deletions
66
packages/neuron-ui/src/components/DataSetting/index.module.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| @import '../../styles/mixin.scss'; | ||
|
|
||
| .root { | ||
| margin-top: 20px; | ||
| display: grid; | ||
| grid-template-columns: auto 1fr 140px; | ||
| grid-gap: 30px 20px; | ||
| align-items: center; | ||
|
|
||
| .name { | ||
| font-weight: bold; | ||
| } | ||
|
|
||
| .content { | ||
| font-size: 12px; | ||
| word-break: break-all; | ||
| } | ||
|
|
||
| button { | ||
| line-height: 1; | ||
| height: 1.625rem; | ||
| } | ||
| } | ||
|
|
||
| .dialog { | ||
| @include dialog-container; | ||
| padding: 30px 50px; | ||
|
|
||
| .describe { | ||
| word-break: break-all; | ||
| font-size: 14px; | ||
| } | ||
|
|
||
| .attention { | ||
| position: relative; | ||
| padding-left: 1rem; | ||
| font-size: 0.75rem; | ||
| letter-spacing: 0.5px; | ||
| margin: 14px 0 20px 0; | ||
| color: #666; | ||
|
|
||
| svg { | ||
| position: absolute; | ||
| left: 0; | ||
| top: 0.13rem; | ||
| filter: grayscale(1) opacity(0.6); | ||
| width: 0.625rem; | ||
| height: 0.625rem; | ||
| } | ||
| } | ||
|
|
||
| .action { | ||
| padding-top: 16px; | ||
| display: flex; | ||
| justify-content: space-between; | ||
| } | ||
| } | ||
|
|
||
| .path { | ||
| display: flex; | ||
| align-items: center; | ||
|
|
||
| & > svg { | ||
| flex-shrink: 0; | ||
| } | ||
| } | ||
|
yanguoyu marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import React, { useCallback } from 'react' | ||
| import { useTranslation } from 'react-i18next' | ||
| import Button from 'widgets/Button' | ||
| import ClearCache from 'components/ClearCache' | ||
| import { useDispatch } from 'states' | ||
| import { getCkbNodeDataPath, getIndexerDataPath, setCkbNodeDataPath, setIndexerDataPath } from 'services/remote' | ||
| import { ReactComponent as Attention } from 'widgets/Icons/ExperimentalAttention.svg' | ||
| import CopyZone from 'widgets/CopyZone' | ||
| import { OpenFolder } from 'widgets/Icons/icon' | ||
| import { shell } from 'electron' | ||
| import { useDataPath } from './hooks' | ||
|
|
||
| import styles from './index.module.scss' | ||
|
|
||
| const itemProps: Record< | ||
| 'ckbNode' | 'indexer', | ||
| { | ||
| type: 'ckb' | 'ckb-indexer' | ||
| getPath: typeof getCkbNodeDataPath | typeof getIndexerDataPath | ||
| setPath: typeof setCkbNodeDataPath | typeof setIndexerDataPath | ||
| titleI18nKey: string | ||
| tipI18nKey: string | ||
| } | ||
| > = { | ||
| ckbNode: { | ||
| type: 'ckb', | ||
| getPath: getCkbNodeDataPath, | ||
| setPath: setCkbNodeDataPath, | ||
| titleI18nKey: 'ckb-node-data', | ||
| tipI18nKey: 'remove-ckb-data-tip', | ||
| }, | ||
| indexer: { | ||
| type: 'ckb-indexer', | ||
| getPath: getIndexerDataPath, | ||
| setPath: setIndexerDataPath, | ||
| titleI18nKey: 'ckb-indexer-data', | ||
| tipI18nKey: 'remove-indexer-data-tip', | ||
| }, | ||
| } | ||
|
|
||
| const SetItem = ({ type }: { type: keyof typeof itemProps }) => { | ||
| const props = itemProps[type] | ||
| const [t] = useTranslation() | ||
| const { onSetting, prevPath, currentPath, dialogRef, onCancel, onConfirm } = useDataPath( | ||
| props.getPath, | ||
| props.setPath, | ||
| props.type | ||
| ) | ||
| const openPath = useCallback(() => { | ||
| if (prevPath) { | ||
| shell.openPath(prevPath!) | ||
| } | ||
| }, [prevPath]) | ||
| return ( | ||
| <> | ||
| <div className={styles.name}>{t(`settings.data.${props.titleI18nKey}`)}:</div> | ||
| <div className={styles.path}> | ||
| <CopyZone content={prevPath || ''} className={styles.content}> | ||
| {prevPath} | ||
| </CopyZone> | ||
| <OpenFolder onClick={openPath} /> | ||
| </div> | ||
| <Button label={t('settings.data.set')} onClick={onSetting} /> | ||
| <dialog ref={dialogRef} className={styles.dialog}> | ||
| <div className={styles.describe}>{t(`settings.data.${props.tipI18nKey}`, { prevPath, currentPath })}</div> | ||
| <div className={styles.attention}> | ||
| <Attention /> | ||
| {t('settings.data.resync-describe')} | ||
| </div> | ||
| <div className={styles.action}> | ||
| <Button label={t('settings.data.cancel')} type="cancel" onClick={onCancel} /> | ||
| <Button label={t('settings.data.move-data-finish')} type="primary" onClick={onConfirm} /> | ||
| <Button label={t('settings.data.re-sync')} type="primary" onClick={onConfirm} /> | ||
| </div> | ||
| </dialog> | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| const DataSetting = () => { | ||
| const dispatch = useDispatch() | ||
| return ( | ||
| <div className={styles.root}> | ||
| <SetItem type="ckbNode" /> | ||
| <SetItem type="indexer" /> | ||
| <ClearCache dispatch={dispatch} /> | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| DataSetting.displayName = 'DataSetting' | ||
| export default DataSetting |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.