Skip to content
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

fix(ui-common): download latest value in MatrixInput component #1962

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(ui-common): dowload latest value in MatrixInput component
skamril committed Mar 4, 2024
commit 9354068ef64317f98289a92a276793cab863e504
57 changes: 35 additions & 22 deletions webapp/src/components/common/MatrixInput/index.tsx
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ import ImportDialog from "../dialogs/ImportDialog";
import MatrixAssignDialog from "./MatrixAssignDialog";
import { downloadMatrix } from "../../../utils/matrixUtils";
import { fetchMatrixFn } from "../../App/Singlestudy/explore/Modelization/Areas/Hydro/utils";
import { LoadingButton } from "@mui/lab";

const logErr = debug("antares:createimportform:error");

@@ -56,29 +57,16 @@ function MatrixInput({
const [t] = useTranslation();
const [openImportDialog, setOpenImportDialog] = useState(false);
const [openMatrixAsignDialog, setOpenMatrixAsignDialog] = useState(false);
const [isDownloading, setIsDownloading] = useState(false);

const {
data: matrixData,
isLoading,
reload: reloadMatrix,
} = usePromiseWithSnackbarError(
async () => {
const res = fetchFn
? await fetchFn(study.id)
: await getStudyData(study.id, url);
if (typeof res === "string") {
const fixed = res
.replace(/NaN/g, '"NaN"')
.replace(/Infinity/g, '"Infinity"');
return JSON.parse(fixed);
}
return res;
},
{
errorMessage: t("data.error.matrix"),
deps: [study, url],
},
);
} = usePromiseWithSnackbarError(fetchMatrixData, {
errorMessage: t("data.error.matrix"),
deps: [study.id, url, fetchFn],
});

const { data: matrixIndex } = usePromiseWithSnackbarError(
async () => {
@@ -99,6 +87,23 @@ function MatrixInput({
*/
const rowNames = fetchFn ? matrixIndex : initialRowNames;

////////////////////////////////////////////////////////////////
// Utils
////////////////////////////////////////////////////////////////

async function fetchMatrixData() {
const res = fetchFn
? await fetchFn(study.id)
: await getStudyData(study.id, url);
if (typeof res === "string") {
const fixed = res
.replace(/NaN/g, '"NaN"')
.replace(/Infinity/g, '"Infinity"');
return JSON.parse(fixed);
}
return res;
}

////////////////////////////////////////////////////////////////
// Event Handlers
////////////////////////////////////////////////////////////////
@@ -133,8 +138,14 @@ function MatrixInput({
}
};

const handleDownload = (matrixData: MatrixType, fileName: string): void => {
downloadMatrix(matrixData, fileName);
const handleDownload = async (matrixData: MatrixType, fileName: string) => {
setIsDownloading(true);

// Re-fetch to get latest data
const data = await fetchMatrixData();
downloadMatrix(data, fileName);

setIsDownloading(false);
};

////////////////////////////////////////////////////////////////
@@ -179,10 +190,12 @@ function MatrixInput({
</Button>

{matrixData?.columns?.length >= 1 && (
<Button
<LoadingButton
sx={{
ml: 2,
}}
loadingPosition="start"
loading={isDownloading}
variant="outlined"
color="primary"
startIcon={<DownloadOutlinedIcon />}
@@ -194,7 +207,7 @@ function MatrixInput({
}
>
{t("global.download")}
</Button>
</LoadingButton>
)}
</Box>
</Header>

Unchanged files with check annotations Beta

import ConfirmationDialog from "../../../../../common/dialogs/ConfirmationDialog";
import LinearProgressWithLabel from "../../../../../common/LinearProgressWithLabel";
export const ColorStatus = {

Check warning on line 33 in webapp/src/components/App/Singlestudy/HomeView/InformationView/LauncherHistory/JobStepper.tsx

GitHub Actions / npm-test (ubuntu-20.04)

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
running: "warning.main",
pending: "grey.400",
success: "success.main",
apiRef?: React.Ref<UseFormReturnPlus<TFieldValues, TContext> | undefined>;
}
export function useFormContextPlus<TFieldValues extends FieldValues>() {

Check warning on line 86 in webapp/src/components/common/Form/index.tsx

GitHub Actions / npm-test (ubuntu-20.04)

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
return useFormContextOriginal() as UseFormReturnPlus<TFieldValues>;
}
};
}
function BooleanFE(props: BooleanFEProps) {

Check warning on line 32 in webapp/src/components/common/fieldEditors/BooleanFE.tsx

GitHub Actions / npm-test (ubuntu-20.04)

Fast refresh only works when a file only exports components. Move your component(s) to a separate file
const {
defaultValue,
value,
);
}
export default reactHookFormSupport({ defaultValue: false })(BooleanFE);

Check warning on line 65 in webapp/src/components/common/fieldEditors/BooleanFE.tsx

GitHub Actions / npm-test (ubuntu-20.04)

Fast refresh can't handle anonymous components. Add a name to your export
helperText?: React.ReactNode;
}
function CheckBoxFE(props: CheckBoxFEProps) {

Check warning on line 21 in webapp/src/components/common/fieldEditors/CheckBoxFE.tsx

GitHub Actions / npm-test (ubuntu-20.04)

Fast refresh only works when a file only exports components. Move your component(s) to a separate file
const {
value,
defaultValue,
);
}
export default reactHookFormSupport({ defaultValue: false })(CheckBoxFE);

Check warning on line 58 in webapp/src/components/common/fieldEditors/CheckBoxFE.tsx

GitHub Actions / npm-test (ubuntu-20.04)

Fast refresh can't handle anonymous components. Add a name to your export
// TODO Add `onChange`'s value in `inputRef` and `onBlur`'s event
function CheckboxesTagsFE<

Check warning on line 45 in webapp/src/components/common/fieldEditors/CheckboxesTagsFE.tsx

GitHub Actions / npm-test (ubuntu-20.04)

Fast refresh only works when a file only exports components. Move your component(s) to a separate file
T,
DisableClearable extends boolean | undefined = undefined,
FreeSolo extends boolean | undefined = undefined,
defaultValue?: string;
};
function ColorPickerFE(props: ColorPickerFEProps) {

Check warning on line 19 in webapp/src/components/common/fieldEditors/ColorPickerFE/index.tsx

GitHub Actions / npm-test (ubuntu-20.04)

Fast refresh only works when a file only exports components. Move your component(s) to a separate file
const { value, defaultValue, onChange, sx, inputRef, ...textFieldProps } =
props;
const [currentColor, setCurrentColor] = useState(defaultValue || value || "");
);
}
export default reactHookFormSupport({ defaultValue: "" })(ColorPickerFE);

Check warning on line 116 in webapp/src/components/common/fieldEditors/ColorPickerFE/index.tsx

GitHub Actions / npm-test (ubuntu-20.04)

Fast refresh can't handle anonymous components. Add a name to your export
helperText?: string;
}
function ListFE<TItem, TOption>(props: ListFEProps<TItem, TOption>) {

Check warning on line 62 in webapp/src/components/common/fieldEditors/ListFE/index.tsx

GitHub Actions / npm-test (ubuntu-20.04)

Fast refresh only works when a file only exports components. Move your component(s) to a separate file
const {
value,
defaultValue,