Skip to content

Commit

Permalink
Merge pull request #1774 from dandi/rest-composition-conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandenburgh authored Dec 14, 2023
2 parents 09b80aa + 4898e6e commit 5cdb89c
Show file tree
Hide file tree
Showing 12 changed files with 275 additions and 263 deletions.
3 changes: 2 additions & 1 deletion web/src/components/AppBar/AppBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<div v-if="!insideIFrame">
<template v-if="loggedIn">
<v-btn
:disabled="!dandiRest.user?.approved"
:disabled="!user?.approved"
:to="{ name: 'createDandiset' }"
exact
class="mx-3"
Expand Down Expand Up @@ -139,6 +139,7 @@ import {
loggedIn as loggedInFunc,
insideIFrame as insideIFrameFunc,
dandiRest,
user,
} from '@/rest';
import {
dandiAboutUrl, dandiDocumentationUrl, dandiHelpUrl, dandihubUrl,
Expand Down
11 changes: 5 additions & 6 deletions web/src/components/AppBar/UserMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
>
<v-list-item>
<v-list-item-content>
<span v-if="dandiRest.user">
<span v-if="user">
You are logged in as <a
:href="`https://github.com/${dandiRest.user.username}`"
:href="`https://github.com/${user.username}`"
target="_blank"
rel="noopener"
v-text="dandiRest.user.username"
v-text="user.username"
/>.
</span>
</v-list-item-content>
</v-list-item>
<ApiKeyItem v-if="dandiRest.user?.approved" />
<ApiKeyItem v-if="user?.approved" />
<v-list-item @click="logout">
<v-list-item-content>
Logout
Expand All @@ -47,10 +47,9 @@
<script setup lang="ts">
import { computed } from 'vue';
import { user as userFunc, dandiRest } from '@/rest';
import { user, dandiRest } from '@/rest';
import ApiKeyItem from '@/components/AppBar/ApiKeyItem.vue';
const user = computed(userFunc);
const userInitials = computed(() => {
if (user.value) {
const { name } = user.value;
Expand Down
7 changes: 3 additions & 4 deletions web/src/components/DLP/DandisetOwnersDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
<script lang="ts">
import { debounce } from 'lodash';
import { dandiRest } from '@/rest';
import { dandiRest, user } from '@/rest';
import { useDandisetStore } from '@/stores/dandiset';
import type { Ref } from 'vue';
import {
Expand Down Expand Up @@ -285,7 +285,6 @@ export default defineComponent({
}
}
const user = computed(() => dandiRest.user);
function ownerIsCurrentUser(owner: User) {
return user.value && user.value.username === owner.username;
}
Expand Down Expand Up @@ -334,10 +333,10 @@ export default defineComponent({
if (currentDandiset.value?.dandiset) {
const owner = owners.value
?.map((u: User) => u.username)
.includes(dandiRest.user!.username);
.includes(user.value!.username);
// If necessary, open display and return. Otherwise, proceed to save.
if (!adminWarningDisplay.value && dandiRest.user?.admin && !owner) {
if (!adminWarningDisplay.value && user.value?.admin && !owner) {
adminWarningDisplay.value = true;
return;
}
Expand Down
20 changes: 10 additions & 10 deletions web/src/components/Meditor/localStorage.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { dandiRest } from '@/rest';
import { user } from '@/rest';
import type { DandiModel } from './types';
// eslint-disable-next-line import/no-cycle
import type { MeditorTransaction } from './transactions';

function getModelLocalStorage(identifier: string) {
const model = localStorage.getItem(`${dandiRest.user?.username}-${identifier}-model`);
const model = localStorage.getItem(`${user.value?.username}-${identifier}-model`);
return model ? JSON.parse(model) : null;
}

function setModelLocalStorage(identifier: string, model: DandiModel) {
localStorage.setItem(`${dandiRest.user?.username}-${identifier}-model`, JSON.stringify(model));
localStorage.setItem(`${user.value?.username}-${identifier}-model`, JSON.stringify(model));
}

function getTransactionsLocalStorage(identifier: string) {
const model = localStorage.getItem(`${dandiRest.user?.username}-${identifier}-transactions`);
const model = localStorage.getItem(`${user.value?.username}-${identifier}-transactions`);
return model ? JSON.parse(model) : null;
}

function setTransactionsLocalStorage(identifier: string, model: MeditorTransaction[]) {
localStorage.setItem(`${dandiRest.user?.username}-${identifier}-transactions`, JSON.stringify(model));
localStorage.setItem(`${user.value?.username}-${identifier}-transactions`, JSON.stringify(model));
}

function getTransactionPointerLocalStorage(identifier: string) {
const model = localStorage.getItem(`${dandiRest.user?.username}-${identifier}-transactionPointer`);
const model = localStorage.getItem(`${user.value?.username}-${identifier}-transactionPointer`);
return model ? JSON.parse(model) : null;
}

function setTransactionPointerLocalStorage(identifier: string, transactionPointer: number) {
localStorage.setItem(`${dandiRest.user?.username}-${identifier}-transactionPointer`, JSON.stringify(transactionPointer));
localStorage.setItem(`${user.value?.username}-${identifier}-transactionPointer`, JSON.stringify(transactionPointer));
}

function dataInLocalStorage(identifier: string) {
Expand All @@ -39,9 +39,9 @@ function dataInLocalStorage(identifier: string) {
}

function clearLocalStorage(identifier: string) {
localStorage.removeItem(`${dandiRest.user?.username}-${identifier}-model`);
localStorage.removeItem(`${dandiRest.user?.username}-${identifier}-transactions`);
localStorage.removeItem(`${dandiRest.user?.username}-${identifier}-transactionPointer`);
localStorage.removeItem(`${user.value?.username}-${identifier}-model`);
localStorage.removeItem(`${user.value?.username}-${identifier}-transactions`);
localStorage.removeItem(`${user.value?.username}-${identifier}-transactionPointer`);
}

export {
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/Search/forms/GenotypeForm.vue
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<script setup lang="ts">
import { ref, watch } from 'vue';
import { debounce } from 'lodash';
import { dandiRest } from '@/rest';
import { client } from '@/rest';
import { searchParameters } from '../store';
const searchTerm = ref<string | null>(null);
const options = ref<string[]>([]);
const loading = ref<boolean>(false);
async function populateGenotypeList(newSearchTerm: string) {
loading.value = true;
const genotypes: string[] = (await dandiRest.client.get('/search/genotypes', { params: { genotype: newSearchTerm } })).data;
const genotypes: string[] = (await client.get('/search/genotypes', { params: { genotype: newSearchTerm } })).data;
options.value = genotypes.filter((g) => g.includes(newSearchTerm));
loading.value = false;
}
Expand Down
4 changes: 2 additions & 2 deletions web/src/components/Search/forms/SpeciesForm.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import { dandiRest } from '@/rest';
import { client } from '@/rest';
import { searchParameters } from '../store';
const searchTerm = ref<string | null>(null);
const options = ref<string[]>([]);
const loading = ref<boolean>(false);
async function populateSpeciesList(newSearchTerm: string = '') {
loading.value = true;
const species: string[] = (await dandiRest.client.get('/search/species', { params: { species: newSearchTerm } })).data;
const species: string[] = (await client.get('/search/species', { params: { species: newSearchTerm } })).data;
options.value = species;
loading.value = false;
}
Expand Down
5 changes: 2 additions & 3 deletions web/src/components/UserStatusBanner.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</template>

<script lang="ts">
import { dandiRest } from '@/rest';
import { user } from '@/rest';
import type { ComputedRef } from 'vue';
import { computed, defineComponent } from 'vue';
Expand All @@ -30,8 +30,7 @@ export default defineComponent({
components: { },
setup() {
const bannerInfo: ComputedRef<StatusBanner|null> = computed(() => {
const { user } = dandiRest;
switch (user?.status) {
switch (user.value?.status) {
case 'PENDING':
return {
text: 'Your DANDI account is currently pending approval. Please allow up to 2 business days for approval and contact the DANDI admins at [email protected] if you have any questions.',
Expand Down
Loading

0 comments on commit 5cdb89c

Please sign in to comment.