Skip to content

Commit

Permalink
Merge pull request #896 from InseeFr/feat/improve-delete-dataset
Browse files Browse the repository at this point in the history
feat: improve dataset deletion
  • Loading branch information
PierreVasseur authored Aug 26, 2024
2 parents 95a7027 + a64fe83 commit 1fa11a7
Show file tree
Hide file tree
Showing 61 changed files with 533 additions and 287 deletions.
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const queryClient = new QueryClient({
},
});

const Error = () => {
const ErrorBlock = () => {
return (
<div>
<div className="container">
Expand All @@ -41,7 +41,7 @@ GeneralApi.getInit()
.then(
(res: any) => (res.ok ? res.json() : Promise.reject(res.statusText)),
(err: any) => {
renderApp(Error, {}, { home: true });
renderApp(ErrorBlock, {}, { home: true });
return Promise.reject(err.toString());
}
)
Expand Down
4 changes: 2 additions & 2 deletions src/packages/auth/components/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const mapDispatchToProps = {
type AuthDumbTypes = {
userRoles?: string[];
userStamp?: string;
roles: string[];
roles: Array<string | [string, (value: string) => boolean]>;
fallback?: any;
complementaryCheck?: boolean;
loadUserStamp?: any;
Expand Down Expand Up @@ -49,7 +49,7 @@ export function AuthDumb({
const isAuthorized = !!roles.find((role) => {
if (Array.isArray(role)) {
const [r, check] = role;
return userRoles?.includes(r) && check(userStamp);
return userRoles?.includes(r) && check(userStamp!);
}
return userRoles?.includes(role);
});
Expand Down
26 changes: 15 additions & 11 deletions src/packages/components/errors-bloc/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,19 @@ export const ErrorBloc = ({
return errorMsg;
});

return formattedErrors.map((e, index) => (
<div
key={index}
className="bauhaus-error-bloc alert alert-danger"
role="alert"
>
{<div dangerouslySetInnerHTML={{ __html: e }} /> || (
<span style={{ whiteSpace: 'pre-wrap' }}> </span>
)}
</div>
));
return (
<>
{formattedErrors.map((e, index) => (
<div
key={index}
className="bauhaus-error-bloc alert alert-danger"
role="alert"
>
{<div dangerouslySetInnerHTML={{ __html: e }} /> || (
<span style={{ whiteSpace: 'pre-wrap' }}> </span>
)}
</div>
))}
</>
);
};
1 change: 1 addition & 0 deletions src/packages/components/explanatory-note/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const ExplanatoryNote = ({
/href="http:\/\/.+?\/codes\/(.+?)\/.+?\/(.+?)"/g,
`href="${window.location.origin}/classifications/classification/$1/item/$2"`
);

return (
<Note
title={title}
Expand Down
4 changes: 2 additions & 2 deletions src/packages/components/tabs/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export const Tabs = ({
<BootstrapTabs
id={id}
defaultActiveKey={0}
onSelect={(index: number) => setActiveTab(index)}
onSelect={setActiveTab}
justified
>
{tabs.map((t, i) => (
<BootstrapTab
key={`tab${i}`}
key={t.title}
eventKey={i}
title={t.title}
disabled={t.disabled}
Expand Down
14 changes: 14 additions & 0 deletions src/packages/model/Classification.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type Classification = {
general: {
id: string;
prefLabelLg1: string;
prefLabelLg2: string;
scopeNoteLg1: string;
scopeNoteLg2: string;
changeNoteLg1: string;
changeNoteLg2: string;
descriptionLg1: string;
descriptionLg2: string;
};
levels: unknown[];
};
6 changes: 6 additions & 0 deletions src/packages/model/Dataset.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type Dataset = {
id?: string;
};
export type Distribution = {
id?: string;
};
4 changes: 4 additions & 0 deletions src/packages/model/ServerSideError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type ServerSideError = {
code: number;
message: string;
};
4 changes: 4 additions & 0 deletions src/packages/model/Sims.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export type Rubric = {
idAttribute: string;
};

export type Sims = {
creators: string[];
};
6 changes: 6 additions & 0 deletions src/packages/model/operations/document.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Sims } from '../Sims';

export type Document = {
id: string;
sims: Sims[];
};
6 changes: 3 additions & 3 deletions src/packages/modules-classifications/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export const useClassification = (id) => {
export const usePublishClassification = (id) => {
const queryClient = useQueryClient();
const {
isLoading: isPublishing,
isPending: isPublishing,
mutate: publish,
error,
} = useMutation({
mutationFn: (id) => {
mutationFn: () => {
return ClassificationsApi.publishClassification(id);
},

Expand All @@ -37,7 +37,7 @@ export const usePublishClassification = (id) => {
export const useUpdateClassification = (id) => {
const queryClient = useQueryClient();
const {
isLoading: isSaving,
isPending: isSaving,
mutate: save,
error,
isSuccess: isSavingSuccess,
Expand Down
7 changes: 2 additions & 5 deletions src/packages/modules-classifications/item/edition/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const ClassificationItemEdition = () => {
true
);

const { data: previousLevels = [], isLoading: isPreviousLevelsLoading } =
const { data: previousLevels = [], isPending: isPreviousLevelsLoading } =
useQuery({
queryKey: ['classification-parent-levels', classificationId, itemId],
queryFn: () => {
Expand Down Expand Up @@ -117,10 +117,7 @@ const ClassificationItemEdition = () => {
});

Object.entries(value).forEach(([key]) => {
if (
key.indexOf('altLabelsLg1_') === 0 ||
key.indexOf('altLabelsLg2_') === 0
) {
if (key.startsWith('altLabelsLg1_') || key.startsWith('altLabelsLg2_')) {
delete value[key];
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { useSelector } from 'react-redux';
import ClassificationVisualization from './home';
import { Loading } from '../../components';
import { useClassification, usePublishClassification } from '../hooks';
import { getLocales, getPermission } from '../../redux/selectors';
import { getLocales } from '../../redux/selectors';
import { getSecondLang } from '../../redux/second-lang';
import { ReduxModel } from '../../redux/model';

const ClassificationVisualizationContainer = () => {
const { id } = useParams();
const langs = useSelector((state) => getLocales(state));
const secondLang = useSelector((state) => getSecondLang(state));
const permission = useSelector((state) => getPermission(state));
const { id } = useParams<{ id: string }>();
const langs = useSelector((state: ReduxModel) => getLocales(state));
const secondLang = useSelector((state: ReduxModel) => getSecondLang(state));

const { isLoading, classification } = useClassification(id);
const { isPublishing, publish, error } = usePublishClassification();
const { isPublishing, publish, error } = usePublishClassification(id);

if (isLoading) {
return <Loading />;
Expand All @@ -28,8 +28,7 @@ const ClassificationVisualizationContainer = () => {
classificationId={id}
secondLang={secondLang}
langs={langs}
permission={permission}
publish={() => publish(id)}
publish={publish}
serverSideError={error}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@ import Notes from './notes';
import Levels from './levels';
import D from '../../deprecated-locales';
import { useTitle } from '../../utils/hooks/useTitle';
import { Classification } from '../../model/Classification';

const ClassificationVisualization = (props) => {
const {
classification: { general, levels },
classificationId,
secondLang,
langs,
publish,
serverSideError,
} = props;
type ClassificationVisualizationTypes = {
classification: Classification;
classificationId: string;
secondLang?: boolean;
langs: { lg1: string; lg2: string };
publish: () => void;
serverSideError?: any;
};
const ClassificationVisualization = ({
classification: { general, levels },
classificationId,
secondLang,
langs,
publish,
serverSideError,
}: ClassificationVisualizationTypes) => {
useTitle(D.classificationsTitle, general?.prefLabelLg1);

const notes = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { useSelector } from 'react-redux';
import {
ActionToolbar,
ReturnButton,
SaveButton,
UpdateButton,
} from '@inseefr/wilco';
import { getPermission } from '../../../redux/selectors';
import { ADMIN, CODELIST_CONTRIBUTOR } from '../../../auth/roles';
import { usePermission } from '../../../redux/hooks/usePermission';
export const CodeSlidingPanelMenu = ({
codelist,
handleSubmit,
handleBack,
creation,
}) => {
const permission = useSelector(getPermission);
const permission = usePermission();

const hasRightsBasedOnStamp =
permission?.stamp === codelist?.contributor &&
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import D from '../../i18n/build-dictionary';
import { useSelector } from 'react-redux';
import { ADMIN, CODELIST_CONTRIBUTOR } from '../../../auth/roles';
import { getPermission } from '../../../redux/selectors';
import { usePermission } from '../../../redux/hooks/usePermission';

export const CodesPanelAddButton = ({ codelist, onHandlePanel }) => {
const permission = useSelector(getPermission);
const permission = usePermission();

if (!codelist.lastCodeUriSegment) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import D, { D1, D2 } from '../../i18n/build-dictionary';
import './edit.scss';
import MainDictionary from '../../../deprecated-locales/build-dictionary';
import { CodesCollapsiblePanel } from './codes-panel';
import { useSelector } from 'react-redux';
import {
TextInput,
Row,
Expand All @@ -23,8 +22,8 @@ import {
Select,
} from '../../../components';
import { useTitle } from '../../../utils/hooks/useTitle';
import { getPermission } from '../../../redux/selectors';
import { ADMIN, CODELIST_CONTRIBUTOR } from '../../../auth/roles';
import { usePermission } from '../../../redux/hooks/usePermission';

const defaultCodelist = {
created: dayjs(),
Expand All @@ -43,7 +42,7 @@ export const DumbCodelistDetailEdit = ({

useTitle(D.codelistsTitle, codelist?.labelLg1 || D.codelistsCreateTitle);

const permission = useSelector(getPermission);
const permission = usePermission();
const stamp = permission?.stamp;
const isContributor =
permission?.roles?.includes(CODELIST_CONTRIBUTOR) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import {
ReturnButton,
UpdateButton,
} from '@inseefr/wilco';
import { useSelector } from 'react-redux';
import { UNPUBLISHED } from '../../..//model/ValidationState';
import { ValidationButton } from '../../../components';
import { ADMIN, CODELIST_CONTRIBUTOR } from '../../../auth/roles';
import { getPermission } from '../../../redux/selectors';
import { usePermission } from '../../../redux/hooks/usePermission';
export const ViewMenu = ({
col,
handleUpdate,
Expand All @@ -19,7 +18,7 @@ export const ViewMenu = ({
updatable,
deletable,
}) => {
const permission = useSelector(getPermission);
const permission = usePermission();

const hasRightsBasedOnStamp =
permission?.stamp === codelist?.contributor &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { validatePartialCodelist, partialInGlobalCodes } from '../../utils';
import D, { D1, D2 } from '../../i18n/build-dictionary';
import '../codelist-detail/edit.scss';
import MainDictionary from '../../../deprecated-locales/build-dictionary';
import { useSelector } from 'react-redux';
import {
TextInput,
Row,
Expand All @@ -24,8 +23,8 @@ import {
} from '../../../components';
import { CodeListApi } from '../../../sdk';
import { useTitle } from '../../../utils/hooks/useTitle';
import { getPermission } from '../../../redux/selectors';
import { ADMIN, CODELIST_CONTRIBUTOR } from '../../../auth/roles';
import { usePermission } from '../../../redux/hooks/usePermission';

const defaultCodelist = {
created: dayjs(),
Expand Down Expand Up @@ -77,7 +76,7 @@ export const DumbCodelistPartialDetailEdit = ({
[codelist, handleParentCode, globalCodeListOptions]
);

const permission = useSelector(getPermission);
const permission = usePermission();
const stamp = permission?.stamp;
const isContributor =
permission?.roles?.includes(CODELIST_CONTRIBUTOR) &&
Expand Down
5 changes: 2 additions & 3 deletions src/packages/modules-codelists/menu/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Menu } from '@inseefr/wilco';
import D from '../i18n/build-dictionary';
import { useSelector } from 'react-redux';
import { useLocation } from 'react-router-dom';
import { getPermission } from '../../redux/selectors';
import { ADMIN } from '../../auth/roles';
import { usePermission } from '../../redux/hooks/usePermission';

const defaultAttrs = { 'aria-current': 'page' };

const MenuCodelists = () => {
const location = useLocation();
const permission = useSelector((state) => getPermission(state));
const permission = usePermission();

const activePath = location.pathname;
if (activePath === '/') return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const CollectionsToExportContainer = () => {
const [ids, setIds] = useState([]);

const { data: collections, isLoading } = useCollections();
const { mutate: exportCollection, isLoading: isExporting } =
const { mutate: exportCollection, isPending: isExporting } =
useCollectionExporter();

if (isExporting) return <Loading textType="exporting" />;
Expand Down
5 changes: 2 additions & 3 deletions src/packages/modules-concepts/collections/menu.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import D from '../../deprecated-locales/build-dictionary';
import check from '../../auth/auth';
import { Button, VerticalMenu, ExportButton } from '@inseefr/wilco';
import { useSelector } from 'react-redux';
import { FeminineButton } from '../../components';
import { getPermission } from '../../redux/selectors';
import { usePermission } from '../../redux/hooks/usePermission';

export const Menu = () => {
const { authType, roles } = useSelector((state) => getPermission(state));
const { authType, roles } = usePermission();

const authImpl = check(authType);
const adminOrCreator = authImpl.isAdminOrCollectionCreator(roles);
Expand Down
Loading

0 comments on commit 1fa11a7

Please sign in to comment.