-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StaticFiles microservice with a files tab #125
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff, just found some TS typing stuff. The UI is still to change so I didn't check on that
const body: any = await response.json() as StaticFiles; | ||
return body; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const body: any = await response.json() as StaticFiles; | |
return body; | |
return await response.json(); |
This is enough for the compiler, as the function already has a Promise<StaticFiles>
return type to it.
export async function addFile(applicationId: string, environment: string, microserviceId: string, fileName: string, file: File): Promise<boolean> { | ||
const url = `${getServerUrlPrefix()}/application/${applicationId}/environment/${environment.toLowerCase()}/staticFiles/${microserviceId}/add/${fileName}`; | ||
const response = await fetch(url, { | ||
method: 'POST', | ||
mode: 'cors', | ||
body: file, | ||
}); | ||
|
||
if (response.status !== 201) { | ||
console.error(response); | ||
throw Error('Failed to add file'); | ||
} | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export async function addFile(applicationId: string, environment: string, microserviceId: string, fileName: string, file: File): Promise<boolean> { | |
const url = `${getServerUrlPrefix()}/application/${applicationId}/environment/${environment.toLowerCase()}/staticFiles/${microserviceId}/add/${fileName}`; | |
const response = await fetch(url, { | |
method: 'POST', | |
mode: 'cors', | |
body: file, | |
}); | |
if (response.status !== 201) { | |
console.error(response); | |
throw Error('Failed to add file'); | |
} | |
return true; | |
} | |
export async function addFile(applicationId: string, environment: string, microserviceId: string, fileName: string, file: File): Promise<void> { | |
const url = `${getServerUrlPrefix()}/application/${applicationId}/environment/${environment.toLowerCase()}/staticFiles/${microserviceId}/add/${fileName}`; | |
const response = await fetch(url, { | |
method: 'POST', | |
mode: 'cors', | |
body: file, | |
}); | |
if (response.status !== 201) { | |
console.error(response); | |
throw Error('Failed to add file'); | |
} | |
} |
I checked that the return wasn't actually checked anywhere currently so we could just make return type a Promise<void>
instead then.
export async function deleteFile(applicationId: string, environment: string, microserviceId: string, fileName: string): Promise<boolean> { | ||
const url = `${getServerUrlPrefix()}/application/${applicationId}/environment/${environment.toLowerCase()}/staticFiles/${microserviceId}/remove/${fileName}`; | ||
// TODO add file | ||
const response = await fetch(url, { | ||
method: 'DELETE', | ||
mode: 'cors', | ||
}); | ||
|
||
|
||
if (response.status !== 200) { | ||
console.error(response); | ||
throw Error('Failed to delete'); | ||
} | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export async function deleteFile(applicationId: string, environment: string, microserviceId: string, fileName: string): Promise<boolean> { | |
const url = `${getServerUrlPrefix()}/application/${applicationId}/environment/${environment.toLowerCase()}/staticFiles/${microserviceId}/remove/${fileName}`; | |
// TODO add file | |
const response = await fetch(url, { | |
method: 'DELETE', | |
mode: 'cors', | |
}); | |
if (response.status !== 200) { | |
console.error(response); | |
throw Error('Failed to delete'); | |
} | |
return true; | |
} | |
export async function deleteFile(applicationId: string, environment: string, microserviceId: string, fileName: string): Promise<void> { | |
const url = `${getServerUrlPrefix()}/application/${applicationId}/environment/${environment.toLowerCase()}/staticFiles/${microserviceId}/remove/${fileName}`; | |
// TODO add file | |
const response = await fetch(url, { | |
method: 'DELETE', | |
mode: 'cors', | |
}); | |
if (response.status !== 200) { | |
console.error(response); | |
throw Error('Failed to delete'); | |
} | |
} |
Same here, I checked that the return wasn't actually checked anywhere currently so we could just make return type Promise<void>
instead then.
const data = _props.data; | ||
const cdnInfo = _props.cdnInfo; | ||
|
||
const items: ListItem[] = data.files.map<ListItem>(e => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const items: ListItem[] = data.files.map<ListItem>(e => { | |
const items = data.files.map<ListItem>(e => { |
The compilers smart enough here if you just define it in the map<ListItem>
type argument to know the resulting type for items
// TODO this should not be hardcoded | ||
// TODO Make sure we remove trailing slash | ||
const cdnInfo = { | ||
domain: 'https://freshteapot-taco.dolittle.cloud', | ||
prefix: '/doc/', | ||
path: '', | ||
} as CdnInfo; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume we need to fix this before going to production.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to move this, to the api response from the platform-api.
Then the Studio is free and the data is correct and from the right place.
Good spot.
const microserviceId = _props.microserviceId; | ||
const environment = _props.environment; | ||
|
||
const [selectedFile, setSelectedFile] = React.useState(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [selectedFile, setSelectedFile] = React.useState(null); | |
const [selectedFile, setSelectedFile] = React.useState<File>(); |
Can use this so that you don't have to later cast it to a File
let suffix = fileName.replace(cdnInfo.path, ''); | ||
suffix = suffix.startsWith('/') ? suffix.substring(1) : suffix; | ||
|
||
await addFile(applicationId, environment, microserviceId, suffix, selectedFile! as File); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await addFile(applicationId, environment, microserviceId, suffix, selectedFile! as File); | |
await addFile(applicationId, environment, microserviceId, suffix, selectedFile!); |
Can remove the as File
part if you set it in the useState<File>
from earlier.
const [reset, setReset] = React.useState(false); | ||
|
||
const [runtimeError, setRuntimeError] = React.useState(null as any); | ||
const [currentFiles, setCurrentFiles] = useState({ files: [] } as StaticFiles); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [currentFiles, setCurrentFiles] = useState({ files: [] } as StaticFiles); | |
const [currentFiles, setCurrentFiles] = useState<StaticFiles>({ files: [] }); |
Same trick here.
// TODO modify when we know how we want to handle state of purchase order data | ||
// Fake it till we are ready |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// TODO modify when we know how we want to handle state of purchase order data | |
// Fake it till we are ready |
Some old copy pasta slipping in 😂
currentMicroservice.live.images[0] && | ||
currentMicroservice.live.images[0].image && | ||
currentMicroservice.live.images[0].image === '453e04a74f9d42f2b36cd51fa2c83fa3.azurecr.io/dolittle/platform/platform-api:dev-x' | ||
currentMicroservice?.live?.images[0]?.image === '453e04a74f9d42f2b36cd51fa2c83fa3.azurecr.io/dolittle/platform/platform-api:dev-x' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to keep learning from you :)
Summary
Adding a view screen for static-files-v1 a new microservice kind, it is not yet possible to add this via Studio, but it is possible to interact with it.