|
|
@ -1,13 +1,17 @@
|
|
|
|
import { useCallback, useMemo, useState } from "react";
|
|
|
|
import { useCallback, useMemo, useState } from "react";
|
|
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
import { useNavigate } from "react-router-dom";
|
|
|
|
import { Column, useRowSelect } from "react-table";
|
|
|
|
import { Column, useRowSelect } from "react-table";
|
|
|
|
import { Box, Container } from "@mantine/core";
|
|
|
|
import { Box, Container, useCombobox } from "@mantine/core";
|
|
|
|
import { faCheck, faUndo } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
import { faCheck, faUndo } from "@fortawesome/free-solid-svg-icons";
|
|
|
|
import { UseMutationResult } from "@tanstack/react-query";
|
|
|
|
import { UseMutationResult } from "@tanstack/react-query";
|
|
|
|
import { uniqBy } from "lodash";
|
|
|
|
import { uniqBy } from "lodash";
|
|
|
|
import { useIsAnyMutationRunning, useLanguageProfiles } from "@/apis/hooks";
|
|
|
|
import { useIsAnyMutationRunning, useLanguageProfiles } from "@/apis/hooks";
|
|
|
|
import { SimpleTable, Toolbox } from "@/components";
|
|
|
|
import {
|
|
|
|
import { Selector, SelectorOption } from "@/components/inputs";
|
|
|
|
GroupedSelector,
|
|
|
|
|
|
|
|
GroupedSelectorOptions,
|
|
|
|
|
|
|
|
SimpleTable,
|
|
|
|
|
|
|
|
Toolbox,
|
|
|
|
|
|
|
|
} from "@/components";
|
|
|
|
import { useCustomSelection } from "@/components/tables/plugins";
|
|
|
|
import { useCustomSelection } from "@/components/tables/plugins";
|
|
|
|
import { GetItemId, useSelectorOptions } from "@/utilities";
|
|
|
|
import { GetItemId, useSelectorOptions } from "@/utilities";
|
|
|
|
|
|
|
|
|
|
|
@ -36,10 +40,26 @@ function MassEditor<T extends Item.Base>(props: MassEditorProps<T>) {
|
|
|
|
|
|
|
|
|
|
|
|
const profileOptions = useSelectorOptions(profiles ?? [], (v) => v.name);
|
|
|
|
const profileOptions = useSelectorOptions(profiles ?? [], (v) => v.name);
|
|
|
|
|
|
|
|
|
|
|
|
const profileOptionsWithAction = useMemo<SelectorOption<Language.Profile>[]>(
|
|
|
|
const profileOptionsWithAction = useMemo<
|
|
|
|
() => [...profileOptions.options],
|
|
|
|
GroupedSelectorOptions<string>[]
|
|
|
|
[profileOptions.options],
|
|
|
|
>(() => {
|
|
|
|
);
|
|
|
|
return [
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
group: "Actions",
|
|
|
|
|
|
|
|
items: [{ label: "Clear", value: "", profileId: null }],
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
group: "Profiles",
|
|
|
|
|
|
|
|
items: profileOptions.options.map((a) => {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
value: a.value.profileId.toString(),
|
|
|
|
|
|
|
|
label: a.label,
|
|
|
|
|
|
|
|
profileId: a.value.profileId,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}),
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}, [profileOptions.options]);
|
|
|
|
|
|
|
|
|
|
|
|
const getKey = useCallback((value: Language.Profile | null) => {
|
|
|
|
const getKey = useCallback((value: Language.Profile | null) => {
|
|
|
|
if (value) {
|
|
|
|
if (value) {
|
|
|
@ -94,8 +114,7 @@ function MassEditor<T extends Item.Base>(props: MassEditorProps<T>) {
|
|
|
|
}, [dirties, mutateAsync]);
|
|
|
|
}, [dirties, mutateAsync]);
|
|
|
|
|
|
|
|
|
|
|
|
const setProfiles = useCallback(
|
|
|
|
const setProfiles = useCallback(
|
|
|
|
(profile: Language.Profile | null) => {
|
|
|
|
(id: number | null) => {
|
|
|
|
const id = profile?.profileId ?? null;
|
|
|
|
|
|
|
|
const newItems = selections.map((v) => ({ ...v, profileId: id }));
|
|
|
|
const newItems = selections.map((v) => ({ ...v, profileId: id }));
|
|
|
|
|
|
|
|
|
|
|
|
setDirties((dirty) => {
|
|
|
|
setDirties((dirty) => {
|
|
|
@ -105,18 +124,29 @@ function MassEditor<T extends Item.Base>(props: MassEditorProps<T>) {
|
|
|
|
[selections],
|
|
|
|
[selections],
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const combobox = useCombobox();
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Container fluid px={0}>
|
|
|
|
<Container fluid px={0}>
|
|
|
|
<Toolbox>
|
|
|
|
<Toolbox>
|
|
|
|
<Box>
|
|
|
|
<Box>
|
|
|
|
<Selector
|
|
|
|
<GroupedSelector
|
|
|
|
allowDeselect
|
|
|
|
onClick={() => combobox.openDropdown()}
|
|
|
|
|
|
|
|
onDropdownClose={() => {
|
|
|
|
|
|
|
|
combobox.resetSelectedOption();
|
|
|
|
|
|
|
|
}}
|
|
|
|
placeholder="Change Profile"
|
|
|
|
placeholder="Change Profile"
|
|
|
|
|
|
|
|
withCheckIcon={false}
|
|
|
|
options={profileOptionsWithAction}
|
|
|
|
options={profileOptionsWithAction}
|
|
|
|
getkey={getKey}
|
|
|
|
getkey={getKey}
|
|
|
|
disabled={selections.length === 0}
|
|
|
|
disabled={selections.length === 0}
|
|
|
|
onChange={setProfiles}
|
|
|
|
comboboxProps={{
|
|
|
|
></Selector>
|
|
|
|
store: combobox,
|
|
|
|
|
|
|
|
onOptionSubmit: (value) => {
|
|
|
|
|
|
|
|
setProfiles(value ? +value : null);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
></GroupedSelector>
|
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
<Box>
|
|
|
|
<Box>
|
|
|
|
<Toolbox.Button icon={faUndo} onClick={onEnded}>
|
|
|
|
<Toolbox.Button icon={faUndo} onClick={onEnded}>
|
|
|
|