Skip to content

Commit

Permalink
Merge pull request #90 from Azure/users/v-aryapparov/onboarding-v2-da…
Browse files Browse the repository at this point in the history
…shboard

onboarding v2 dashboard
  • Loading branch information
shnooshnoo authored Sep 15, 2023
2 parents 07e7d0b + d522c15 commit 6e673c9
Show file tree
Hide file tree
Showing 36 changed files with 877 additions and 983 deletions.
41 changes: 9 additions & 32 deletions src/common/api/conversion.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getEnvs } from 'common/functions';
import { useUserStore } from '../store/user.store';
import { useConversionStore } from '../store/conversion.store';
import { useReviewManifestStore } from '../store/review-manifest.store';

const apiVersion = '2.0';
const previewApiVersion = '2023-03-01-preview';
Expand All @@ -10,7 +10,8 @@ const conversionOutputOntology = 'facility-2.0';

export const uploadConversion = (file) => {
const { geography, subscriptionKey } = useUserStore.getState();
const url = `${getEnvs()[geography].URL}/mapData?dataFormat=${dataFormat}&api-version=${apiVersion}&subscription-key=${subscriptionKey}`;
const { getOriginalPackageName } = useReviewManifestStore.getState();
const url = `${getEnvs()[geography].URL}/mapData?dataFormat=${dataFormat}&api-version=${apiVersion}&subscription-key=${subscriptionKey}&description=${getOriginalPackageName()}`;
return fetch(url, {
method: 'POST',
headers: {
Expand All @@ -22,51 +23,27 @@ export const uploadConversion = (file) => {

export const startConversion = (udid) => {
const { geography, subscriptionKey } = useUserStore.getState();
const url = `${getEnvs()[geography].URL}/conversions?udid=${udid}&outputOntology=${conversionOutputOntology}&api-version=${previewApiVersion}&subscription-key=${subscriptionKey}&dwgPackageVersion=${conversionDwgPackageVersion}`;
const { getOriginalPackageName } = useReviewManifestStore.getState();
const url = `${getEnvs()[geography].URL}/conversions?udid=${udid}&outputOntology=${conversionOutputOntology}&api-version=${previewApiVersion}&subscription-key=${subscriptionKey}&dwgPackageVersion=${conversionDwgPackageVersion}&description=${getOriginalPackageName()}`;
return fetch(url, {
method: 'POST',
});
};

export const startDataset = (conversionId) => {
const { geography, subscriptionKey } = useUserStore.getState();
const url = `${getEnvs()[geography].URL}/datasets?api-version=${apiVersion}&conversionId=${conversionId}&subscription-key=${subscriptionKey}`;
const { getOriginalPackageName } = useReviewManifestStore.getState();
const url = `${getEnvs()[geography].URL}/datasets?api-version=${apiVersion}&conversionId=${conversionId}&subscription-key=${subscriptionKey}&description=${getOriginalPackageName()}`;
return fetch(url, {
method: 'POST',
});
};

export const startTileset = (datasetId) => {
const { geography, subscriptionKey } = useUserStore.getState();
const url = `${getEnvs()[geography].URL}/tilesets?api-version=${previewApiVersion}&datasetId=${datasetId}&subscription-key=${subscriptionKey}`;
const { getOriginalPackageName } = useReviewManifestStore.getState();
const url = `${getEnvs()[geography].URL}/tilesets?api-version=${previewApiVersion}&datasetId=${datasetId}&subscription-key=${subscriptionKey}&description=${getOriginalPackageName()}`;
return fetch(url, {
method: 'POST',
});
};

export const deleteCreatedData = () => {
const { geography, subscriptionKey } = useUserStore.getState();
const { uploadUdId, conversionId, datasetId, tilesetId } = useConversionStore.getState();

if (tilesetId !== null) {
return;
}
if (uploadUdId !== null) {
fetch(`${getEnvs()[geography].URL}/mapData/${uploadUdId}?api-version=2.0&subscription-key=${subscriptionKey}`, {
method: 'DELETE',
keepalive: true,
});
}
if (conversionId !== null) {
fetch(`${getEnvs()[geography].URL}/conversions/${conversionId}?api-version=2.0&subscription-key=${subscriptionKey}`, {
method: 'DELETE',
keepalive: true,
});
}
if (datasetId !== null) {
fetch(`${getEnvs()[geography].URL}/datasets/${datasetId}?api-version=2.0&subscription-key=${subscriptionKey}`, {
method: 'DELETE',
keepalive: true,
});
}
};
70 changes: 5 additions & 65 deletions src/common/api/conversion.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { uploadConversion, startConversion, startDataset, startTileset, deleteCreatedData } from './conversion';
import { useConversionStore } from '../store';
import { uploadConversion, startConversion, startDataset, startTileset } from './conversion';

jest.mock('../store/user.store', () => ({
useUserStore: {
Expand All @@ -14,91 +13,32 @@ describe('conversion api', () => {
it('should call uploadConversion request', () => {
uploadConversion('myFile');
expect(global.fetch).toHaveBeenCalledWith(
'https://eu.atlas.microsoft.com/mapData?dataFormat=dwgzippackage&api-version=2.0&subscription-key=subKeeeeeeey',
'https://eu.atlas.microsoft.com/mapData?dataFormat=dwgzippackage&api-version=2.0&subscription-key=subKeeeeeeey&description=',
{ 'body': 'myFile', 'headers': { 'Content-Type': 'application/octet-stream' }, 'method': 'POST' },
);
});

it('should call startConversion request', () => {
startConversion('yuuu-deee-iii-deeee');
expect(global.fetch).toHaveBeenCalledWith(
'https://eu.atlas.microsoft.com/conversions?udid=yuuu-deee-iii-deeee&outputOntology=facility-2.0&api-version=2023-03-01-preview&subscription-key=subKeeeeeeey&dwgPackageVersion=2.0',
'https://eu.atlas.microsoft.com/conversions?udid=yuuu-deee-iii-deeee&outputOntology=facility-2.0&api-version=2023-03-01-preview&subscription-key=subKeeeeeeey&dwgPackageVersion=2.0&description=',
{ 'method': 'POST' },
);
});

it('should call startDataset request', () => {
startDataset('con-ver-sion-id');
expect(global.fetch).toHaveBeenCalledWith(
'https://eu.atlas.microsoft.com/datasets?api-version=2.0&conversionId=con-ver-sion-id&subscription-key=subKeeeeeeey',
'https://eu.atlas.microsoft.com/datasets?api-version=2.0&conversionId=con-ver-sion-id&subscription-key=subKeeeeeeey&description=',
{ 'method': 'POST' },
);
});

it('should call startTileset request', () => {
startTileset('da-ta-set-id');
expect(global.fetch).toHaveBeenCalledWith(
'https://eu.atlas.microsoft.com/tilesets?api-version=2023-03-01-preview&datasetId=da-ta-set-id&subscription-key=subKeeeeeeey',
'https://eu.atlas.microsoft.com/tilesets?api-version=2023-03-01-preview&datasetId=da-ta-set-id&subscription-key=subKeeeeeeey&description=',
{ 'method': 'POST' },
);
});

it('should delete uploaded data', () => {
useConversionStore.setState({
uploadUdId: 123,
});
deleteCreatedData();
expect(global.fetch).toHaveBeenCalledWith(
'https://eu.atlas.microsoft.com/mapData/123?api-version=2.0&subscription-key=subKeeeeeeey',
{ 'method': 'DELETE', 'keepalive': true },
);
});

it('should delete uploaded data and conversion', () => {
useConversionStore.setState({
uploadUdId: 123,
conversionId: 234,
});
deleteCreatedData();
expect(global.fetch).toHaveBeenCalledWith(
'https://eu.atlas.microsoft.com/mapData/123?api-version=2.0&subscription-key=subKeeeeeeey',
{ 'method': 'DELETE', 'keepalive': true },
);
expect(global.fetch).toHaveBeenCalledWith(
'https://eu.atlas.microsoft.com/conversions/234?api-version=2.0&subscription-key=subKeeeeeeey',
{ 'method': 'DELETE', 'keepalive': true },
);
});

it('should delete uploaded data and conversion and dataset', () => {
useConversionStore.setState({
uploadUdId: 123,
conversionId: 234,
datasetId: 345,
});
deleteCreatedData();
expect(global.fetch).toHaveBeenCalledWith(
'https://eu.atlas.microsoft.com/mapData/123?api-version=2.0&subscription-key=subKeeeeeeey',
{ 'method': 'DELETE', 'keepalive': true },
);
expect(global.fetch).toHaveBeenCalledWith(
'https://eu.atlas.microsoft.com/conversions/234?api-version=2.0&subscription-key=subKeeeeeeey',
{ 'method': 'DELETE', 'keepalive': true },
);
expect(global.fetch).toHaveBeenCalledWith(
'https://eu.atlas.microsoft.com/datasets/345?api-version=2.0&subscription-key=subKeeeeeeey',
{ 'method': 'DELETE', 'keepalive': true },
);
});

it('should delete nothing when tileset id is not null', () => {
useConversionStore.setState({
uploadUdId: 123,
conversionId: 234,
datasetId: 345,
tilesetId: 456,
});
deleteCreatedData();
expect(global.fetch).not.toHaveBeenCalled();
});
});
42 changes: 42 additions & 0 deletions src/common/api/conversions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { getEnvs } from 'common/functions';
import { useUserStore } from '../store/user.store';

const uploadApiVersion = '2.0';
const creatorApiVersion = '2023-03-01-preview';

const getUploads = () => {
const { geography, subscriptionKey } = useUserStore.getState();
const url = `${getEnvs()[geography].URL}/mapData?api-version=${uploadApiVersion}&subscription-key=${subscriptionKey}`;
return fetch(url);
};

const getConversions = () => {
const { geography, subscriptionKey } = useUserStore.getState();
const url = `${getEnvs()[geography].URL}/conversions?api-version=${creatorApiVersion}&subscription-key=${subscriptionKey}`;
return fetch(url);
};

const getDatasets = () => {
const { geography, subscriptionKey } = useUserStore.getState();
const url = `${getEnvs()[geography].URL}/datasets?api-version=${creatorApiVersion}&subscription-key=${subscriptionKey}`;
return fetch(url);
};

const getTilesets = () => {
const { geography, subscriptionKey } = useUserStore.getState();
const url = `${getEnvs()[geography].URL}/tilesets?api-version=${creatorApiVersion}&subscription-key=${subscriptionKey}`;
return fetch(url);
};

export const getAllData = () => (
Promise.all([getUploads(), getConversions(), getDatasets(), getTilesets()]).then(re => (
Promise.all([re[0].json(), re[1].json(), re[2].json(), re[3].json()])
)).then(([uploads, conversions, datasets, tilesets]) => (
{
...uploads,
...conversions,
...datasets,
...tilesets,
}
))
);
3 changes: 3 additions & 0 deletions src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ export const PATHS = {
CREATE_GEOREFERENCE: '/create-georeference',
REVIEW_CREATE: '/review-create',
CONVERSION: '/review-create/conversion',
PAST_CONVERSION: '/past-conversion',
CONVERSIONS: '/conversions',
LAYERS: '/layers',
LEVELS: '/levels',
INVALID_PATH: '/*',
Expand All @@ -18,6 +20,7 @@ export const ROUTE_NAME_BY_PATH = {
[PATHS.INVALID_PATH]: 'redirect',
[PATHS.REVIEW_CREATE]: 'prepare.drawing.package',
[PATHS.CONVERSION]: 'create.indoor.map',
[PATHS.CONVERSIONS]: 'All conversions',
};

export const TRUNCATE_FRACTION_DIGITS = 8;
Expand Down
21 changes: 21 additions & 0 deletions src/common/store/conversion-past.store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { create } from 'zustand';

import { conversionStatuses, conversionSteps} from './conversion.store';

export const useConversionPastStore = create((set) => ({
selectedStep: conversionSteps.upload,
uploadStepStatus: conversionStatuses.empty,
uploadUdId: null,
conversionStepStatus: conversionStatuses.empty,
conversionId: null,
datasetStepStatus: conversionStatuses.empty,
datasetId: null,
tilesetStepStatus: conversionStatuses.empty,
tilesetId: null,
mapConfigurationId: null,
bbox: null,
setStep: (selectedStep) => set({
selectedStep,
}),
setData: (data) => set(data),
}));
Loading

0 comments on commit 6e673c9

Please sign in to comment.