-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: convert d2 to app runtime (#1294)
Remove schema fetching as with dataEngine we don't need d2 models anymore. Convert CRUD operations to use dataEngine instead of d2. The TranslationsDialog expects a d2 model representing the object on which apply translations. If the object passed has the href attribute, the dialog does not try to access the api endpoint via the modelDefinition. Simulate a model by adding the modelDefinition object and make the dialog api requests work by making sure the object has the href property. Co-authored-by: Jen Jones Arnesen <jennifer@dhis2.org>
- Loading branch information
1 parent
5bbf13c
commit 5825008
Showing
32 changed files
with
340 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/node_modules/* | ||
/i18n/* | ||
/public/* | ||
/src/locales/* | ||
/cypress/assets | ||
/cypress/fixtures |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,99 @@ | ||
import { getInstance } from 'd2' | ||
import arrayClean from 'd2-utilizr/lib/arrayClean' | ||
import { onError, getDashboardFields } from './index' | ||
|
||
// Get "all" dashboards on startup | ||
export const apiFetchDashboards = () => | ||
getInstance() | ||
.then(d2 => | ||
d2.models.dashboard.list({ | ||
fields: [ | ||
getDashboardFields().join(','), | ||
'dashboardItems[id]', | ||
].join(','), | ||
paging: 'false', | ||
export const dashboardsQuery = { | ||
resource: 'dashboards', | ||
params: { | ||
fields: [getDashboardFields(), 'dashboardItems[id]'].join(','), | ||
paging: false, | ||
}, | ||
} | ||
|
||
export const dashboardQuery = { | ||
resource: 'dashboards', | ||
id: ({ id }) => id, | ||
params: { | ||
fields: arrayClean( | ||
getDashboardFields({ | ||
withItems: true, | ||
withFavorite: { withDimensions: false }, | ||
}) | ||
) | ||
.catch(onError) | ||
).join(','), | ||
}, | ||
} | ||
|
||
export const starDashboardMutation = { | ||
type: 'create', | ||
resource: 'dashboards', | ||
// TODO create mutation does not accept the id function | ||
// we must use a workaround until dataEngine supports dynamic resource/path | ||
id: ({ id }) => `${id}/favorite`, | ||
} | ||
|
||
export const unstarDashboardMutation = { | ||
type: 'delete', | ||
resource: 'dashboards', | ||
id: ({ id }) => `${id}/favorite`, | ||
} | ||
|
||
export const deleteDashboardMutation = { | ||
type: 'delete', | ||
resource: 'dashboards', | ||
id: ({ id }) => id, | ||
} | ||
|
||
// Get "all" dashboards on startup | ||
export const apiFetchDashboards = async dataEngine => { | ||
try { | ||
const dashboardsData = await dataEngine.query({ | ||
dashboards: dashboardsQuery, | ||
}) | ||
|
||
return dashboardsData.dashboards.dashboards | ||
} catch (error) { | ||
onError(error) | ||
} | ||
} | ||
|
||
// Get more info about selected dashboard | ||
export const apiFetchDashboard = id => | ||
getInstance() | ||
.then(d2 => | ||
d2.models.dashboard.get(id, { | ||
fields: arrayClean( | ||
getDashboardFields({ | ||
withItems: true, | ||
withFavorite: { withDimensions: false }, | ||
}) | ||
).join(','), | ||
}) | ||
export const apiFetchDashboard = async (dataEngine, id) => { | ||
try { | ||
const dashboardData = await dataEngine.query( | ||
{ dashboard: dashboardQuery }, | ||
{ | ||
variables: { | ||
id, | ||
}, | ||
} | ||
) | ||
.catch(onError) | ||
|
||
// Star dashboard | ||
export const apiStarDashboard = (id, isStarred) => { | ||
const url = `dashboards/${id}/favorite` | ||
return dashboardData.dashboard | ||
} catch (error) { | ||
onError(error) | ||
} | ||
} | ||
|
||
getInstance().then(d2 => { | ||
// Star dashboard | ||
export const apiStarDashboard = async (dataEngine, id, isStarred) => { | ||
try { | ||
if (isStarred) { | ||
d2.Api.getApi().post(url) | ||
await dataEngine.mutate(starDashboardMutation, { | ||
variables: { id }, | ||
}) | ||
} else { | ||
d2.Api.getApi().delete(url) | ||
await dataEngine.mutate(unstarDashboardMutation, { | ||
variables: { id }, | ||
}) | ||
} | ||
}) | ||
} catch (error) { | ||
onError(error) | ||
} | ||
} | ||
|
||
export const apiDeleteDashboard = id => { | ||
return getInstance() | ||
.then(d2 => { | ||
return d2.models.dashboards | ||
.get(id) | ||
.then(dashboard => dashboard.delete()) | ||
}) | ||
.catch(onError) | ||
export const apiDeleteDashboard = async (dataEngine, id) => { | ||
try { | ||
await dataEngine.mutate(deleteDashboardMutation, { variables: { id } }) | ||
} catch (error) { | ||
onError(error) | ||
} | ||
} |
Oops, something went wrong.