-
Notifications
You must be signed in to change notification settings - Fork 89
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
feat(frontend): manage incoming auth tokens #2935
base: main
Are you sure you want to change the base?
Changes from 4 commits
9396d96
8dc334b
5aab138
0a1bdbf
f75bf30
2405bd3
ab51f51
825e11d
bb3293e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import type { ReactNode } from 'react' | ||
import { useEffect, useState } from 'react' | ||
import { Input } from './Input' | ||
import { Table } from './Table' | ||
import { FieldError } from './FieldError' | ||
import { Button } from './Button' | ||
|
||
type EditableTableProps = { | ||
name: string | ||
label: string | ||
options: EditableTableOption[] | ||
error?: string | string[] | ||
description?: ReactNode | ||
valueFormatter?: (values: string[]) => string | ||
required?: boolean | ||
} | ||
|
||
type EditableTableOption = { | ||
label: string | ||
value: string | ||
canDelete?: boolean | ||
canEdit?: boolean | ||
showInput?: boolean | ||
} | ||
|
||
export const EditableTable = ({ | ||
name, | ||
label, | ||
options, | ||
error, | ||
description = undefined, | ||
valueFormatter = (values) => values.join(','), | ||
required = false | ||
}: EditableTableProps) => { | ||
const [optionsList, setOptionsList] = useState<EditableTableOption[]>(options) | ||
const [value, setValue] = useState<string>('') | ||
|
||
const toggleEditInput = (index: number) => { | ||
setOptionsList( | ||
optionsList.map((option, i) => { | ||
if (i === index) { | ||
return { | ||
...option, | ||
showInput: true | ||
} | ||
} | ||
return option | ||
}) | ||
) | ||
} | ||
|
||
const editOption = (index: number, value: string) => { | ||
if (!value) { | ||
deleteOption(index) | ||
return | ||
} | ||
setOptionsList( | ||
optionsList.map((option, i) => { | ||
if (i === index) { | ||
return { | ||
...option, | ||
showInput: false, | ||
value | ||
} | ||
} | ||
return option | ||
}) | ||
) | ||
} | ||
|
||
const deleteOption = (index: number) => { | ||
setOptionsList(optionsList.filter((_, i) => i !== index)) | ||
} | ||
|
||
const addOption = () => { | ||
setOptionsList([ | ||
...optionsList, | ||
{ label: '', value: '', canDelete: true, canEdit: true, showInput: true } | ||
]) | ||
} | ||
|
||
useEffect(() => { | ||
setValue(getValue()) | ||
}, [optionsList]) | ||
|
||
const getValue = () => { | ||
return valueFormatter(optionsList.map((option) => option.value)) | ||
} | ||
furkan-bilgin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return ( | ||
<> | ||
<Input | ||
type='hidden' | ||
name={name} | ||
value={value} | ||
required={required} | ||
label={label} | ||
/> | ||
<Table> | ||
<Table.Head columns={['Token', 'Action']} /> | ||
<Table.Body> | ||
{(optionsList || []).map((option, index) => ( | ||
<Table.Row key={index}> | ||
<Table.Cell key={0}> | ||
{option.showInput ? ( | ||
<Input | ||
type='text' | ||
onKeyDown={(e) => | ||
e.key === 'Enter' && | ||
(e.preventDefault(), | ||
editOption(index, e.currentTarget.value)) | ||
} | ||
defaultValue={option.value} | ||
required={required} | ||
/> | ||
) : ( | ||
<span>{option.value}</span> | ||
)} | ||
</Table.Cell> | ||
<Table.Cell key={1}> | ||
{option.canEdit && !option.showInput ? ( | ||
<Button | ||
aria-label='edit' | ||
onClick={() => toggleEditInput(index)} | ||
> | ||
Edit | ||
</Button> | ||
) : null} | ||
{option.canDelete ? ( | ||
<Button | ||
className='ml-2' | ||
aria-label='delete' | ||
onClick={() => deleteOption(index)} | ||
> | ||
Delete | ||
</Button> | ||
) : null} | ||
</Table.Cell> | ||
</Table.Row> | ||
))} | ||
</Table.Body> | ||
</Table> | ||
<div className='flex justify-end mt-2'> | ||
<Button aria-label='add' onClick={() => addOption()}> | ||
Add | ||
</Button> | ||
</div> | ||
{description ? ( | ||
<div className='font-medium text-sm'>{description}</div> | ||
) : null} | ||
<FieldError error={error} /> | ||
</> | ||
) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,7 @@ export const getPeer = async (args: QueryPeerArgs) => { | |
authToken | ||
} | ||
} | ||
incomingTokens | ||
} | ||
} | ||
`, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
I think
incomingTokens
would probably benefit from a separate resolver kind of likeliquidity
is done. Checkpackages/backend/src/graphql/resolvers/index.ts
. This will require a new function in theHttpTokenService
instead of doing.withGraphFetched('incomingTokens')
in the getter in peer service.