Skip to content

Commit

Permalink
Fix false positive warning in migrations UI (#2227)
Browse files Browse the repository at this point in the history
  • Loading branch information
usenko-timur authored Apr 18, 2024
1 parent 7eb0ad9 commit 44c81ba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
4 changes: 2 additions & 2 deletions webui/src/models/migrations/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/* eslint-disable @typescript-eslint/ban-ts-comment */
import { sample } from 'effector';
import { createGate } from 'effector-react';
import { TypeOf, array, object, record, string } from 'zod';
import { TypeOf, array, object, record, string, union, unknown } from 'zod';

import { app } from 'src/models';
import { getMigrationsStates, migrationsMove, migrationsUp } from 'src/store/request/app.requests';

const schema = object({
data: object({
applied: record(array(string())),
applied: union([record(array(string())), array(unknown())]),
}),
});

Expand Down
46 changes: 21 additions & 25 deletions webui/src/pages/Migrations/components/MigrationsState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,33 @@ export const MigrationsState = () => {
const state = useStore(migrations.$migrationsState);
const data = useMemo(
() =>
Object.keys(state?.applied ?? {}).reduce((acc: { name: string; migrations: string }[], key) => {
const item = state?.applied?.[key];
if (item) {
acc.push({
name: key,
migrations: item.length > 0 ? item.join(', ') : '-',
});
}
!state?.applied || Array.isArray(state?.applied)
? []
: Object.keys(state.applied).reduce((acc: { name: string; migrations: string; hash: string }[], key) => {
const item = state?.applied?.[key];
if (item) {
acc.push({
name: key,
migrations: item.length > 0 ? item.join(', ') : '-',
hash: [...item].sort().join(','),
});
}

return acc;
}, []),
return acc;
}, []),
[state?.applied]
);

const withWarning = useMemo(
() =>
Object.keys(state?.applied ?? {}).reduce(
(acc, key) => {
if (!acc.result) {
const item = state?.applied?.[key];
if (item) {
const hash = [...item].sort().join(',');
acc.result = hash !== acc.hash;
acc.hash = hash;
}
}

data.reduce((acc, current, index, list) => {
if (acc || index <= 0) {
return acc;
},
{ result: false, hash: '' } as { result: boolean; hash: string }
).result,
[state?.applied]
}

return current.hash !== list[index - 1]?.hash;
}, false),
[data]
);

return (
Expand Down

0 comments on commit 44c81ba

Please sign in to comment.