Skip to content

Commit

Permalink
fix(metadata): fix cancel not working on metadata dropzone
Browse files Browse the repository at this point in the history
  • Loading branch information
cberthou committed Oct 20, 2022
1 parent a1bfbff commit fbe380a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
Expand Up @@ -11,6 +11,7 @@ import { MetadataModalPreview } from "./MetadataModalPreview";
import type {
MetadataModalContext,
MetadataModalState,
SimpleMetadataEvents,
} from "./MetadataModalStateMachine";
import { metadataModalMachine } from "./MetadataModalStateMachine";
import type {
Expand All @@ -29,7 +30,7 @@ const getActionsByState = (state: MetadataModalState): ModalAction[] => {
if (state.matches("importDropzone")) {
return [
{
id: "cancel",
id: "ABORT",
label: "cancel",
},
];
Expand Down Expand Up @@ -100,18 +101,8 @@ export const MetadataModalContainer: React.FC<ImportModalContainerProps> = ({
});
};

const onAction = (actionId: string) => {
if (actionId === "IMPORT") {
send("IMPORT");
}

if (actionId === "LOAD_METADATA") {
send("LOAD_METADATA");
}

if (actionId === "LOAD_METADATA") {
send("LOAD_METADATA");
}
const onAction = (actionId: SimpleMetadataEvents["type"]) => {
send(actionId);
};

const actions = getActionsByState(state);
Expand Down
Expand Up @@ -9,6 +9,7 @@ import styled from "styled-components";

import { useStyles } from "../../../hooks/use-styles";
import { ModalHeader } from "../modal-header";
import type { SimpleMetadataEvents } from "./MetadataModalStateMachine";
import type { ModalAction } from "./MetadataModalTypes";

interface ModalProps {
Expand All @@ -18,7 +19,7 @@ interface ModalProps {

interface MetadataModalContentProps extends ModalProps {
actions: ModalAction[];
onAction: (actionId: string) => void;
onAction: (actionId: SimpleMetadataEvents["type"]) => void;
}

const StyledPaper = styled(Paper)`
Expand Down
Expand Up @@ -38,10 +38,7 @@ interface FieldsConfigChanged {
type: "FIELDS_CONFIG_CHANGED";
}

type Events =
| ConfigChanged
| FieldsConfigChanged
| FilePathPicked
export type SimpleMetadataEvents =
| { type: "ABORT" }
| { type: "CONTINUE" }
| { type: "FULFIL" }
Expand All @@ -50,9 +47,18 @@ type Events =
| { type: "REJECT" }
| { type: "RETRY" };

export type MetadataModalState = State<MetadataModalContext, Events>;
export type MetadataEvents =
| ConfigChanged
| FieldsConfigChanged
| FilePathPicked
| SimpleMetadataEvents;

export type MetadataModalState = State<MetadataModalContext, MetadataEvents>;

export const metadataModalMachine = createMachine<MetadataModalContext, Events>(
export const metadataModalMachine = createMachine<
MetadataModalContext,
MetadataEvents
>(
{
context: {
config: defaultConfig,
Expand All @@ -67,12 +73,13 @@ export const metadataModalMachine = createMachine<MetadataModalContext, Events>(
predictableActionArguments: true,
schema: {
context: {} as MetadataModalContext,
events: {} as Events,
events: {} as MetadataEvents,
},
states: {
importDropzone: {
id: "importDropzone",
on: {
ABORT: "metadataView",
FILE_PATH_PICKED: {
actions: assign<MetadataModalContext, FilePathPicked>({
filePath: (context, event) => event.filePath,
Expand Down
@@ -1,5 +1,7 @@
import type { LoadCsvFileToArrayOptions } from "@common/utils/csv";

import type { SimpleMetadataEvents } from "./MetadataModalStateMachine";

export type ImportModalState = "importDropzone" | "importPreview" | "view";

export interface MetadataImportConfig {
Expand All @@ -8,7 +10,7 @@ export interface MetadataImportConfig {
}

export interface ModalAction {
id: string;
id: SimpleMetadataEvents["type"];
label: string;
}

Expand Down
Expand Up @@ -21,11 +21,10 @@ export const MetadataModalView: FC<MetadataModalViewProps> = ({
metadataList,
}) => {
const [mapping, setMapping] = useSedaMapping();
console.log(mapping);

const onMappingChange =
(metadataId: string): SedaPropertySelectorProps["onChange"] =>
(field) => {
console.log(metadataId, field);
setMapping({
...mapping,
[metadataId]: field,
Expand Down

0 comments on commit fbe380a

Please sign in to comment.