-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0519b5
commit 15fb8f7
Showing
13 changed files
with
216 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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
Binary file modified
BIN
+31 Bytes
(110%)
packages/platform-server/src/utils/__tests__/__snapshots__/get-lh-run-data.spec.ts.snap
Binary file not shown.
This file contains 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 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 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
147 changes: 147 additions & 0 deletions
147
packages/platform/src/modules/project/settings/settings-environments/form-localstorage.tsx
This file contains 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,147 @@ | ||
/* | ||
Copyright 2022 ByteDance and/or its affiliates. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import { DefaultButton, Label, Stack, IconButton, SharedColors, TextField } from '@fluentui/react' | ||
import { FormEvent, forwardRef, useCallback, useImperativeHandle, useMemo, useState, memo } from 'react' | ||
|
||
import { LocalStorageType } from '@perfsee/shared' | ||
|
||
import { NormalToken } from '../style' | ||
|
||
type FormStorageProps = { | ||
index: number | ||
item: LocalStorageType | ||
onStorageRemove: (index: number) => void | ||
onStorageChange: (item: LocalStorageType, index: number) => void | ||
} | ||
|
||
const FormStorage = memo((props: FormStorageProps) => { | ||
const { index, item, onStorageRemove, onStorageChange } = props | ||
|
||
const onRemove = useCallback(() => { | ||
onStorageRemove(index) | ||
}, [index, onStorageRemove]) | ||
|
||
const onChange = useCallback( | ||
(e?: FormEvent<HTMLElement | HTMLInputElement>, value?: string) => { | ||
if (!e || value === undefined) { | ||
return | ||
} | ||
const type = (e.target as HTMLInputElement).dataset.type! | ||
onStorageChange({ ...item, [type]: value }, index) | ||
}, | ||
[index, item, onStorageChange], | ||
) | ||
|
||
const inputValidate = useCallback((value: string) => { | ||
if (!value) { | ||
return 'Required' | ||
} | ||
|
||
if (value.length > 1024) { | ||
return 'length exceed 1024 bytes' | ||
} | ||
}, []) | ||
|
||
return ( | ||
<div> | ||
<Stack horizontal horizontalAlign="space-between" verticalAlign="center" tokens={{ padding: '8px 0 0 0' }}> | ||
LocalStorage #{index + 1} | ||
<IconButton | ||
iconProps={{ iconName: 'delete' }} | ||
styles={{ root: { color: SharedColors.red10 }, rootHovered: { color: SharedColors.red10 } }} | ||
onClick={onRemove} | ||
/> | ||
</Stack> | ||
<Stack horizontal tokens={NormalToken}> | ||
<TextField | ||
value={item.key} | ||
data-type="key" | ||
onChange={onChange} | ||
styles={{ root: { flexGrow: 2 } }} | ||
placeholder="Key" | ||
onGetErrorMessage={inputValidate} | ||
/> | ||
<TextField | ||
data-type="value" | ||
onChange={onChange} | ||
value={item.value} | ||
styles={{ root: { flexGrow: 2 } }} | ||
placeholder="Value" | ||
onGetErrorMessage={inputValidate} | ||
/> | ||
</Stack> | ||
</div> | ||
) | ||
}) | ||
|
||
type Props = { defaultLocalStorage: LocalStorageType[] } | ||
|
||
export const FormLocalStorage = forwardRef((props: Props, ref) => { | ||
const [storages, setStorages] = useState<LocalStorageType[]>(props.defaultLocalStorage) | ||
|
||
useImperativeHandle( | ||
ref, | ||
() => ({ | ||
getLocalStorage: () => storages, | ||
}), | ||
[storages], | ||
) | ||
|
||
const onStorageChange = useCallback( | ||
(storage: LocalStorageType, index: number) => { | ||
const newStorages = [...storages] | ||
newStorages[index] = storage | ||
setStorages(newStorages) | ||
}, | ||
[storages], | ||
) | ||
|
||
const onStorageRemove = useCallback((index: number) => { | ||
setStorages((storages) => { | ||
storages.splice(index, 1) | ||
return [...storages] | ||
}) | ||
}, []) | ||
|
||
const onAddStorage = useCallback(() => { | ||
setStorages([...storages, { key: '', value: '' }]) | ||
}, [storages]) | ||
|
||
const newHeaders = useMemo(() => { | ||
return storages.map((item, i) => { | ||
return ( | ||
<FormStorage | ||
key={i} | ||
index={i} | ||
item={item} | ||
onStorageChange={onStorageChange} | ||
onStorageRemove={onStorageRemove} | ||
/> | ||
) | ||
}) | ||
}, [onStorageChange, onStorageRemove, storages]) | ||
|
||
return ( | ||
<> | ||
<Stack horizontal horizontalAlign="space-between" tokens={{ padding: '8px 0 0 0' }}> | ||
<Label htmlFor="localStorage">LocalStorage</Label> | ||
<DefaultButton onClick={onAddStorage}>add localStorage</DefaultButton> | ||
</Stack> | ||
{newHeaders} | ||
</> | ||
) | ||
}) |
This file contains 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 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 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 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.