-
Notifications
You must be signed in to change notification settings - Fork 2
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
Program renaming feature #140
Changes from all commits
f121167
52f940b
338180d
5b43894
65439db
f2fcf9f
ad5322e
b047509
d9302dc
c8d71da
e3b2b43
86237c1
20e981d
288d0e6
798c72b
3c9108d
d30bfeb
a076667
a48f027
8d93d43
df94e7e
35767c4
96d2376
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,100 @@ | ||||||
import { | ||||||
HStack, | ||||||
Icon, | ||||||
Text, | ||||||
useBreakpointValue, | ||||||
useDisclosure, | ||||||
useColorMode, | ||||||
useColorModeValue, | ||||||
} from '@chakra-ui/react'; | ||||||
import { useState } from 'react'; | ||||||
import { IoTrashSharp } from 'react-icons/io5'; | ||||||
|
||||||
import { useDriveContext } from 'contexts/drive'; | ||||||
import { useUserContext } from 'contexts/user'; | ||||||
|
||||||
import Button from 'components/Button'; | ||||||
import Modal from 'components/Modal'; | ||||||
import type { IPCProgram } from 'types/types'; | ||||||
import { textColorMode } from 'config/colorMode'; | ||||||
|
||||||
type DeleteProgramProps = { | ||||||
program: IPCProgram; | ||||||
}; | ||||||
|
||||||
const DeleteProgram = ({ program }: DeleteProgramProps): JSX.Element => { | ||||||
const { user } = useUserContext(); | ||||||
const { programs, setPrograms } = useDriveContext(); | ||||||
|
||||||
const [isLoading, setIsLoading] = useState(false); | ||||||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||||||
|
||||||
const isDrawer = useBreakpointValue({ base: true, sm: false }) || false; | ||||||
const textColor = useColorModeValue(textColorMode.light, textColorMode.dark); | ||||||
const { colorMode } = useColorMode(); | ||||||
|
||||||
const DeleteActualProgram = async () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Use PascalCase only for component names, not for functions 😉 |
||||||
setIsLoading(true); | ||||||
console.log(`hash = ${program.hash}`); | ||||||
const update = await user.computing.UpdateDeleteProgram(program.hash); | ||||||
console.log(`message = ${update.message}`); | ||||||
if (update.success) | ||||||
setPrograms([...programs]); | ||||||
setIsLoading(false); | ||||||
onClose(); | ||||||
} | ||||||
|
||||||
return ( | ||||||
<HStack | ||||||
spacing={isDrawer ? '24px' : '12px'} | ||||||
p="8px 12px" | ||||||
borderRadius="8px" | ||||||
role="group" | ||||||
onClick={onOpen} | ||||||
w="100%" | ||||||
cursor="pointer" | ||||||
id="ipc-dashboard-delete-button" | ||||||
_hover={{ | ||||||
bg: colorMode === 'light' ? 'blue.50' : 'gray.750', | ||||||
}} | ||||||
> | ||||||
<Icon | ||||||
as={IoTrashSharp} | ||||||
_groupHover={{ color: 'red.800' }} | ||||||
w={isDrawer ? '24px' : '20px'} | ||||||
h={isDrawer ? '24px' : '20px'} | ||||||
/> | ||||||
<Text | ||||||
fontSize="16px" | ||||||
fontWeight="400" | ||||||
_groupHover={{ | ||||||
color: 'red.800', | ||||||
fontWeight: '500', | ||||||
}} | ||||||
color={textColor} | ||||||
> | ||||||
Delete | ||||||
</Text> | ||||||
<Modal | ||||||
isOpen={isOpen} | ||||||
onClose={onClose} | ||||||
title="Delete program" | ||||||
CTA={ | ||||||
<Button | ||||||
variant="primary" | ||||||
size="lg" | ||||||
onClick={DeleteActualProgram} | ||||||
isLoading={isLoading} | ||||||
id="ipc-dashboard-delete-program-button" | ||||||
> | ||||||
Delete | ||||||
</Button> | ||||||
} | ||||||
> | ||||||
<Text color={textColor}>Are you sure you want to delete this program?</Text> | ||||||
</Modal> | ||||||
</HStack> | ||||||
); | ||||||
}; | ||||||
|
||||||
export default DeleteProgram; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { | ||
HStack, | ||
FormControl, | ||
FormLabel, | ||
Input, | ||
useDisclosure, | ||
Icon, | ||
Text, | ||
useBreakpointValue, | ||
useColorMode, | ||
useColorModeValue | ||
} from '@chakra-ui/react'; | ||
|
||
import { BsPencil } from 'react-icons/bs'; | ||
|
||
import type { IPCProgram } from 'types/types'; | ||
|
||
import { textColorMode } from 'config/colorMode'; | ||
|
||
import Modal from 'components/Modal'; | ||
import Button from 'components/Button'; | ||
|
||
import { ChangeEvent, useState } from 'react'; | ||
|
||
|
||
import { useUserContext } from 'contexts/user'; | ||
import { useDriveContext } from 'contexts/drive'; | ||
|
||
type RenameProgramProps = { | ||
program: IPCProgram; | ||
}; | ||
|
||
const RenameProgram = ({ program }: RenameProgramProps): JSX.Element => { | ||
const isDrawer = useBreakpointValue({ base: true, sm: false }) || false; | ||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||
const textColor = useColorModeValue(textColorMode.light, textColorMode.dark); | ||
const [name, setName] = useState(''); | ||
const { colorMode } = useColorMode(); | ||
const [isLoading, setIsLoading] = useState(false); | ||
|
||
const { user } = useUserContext(); | ||
const {programs, setPrograms} = useDriveContext(); | ||
|
||
const updateProgramName = async () => { | ||
setIsLoading(true); | ||
if (name) { | ||
const update = await user.computing.updateProgramName(program, name); | ||
if (update.success) { | ||
const index = programs.indexOf(program); | ||
if (index !== -1) { | ||
programs[index].name = name; | ||
programs[index].log.push({ | ||
action: `Renamed program to ${name}`, | ||
date: Date.now(), | ||
}); | ||
} | ||
setPrograms([...programs]); | ||
} | ||
} | ||
setName(''); | ||
setIsLoading(false); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<HStack | ||
spacing={isDrawer ? '24px' : '12px'} | ||
p="8px 12px" | ||
borderRadius="8px" | ||
role="group" | ||
onClick={onOpen} | ||
w="100%" | ||
cursor="pointer" | ||
id="ipc-dashboard-rename-button" | ||
_hover={{ | ||
bg: colorMode === 'light' ? 'blue.50' : 'gray.750', | ||
}} | ||
> | ||
<Icon | ||
as={BsPencil} | ||
_groupHover={{ color: 'red.800' }} | ||
w={isDrawer ? '24px' : '20px'} | ||
h={isDrawer ? '24px' : '20px'} | ||
/> | ||
<Text | ||
fontSize="16px" | ||
fontWeight="400" | ||
_groupHover={{ | ||
color: 'red.800', | ||
fontWeight: '500', | ||
}} | ||
color={textColor} | ||
> | ||
Rename | ||
</Text> | ||
<Modal | ||
isOpen={isOpen} | ||
onClose={onClose} | ||
title="Rename the program" | ||
CTA={ | ||
<Button | ||
variant="primary" | ||
size="lg" | ||
onClick={updateProgramName} | ||
isLoading={isLoading} | ||
id="ipc-dashboard-update-programName-button" | ||
> | ||
OK | ||
</Button> | ||
} | ||
> | ||
<FormControl> | ||
<FormLabel color={textColor}>New program name</FormLabel> | ||
<Input | ||
type="text" | ||
w="100%" | ||
p="10px" | ||
my="4px" | ||
placeholder={program.name} | ||
onChange={(e: ChangeEvent<HTMLInputElement>) => setName(e.target.value)} | ||
id="ipc-dashboard-input-update-programame" | ||
/> | ||
</FormControl> | ||
</Modal> | ||
</HStack> | ||
); | ||
} | ||
|
||
export default RenameProgram; |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -34,6 +34,7 @@ class Computing { | |||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
public async load(): Promise<ResponseType> { | ||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||
if (this.account) { | ||||||||||||||||||||||||||||||||||||||
|
@@ -53,16 +54,15 @@ class Computing { | |||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
public async deleteProgram(programHash: string): Promise<ResponseType> { | ||||||||||||||||||||||||||||||||||||||
public async UpdateDeleteProgram(programHash: string): Promise<ResponseType> { | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This function is only deleting a program, not updating it ? |
||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||
if (this.account) { | ||||||||||||||||||||||||||||||||||||||
await forget.Publish({ | ||||||||||||||||||||||||||||||||||||||
const test = await forget.Publish({ | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
channel: ALEPH_CHANNEL, | ||||||||||||||||||||||||||||||||||||||
hashes: [programHash], | ||||||||||||||||||||||||||||||||||||||
storageEngine: ItemType.ipfs, | ||||||||||||||||||||||||||||||||||||||
storageEngine: ItemType.storage, | ||||||||||||||||||||||||||||||||||||||
account: this.account, | ||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
return { success: true, message: 'program deleted' }; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
return { success: false, message: 'Failed to load account' }; | ||||||||||||||||||||||||||||||||||||||
|
@@ -72,6 +72,29 @@ class Computing { | |||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
public async updateProgramName( | ||||||||||||||||||||||||||||||||||||||
concernedProgram: IPCProgram, | ||||||||||||||||||||||||||||||||||||||
newName: string, | ||||||||||||||||||||||||||||||||||||||
): Promise<ResponseType> { | ||||||||||||||||||||||||||||||||||||||
try { | ||||||||||||||||||||||||||||||||||||||
const copy = concernedProgram; | ||||||||||||||||||||||||||||||||||||||
await Promise.all( | ||||||||||||||||||||||||||||||||||||||
this.programs.map(async () => { | ||||||||||||||||||||||||||||||||||||||
copy.name = newName; | ||||||||||||||||||||||||||||||||||||||
copy.log.push({ | ||||||||||||||||||||||||||||||||||||||
action: `Renamed program to ${newName}`, | ||||||||||||||||||||||||||||||||||||||
date: Date.now(), | ||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||
Comment on lines
+80
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this will work 🤔 Maybe something like this:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw you can remove the |
||||||||||||||||||||||||||||||||||||||
await this.publishAggregate(); | ||||||||||||||||||||||||||||||||||||||
}), | ||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
return { success: true, message: 'Program name updated' }; | ||||||||||||||||||||||||||||||||||||||
} catch (err) { | ||||||||||||||||||||||||||||||||||||||
console.error(err); | ||||||||||||||||||||||||||||||||||||||
return { success: false, message: 'Failed to update program name' }; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
public async uploadProgram( | ||||||||||||||||||||||||||||||||||||||
myProgram: IPCProgram, | ||||||||||||||||||||||||||||||||||||||
uploadFile: File, | ||||||||||||||||||||||||||||||||||||||
|
@@ -82,20 +105,18 @@ class Computing { | |||||||||||||||||||||||||||||||||||||
if (this.account) { | ||||||||||||||||||||||||||||||||||||||
// remove old program from user's programs array | ||||||||||||||||||||||||||||||||||||||
if (isRedeploy && oldProgramHash) { | ||||||||||||||||||||||||||||||||||||||
const newProgramsArray: IPCProgram[] = this.programs.filter( | ||||||||||||||||||||||||||||||||||||||
const newProgramsArray: IPCProgram[] = this.programs.filter ( | ||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
(oldProgram: IPCProgram) => oldProgram !== oldProgramHash, | ||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||
this.programs = newProgramsArray; | ||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const programHashPublishProgram = await program.publish({ | ||||||||||||||||||||||||||||||||||||||
channel: ALEPH_CHANNEL, | ||||||||||||||||||||||||||||||||||||||
account: this.account, | ||||||||||||||||||||||||||||||||||||||
storageEngine: ItemType.storage, | ||||||||||||||||||||||||||||||||||||||
file: uploadFile, | ||||||||||||||||||||||||||||||||||||||
entrypoint: myProgram.entrypoint, | ||||||||||||||||||||||||||||||||||||||
}); | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
const newProgram: IPCProgram = { | ||||||||||||||||||||||||||||||||||||||
...myProgram, | ||||||||||||||||||||||||||||||||||||||
hash: programHashPublishProgram.item_hash, | ||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like it's still not properly linted 👀