Closes https://github.com/twentyhq/core-team-issues/issues/250 https://github.com/user-attachments/assets/9c120188-497d-4273-9137-f8d0de3bd884
130 lines
4.2 KiB
TypeScript
130 lines
4.2 KiB
TypeScript
import { actionMenuEntriesComponentState } from '@/action-menu/states/actionMenuEntriesComponentState';
|
|
import { contextStoreCurrentObjectMetadataIdComponentState } from '@/context-store/states/contextStoreCurrentObjectMetadataIdComponentState';
|
|
import { contextStoreCurrentViewIdComponentState } from '@/context-store/states/contextStoreCurrentViewIdComponentState';
|
|
import { contextStoreCurrentViewTypeComponentState } from '@/context-store/states/contextStoreCurrentViewTypeComponentState';
|
|
import { contextStoreFiltersComponentState } from '@/context-store/states/contextStoreFiltersComponentState';
|
|
import { contextStoreNumberOfSelectedRecordsComponentState } from '@/context-store/states/contextStoreNumberOfSelectedRecordsComponentState';
|
|
import { contextStoreTargetedRecordsRuleComponentState } from '@/context-store/states/contextStoreTargetedRecordsRuleComponentState';
|
|
import { useRecoilCallback } from 'recoil';
|
|
|
|
export const useCopyContextStoreStates = () => {
|
|
const copyContextStoreStates = useRecoilCallback(
|
|
({ snapshot, set }) =>
|
|
({
|
|
instanceIdToCopyFrom,
|
|
instanceIdToCopyTo,
|
|
}: {
|
|
instanceIdToCopyFrom: string;
|
|
instanceIdToCopyTo: string;
|
|
}) => {
|
|
const contextStoreCurrentObjectMetadataId = snapshot
|
|
.getLoadable(
|
|
contextStoreCurrentObjectMetadataIdComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyFrom,
|
|
}),
|
|
)
|
|
.getValue();
|
|
|
|
set(
|
|
contextStoreCurrentObjectMetadataIdComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyTo,
|
|
}),
|
|
contextStoreCurrentObjectMetadataId,
|
|
);
|
|
|
|
const contextStoreTargetedRecordsRule = snapshot
|
|
.getLoadable(
|
|
contextStoreTargetedRecordsRuleComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyFrom,
|
|
}),
|
|
)
|
|
.getValue();
|
|
|
|
set(
|
|
contextStoreTargetedRecordsRuleComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyTo,
|
|
}),
|
|
contextStoreTargetedRecordsRule,
|
|
);
|
|
|
|
const contextStoreNumberOfSelectedRecords = snapshot
|
|
.getLoadable(
|
|
contextStoreNumberOfSelectedRecordsComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyFrom,
|
|
}),
|
|
)
|
|
.getValue();
|
|
|
|
set(
|
|
contextStoreNumberOfSelectedRecordsComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyTo,
|
|
}),
|
|
contextStoreNumberOfSelectedRecords,
|
|
);
|
|
|
|
const contextStoreFilters = snapshot
|
|
.getLoadable(
|
|
contextStoreFiltersComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyFrom,
|
|
}),
|
|
)
|
|
.getValue();
|
|
|
|
set(
|
|
contextStoreFiltersComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyTo,
|
|
}),
|
|
contextStoreFilters,
|
|
);
|
|
|
|
const contextStoreCurrentViewId = snapshot
|
|
.getLoadable(
|
|
contextStoreCurrentViewIdComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyFrom,
|
|
}),
|
|
)
|
|
.getValue();
|
|
|
|
set(
|
|
contextStoreCurrentViewIdComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyTo,
|
|
}),
|
|
contextStoreCurrentViewId,
|
|
);
|
|
|
|
const contextStoreCurrentViewType = snapshot
|
|
.getLoadable(
|
|
contextStoreCurrentViewTypeComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyFrom,
|
|
}),
|
|
)
|
|
.getValue();
|
|
|
|
set(
|
|
contextStoreCurrentViewTypeComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyTo,
|
|
}),
|
|
contextStoreCurrentViewType,
|
|
);
|
|
|
|
const actionMenuEntries = snapshot
|
|
.getLoadable(
|
|
actionMenuEntriesComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyFrom,
|
|
}),
|
|
)
|
|
.getValue();
|
|
|
|
set(
|
|
actionMenuEntriesComponentState.atomFamily({
|
|
instanceId: instanceIdToCopyTo,
|
|
}),
|
|
actionMenuEntries,
|
|
);
|
|
},
|
|
[],
|
|
);
|
|
|
|
return { copyContextStoreStates };
|
|
};
|