-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
9 changed files
with
217 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useCallback, useState } from "react"; | ||
|
||
export default function ActionsCell({ table, row: { original } }) { | ||
const [running, setRunning] = useState(false); | ||
|
||
const runDelete = useCallback(async () => { | ||
setRunning(true); | ||
await table.options.meta?.deleteRow({ id: original.id }); | ||
setRunning(false); | ||
}, [original.id, table.options]); | ||
|
||
return ( | ||
<div className="flex"> | ||
<button | ||
disabled={running} | ||
className="btn bg-red-500 text-white" | ||
onClick={runDelete} | ||
> | ||
<i className={`fas ${running ? "fa-spin fa-spinner" : "fa-trash"}`}></i> | ||
</button> | ||
</div> | ||
); | ||
} |
51 changes: 51 additions & 0 deletions
51
src/frontend/src/samples/components/Cell/MultiSelectCell.jsx
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,51 @@ | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import { useEffect, useMemo, useState } from "react"; | ||
import AsyncSelect from "react-select/async"; | ||
|
||
const datePortal = document.getElementById('date-portal'); | ||
|
||
export default function MultiSelectCell({ | ||
getValue, | ||
row: { original }, | ||
column: { id }, | ||
table, | ||
loadOptions, | ||
queryKey, | ||
idField = 'id', | ||
labelField = 'name', | ||
}) { | ||
const queryClient = useQueryClient(); | ||
const initialValue = getValue(); | ||
const [value, setValue] = useState(initialValue); | ||
|
||
// When the input is blurred, we'll call our table meta's updateData function | ||
const handleBlur = () => { | ||
if (value !== initialValue) { | ||
console.log(value) | ||
table.options.meta?.updateData({ id: original.id, [id]: value.map(v => v[idField]) }); | ||
} | ||
}; | ||
|
||
// If the initialValue is changed external, sync it up with our state | ||
useEffect(() => { | ||
setValue(initialValue || ""); | ||
}, [initialValue]); | ||
|
||
const load = async (input) => await queryClient.fetchQuery({ queryKey: [queryKey, input], queryFn: () => loadOptions(input) }); | ||
|
||
return ( | ||
<AsyncSelect | ||
isMulti | ||
defaultOptions | ||
loadOptions={load} | ||
getOptionLabel={(o) => o[labelField]} | ||
getOptionValue={(o) => o[idField]} | ||
onBlur={handleBlur} | ||
classNamePrefix="react-select" | ||
className="" | ||
value={value} | ||
onChange={setValue} | ||
menuPortalTarget={datePortal} | ||
/> | ||
); | ||
} |
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,47 @@ | ||
import { useQueryClient } from "@tanstack/react-query"; | ||
import { useEffect, useMemo, useState } from "react"; | ||
import AsyncSelect from "react-select/async"; | ||
|
||
const datePortal = document.getElementById('date-portal'); | ||
|
||
export default function SelectCell({ | ||
getValue, | ||
row: { original }, | ||
column: { id }, | ||
table, | ||
loadOptions, | ||
queryKey, | ||
}) { | ||
const queryClient = useQueryClient(); | ||
const initialValue = getValue(); | ||
const [value, setValue] = useState(initialValue); | ||
|
||
// When the input is blurred, we'll call our table meta's updateData function | ||
const handleBlur = () => { | ||
if (value !== initialValue) { | ||
table.options.meta?.updateData({ id: original.id, [id]: value.id }); | ||
} | ||
}; | ||
|
||
// If the initialValue is changed external, sync it up with our state | ||
useEffect(() => { | ||
setValue(initialValue || ""); | ||
}, [initialValue]); | ||
|
||
const load = async (input) => await queryClient.fetchQuery({ queryKey: [queryKey, input], queryFn: () => loadOptions(input) }); | ||
|
||
return ( | ||
<AsyncSelect | ||
defaultOptions | ||
loadOptions={load} | ||
getOptionLabel={(o) => o.name} | ||
getOptionValue={(o) => o.id} | ||
onBlur={handleBlur} | ||
classNamePrefix="react-select" | ||
className="" | ||
value={value} | ||
onChange={setValue} | ||
menuPortalTarget={datePortal} | ||
/> | ||
); | ||
} |
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
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